support multiple DNS resolvers for queries (in DNSSTUB and GNS2DNS resolution for...
[oweals/gnunet.git] / src / gns / test_gns_rel_expiration.sh
1 #!/bin/bash
2 trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT
3
4 LOCATION=$(which gnunet-config)
5 if [ -z $LOCATION ]
6 then
7   LOCATION="gnunet-config"
8 fi
9 $LOCATION --version 1> /dev/null
10 if test $? != 0
11 then
12         echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
13         exit 77
14 fi
15
16 MY_EGO="myego"
17 OTHER_EGO="delegatedego"
18
19 rm -rf /tmp/test-gnunet-gns-peer-1/
20 which timeout &> /dev/null && DO_TIMEOUT="timeout 5"
21 TEST_IP="127.0.0.1"
22 gnunet-arm -s -c test_gns_lookup.conf
23 gnunet-identity -C $MY_EGO -c test_gns_lookup.conf
24 gnunet-identity -C $OTHER_EGO -c test_gns_lookup.conf
25 DELEGATED_PKEY=$(gnunet-identity -d -c test_gns_lookup.conf | grep $OTHER_EGO | awk '{print $3}')
26 gnunet-namestore -p -z $MY_EGO -a -n b -t PKEY -V $DELEGATED_PKEY -e never -c test_gns_lookup.conf
27 gnunet-namestore -p -z $OTHER_EGO -a -n www -t A -V $TEST_IP -e '5 s' -c test_gns_lookup.conf
28 gnunet-arm -i gns -c test_gns_lookup.conf
29 # confirm that lookup currently works
30 RES_IP=`$DO_TIMEOUT gnunet-gns --raw -u www.b.$MY_EGO -t A -c test_gns_lookup.conf`
31 # remove entry
32 gnunet-namestore -z $OTHER_EGO -d -n www -t A -V $TEST_IP  -e '5 s' -c test_gns_lookup.conf
33 # wait for old entry with 5s 'expiration' to definitively expire
34 sleep 6
35 # try again, should no longer work
36 RES_IP_EXP=`$DO_TIMEOUT gnunet-gns --raw -u www.b.$MY_EGO -t A -c test_gns_lookup.conf`
37 gnunet-namestore -z $MY_EGO -d -n b -t PKEY -V $DELEGATED_PKEY  -e never -c test_gns_lookup.conf
38 gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
39 gnunet-identity -D $OTHER_EGO -c test_gns_lookup.conf
40 gnunet-arm -e -c test_gns_lookup.conf
41 rm -rf /tmp/test-gnunet-gns-peer-1/
42
43 if [ "$RES_IP_EXP" == "$TEST_IP" ]
44 then
45   echo "Failed to properly expire IP, got $RES_IP_EXP."
46   exit 1
47 fi
48
49 if [ "$RES_IP" == "$TEST_IP" ]
50 then
51   exit 0
52 else
53   echo "Failed to properly resolve IP, got $RES_IP."
54   exit 1
55 fi