NAMESTORE/JSON: fix parsing exp and flags
[oweals/gnunet.git] / src / namestore / test_namestore_lookup.sh
1 #!/bin/bash
2 CONFIGURATION="test_namestore_api.conf"
3 trap "gnunet-arm -e -c $CONFIGURATION" 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 `$LOCATION -c $CONFIGURATION -s PATHS -o GNUNET_HOME`
18 TEST_IP_PLUS="127.0.0.1"
19 TEST_RECORD_NAME_DNS="www3"
20 which timeout &> /dev/null && DO_TIMEOUT="timeout 5"
21
22 # start peer
23 gnunet-arm -s -c $CONFIGURATION
24 gnunet-identity -C testego -c $CONFIGURATION
25
26 # Create a public record
27 gnunet-namestore -p -z testego -a -n $TEST_RECORD_NAME_DNS -t A -V $TEST_IP_PLUS -e never -c $CONFIGURATION
28 NAMESTORE_RES=$?
29 # Lookup specific name
30 OUTPUT=`gnunet-namestore -p -z testego -n $TEST_RECORD_NAME_DNS -D`
31
32
33 FOUND_IP=false
34 FOUND_NAME=false
35 for LINE in $OUTPUT ;
36  do
37         if echo "$LINE" | grep -q "$TEST_RECORD_NAME_DNS"; then
38                 FOUND_NAME=true;
39                 #echo $FOUND_NAME
40         fi
41         if echo "$LINE" | grep -q "$TEST_IP_PLUS"; then
42                 FOUND_IP=true;
43                 #echo $FOUND_IP
44         fi
45 done
46 # stop peer
47 gnunet-identity -D testego -c $CONFIGURATION
48 gnunet-arm -e -c $CONFIGURATION
49
50
51 if [ $FOUND_NAME = true -a $FOUND_IP = true ]
52 then
53   echo "PASS: Lookup name in namestore"
54   exit 0
55 elif [ $FOUND_NAME = false ]
56 then
57   echo "FAIL: Lookup name in namestore: name not returned"
58   exit 1
59 elif [ $FOUND_IP = false ]
60 then
61   echo "FAIL: Lookup name in namestore: IP not returned"
62   exit 1
63 fi