]>
git.defcon.no Git - hermes/blob - api/t/alias.t
94ce09dc9971e11b4b9a2507d6c8a586db57030d
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:
17 my ($data, $temp, $test_number_start, $test_alias, $test_e164alias, $test_domain, $test_remote_domain);
19 our $test_alias = "testalias-" . int(rand(255));
21 $test_e164alias .= int(rand(255))
22 while ( length( $test_e164alias ) < 8 );
24 $test_e164alias = '+47' . substr( $test_e164alias, 0, 8 );
26 isa_ok
( $g_ua, 'LWP::UserAgent', '$g_ua');
27 isa_ok
( $g_ua->cookie_jar, 'HTTP::Cookies', '$g_ua->cookies');
31 # First: fetch a supported domain from the API...
32 $data = exec_apinode
("domain/list", undef);
33 ok
($data, 'domain/list JSON decode');
34 is
( $data->{'response'}, 'ok', 'domain/list result');
35 ok
($data->{'list'}, 'domain/list array');
37 # NOW: Set the $test_domain to something useful (i.e. the first reported domain)
38 $test_domain = $data->{'list'}[0];
39 $test_remote_domain = "external." . $test_domain;
41 ok
($test_domain, 'test_domain set.');
42 ok
($test_remote_domain, 'test_remote_domain set.');
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');
56 $data = exec_apinode
("alias/list", undef);
57 is
( $data->{'response'}, 'ok', 'alias/list result');
58 ok
($data->{'aliases'}, 'alias/list array');
61 $data = exec_apinode
("alias/add", {
62 'alias' => $test_alias . "\@" . $test_domain,
63 'destination' => $test_username . "\@" . $test_domain,
65 is
( $data->{'response'}, 'ok', 'alias/add result');
66 ok
( $data->{'destination'}, 'alias/add destination');
67 ok
( $data->{'alias'}, 'alias/add alias');
70 $data = exec_apinode
("alias/add", {
71 'alias' => $test_alias . "\@" . $test_domain,
72 'destination' => $test_username . "\@" . $test_domain,
74 is
( $data->{'response'}, 'failed', 'alias/add for existing alias result');
79 $data = exec_apinode
("alias/add", {
80 'alias' => $test_e164alias . "\@" . $test_domain,
81 'destination' => $test_username . "\@" . $test_domain,
83 is
( $data->{'response'}, 'ok', 'alias/add e164 result');
84 ok
( $data->{'destination'}, 'alias/add destination');
85 ok
( $data->{'alias'}, 'alias/add alias');
88 $data = exec_apinode
("alias/list", { 'destination' => $test_username . "\@" . $test_domain });
89 is
( $data->{'response'}, 'ok', 'alias/list w/destination result');
90 ok
($data->{'aliases'}, 'alias/list w/destination array');
93 $data = exec_apinode
("alias/list", { 'destination' => $test_username . "\@" . $test_domain });
94 is
( $data->{'response'}, 'ok', 'alias/list w/e164 result');
95 ok
($data->{'aliases'}, 'alias/list w/e164 array');
96 ok
($data->{'aliases'}[0]->{'destination'}, 'alias/list w/e164 destination');
99 $data = exec_apinode
("alias/remove", {
100 'alias' => $test_alias . "\@" . $test_domain,
102 is
( $data->{'response'}, 'ok', 'alias/remove result');
103 ok
( $data->{'alias'}, 'alias/remove alias');
106 $data = exec_apinode
("alias/remove", {
107 'alias' => $test_e164alias . "\@" . $test_domain,
109 is
( $data->{'response'}, 'ok', 'alias/remove e164 result');
110 ok
( $data->{'alias'}, 'alias/remove alias');
113 $data = exec_apinode
("user/remove", { "user" => $test_username . "\@" . $test_domain });
114 is
( $data->{'response'}, 'ok', 'user/remove deleted user');
117 $data = exec_apinode
("alias/add", {
118 'alias' => $test_username . "\@" . $test_domain,
119 'destination' => $test_alias . "\@" . $test_domain,
121 is
( $data->{'response'}, 'failed', 'alias/add for existing user result');