package tests_common;
+# Copyright (c) 2012, Gjøvik University College
+# All rights reserved.
+
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# * Neither the name of the Gjøvik University College nor the
+# names of its contributors may be used to endorse or promote products
+# derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY Gjøvik University College ''AS IS'' AND ANY
+# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL Gjøvik University College BE LIABLE FOR ANY
+# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
use Test::More;
%EXPORT_TAGS = ( 'all' => [ qw( ) ] );
@EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
}
-our $api_base = "http://10.0.2.5/hermes/api/";
-our $api_key = "4hErgw3QFJLeuXGW";
+our $api_base = "http://sippbx.hig.no/hermes/api/";
+our $api_key = "e065gBpUwqzY0a5o";
our $invalid_key = "invalidkey" . int(rand(255));
our $test_username = "testauth-" . int(rand(255));
$session = "" if not defined $session;
$auth_key = "" if not defined $auth_key;
- my $url = $api_base . $node .
- "?session=" . $session .
- "&auth_key=" . $auth_key;
+ my $url = $api_base . $node;
- foreach my $key ( keys %$param )
- {
- $url .= "&" . $key . "=" . $param->{$key};
- }
- $response = $g_ua->get( $url );
+ $param->{'session'} = $session;
+ $param->{'auth_key'} = $auth_key;
+
+ $response = $g_ua->post( $url, $param );
if ( $response->is_success )
{
if ( $response->content =~ m/\s*{/ )
sub login_apikey
{
- my $response = $g_ua->get( $api_base . "auth/login" .
- "?api_key=" . $api_key );
+ my $response = $g_ua->post( $api_base . "auth/login",
+ [ "api_key" => $api_key ] );
+
ok ($response->is_success, 'login_apikey request is_success');
my $data = decode_json( $response->content) if $response->is_success;
die("HTTP error") unless $response->is_success;
sub login_user
{
- my $response = $g_ua->get( $api_base . "auth/login" .
- "?username=" . $test_username .
- "&password=" . $test_password );
+ my $response = $g_ua->post( $api_base . "auth/login",
+ [ "username" => $test_username,
+ "password" => $test_password ] );
+
ok ($response->is_success, 'login_user request is_success');
my $data = decode_json( $response->content) if $response->is_success;
sub logout
{
- my $response = $g_ua->get( $api_base . "auth/logout" .
- "?session=" . $session );
+ my $response = $g_ua->post( $api_base . "auth/logout",
+ [ "session" => $session ] );
ok ($response->is_success, 'logout request is_success');
die("HTTP error") unless $response->is_success;