my $api_user = "test";
my $api_pass = "Very5ecr3t";
-my $test_domain = "example.com"; #TODO: Must fetch this from API
+my $test_domain = undef;
# plan tests => 2;
-my ($g_ua, $response, $data, $temp);
+my ($g_ua, $response, $data, $temp, @t);
$g_ua = LWP::UserAgent->new;
ok($data, 'domain/list JSON decode');
is( $data->{'response'}, 'ok', 'domain/list result');
ok($data->{'list'}, 'domain/list array');
+
+# NOW: Set the $test_domain to something useful (i.e. the first reported domain)
+$test_domain = $data->{'list'}[0];
+ok($test_domain, 'test_domain set.');
undef $response; undef $data;
-TODO: {
- local $TODO = 'not implemented yet';
- $response = $g_ua->get( $api_base . "domain/get_servers");
- isa_ok( $response, 'HTTP::Response', 'domain/list $response');
- ok ($response->is_success, 'domain/list is_success');
- $data = decode_json( $response->content);
- ok($data, 'domain/get_servers JSON decode');
- is( $data->{'response'}, 'ok', 'domain/get_servers result');
- ok($data->{'server'}->{'domain'}, 'domain/get_servers - domain');
- ok($data->{'server'}->{'registrar'}, 'domain/get_servers - registrar');
- ok($data->{'server'}->{'r_port'}, 'domain/get_servers - r_port');
- ok($data->{'server'}->{'proxy'}, 'domain/get_servers - proxy');
- ok($data->{'server'}->{'p_port'}, 'domain/get_servers - p_port');
- ok($data->{'server'}->{'prov_url'}, 'domain/get_servers - prov_url');
- undef $response; undef $data;
+$response = $g_ua->get( $api_base . "domain/get_servers?domain=" . $test_domain );
+isa_ok( $response, 'HTTP::Response', 'domain/list $response');
+ok ($response->is_success, 'domain/list is_success');
+$data = decode_json( $response->content);
+ok($data, 'domain/get_servers JSON decode');
+is( $data->{'response'}, 'ok', 'domain/get_servers result');
+ok($data->{'servers'}->{'domain'}, 'domain/get_servers - domain');
+ok($data->{'servers'}->{'registrar'}, 'domain/get_servers - registrar');
+ok($data->{'servers'}->{'r_port'}, 'domain/get_servers - r_port');
+ok($data->{'servers'}->{'proxy'}, 'domain/get_servers - proxy');
+ok($data->{'servers'}->{'p_port'}, 'domain/get_servers - p_port');
+ok($data->{'servers'}->{'prov_url'}, 'domain/get_servers - prov_url');
+undef $response; undef $data;
-}
+$response = $g_ua->get( $api_base . "domain/set_servers" .
+ "?domain=" . $test_domain .
+ "®istrar=registrar." . $test_domain .
+ "&r_port=5060" .
+ "&proxy=proxy." . $test_domain .
+ "&p_port=5060" .
+ "&prov_url=http://phone." . $test_domain . "/hermes/prov/" );
+
+isa_ok( $response, 'HTTP::Response', 'domain/list $response');
+ok ($response->is_success, 'domain/list is_success');
+$data = decode_json( $response->content);
+ok($data, 'domain/set_servers JSON decode');
+is( $data->{'response'}, 'ok', 'domain/set_servers result');
+ok($data->{'servers'}->{'domain'}, 'domain/set_servers - domain');
+ok($data->{'servers'}->{'registrar'}, 'domain/set_servers - registrar');
+ok($data->{'servers'}->{'r_port'}, 'domain/set_servers - r_port');
+ok($data->{'servers'}->{'proxy'}, 'domain/set_servers - proxy');
+ok($data->{'servers'}->{'p_port'}, 'domain/set_servers - p_port');
+ok($data->{'servers'}->{'prov_url'}, 'domain/set_servers - prov_url');
+undef $response; undef $data;
TODO: {
- local $TODO = 'not implemented yet';
- $response = $g_ua->get( $api_base . "domain/set_servers" .
- "?domain=" . $test_domain . # TODO This should be fetched from domain/list !!
- "®istrar=registrar." . $test_domain .
- "&r_port=5060" .
- "&proxy=proxy." . $test_domain .
- "&p_port=5060" .
- "&prov_url=http://phone." . $test_domain );
-
- isa_ok( $response, 'HTTP::Response', 'domain/list $response');
- ok ($response->is_success, 'domain/list is_success');
- $data = decode_json( $response->content);
- ok($data, 'domain/get_servers JSON decode');
- is( $data->{'response'}, 'ok', 'domain/get_servers result');
- ok($data->{'server'}->{'domain'}, 'domain/get_servers - domain');
- ok($data->{'server'}->{'registrar'}, 'domain/get_servers - registrar');
- ok($data->{'server'}->{'r_port'}, 'domain/get_servers - r_port');
- ok($data->{'server'}->{'proxy'}, 'domain/get_servers - proxy');
- ok($data->{'server'}->{'p_port'}, 'domain/get_servers - p_port');
- ok($data->{'server'}->{'prov_url'}, 'domain/get_servers - prov_url');
+ local $TODO = 'auth/logout not implemented yet';
+ $response = $g_ua->get( $api_base . "auth/logout");
+ #$data = decode_json( $response->content);
+ is( $data->{'response'}, 'ok', 'auth/logout');
undef $response; undef $data;
}
my $test_username = "testuser-" . int(rand(255));
my $test_aliasname = "testalias-" . int(rand(255));
-my $test_domain = "example.com"; #TODO: Must fetch this from API
+my $test_domain = undef;
+
+my $test_remote_domain = undef;
-my $test_remote_domain = "external.example.com";
# plan tests => 2;
my ($g_ua, $response, $data, $temp);
undef $response; undef $data;
}
+# First: fetch a supported domain from the API...
+$response = $g_ua->get( $api_base . "domain/list");
+isa_ok( $response, 'HTTP::Response', 'domain/list $response');
+ok ($response->is_success, 'domain/list is_success');
+$data = decode_json( $response->content);
+ok($data, 'domain/list JSON decode');
+is( $data->{'response'}, 'ok', 'domain/list result');
+ok($data->{'list'}, 'domain/list array');
+
+# NOW: Set the $test_domain to something useful (i.e. the first reported domain)
+$test_domain = $data->{'list'}[0];
+$test_remote_domain = "external." . $test_domain;
+
+ok($test_domain, 'test_domain set.');
+ok($test_remote_domain, 'test_remote_domain set.');
+undef $response; undef $data;
+
$response = $g_ua->get( $api_base . "user/list");
isa_ok( $response, 'HTTP::Response', 'user/list $response');
ok ($response->is_success, 'user/list is_success');
Returns 'invalid' with 'cause' = 'address' if the given alias is not a
valid SIP adress.
+domain/list
+ Returns a list of configured and valid domains. May return an empty
+ list if no domains are configured for kamailio. No node is provided
+ to add domains, this is not a task for Hermes, but a kamailio
+ configuration task.
+
+ Returns 'failed' on database errors.
+
+domain/get_servers?domain=bar.bz
+ Provides the default registrar/proxy/provisioning server information
+ for the given domain.
+
+ Returns 'ok' with 'servers' set to a kvp-set on success, containing:
+ 'registrar', 'r_port', 'proxy', 'p_port', 'prov_url'.
+
+ Returns 'failed' with 'cause' = 'nonexistant' if lookup of data for
+ given domain results in an empty set (not configured).
+
+domain/set_servers?domain=bar.bz®istrar=server.bar.bz&r_port=5060&proxy=proxy.bar.bz&p_port=5060&prov_url=http://server.bar.bz/hermes/prov
+ Sets the server data for the given domain. All of these parameters
+ are required: 'domain', 'registrar', 'r_port', 'proxy', 'p_port', 'prov_url'.
+ If no defaul server data is defined, the configuration is added.
+ If server configuration existed, the default data is updated.
+
+ Returns 'ok' with 'servers' set as domain/get_servers on success.
+
+ Returns 'failed' with 'cause' set to 'cause' set to 'parameters'
+ if one of these is true:
+ * Missing parameters
+ * One or more NULL/empty parameters
+ * Non-numeric values for port-numbers.
+ If you need to determine which of these triggered, the
+ 'description' contains a text describing the actual fail.
+
+ Return 'failed' with 'cause' = 'error' on database failure.
BUGS:
---------------------