From d84439cb61f1964534363219d800036e28112cd4 Mon Sep 17 00:00:00 2001 From: Jon Langseth Date: Wed, 18 Jan 2012 17:21:05 +0100 Subject: [PATCH] Ooops on last commit. forgot to include a majority of the changes... --- api/config.php.sample | 1 + api/lib/domain_functions.php | 1 - api/t/domain.t | 81 +++++++++++++++++++----------------- api/t/user.t | 22 +++++++++- doc/api-nodes.txt | 35 ++++++++++++++++ doc/sql-data/sample-data.sql | 2 +- 6 files changed, 100 insertions(+), 42 deletions(-) diff --git a/api/config.php.sample b/api/config.php.sample index 5b0a82b..66d03dc 100644 --- a/api/config.php.sample +++ b/api/config.php.sample @@ -11,6 +11,7 @@ function get_config() 'kamailio_domain_table' => 'domain', 'kamailio_subscriber_table' => 'subscriber', 'kamailio_alias_table' => 'dbaliases', + 'kamailio_domain_table' => 'domain', 'provision_db' => 'provision', 'provision_users_table' => 'users', 'provision_phones_table' => 'phones', diff --git a/api/lib/domain_functions.php b/api/lib/domain_functions.php index d28c0be..74095b8 100644 --- a/api/lib/domain_functions.php +++ b/api/lib/domain_functions.php @@ -56,6 +56,5 @@ function set_servers ( $domain, $registrar, $r_port, $proxy, $p_port, $prov_url } return sql_dbexec( $config['provision_db'], $query ); - return false; } ?> diff --git a/api/t/domain.t b/api/t/domain.t index 38467df..917ab16 100644 --- a/api/t/domain.t +++ b/api/t/domain.t @@ -12,10 +12,10 @@ my $api_key = "6327c08b70f9"; 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; @@ -41,46 +41,51 @@ $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]; +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; } diff --git a/api/t/user.t b/api/t/user.t index 6548f26..81d908d 100644 --- a/api/t/user.t +++ b/api/t/user.t @@ -15,9 +15,10 @@ my $api_pass = "Very5ecr3t"; 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); @@ -39,6 +40,23 @@ TODO: { 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'); diff --git a/doc/api-nodes.txt b/doc/api-nodes.txt index 9d0e347..19dfa06 100644 --- a/doc/api-nodes.txt +++ b/doc/api-nodes.txt @@ -231,6 +231,41 @@ alias/remove?alias=foo@bar.bz 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: --------------------- diff --git a/doc/sql-data/sample-data.sql b/doc/sql-data/sample-data.sql index 4c744c7..8794d41 100644 --- a/doc/sql-data/sample-data.sql +++ b/doc/sql-data/sample-data.sql @@ -471,7 +471,7 @@ UNLOCK TABLES; LOCK TABLES `servers` WRITE; /*!40000 ALTER TABLE `servers` DISABLE KEYS */; -INSERT INTO `servers` VALUES (1,'example.com','example.com',5062,'pbx.example.com',5060,NULL); +INSERT INTO `servers` VALUES (1,'example.com','example.com',5062,'pbx.example.com',5060,'http://pbx.example.com/hermes/prov/'); /*!40000 ALTER TABLE `servers` ENABLE KEYS */; UNLOCK TABLES; -- 2.39.2