test_gns_rel_expiration.sh 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/bin/sh
  2. # This file is in the public domain.
  3. trap "gnunet-arm -e -c test_gns_lookup.conf" INT
  4. LOCATION=$(which gnunet-config)
  5. if [ -z $LOCATION ]
  6. then
  7. LOCATION="gnunet-config"
  8. fi
  9. if [ -z $(which timeout) ]
  10. then
  11. echo "timeout utility not found which is required for test."
  12. exit 77
  13. fi
  14. $LOCATION --version 1> /dev/null
  15. if test $? != 0
  16. then
  17. echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
  18. exit 77
  19. fi
  20. MY_EGO="myego"
  21. OTHER_EGO="delegatedego"
  22. rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
  23. which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 5"
  24. TEST_IP="127.0.0.1"
  25. gnunet-arm -s -c test_gns_lookup.conf
  26. gnunet-identity -C $MY_EGO -c test_gns_lookup.conf
  27. gnunet-identity -C $OTHER_EGO -c test_gns_lookup.conf
  28. DELEGATED_PKEY=$(gnunet-identity -d -c test_gns_lookup.conf | grep $OTHER_EGO | awk '{print $3}')
  29. gnunet-namestore -p -z $MY_EGO -a -n b -t PKEY -V $DELEGATED_PKEY -e never -c test_gns_lookup.conf
  30. gnunet-namestore -p -z $OTHER_EGO -a -n www -t A -V $TEST_IP -e '5 s' -c test_gns_lookup.conf
  31. gnunet-arm -i gns -c test_gns_lookup.conf
  32. # confirm that lookup currently works
  33. RES_IP=`$DO_TIMEOUT gnunet-gns --raw -u www.b.$MY_EGO -t A -c test_gns_lookup.conf`
  34. # remove entry
  35. gnunet-namestore -z $OTHER_EGO -d -n www -t A -V $TEST_IP -e '5 s' -c test_gns_lookup.conf
  36. # wait for old entry with 5s 'expiration' to definitively expire
  37. sleep 6
  38. # try again, should no longer work
  39. RES_IP_EXP=`$DO_TIMEOUT gnunet-gns --raw -u www.b.$MY_EGO -t A -c test_gns_lookup.conf`
  40. gnunet-namestore -z $MY_EGO -d -n b -t PKEY -V $DELEGATED_PKEY -e never -c test_gns_lookup.conf
  41. gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
  42. gnunet-identity -D $OTHER_EGO -c test_gns_lookup.conf
  43. gnunet-arm -e -c test_gns_lookup.conf
  44. rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
  45. if [ "$RES_IP_EXP" = "$TEST_IP" ]
  46. then
  47. echo "Failed to properly expire IP, got $RES_IP_EXP."
  48. exit 1
  49. fi
  50. if [ "$RES_IP" = "$TEST_IP" ]
  51. then
  52. exit 0
  53. else
  54. echo "Failed to properly resolve IP, got $RES_IP."
  55. exit 1
  56. fi