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