Merge branch 'master' of gnunet.org:gnunet
[oweals/gnunet.git] / src / gns / test_gns_gns2dns_cname_lookup.sh
1 #!/bin/bash
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 rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
18 # IP address of 'www.gnunet.org'
19 TEST_IP="131.159.74.67"
20 # IPv6 address of 'gnunet.org'
21 TEST_IP6="2001:4ca0:2001:42:225:90ff:fe6b:d60"
22
23 # main label used during resolution
24 TEST_RECORD_NAME="homepage"
25
26 XNS=ns.joker.com
27
28 if ! nslookup gnunet.org a.$XNS &> /dev/null
29 then
30   echo "Cannot reach DNS, skipping test"
31   exit 77
32 fi
33
34 # helper record for pointing to the DNS resolver
35 TEST_RESOLVER_LABEL="resolver"
36 # GNS2DNS record value: delegate to DNS domain 'gnunet.org'
37 # using the TEST_RESOLVER_LABEL DNS server for resolution
38 TEST_RECORD_GNS2DNS1="gnunet.org@a.$XNS"
39 TEST_RECORD_GNS2DNS2="gnunet.org@b.$XNS"
40 TEST_RECORD_GNS2DNS3="gnunet.org@c.$XNS"
41
42 MY_EGO="myego"
43 # various names we will use for resolution
44 TEST_DOMAIN="www.${TEST_RECORD_NAME}.$MY_EGO"
45
46 which timeout &> /dev/null && DO_TIMEOUT="timeout 15"
47
48
49 gnunet-arm -s -c test_gns_lookup.conf
50
51 echo $OUT | grep $TEST_IP - > /dev/null || { gnunet-arm -e -c test_gns_lookup.conf ; echo "IPv4 for gnunet.org not found, skipping test"; exit 77; }
52 echo $OUT | grep $TEST6_IP - > /dev/null || { gnunet-arm -e -c test_gns_lookup.conf ; echo "IPv6 for gnunet.org not found, skipping test"; exit 77; }
53
54
55 gnunet-identity -C $MY_EGO -c test_gns_lookup.conf
56
57 # set IP address for DNS resolver for resolving in gnunet.org domain
58 # map '$TEST_RECORD_NAME.$MY_EGO' to 'gnunet.org' in DNS
59 gnunet-namestore -p -z $MY_EGO -a -n $TEST_RECORD_NAME -t GNS2DNS -V $TEST_RECORD_GNS2DNS1 -e never -c test_gns_lookup.conf
60 gnunet-namestore -p -z $MY_EGO -a -n $TEST_RECORD_NAME -t GNS2DNS -V $TEST_RECORD_GNS2DNS2 -e never -c test_gns_lookup.conf
61 gnunet-namestore -p -z $MY_EGO -a -n $TEST_RECORD_NAME -t GNS2DNS -V $TEST_RECORD_GNS2DNS3 -e never -c test_gns_lookup.conf
62
63
64 echo "EGOs:"
65 gnunet-identity -d
66
67 # lookup 'www.gnunet.org', IPv4
68 RES_IP=`$DO_TIMEOUT gnunet-gns --raw -u $TEST_DOMAIN -t A -c test_gns_lookup.conf`
69 # lookup 'www.gnunet.org', IPv6
70 RES_IP6=`$DO_TIMEOUT gnunet-gns --raw -u $TEST_DOMAIN -t AAAA -c test_gns_lookup.conf`
71
72 # clean up
73 gnunet-namestore -z $MY_EGO -d -n $TEST_RECORD_NAME -t GNS2DNS -V $TEST_RECORD_GNS2DNS1 -e never -c test_gns_lookup.conf
74 gnunet-namestore -z $MY_EGO -d -n $TEST_RECORD_NAME -t GNS2DNS -V $TEST_RECORD_GNS2DNS2 -e never -c test_gns_lookup.conf
75 gnunet-namestore -z $MY_EGO -d -n $TEST_RECORD_NAME -t GNS2DNS -V $TEST_RECORD_GNS2DNS3 -e never -c test_gns_lookup.conf
76 gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
77 gnunet-arm -e -c test_gns_lookup.conf
78 rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
79
80 ret=0
81 if [ "$RES_IP" == "$TEST_IP" ]
82 then
83   echo "PASS: Resolved $TEST_DOMAIN to $RES_IP."
84 else
85   echo "Failed to resolve to proper IP for $TEST_DOMAIN, got $RES_IP, wanted $TEST_IP."
86   ret=1
87 fi
88
89 if [ "$RES_IP6" == "$TEST_IP6" ]
90 then
91   echo "PASS: Resolved $TEST_DOMAIN to $RES_IP6."
92 else
93   echo "Failed to resolve to proper IP for $TEST_DOMAIN, got $RES_IP6, wanted $TEST_IP6."
94   ret=1
95 fi
96
97 exit $ret