-test for mangle support
[oweals/gnunet.git] / src / dns / test_gnunet_dns.sh
1 #!/bin/bash
2
3 ME=`whoami`
4 if [ "$ME" != "root" ]
5 then
6   echo "This test only works if run as root.  Skipping."
7   exit 0
8 fi
9 if ! which sudo > /dev/null 
10 then
11   echo "This test requires sudo.  Skipping."
12   exit 0
13 fi
14 if [ ! -x `which sudo` ]
15 then
16   echo "This test requires sudo.  Skipping."
17   exit 0
18 fi
19 if ! which nslookup > /dev/null
20 then 
21   echo "This test requires nslookup.  Skipping."
22   exit 0
23 fi
24 if [ ! -x `which nslookup` ]
25 then
26   echo "This test requires nslookup.  Skipping."
27   exit 0
28 fi
29 if ! iptables -t mangle --list &> /dev/null
30 then
31   echo "This test requires iptables with 'mangle' support. Skipping."
32 fi
33
34 export PATH=".:$PATH"
35 gnunet-service-dns -c dns.conf &
36 gnunet-dns-redirector -c dns.conf -4 127.0.0.1 &
37 sleep 1
38 # need to run 'nslookup' as 'nobody', as gnunet-service-dns runs as root
39 # and thus 'root' is excepted from DNS interception!
40 LO=`sudo -u nobody nslookup gnunet.org | grep Address | tail -n1`
41 if [ "$LO" != "Address: 127.0.0.1" ]
42 then
43  echo "Fail: got address $LO, wanted 127.0.0.1"
44  ret=1
45 else
46  echo "Test run, with success."
47  ret=0
48 fi
49 kill `jobs -p`
50 exit $ret