]> git.defcon.no Git - hermes/blob - api/t/alias.t
94ce09dc9971e11b4b9a2507d6c8a586db57030d
[hermes] / api / t / alias.t
1 #!/usr/bin/perl
2
3 use strict;
4 use Test::More 'no_plan';
5 use tests_common;
6
7 # Configuration variables defined in tests_common
8 # Make sure those are updated/set correctly..
9 # $api_base
10 # $api_key
11 #
12 # Further variables defined in tests_common:
13 # $invalid_key
14 # $test_username
15 # $test_password
16 # $invalid_username
17 my ($data, $temp, $test_number_start, $test_alias, $test_e164alias, $test_domain, $test_remote_domain);
18
19 our $test_alias = "testalias-" . int(rand(255));
20
21 $test_e164alias .= int(rand(255))
22 while ( length( $test_e164alias ) < 8 );
23
24 $test_e164alias = '+47' . substr( $test_e164alias, 0, 8 );
25
26 isa_ok( $g_ua, 'LWP::UserAgent', '$g_ua');
27 isa_ok( $g_ua->cookie_jar, 'HTTP::Cookies', '$g_ua->cookies');
28
29 login_apikey();
30
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');
36
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;
40
41 ok($test_domain, 'test_domain set.');
42 ok($test_remote_domain, 'test_remote_domain set.');
43 undef $data;
44
45 $data = exec_apinode("user/available", { "user" => $test_username . "\@" . $test_domain });
46 is( $data->{'response'}, 'ok', 'user/available is available');
47 undef $data;
48
49 $data = exec_apinode("user/add_local", {
50 "user" => $test_username . "\@" . $test_domain,
51 "displayname" => "Automatic testing",
52 "email" => "noreply\@" . $test_domain,
53 } );
54 is( $data->{'response'}, 'ok', 'user/add_local created new account');
55
56 $data = exec_apinode("alias/list", undef);
57 is( $data->{'response'}, 'ok', 'alias/list result');
58 ok($data->{'aliases'}, 'alias/list array');
59 undef $data;
60
61 $data = exec_apinode("alias/add", {
62 'alias' => $test_alias . "\@" . $test_domain,
63 'destination' => $test_username . "\@" . $test_domain,
64 });
65 is( $data->{'response'}, 'ok', 'alias/add result');
66 ok( $data->{'destination'}, 'alias/add destination');
67 ok( $data->{'alias'}, 'alias/add alias');
68 undef $data;
69
70 $data = exec_apinode("alias/add", {
71 'alias' => $test_alias . "\@" . $test_domain,
72 'destination' => $test_username . "\@" . $test_domain,
73 });
74 is( $data->{'response'}, 'failed', 'alias/add for existing alias result');
75 undef $data;
76
77
78
79 $data = exec_apinode("alias/add", {
80 'alias' => $test_e164alias . "\@" . $test_domain,
81 'destination' => $test_username . "\@" . $test_domain,
82 });
83 is( $data->{'response'}, 'ok', 'alias/add e164 result');
84 ok( $data->{'destination'}, 'alias/add destination');
85 ok( $data->{'alias'}, 'alias/add alias');
86 undef $data;
87
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');
91 undef $data;
92
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');
97 undef $data;
98
99 $data = exec_apinode("alias/remove", {
100 'alias' => $test_alias . "\@" . $test_domain,
101 });
102 is( $data->{'response'}, 'ok', 'alias/remove result');
103 ok( $data->{'alias'}, 'alias/remove alias');
104 undef $data;
105
106 $data = exec_apinode("alias/remove", {
107 'alias' => $test_e164alias . "\@" . $test_domain,
108 });
109 is( $data->{'response'}, 'ok', 'alias/remove e164 result');
110 ok( $data->{'alias'}, 'alias/remove alias');
111 undef $data;
112
113 $data = exec_apinode("user/remove", { "user" => $test_username . "\@" . $test_domain });
114 is( $data->{'response'}, 'ok', 'user/remove deleted user');
115 undef $data;
116
117 $data = exec_apinode("alias/add", {
118 'alias' => $test_username . "\@" . $test_domain,
119 'destination' => $test_alias . "\@" . $test_domain,
120 });
121 is( $data->{'response'}, 'failed', 'alias/add for existing user result');
122 undef $data;
123
124
125 logout();