Skip testcase when DNS is not available
[oweals/gnunet.git] / src / gns / test_gns_cname_lookup.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 # permissive DNS resolver we will use for the test
17 DNS_RESOLVER="8.8.8.8"
18 if ! nslookup gnunet.org $DNS_RESOLVER &> /dev/null
19 then
20   echo "Cannot reach DNS, skipping test"
21   exit 77
22 fi
23
24
25 rm -rf /tmp/test-gnunet-gns-peer-1/
26
27 TEST_DOMAIN_PLUS="www.gnu"
28 TEST_DOMAIN_DNS="www3.gnu"
29 TEST_IP_PLUS="127.0.0.1"
30 TEST_IP_DNS="131.159.74.67"
31 TEST_RECORD_CNAME_SERVER="server"
32 TEST_RECORD_CNAME_PLUS="server.+"
33 TEST_RECORD_CNAME_DNS="gnunet.org"
34 TEST_RECORD_NAME_SERVER="server"
35 TEST_RECORD_NAME_PLUS="www"
36 TEST_RECORD_NAME_DNS="www3"
37 which timeout &> /dev/null && DO_TIMEOUT="timeout 5"
38
39 gnunet-arm -s -c test_gns_lookup.conf
40 gnunet-identity -C testego -c test_gns_lookup.conf
41 gnunet-namestore -p -z testego -a -n $TEST_RECORD_NAME_DNS -t CNAME -V $TEST_RECORD_CNAME_DNS -e never -c test_gns_lookup.conf
42 gnunet-namestore -p -z testego -a -n $TEST_RECORD_NAME_PLUS -t CNAME -V $TEST_RECORD_CNAME_PLUS -e never -c test_gns_lookup.conf
43 gnunet-namestore -p -z testego -a -n $TEST_RECORD_CNAME_SERVER -t A -V $TEST_IP_PLUS -e never -c test_gns_lookup.conf
44 RES_CNAME=`$DO_TIMEOUT gnunet-gns --raw -z testego -u www.gnu -t A -c test_gns_lookup.conf`
45 RES_CNAME_RAW=`$DO_TIMEOUT gnunet-gns --raw -z testego -u www.gnu -t CNAME -c test_gns_lookup.conf`
46 RES_CNAME_DNS=`$DO_TIMEOUT gnunet-gns --raw -z testego -u www3.gnu -t A -c test_gns_lookup.conf`
47 TESTEGOZONE=`gnunet-identity -c test_gns_lookup.conf -d | awk '{print $3}'`
48 gnunet-namestore -p -z testego -d -n $TEST_RECORD_NAME_DNS -t CNAME -V $TEST_RECORD_CNAME_DNS -e never -c test_gns_lookup.conf
49 gnunet-namestore -p -z testego -d -n $TEST_RECORD_NAME_PLUS -t CNAME -V $TEST_RECORD_CNAME_PLUS -e never -c test_gns_lookup.conf
50 gnunet-namestore -p -z testego -d -n $TEST_RECORD_CNAME_SERVER -t A -V $TEST_IP_PLUS -e never -c test_gns_lookup.conf
51 gnunet-identity -D testego -c test_gns_lookup.conf
52 gnunet-arm -e -c test_gns_lookup.conf
53 rm -rf /tmp/test-gnunet-gns-peer-1/
54
55 if [ "$RES_CNAME_RAW" == "server.$TESTEGOZONE.zkey" ]
56 then
57   echo "PASS: CNAME resulution from GNS"
58 else
59   echo "FAIL: CNAME resolution from GNS, got $RES_CNAME_RAW."
60   exit 1
61 fi
62
63 if [ "$RES_CNAME" == "$TEST_IP_PLUS" ]
64 then
65   echo "PASS: IP resulution from GNS"
66 else
67   echo "FAIL: IP resolution from GNS, got $RES_CNAME."
68   exit 1
69 fi
70
71 if [ "$RES_CNAME_DNS" == "$TEST_IP_DNS" ]
72 then
73   echo "PASS: IP resulution from DNS"
74   exit 0
75 else
76   echo "FAIL: IP resulution from DNS, got $RES_IP."
77   exit 1
78 fi