test_gns_cname_lookup.sh 3.0 KB

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