]>
git.defcon.no Git - hermes/blob - api/t/alias.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:
41 my ($data, $temp, $test_number_start, $test_alias, $test_e164alias, $test_domain, $test_remote_domain);
43 our $test_alias = "testalias-" . int(rand(255));
45 $test_e164alias .= int(rand(255))
46 while ( length( $test_e164alias ) < 8 );
48 $test_e164alias = '+47' . substr( $test_e164alias, 0, 8 );
50 isa_ok
( $g_ua, 'LWP::UserAgent', '$g_ua');
51 isa_ok
( $g_ua->cookie_jar, 'HTTP::Cookies', '$g_ua->cookies');
55 # First: fetch a supported domain from the API...
56 $data = exec_apinode
("domain/list", undef);
57 ok
($data, 'domain/list JSON decode');
58 is
( $data->{'response'}, 'ok', 'domain/list result');
59 ok
($data->{'list'}, 'domain/list array');
61 # NOW: Set the $test_domain to something useful (i.e. the first reported domain)
62 $test_domain = $data->{'list'}[0];
63 $test_remote_domain = "external." . $test_domain;
65 ok
($test_domain, 'test_domain set.');
66 ok
($test_remote_domain, 'test_remote_domain set.');
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');
80 $data = exec_apinode
("alias/list", undef);
81 is
( $data->{'response'}, 'ok', 'alias/list result');
82 ok
($data->{'aliases'}, 'alias/list array');
85 $data = exec_apinode
("alias/add", {
86 'alias' => $test_alias . "\@" . $test_domain,
87 'destination' => $test_username . "\@" . $test_domain,
89 is
( $data->{'response'}, 'ok', 'alias/add result');
90 ok
( $data->{'destination'}, 'alias/add destination');
91 ok
( $data->{'alias'}, 'alias/add alias');
94 $data = exec_apinode
("alias/add", {
95 'alias' => $test_alias . "\@" . $test_domain,
96 'destination' => $test_username . "\@" . $test_domain,
98 is
( $data->{'response'}, 'failed', 'alias/add for existing alias result');
103 $data = exec_apinode
("alias/add", {
104 'alias' => $test_e164alias . "\@" . $test_domain,
105 'destination' => $test_username . "\@" . $test_domain,
107 is
( $data->{'response'}, 'ok', 'alias/add e164 result');
108 ok
( $data->{'destination'}, 'alias/add destination');
109 ok
( $data->{'alias'}, 'alias/add alias');
112 $data = exec_apinode
("alias/list", { 'destination' => $test_username . "\@" . $test_domain });
113 is
( $data->{'response'}, 'ok', 'alias/list w/destination result');
114 ok
($data->{'aliases'}, 'alias/list w/destination array');
117 $data = exec_apinode
("alias/list", { 'destination' => $test_username . "\@" . $test_domain });
118 is
( $data->{'response'}, 'ok', 'alias/list w/e164 result');
119 ok
($data->{'aliases'}, 'alias/list w/e164 array');
120 ok
($data->{'aliases'}[0]->{'destination'}, 'alias/list w/e164 destination');
123 $data = exec_apinode
("alias/remove", {
124 'alias' => $test_alias . "\@" . $test_domain,
126 is
( $data->{'response'}, 'ok', 'alias/remove result');
127 ok
( $data->{'alias'}, 'alias/remove alias');
130 $data = exec_apinode
("alias/remove", {
131 'alias' => $test_e164alias . "\@" . $test_domain,
133 is
( $data->{'response'}, 'ok', 'alias/remove e164 result');
134 ok
( $data->{'alias'}, 'alias/remove alias');
137 $data = exec_apinode
("user/remove", { "user" => $test_username . "\@" . $test_domain });
138 is
( $data->{'response'}, 'ok', 'user/remove deleted user');
141 $data = exec_apinode
("alias/add", {
142 'alias' => $test_username . "\@" . $test_domain,
143 'destination' => $test_alias . "\@" . $test_domain,
145 is
( $data->{'response'}, 'failed', 'alias/add for existing user result');