test_gns_multiple_record_lookup.sh 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/bin/bash
  2. # This file is in the public domain.
  3. trap "gnunet-arm -e -c test_gns_lookup_peer1.conf" INT
  4. trap "gnunet-arm -e -c test_gns_lookup_peer2.conf" INT
  5. which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 5"
  6. unset XDG_DATA_HOME
  7. unset XDG_CONFIG_HOME
  8. unset XDG_CACHE_HOME
  9. LOCATION=$(which gnunet-config)
  10. if [ -z $LOCATION ]
  11. then
  12. LOCATION="gnunet-config"
  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. rm -rf `gnunet-config -c test_gns_lookup_peer1.conf -f -s paths -o GNUNET_TEST_HOME`
  21. rm -rf `gnunet-config -c test_gns_lookup_peer2.conf -f -s paths -o GNUNET_TEST_HOME`
  22. MY_EGO="localego"
  23. OTHER_EGO="remoteego"
  24. TEST_IP="127.0.0.1"
  25. TEST_IPV6="dead::beef"
  26. LABEL="fnord"
  27. gnunet-arm -s -c test_gns_lookup_peer2.conf
  28. PKEY=`$DO_TIMEOUT gnunet-identity -V -C $OTHER_EGO -c test_gns_lookup_peer2.conf`
  29. # Note: if zonemaster is kept running, it MAY publish the "A" record in the
  30. # DHT immediately and then _LATER_ also the "AAAA" record. But as then there
  31. # will be TWO valid blocks in the DHT (one with only A and one with A and
  32. # AAAA), the subsequent GET for both may fail and only return the result with
  33. # just the "A" record).
  34. # If we _waited_ until the original block with just "A" expired, everything
  35. # would be fine, but we don't want to do that for the test, so we
  36. # simply pause publishing to the DHT until all records are defined.
  37. # In the future, it would be good to have an enhanced gnunet-namestore command
  38. # that would read a series of changes to be made to a record set from
  39. # stdin and do them _all_ *atomically*. Then we would not need to do this.
  40. gnunet-arm -c test_gns_lookup_peer2.conf -k zonemaster
  41. gnunet-arm -c test_gns_lookup_peer2.conf -k zonemaster-monitor
  42. gnunet-namestore -p -z $OTHER_EGO -a -n $LABEL -t A -V $TEST_IP -e 3600s -c test_gns_lookup_peer2.conf
  43. gnunet-namestore -p -z $OTHER_EGO -a -n $LABEL -t AAAA -V $TEST_IPV6 -e 3600s -c test_gns_lookup_peer2.conf
  44. gnunet-namestore -D -z $OTHER_EGO -n $LABEL
  45. gnunet-arm -c test_gns_lookup_peer2.conf -i zonemaster
  46. gnunet-arm -c test_gns_lookup_peer2.conf -i zonemaster-monitor
  47. gnunet-arm -s -c test_gns_lookup_peer1.conf
  48. RESP=`$DO_TIMEOUT gnunet-gns --raw -u $LABEL.$PKEY -t ANY -c test_gns_lookup_peer1.conf`
  49. RESP1=`$DO_TIMEOUT gnunet-gns --raw -u $LABEL.$PKEY -t A -c test_gns_lookup_peer1.conf`
  50. RESP2=`$DO_TIMEOUT gnunet-gns --raw -u $LABEL.$PKEY -t AAAA -c test_gns_lookup_peer1.conf`
  51. gnunet-arm -e -c test_gns_lookup_peer1.conf
  52. gnunet-arm -e -c test_gns_lookup_peer2.conf
  53. rm -rf `gnunet-config -c test_gns_lookup_peer1.conf -f -s paths -o GNUNET_TEST_HOME`
  54. rm -rf `gnunet-config -c test_gns_lookup_peer2.conf -f -s paths -o GNUNET_TEST_HOME`
  55. RESPONSES=($(echo $RESP | tr "\n" " " ))
  56. if [ "$RESP1" == "$TEST_IP" ]
  57. then
  58. echo "PASS: A record resolution from DHT via separate peer"
  59. else
  60. echo "FAIL: A record resolution from DHT via separate peer, got $RESP1, expected $TEST_IP"
  61. exit 1
  62. fi
  63. if [ "$RESP2" == "$TEST_IPV6" ]
  64. then
  65. echo "PASS: AAAA record resolution from DHT via separate peer"
  66. else
  67. echo "FAIL: AAAA record resolution from DHT via separate peer, got $RESP2, expected $TEST_IPV6"
  68. exit 1
  69. fi
  70. if [[ "${RESPONSES[0]} ${RESPONSES[1]}" == "$TEST_IPV6 $TEST_IP" ]] || [[ "${RESPONSES[0]} ${RESPONSES[1]}" == "$TEST_IP $TEST_IPV6" ]]
  71. then
  72. echo "PASS: ANY record resolution from DHT via separate peer"
  73. else
  74. echo "FAIL: ANY record resolution from DHT via separate peer, got $RESP, expected $TEST_IPV6 $TEST_IP or $TEST_IP $TEST_IPV6"
  75. exit 1
  76. fi