]>
git.defcon.no Git - hermes/blob - api/t/user.t
fca67eb8acf96c5596cbbbeffe277ee91c41c811
4 use Test
::More
'no_plan';
7 # Configuration variables defined in tests_common
8 # Make sure those are updated/set correctly..
12 # Further variables defined in tests_common:
18 my ($data, $temp, $test_domain, $test_remote_domain );
20 isa_ok
( $g_ua, 'LWP::UserAgent', '$g_ua');
21 isa_ok
( $g_ua->cookie_jar, 'HTTP::Cookies', '$g_ua->cookies');
25 # First: fetch a supported domain from the API...
26 $data = exec_apinode
("domain/list", undef);
27 ok
($data, 'domain/list JSON decode');
28 is
( $data->{'response'}, 'ok', 'domain/list result');
29 ok
($data->{'list'}, 'domain/list array');
31 # NOW: Set the $test_domain to something useful (i.e. the first reported domain)
32 $test_domain = $data->{'list'}[0];
33 $test_remote_domain = "external." . $test_domain;
35 ok
($test_domain, 'test_domain set.');
36 ok
($test_remote_domain, 'test_remote_domain set.');
39 $data = exec_apinode
("user/list", undef);
40 ok
($data, 'user/list JSON decode');
41 is
($data->{'response'}, 'ok', 'user/list result');
42 ok
($data->{'list'}, 'user/list array');
45 $data = exec_apinode
("user/available", { "user" => $test_username . "\@" . $test_domain });
46 is
( $data->{'response'}, 'ok', 'user/available is available');
49 $data = exec_apinode
("user/add_local", {
50 "user" => $test_username . "\@" . $test_domain,
51 "displayname" => "Automatic testing",
52 "email" => "noreply\@" . $test_domain,
54 is
( $data->{'response'}, 'ok', 'user/add_local created new account');
55 #TODO: Add tests to verify the data from add_local...
58 $data = exec_apinode
("user/available", { "user" => $test_username . "\@" . $test_domain });
59 is
( $data->{'response'}, 'failed', 'user/available has been created');
62 $data = exec_apinode
("user/get", { "user" => $test_username . "\@" . $test_domain });
63 is
( $data->{'response'}, 'ok', 'user/get returns');
64 is
( $data->{'user'}->{'username'}, $test_username, 'user/get username correct');
65 is
( $data->{'user'}->{'domain'}, $test_domain, 'user/get domain correct');
66 ok
( $data->{'user'}->{'ha1'} =~ m/[a-z0-9]{16,}/, 'user/get ha1 hash generated');
69 $data = exec_apinode
("user/gen_pw", undef);
70 ok
( $data =~ m/[a-zA-Z0-9]{24}/, 'user/gen_pw format OK');
74 $data = exec_apinode
("user/change_pw", {
75 "user" => $test_username . "\@" . $test_domain,
78 is
( $data->{'response'}, 'ok', 'user/change_pw');
81 # TODO: This tests _almost_ all parameters. Update API docs, then update this test.
82 $data = exec_apinode
("user/update", {
83 "user" => $test_username . "\@" . $test_domain,
84 "displayname" => "Changed",
85 "linetext" => $test_username,
86 "registrar" => "registrar." . $test_domain,
88 "proxy" => "proxy." . $test_domain,
91 is
( $data->{'response'}, 'ok', 'user/update');
92 ok
( $data->{'updated'}, 'user/update updated list');
93 ok
( $data->{'skipped'}, 'user/update skipped list');
96 $data = exec_apinode
("user/remove", { "user" => $test_username . "\@" . $test_domain });
97 is
( $data->{'response'}, 'ok', 'user/remove deleted user');
100 $data = exec_apinode
("user/add_remote", {
101 "user" => $test_username . "\@" . $test_domain,
102 "displayname" => "Automatic testing",
103 "password" => "verysecretpasswd",
104 "registrar" => "registrar" . $test_domain,
106 is
( $data->{'response'}, 'failed', 'user/add_remote fails for local domain');
107 #TODO: Add tests to verify the data from add_local...
110 $data = exec_apinode
("user/add_remote", {
111 "user" => $test_username . "\@" . $test_remote_domain,
112 "displayname" => "Automatic testing",
113 "password" => "verysecretpasswd",
114 "registrar" => "registrar" . $test_domain,
117 is
( $data->{'response'}, 'ok', 'user/add_remote ok for remote domain');
118 #TODO: Add tests to verify the data from add_remote...
121 $data = exec_apinode
("user/available", { "user" => $test_username . "\@" . $test_remote_domain });
122 is
( $data->{'response'}, 'failed', 'user/available has been created');
126 $data = exec_apinode
("user/remove", { "user" => $test_username . "\@" . $test_remote_domain });
127 is
( $data->{'response'}, 'ok', 'user/remove deleted user');