From: Schanzenbach, Martin Date: Fri, 11 Oct 2019 14:17:23 +0000 (+0200) Subject: add namestore rest tests X-Git-Tag: v0.11.7~62^2~6 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=47ab1ded5ef79da36c4e769fae7fba2af84405d7;p=oweals%2Fgnunet.git add namestore rest tests --- diff --git a/src/gns/test_plugin_rest_gns.sh b/src/gns/test_plugin_rest_gns.sh index 09f155e01..da46330d6 100755 --- a/src/gns/test_plugin_rest_gns.sh +++ b/src/gns/test_plugin_rest_gns.sh @@ -23,7 +23,7 @@ curl_get () { #$1 is link #$2 is grep cache="$(gnurl -v "$1" 2>&1 | grep "$2")" - echo "$cache" + #echo "$cache" if [ "" == "$cache" ] then gnunet-identity -D "$TEST_TLD" -c test_gns_lookup.conf > /dev/null 2>&1 @@ -34,9 +34,6 @@ curl_get () { TEST_TLD="testtld" gnunet-arm -s -c test_gns_lookup.conf -gnunet-arm -I -gnunet-identity -D "$TEST_TLD" -c test_gns_lookup.conf > /dev/null 2>&1 - curl_get "$gns_link/www.$TEST_TLD" "error" gnunet-identity -C "$TEST_TLD" -c test_gns_lookup.conf @@ -67,5 +64,5 @@ gnunet-namestore -z "$TEST_TLD" -d -n www -c test_gns_lookup.conf gnunet-identity -D "$TEST_TLD" -c test_gns_lookup.conf > /dev/null 2>&1 curl_get "$gns_link/www1.$TEST_TLD" "error" - +gnunet-arm -e -c -c test_gns_lookup.conf exit 0 diff --git a/src/namestore/Makefile.am b/src/namestore/Makefile.am index b9fa83103..646effd9b 100644 --- a/src/namestore/Makefile.am +++ b/src/namestore/Makefile.am @@ -681,6 +681,13 @@ check_SCRIPTS = \ test_namestore_lookup.sh \ test_namestore_delete.sh +if HAVE_MHD +if HAVE_JSON +check_SCRIPTS += \ + test_plugin_rest_namestore.sh +endif +endif + EXTRA_DIST = \ test_common.c \ test_namestore_api.conf \ diff --git a/src/namestore/test_plugin_rest_namestore.sh b/src/namestore/test_plugin_rest_namestore.sh index 532c7caae..f3a4b7c49 100755 --- a/src/namestore/test_plugin_rest_namestore.sh +++ b/src/namestore/test_plugin_rest_namestore.sh @@ -1,44 +1,65 @@ -#!/usr/bin/bash +#!/bin/sh +trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT -#First, start gnunet-arm and the rest-service. -#Exit 0 means success, exit 1 means failed test +LOCATION=$(which gnunet-config) +if [ -z $LOCATION ] +then + LOCATION="gnunet-config" +fi +$LOCATION --version 1> /dev/null +if test $? != 0 +then + echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX" + exit 77 +fi + +rm -rf `gnunet-config -c test_namestore_api.conf -f -s paths -o GNUNET_TEST_HOME` namestore_link="http://localhost:7776/namestore" wrong_link="http://localhost:7776/namestoreandmore" curl_get () { - #$1 is link - #$2 is grep - cache="$(curl -v "$1" 2>&1 | grep "$2")" - echo $cache - if [ "" == "$cache" ] - then - exit 1 - fi + #$1 is link + #$2 is grep + resp=$(curl -v "$1" 2>&1) + cache="$(echo $resp | grep "$2")" + #echo $cache + if [ "" == "$cache" ] + then + echo "Error in get response: $resp, expected $2" + gnunet-arm -e -c test_namestore_api.conf + exit 1 + fi } curl_post () { - #$1 is link - #$2 is data - #$3 is grep - cache="$(curl -v -X "POST" "$1" --data "$2" 2>&1 | grep "$3")" - echo $cache - if [ "" == "$cache" ] - then - exit 1 - fi + #$1 is link + #$2 is data + #$3 is grep + resp=$(curl -v -X "POST" "$1" --data "$2" 2>&1) + cache="$(echo $resp | grep "$3")" + #echo $cache + if [ "" == "$cache" ] + then + echo "Error in post response: $resp ($2), expected $3" + gnunet-arm -e -c test_namestore_api.conf + exit 1 + fi } curl_delete () { - #$1 is link - #$2 is grep - cache="$(curl -v -X "DELETE" "$1" 2>&1 | grep "$2")" - echo $cache - if [ "" == "$cache" ] - then - exit 1 - fi + #$1 is link + #$2 is grep + resp=$(curl -v -X "DELETE" "$1" 2>&1) + cache="$(echo $resp | grep "$2")" + #echo $cache + if [ "" == "$cache" ] + then + echo "Error in delete response: $resp, expected $2" + gnunet-arm -e -c test_namestore_api.conf + exit 1 + fi } # curl_put () { @@ -55,93 +76,61 @@ curl_delete () { #Test subsystem default identity +TEST_ID="test" +gnunet-arm -s -c test_namestore_api.conf +gnunet-arm -i rest -c test_namestore_api.conf #Test GET -gnunet-identity -D "test_plugin_rest_namestore" -gnunet-identity -C "test_plugin_rest_namestore" -test="$(gnunet-namestore -D -z "test_plugin_rest_namestore")" -name="test_plugin_rest_namestore" -public="$(gnunet-identity -d | grep "test_plugin_rest_namestore" | awk 'NR==1{print $3}')" -if [ "" == "$test" ] -then - #if no entries for test_plugin_rest_namestore - curl_get "${namestore_link}/$name" "error" - curl_get "${namestore_link}/" "error" - curl_get "${namestore_link}/$public" "error" -else - #if entries exists (that should not be possible) - curl_get "${namestore_link}" "HTTP/1.1 200 OK" - curl_get "${namestore_link}/$name" "HTTP/1.1 200 OK" - curl_get "${namestore_link}/" "error" - curl_get "${namestore_link}/$public" "error" -fi -gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY" +gnunet-identity -C $TEST_ID -c test_namestore_api.conf +test="$(gnunet-namestore -D -z $TEST_ID -c test_namestore_api.conf)" +name=$TEST_ID +public="$(gnunet-identity -d -c test_namestore_api.conf | grep $TEST_ID | awk 'NR==1{print $3}')" +gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY" -c test_namestore_api.conf curl_get "${namestore_link}" "HTTP/1.1 200 OK" curl_get "${namestore_link}/$name" "HTTP/1.1 200 OK" -curl_get "${namestore_link}/" "error" curl_get "${namestore_link}/$public" "error" -gnunet-namestore -z $name -d -n "test_entry" +gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf #Test POST with NAME -curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "HTTP/1.1 204 No Content" -gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 -#value -curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRGxxx", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "error" -gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 -curl_post "${namestore_link}/$name" '{"value":"", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "error" -gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 -curl_post "${namestore_link}/$name" '{"value_missing":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRGxxx", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "error" -gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 -#time -curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"0d","flag":0,"record_name":"test_entry"}' "HTTP/1.1 204" -gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 -curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"10000d","flag":0,"record_name":"test_entry"}' "HTTP/1.1 204" -gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 -curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"now","flag":0,"record_name":"test_entry"}' "error" -gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 -curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"","flag":0,"record_name":"test_entry"}' "error" -gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 -curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time_missing":"1d","flag":0,"record_name":"test_entry"}' "error" -gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 -#flag -curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "HTTP/1.1 204 No Content" -gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 -curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":2,"record_name":"test_entry"}' "HTTP/1.1 204 No Content" -gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 -curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":8,"record_name":"test_entry"}' "HTTP/1.1 204 No Content" -gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 -curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":16,"record_name":"test_entry"}' "HTTP/1.1 204 No Content" -gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 -curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":-1,"record_name":"test_entry"}' "error" -gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 -curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":"Test","record_name":"test_entry"}' "error" -gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 -curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":,"record_name":"test_entry"}' "error" -gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 -curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag_missing":0,"record_name":"test_entry"}' "error" -gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 +curl_post "${namestore_link}/$name" '{"data": [{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0}],"record_name":"test_entry"}' "HTTP/1.1 204 No Content" +gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1 + +# invalid values +curl_post "${namestore_link}/$name" '{"data": [{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRGxxx", "record_type":"PKEY", "expiration_time":"1d","flag":0}],"record_name":"test_entry"}' "error" +gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1 + + +curl_post "${namestore_link}/$name" '{"data": [{"value":"", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name"}]:"test_entry"}' "error" +gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1 + +curl_post "${namestore_link}/$name" '{"data": [{"record_type":"PKEY", "expiration_time":"1d","flag":0}],"record_name":"test_entry"}' "error" +gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1 + +#expirations +curl_post "${namestore_link}/$name" '{"data": [{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"0d","flag":0}],"record_name":"test_entry"}' "HTTP/1.1 204" +gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1 + +curl_post "${namestore_link}/$name" '{"data": [{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"10000d","flag":0}],"record_name":"test_entry"}' "HTTP/1.1 204" +gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1 + +curl_post "${namestore_link}/$name" '{"data": [{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"now","flag":0}],"record_name":"test_entry"}' "error" +gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1 + +curl_post "${namestore_link}/$name" '{"data": [{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time_missing":"1d","flag":0}],"record_name":"test_entry"}' "error" +gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1 + #record_name -curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "HTTP/1.1 204 No Content" -curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "HTTP/1.1 204 No Content" -gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 -curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":""}' "error" -gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 -curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name_missing":"test_entry"}' "error" -gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 - -#wrong zone -curl_post "${namestore_link}/$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "error" -gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 +curl_post "${namestore_link}/$name" '{"data": [{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0}],"record_name":""}' "error" +gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1 +curl_post "${namestore_link}/$name" '{"data": [{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0}],"record_name_missing":"test_entry"}' "error" +gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1 #Test DELETE -gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY" +gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY" -c test_namestore_api.conf curl_delete "${namestore_link}/$name?record_name=test_entry" "HTTP/1.1 204" curl_delete "${namestore_link}/$name?record_name=test_entry" "error" -gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY" +gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY" -c test_namestore_api.conf curl_delete "${namestore_link}/$public?record_name=test_entry" "error" - -#Test default identity -#not possible without defining - +gnunet-arm -e -c test_namestore_api.conf exit 0;