d168e4acb264a3248753da9a5bde09080067fa17
[oweals/gnunet.git] / src / gns / test_gns_cname_lookup.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 # permissive DNS resolver we will use for the test
18 DNS_RESOLVER="8.8.8.8"
19 if ! nslookup gnunet.org $DNS_RESOLVER > /dev/null 2>&1
20 then
21   echo "Cannot reach DNS, skipping test"
22   exit 77
23 fi
24
25
26 rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
27
28 TEST_IP_PLUS="127.0.0.1"
29 TEST_IP_DNS="131.159.74.67"
30 TEST_RECORD_CNAME_SERVER="server"
31 TEST_RECORD_CNAME_PLUS="server.+"
32 TEST_RECORD_CNAME_DNS="gnunet.org"
33 TEST_RECORD_NAME_SERVER="server"
34 TEST_RECORD_NAME_PLUS="www"
35 TEST_RECORD_NAME_DNS="www3"
36 MY_EGO="myego"
37 TEST_DOMAIN_PLUS="www.$MY_EGO"
38 TEST_DOMAIN_DNS="www3.$MY_EGO"
39 which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 15"
40
41 gnunet-arm -s -c test_gns_lookup.conf
42 gnunet-identity -C $MY_EGO -c test_gns_lookup.conf
43 gnunet-namestore -p -z $MY_EGO -a -n $TEST_RECORD_NAME_DNS -t CNAME -V $TEST_RECORD_CNAME_DNS -e never -c test_gns_lookup.conf
44 gnunet-namestore -p -z $MY_EGO -a -n $TEST_RECORD_NAME_PLUS -t CNAME -V $TEST_RECORD_CNAME_PLUS -e never -c test_gns_lookup.conf
45 gnunet-namestore -p -z $MY_EGO -a -n $TEST_RECORD_CNAME_SERVER -t A -V $TEST_IP_PLUS -e never -c test_gns_lookup.conf
46 RES_CNAME=`$DO_TIMEOUT gnunet-gns --raw -u $TEST_DOMAIN_PLUS -t A -c test_gns_lookup.conf`
47 RES_CNAME_RAW=`$DO_TIMEOUT gnunet-gns --raw -u $TEST_DOMAIN_PLUS -t CNAME -c test_gns_lookup.conf`
48 RES_CNAME_DNS=`$DO_TIMEOUT gnunet-gns --raw -u $TEST_DOMAIN_DNS -t A -c test_gns_lookup.conf`
49 echo NOW
50 gnunet-gns --raw -u $TEST_DOMAIN_DNS -t A -c test_gns_lookup.conf
51 echo WON
52 TESTEGOZONE=`gnunet-identity -c test_gns_lookup.conf -d | awk '{print $3}'`
53 gnunet-namestore -p -z $MY_EGO -d -n $TEST_RECORD_NAME_DNS -t CNAME -V $TEST_RECORD_CNAME_DNS -e never -c test_gns_lookup.conf
54 gnunet-namestore -p -z $MY_EGO -d -n $TEST_RECORD_NAME_PLUS -t CNAME -V $TEST_RECORD_CNAME_PLUS -e never -c test_gns_lookup.conf
55 gnunet-namestore -p -z $MY_EGO -d -n $TEST_RECORD_CNAME_SERVER -t A -V $TEST_IP_PLUS -e never -c test_gns_lookup.conf
56 gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
57 gnunet-arm -e -c test_gns_lookup.conf
58 rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
59
60 # make cmp case-insensitive by converting to lower case first
61 RES_CNAME_RAW=`echo $RES_CNAME_RAW | tr [A-Z] [a-z]`
62 TESTEGOZONE=`echo $TESTEGOZONE | tr [A-Z] [a-z]`
63 if [ "$RES_CNAME_RAW" = "server.$TESTEGOZONE" ]
64 then
65   echo "PASS: CNAME resolution from GNS"
66 else
67   echo "FAIL: CNAME resolution from GNS, got $RES_CNAME_RAW, expected server.$TESTEGOZONE."
68   exit 1
69 fi
70
71 if [ "$RES_CNAME" = "$TEST_IP_PLUS" ]
72 then
73   echo "PASS: IP resolution from GNS"
74 else
75   echo "FAIL: IP resolution from GNS, got $RES_CNAME, expected $TEST_IP_PLUS."
76   exit 1
77 fi
78
79 if [ "$RES_CNAME_DNS" = "$TEST_IP_DNS" ]
80 then
81   echo "PASS: IP resolution from DNS"
82   exit 0
83 else
84   echo "FAIL: IP resolution from DNS, got $RES_CNAME_DNS, expected $TEST_IP_DNS."
85   exit 1
86 fi