X-Git-Url: https://git.defcon.no/?a=blobdiff_plain;f=api%2Ft%2Ftests_common.pm;h=43356324a8c5f4363102a2ac97e89ad158583b3b;hb=e3ea78bd48d210947fcfcb73977e6a34e6b31293;hp=9c2ec83266683cc68612be6476ad258c5fdfda4a;hpb=1455ccca33de385a5d18db4d2aae30ab46472f9d;p=hermes diff --git a/api/t/tests_common.pm b/api/t/tests_common.pm index 9c2ec83..4335632 100644 --- a/api/t/tests_common.pm +++ b/api/t/tests_common.pm @@ -1,4 +1,28 @@ 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; @@ -17,8 +41,8 @@ BEGIN { %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)); @@ -40,15 +64,12 @@ sub exec_apinode($$) $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*{/ ) @@ -66,8 +87,9 @@ sub exec_apinode($$) 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; @@ -89,9 +111,10 @@ sub login_apikey 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; @@ -114,8 +137,8 @@ sub login_user 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;