]> git.defcon.no Git - hermes/blob - api/t/phone.t
Added license text
[hermes] / api / t / phone.t
1 #!/usr/bin/perl
2 # Copyright (c) 2012, Gjøvik University College
3 # All rights reserved.
4
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.
15 #
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.
26
27 use strict;
28 use Test::More 'no_plan';
29 use tests_common;
30
31 # Configuration variables defined in tests_common
32 # Make sure those are updated/set correctly..
33 # $api_base
34 # $api_key
35 #
36 # Further variables defined in tests_common:
37 # $invalid_key
38 # $test_username
39 # $test_password
40 # $invalid_username
41
42 my ($data, $temp, $test_domain);
43
44 my $test_macaddress = '12341d6db76c';
45
46 isa_ok( $g_ua, 'LWP::UserAgent', '$g_ua');
47 isa_ok( $g_ua->cookie_jar, 'HTTP::Cookies', '$g_ua->cookies');
48
49 login_apikey();
50
51 # First: fetch a supported domain from the API...
52 $data = exec_apinode("domain/list", undef);
53 ok($data, 'domain/list JSON decode');
54 is( $data->{'response'}, 'ok', 'domain/list result');
55 ok($data->{'list'}, 'domain/list array');
56
57 # NOW: Set the $test_domain to something useful (i.e. the first reported domain)
58 $test_domain = $data->{'list'}[0];
59
60 ok($test_domain, 'test_domain set.');
61 undef $data;
62
63 $data = exec_apinode("user/available", { "user" => $test_username . "\@" . $test_domain });
64 is( $data->{'response'}, 'ok', 'user/available is available');
65 undef $data;
66
67 $data = exec_apinode("user/add_local", {
68 "user" => $test_username . "\@" . $test_domain,
69 "displayname" => "Automatic testing",
70 "email" => "noreply\@" . $test_domain,
71 } );
72 is( $data->{'response'}, 'ok', 'user/add_local created new account');
73
74 $data = exec_apinode("phone/list", undef);
75 is( $data->{'response'}, 'ok', 'phone/list result');
76 ok($data->{'list'}, 'phone/list array');
77 undef $data;
78
79 $data = exec_apinode("phone/add", {
80 'user' => $test_username . "\@" . $test_domain,
81 'mac' => $test_macaddress,
82 });
83
84 is( $data->{'response'}, 'ok', 'phone/add result');
85 ok($data->{'mac'}, 'phone/add mac set');
86 ok($data->{'username'}, 'phone/add username set');
87 ok($data->{'domain'}, 'phone/add domain set');
88 undef $data;
89
90 $data = exec_apinode("phone/list", { 'search' => $test_macaddress });
91 is( $data->{'response'}, 'ok', 'phone/list search result');
92 ok($data->{'list'}, 'phone/list search array');
93 undef $data;
94
95 $data = exec_apinode("phone/get", { 'mac' => $test_macaddress });
96 is( $data->{'response'}, 'ok', 'phone/get mac result');
97 ok($data->{'list'}, 'phone/get mac array');
98 undef $data;
99
100 $data = exec_apinode("phone/get", { 'user' => $test_username . "\@" . $test_domain });
101 is( $data->{'response'}, 'ok', 'phone/get user result');
102 ok($data->{'list'}, 'phone/get user array');
103 undef $data;
104
105 $data = exec_apinode("phone/remove", {
106 'user' => $test_username . "\@" . $test_domain,
107 'mac' => $test_macaddress,
108 });
109 is( $data->{'response'}, 'ok', 'phone/remove result');
110 ok($data->{'mac'}, 'phone/remove mac set');
111 ok($data->{'username'}, 'phone/remove username set');
112 ok($data->{'domain'}, 'phone/remove domain set');
113 undef $data;
114
115 $data = exec_apinode("user/remove", { "user" => $test_username . "\@" . $test_domain });
116 is( $data->{'response'}, 'ok', 'user/remove deleted user');
117 undef $data;
118
119
120 logout();