fix #3275 with solution from https://gnunet.org/bugs/view.php?id=3275#c8029
[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 function start_peer
23 {
24         gnunet-arm -s -c $CONFIGURATION
25         gnunet-identity -C testego -c $CONFIGURATION
26 }
27
28 function stop_peer
29 {
30         gnunet-identity -D testego -c $CONFIGURATION
31         gnunet-arm -e -c $CONFIGURATION
32 }
33
34
35 start_peer
36 # Create a public record
37 gnunet-namestore -p -z testego -a -n $TEST_RECORD_NAME_DNS -t A -V $TEST_IP_PLUS -e never -c $CONFIGURATION
38 NAMESTORE_RES=$?
39 # Lookup specific name
40 OUTPUT=`gnunet-namestore -p -z testego -n $TEST_RECORD_NAME_DNS -D`
41
42
43 FOUND_IP=false
44 FOUND_NAME=false
45 for LINE in $OUTPUT ;
46  do
47         if echo "$LINE" | grep -q "$TEST_RECORD_NAME_DNS"; then
48                 FOUND_NAME=true;
49                 #echo $FOUND_NAME
50         fi
51         if echo "$LINE" | grep -q "$TEST_IP_PLUS"; then
52                 FOUND_IP=true;
53                 #echo $FOUND_IP
54         fi
55  done
56 stop_peer
57
58
59 if [ $FOUND_NAME == true -a $FOUND_IP == true ]
60 then
61   echo "PASS: Lookup name in namestore"
62   exit 0
63 elif [ $FOUND_NAME == false ]
64 then
65   echo "FAIL: Lookup name in namestore: name not returned"
66   exit 1
67 elif [ $FOUND_IP == false ]
68 then
69   echo "FAIL: Lookup name in namestore: IP not returned"
70   exit 1
71 fi