fix rest; uncrustify
[oweals/gnunet.git] / src / gns / test_plugin_rest_gns.sh
1 #!/bin/sh
2 # This file is in the public domain.
3 trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT
4
5 LOCATION=$(which gnunet-config)
6 if [ -z $LOCATION ]
7 then
8   LOCATION="gnunet-config"
9 fi
10 $LOCATION --version 1> /dev/null
11 if test $? != 0
12 then
13         echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
14         exit 77
15 fi
16
17 rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
18
19 gns_link="http://localhost:7776/gns"
20 wrong_link="http://localhost:7776/gnsandmore"
21
22 curl_get () {
23     #$1 is link
24     #$2 is grep
25     cache="$(gnurl -v "$1" 2>&1 | grep "$2")"
26     echo "$cache"
27     if [ "" == "$cache" ]
28     then
29         gnunet-identity -D "$TEST_TLD" -c test_gns_lookup.conf > /dev/null 2>&1
30         gnunet-arm -e -c test_gns_lookup.conf
31         exit 1
32     fi
33 }
34 TEST_TLD="testtld"
35
36 gnunet-arm -s -c test_gns_lookup.conf
37 gnunet-arm -I
38 gnunet-identity -D "$TEST_TLD" -c test_gns_lookup.conf > /dev/null 2>&1
39
40 curl_get "$gns_link/www.$TEST_TLD" "error"
41
42 gnunet-identity -C "$TEST_TLD"  -c test_gns_lookup.conf
43 sleep 0.5
44 curl_get "$gns_link/www.$TEST_TLD" "\[\]"
45
46 gnunet-namestore -z "$TEST_TLD" -p -a -n www -e 1d -V 1.1.1.1 -t A -c test_gns_lookup.conf
47
48 curl_get "$gns_link/www.$TEST_TLD" "1.1.1.1"
49
50 gnunet-namestore -z "$TEST_TLD" -p -a -n www -e 1d -V 1::1 -t AAAA -c test_gns_lookup.conf
51
52 curl_get "$gns_link/www.$TEST_TLD" "1::1.*1.1.1.1"
53
54 gnunet-namestore -z "$TEST_TLD" -p -a -n www -e 1d -V 1.1.1.2 -t A -c test_gns_lookup.conf
55
56 curl_get "$gns_link/www.$TEST_TLD" "1.1.1.2.*1::1.*1.1.1.1"
57 curl_get "$gns_link/www.$TEST_TLD?record_type=A" "1.1.1.2.*1.1.1.1"
58 curl_get "$gns_link/www.$TEST_TLD?record_type=AAAA" "1::1"
59 curl_get "$gns_link/www.$TEST_TLD?record_type=WRONG_TYPE" "1.1.1.2.*1::1.*1.1.1.1"
60
61 gnunet-namestore -z "$TEST_TLD" -p -a -n www1 -e 1d -V 1.1.1.1 -t A -c test_gns_lookup.conf
62 curl_get "$gns_link/www1.$TEST_TLD" "1.1.1.1"
63
64 gnunet-namestore -z "$TEST_TLD" -d -n www1 -c test_gns_lookup.conf
65 gnunet-namestore -z "$TEST_TLD" -d -n www -c test_gns_lookup.conf
66
67 gnunet-identity -D "$TEST_TLD" -c test_gns_lookup.conf > /dev/null 2>&1
68
69 curl_get "$gns_link/www1.$TEST_TLD" "error"
70
71 exit 0