]> git.defcon.no Git - hermes/blob - api/t/domain.t
917ab1657273a74327a53e14d2e195aaafec01af
[hermes] / api / t / domain.t
1 #!/usr/bin/perl
2
3 use Test::More 'no_plan';
4
5 use strict;
6 use LWP;
7 use Data::Dumper;
8 use JSON;
9
10 my $api_base = "http://10.0.2.5/hermes/api/";
11 my $api_key = "6327c08b70f9";
12 my $api_user = "test";
13 my $api_pass = "Very5ecr3t";
14
15 my $test_domain = undef;
16
17 # plan tests => 2;
18 my ($g_ua, $response, $data, $temp, @t);
19
20
21 $g_ua = LWP::UserAgent->new;
22 isa_ok( $g_ua, 'LWP::UserAgent', '$g_ua');
23
24 $g_ua->cookie_jar({}); # In-memory jar, look at HTTP::Cookies for persistant
25 isa_ok( $g_ua->cookie_jar, 'HTTP::Cookies', '$g_ua->cookies');
26
27 TODO: {
28 local $TODO = 'auth/login not implemented yet';
29 $response = $g_ua->get( $api_base . "auth/login?username=" . $api_user .
30 "password=" . $api_pass . "&key=" . $api_key);
31
32 #$data = decode_json( $response->content);
33 is( $data->{'response'}, 'ok', 'auth/login');
34 undef $response; undef $data;
35 }
36
37 $response = $g_ua->get( $api_base . "domain/list");
38 isa_ok( $response, 'HTTP::Response', 'domain/list $response');
39 ok ($response->is_success, 'domain/list is_success');
40 $data = decode_json( $response->content);
41 ok($data, 'domain/list JSON decode');
42 is( $data->{'response'}, 'ok', 'domain/list result');
43 ok($data->{'list'}, 'domain/list array');
44
45 # NOW: Set the $test_domain to something useful (i.e. the first reported domain)
46 $test_domain = $data->{'list'}[0];
47 ok($test_domain, 'test_domain set.');
48 undef $response; undef $data;
49
50 $response = $g_ua->get( $api_base . "domain/get_servers?domain=" . $test_domain );
51 isa_ok( $response, 'HTTP::Response', 'domain/list $response');
52 ok ($response->is_success, 'domain/list is_success');
53 $data = decode_json( $response->content);
54 ok($data, 'domain/get_servers JSON decode');
55 is( $data->{'response'}, 'ok', 'domain/get_servers result');
56 ok($data->{'servers'}->{'domain'}, 'domain/get_servers - domain');
57 ok($data->{'servers'}->{'registrar'}, 'domain/get_servers - registrar');
58 ok($data->{'servers'}->{'r_port'}, 'domain/get_servers - r_port');
59 ok($data->{'servers'}->{'proxy'}, 'domain/get_servers - proxy');
60 ok($data->{'servers'}->{'p_port'}, 'domain/get_servers - p_port');
61 ok($data->{'servers'}->{'prov_url'}, 'domain/get_servers - prov_url');
62 undef $response; undef $data;
63
64 $response = $g_ua->get( $api_base . "domain/set_servers" .
65 "?domain=" . $test_domain .
66 "&registrar=registrar." . $test_domain .
67 "&r_port=5060" .
68 "&proxy=proxy." . $test_domain .
69 "&p_port=5060" .
70 "&prov_url=http://phone." . $test_domain . "/hermes/prov/" );
71
72 isa_ok( $response, 'HTTP::Response', 'domain/list $response');
73 ok ($response->is_success, 'domain/list is_success');
74 $data = decode_json( $response->content);
75 ok($data, 'domain/set_servers JSON decode');
76 is( $data->{'response'}, 'ok', 'domain/set_servers result');
77 ok($data->{'servers'}->{'domain'}, 'domain/set_servers - domain');
78 ok($data->{'servers'}->{'registrar'}, 'domain/set_servers - registrar');
79 ok($data->{'servers'}->{'r_port'}, 'domain/set_servers - r_port');
80 ok($data->{'servers'}->{'proxy'}, 'domain/set_servers - proxy');
81 ok($data->{'servers'}->{'p_port'}, 'domain/set_servers - p_port');
82 ok($data->{'servers'}->{'prov_url'}, 'domain/set_servers - prov_url');
83 undef $response; undef $data;
84
85 TODO: {
86 local $TODO = 'auth/logout not implemented yet';
87 $response = $g_ua->get( $api_base . "auth/logout");
88 #$data = decode_json( $response->content);
89 is( $data->{'response'}, 'ok', 'auth/logout');
90 undef $response; undef $data;
91 }