fix rest; uncrustify
[oweals/gnunet.git] / src / gns / test_gns_gns2dns_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 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 2>&1
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 2>&1 && DO_TIMEOUT="timeout 15"
47
48 gnunet-arm -s -c test_gns_lookup.conf
49 OUT=`$DO_TIMEOUT gnunet-resolver -c test_gns_lookup.conf gnunet.org`
50 echo $OUT | grep $TEST_IP - > /dev/null || { gnunet-arm -e -c test_gns_lookup.conf ; echo "IPv4 for gnunet.org not found ($OUT), skipping test"; exit 77; }
51 echo $OUT | grep $TEST_IP6 - > /dev/null || { gnunet-arm -e -c test_gns_lookup.conf ; echo "IPv6 for gnunet.org not found ($OUT), skipping test"; exit 77; }
52
53
54 gnunet-identity -C $MY_EGO -c test_gns_lookup.conf
55
56 # set IP address for DNS resolver for resolving in gnunet.org domain
57 # map '$TEST_RECORD_NAME.$MY_EGO' to 'gnunet.org' in DNS
58 gnunet-namestore -p -z $MY_EGO -a -n $TEST_RECORD_NAME -t GNS2DNS -V $TEST_RECORD_GNS2DNS1 -e never -c test_gns_lookup.conf
59 gnunet-namestore -p -z $MY_EGO -a -n $TEST_RECORD_NAME -t GNS2DNS -V $TEST_RECORD_GNS2DNS2 -e never -c test_gns_lookup.conf
60 gnunet-namestore -p -z $MY_EGO -a -n $TEST_RECORD_NAME -t GNS2DNS -V $TEST_RECORD_GNS2DNS3 -e never -c test_gns_lookup.conf
61
62
63 echo "EGOs:"
64 gnunet-identity -d
65
66 # lookup 'www.gnunet.org', IPv4
67 RES_IP=`$DO_TIMEOUT gnunet-gns --raw -u $TEST_DOMAIN -t A -c test_gns_lookup.conf`
68 # lookup 'www.gnunet.org', IPv6
69 RES_IP6=`$DO_TIMEOUT gnunet-gns --raw -u $TEST_DOMAIN -t AAAA -c test_gns_lookup.conf`
70
71 # clean up
72 gnunet-namestore -z $MY_EGO -d -n $TEST_RECORD_NAME -t GNS2DNS -V $TEST_RECORD_GNS2DNS1 -e never -c test_gns_lookup.conf
73 gnunet-namestore -z $MY_EGO -d -n $TEST_RECORD_NAME -t GNS2DNS -V $TEST_RECORD_GNS2DNS2 -e never -c test_gns_lookup.conf
74 gnunet-namestore -z $MY_EGO -d -n $TEST_RECORD_NAME -t GNS2DNS -V $TEST_RECORD_GNS2DNS3 -e never -c test_gns_lookup.conf
75 gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
76 gnunet-arm -e -c test_gns_lookup.conf
77 rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
78
79 ret=0
80 if echo "$RES_IP" | grep "$TEST_IP" > /dev/null
81 then
82   echo "PASS: Resolved $TEST_DOMAIN to $RES_IP."
83 else
84   echo "Failed to resolve to proper IP for $TEST_DOMAIN, got $RES_IP, wanted $TEST_IP."
85   ret=1
86 fi
87
88 if echo "$RES_IP6" | grep "$TEST_IP6" > /dev/null
89 then
90   echo "PASS: Resolved $TEST_DOMAIN to $RES_IP6."
91 else
92   echo "Failed to resolve to proper IP for $TEST_DOMAIN, got $RES_IP6, wanted $TEST_IP6."
93   ret=1
94 fi
95
96 exit $ret