]>
git.defcon.no Git - hermes/blob - api/t/user.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 # Configuration variables defined in tests_common
32 # Make sure those are updated/set correctly..
36 # Further variables defined in tests_common:
42 my ($data, $temp, $test_domain, $test_remote_domain );
44 isa_ok
( $g_ua, 'LWP::UserAgent', '$g_ua');
45 isa_ok
( $g_ua->cookie_jar, 'HTTP::Cookies', '$g_ua->cookies');
49 # First: fetch a supported domain from the API...
50 $data = exec_apinode
("domain/list", undef);
51 ok
($data, 'domain/list JSON decode');
52 is
( $data->{'response'}, 'ok', 'domain/list result');
53 ok
($data->{'list'}, 'domain/list array');
55 # NOW: Set the $test_domain to something useful (i.e. the first reported domain)
56 $test_domain = $data->{'list'}[0];
57 $test_remote_domain = "external." . $test_domain;
59 ok
($test_domain, 'test_domain set.');
60 ok
($test_remote_domain, 'test_remote_domain set.');
63 $data = exec_apinode
("user/list", undef);
64 ok
($data, 'user/list JSON decode');
65 is
($data->{'response'}, 'ok', 'user/list result');
66 ok
($data->{'list'}, 'user/list array');
69 $data = exec_apinode
("user/available", { "user" => $test_username . "\@" . $test_domain });
70 is
( $data->{'response'}, 'ok', 'user/available is available');
73 $data = exec_apinode
("user/add_local", {
74 "user" => $test_username . "\@" . $test_domain,
75 "displayname" => "Automatic testing",
76 "email" => "noreply\@" . $test_domain,
78 is
( $data->{'response'}, 'ok', 'user/add_local created new account');
79 #TODO: Add tests to verify the data from add_local...
82 $data = exec_apinode
("user/available", { "user" => $test_username . "\@" . $test_domain });
83 is
( $data->{'response'}, 'failed', 'user/available has been created');
86 $data = exec_apinode
("user/get", { "user" => $test_username . "\@" . $test_domain });
87 is
( $data->{'response'}, 'ok', 'user/get returns');
88 is
( $data->{'user'}->{'username'}, $test_username, 'user/get username correct');
89 is
( $data->{'user'}->{'domain'}, $test_domain, 'user/get domain correct');
90 ok
( $data->{'user'}->{'ha1'} =~ m/[a-z0-9]{16,}/, 'user/get ha1 hash generated');
93 $data = exec_apinode
("user/gen_pw", undef);
94 ok
( $data =~ m/[a-zA-Z0-9]{24}/, 'user/gen_pw format OK');
98 $data = exec_apinode
("user/change_pw", {
99 "user" => $test_username . "\@" . $test_domain,
102 is
( $data->{'response'}, 'ok', 'user/change_pw');
105 # TODO: This tests _almost_ all parameters. Update API docs, then update this test.
106 $data = exec_apinode
("user/update", {
107 "user" => $test_username . "\@" . $test_domain,
108 "displayname" => "Changed",
109 "linetext" => $test_username,
110 "registrar" => "registrar." . $test_domain,
112 "proxy" => "proxy." . $test_domain,
115 is
( $data->{'response'}, 'ok', 'user/update');
116 ok
( $data->{'updated'}, 'user/update updated list');
117 ok
( $data->{'skipped'}, 'user/update skipped list');
120 $data = exec_apinode
("user/remove", { "user" => $test_username . "\@" . $test_domain });
121 is
( $data->{'response'}, 'ok', 'user/remove deleted user');
124 $data = exec_apinode
("user/add_remote", {
125 "user" => $test_username . "\@" . $test_domain,
126 "displayname" => "Automatic testing",
127 "password" => "verysecretpasswd",
128 "registrar" => "registrar" . $test_domain,
130 is
( $data->{'response'}, 'failed', 'user/add_remote fails for local domain');
131 #TODO: Add tests to verify the data from add_local...
134 $data = exec_apinode
("user/add_remote", {
135 "user" => $test_username . "\@" . $test_remote_domain,
136 "displayname" => "Automatic testing",
137 "password" => "verysecretpasswd",
138 "registrar" => "registrar" . $test_domain,
141 is
( $data->{'response'}, 'ok', 'user/add_remote ok for remote domain');
142 #TODO: Add tests to verify the data from add_remote...
145 $data = exec_apinode
("user/available", { "user" => $test_username . "\@" . $test_remote_domain });
146 is
( $data->{'response'}, 'failed', 'user/available has been created');
150 $data = exec_apinode
("user/remove", { "user" => $test_username . "\@" . $test_remote_domain });
151 is
( $data->{'response'}, 'ok', 'user/remove deleted user');