]>
git.defcon.no Git - hermes/blob - api/t/permissions.t
2 # Copyright (c) 2012, Gjøvik University College
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are met:
7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above copyright
10 # notice, this list of conditions and the following disclaimer in the
11 # documentation and/or other materials provided with the distribution.
12 # * Neither the name of the Gjøvik University College nor the
13 # names of its contributors may be used to endorse or promote products
14 # derived from this software without specific prior written permission.
16 # THIS SOFTWARE IS PROVIDED BY Gjøvik University College ''AS IS'' AND ANY
17 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 # DISCLAIMED. IN NO EVENT SHALL Gjøvik University College BE LIABLE FOR ANY
20 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 use Test
::More
'no_plan';
31 my ($data, $temp, $test_domain );
33 isa_ok
( $g_ua, 'LWP::UserAgent', '$g_ua');
34 isa_ok
( $g_ua->cookie_jar, 'HTTP::Cookies', '$g_ua->cookies');
38 # First: fetch a supported domain from the API...
39 $data = exec_apinode
("domain/list", undef);
40 ok
($data, 'domain/list JSON decode');
41 is
( $data->{'response'}, 'ok', 'domain/list result');
42 ok
($data->{'list'}, 'domain/list array');
44 # NOW: Set the $test_domain to something useful (i.e. the first reported domain)
45 $test_domain = $data->{'list'}[0];
47 ok
($test_domain, 'test_domain set.');
50 $data = exec_apinode
("user/available", { "user" => $test_username . "\@" . $test_domain });
51 is
( $data->{'response'}, 'ok', 'user/available is available');
54 $data = exec_apinode
("permissions/get", { "user" => $test_username . "\@" . $test_domain });
55 is
( $data->{'response'}, 'failed', 'permissions/get returns failed');
56 is
( $data->{'cause'}, 'nonexistant', 'permissions/get gives nonexistant');
59 $data = exec_apinode
("user/add_local", {
60 "user" => $test_username . "\@" . $test_domain,
61 "displayname" => "Automatic testing",
62 "email" => "noreply\@" . $test_domain,
64 is
( $data->{'response'}, 'ok', 'user/add_local created new account');
67 $data = exec_apinode
("permissions/get", { "user" => $test_username . "\@" . $test_domain });
68 is
( $data->{'response'}, 'ok', 'permissions/get returns');
69 ok
( $data->{'permission'}, 'permissions/get is set');
70 isnt
( $data->{'permission'}, -1, 'permissions/get is not -1');
73 $data = exec_apinode
("permissions/set", { "user" => $test_username . "\@" . $test_domain, "permission" => 31 });
74 is
( $data->{'response'}, 'ok', 'permissions/set returns');
75 is
( $data->{'permission'}, 31, 'permissions/set is 31');
78 $data = exec_apinode
("permissions/get", { "user" => $test_username . "\@" . $test_domain });
79 is
( $data->{'response'}, 'ok', 'permissions/get returns');
80 ok
( $data->{'permission'}, 'permissions/get is set');
81 is
( $data->{'permission'}, 31, 'permissions/get is 31');
84 $data = exec_apinode
("user/remove", { "user" => $test_username . "\@" . $test_domain });
85 is
( $data->{'response'}, 'ok', 'user/remove deleted user');
88 $data = exec_apinode
("permissions/get", { "user" => $test_username . "\@" . $test_domain });
89 is
( $data->{'response'}, 'failed', 'permissions/get return failed');