]> git.defcon.no Git - hermes/blob - api/t/domain.t
Changed sql_dbquery to return result on zero rows. Resulted in some patchings. Added...
[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 = "example.com"; #TODO: Must fetch this from API
16
17 # plan tests => 2;
18 my ($g_ua, $response, $data, $temp);
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 undef $response; undef $data;
45
46 TODO: {
47 local $TODO = 'not implemented yet';
48 $response = $g_ua->get( $api_base . "domain/get_servers");
49 isa_ok( $response, 'HTTP::Response', 'domain/list $response');
50 ok ($response->is_success, 'domain/list is_success');
51 $data = decode_json( $response->content);
52 ok($data, 'domain/get_servers JSON decode');
53 is( $data->{'response'}, 'ok', 'domain/get_servers result');
54 ok($data->{'server'}->{'domain'}, 'domain/get_servers - domain');
55 ok($data->{'server'}->{'registrar'}, 'domain/get_servers - registrar');
56 ok($data->{'server'}->{'r_port'}, 'domain/get_servers - r_port');
57 ok($data->{'server'}->{'proxy'}, 'domain/get_servers - proxy');
58 ok($data->{'server'}->{'p_port'}, 'domain/get_servers - p_port');
59 ok($data->{'server'}->{'prov_url'}, 'domain/get_servers - prov_url');
60 undef $response; undef $data;
61
62 }
63
64 TODO: {
65 local $TODO = 'not implemented yet';
66 $response = $g_ua->get( $api_base . "domain/set_servers" .
67 "?domain=" . $test_domain . # TODO This should be fetched from domain/list !!
68 "&registrar=registrar." . $test_domain .
69 "&r_port=5060" .
70 "&proxy=proxy." . $test_domain .
71 "&p_port=5060" .
72 "&prov_url=http://phone." . $test_domain );
73
74 isa_ok( $response, 'HTTP::Response', 'domain/list $response');
75 ok ($response->is_success, 'domain/list is_success');
76 $data = decode_json( $response->content);
77 ok($data, 'domain/get_servers JSON decode');
78 is( $data->{'response'}, 'ok', 'domain/get_servers result');
79 ok($data->{'server'}->{'domain'}, 'domain/get_servers - domain');
80 ok($data->{'server'}->{'registrar'}, 'domain/get_servers - registrar');
81 ok($data->{'server'}->{'r_port'}, 'domain/get_servers - r_port');
82 ok($data->{'server'}->{'proxy'}, 'domain/get_servers - proxy');
83 ok($data->{'server'}->{'p_port'}, 'domain/get_servers - p_port');
84 ok($data->{'server'}->{'prov_url'}, 'domain/get_servers - prov_url');
85 undef $response; undef $data;
86 }