test_namestore_put_multiple.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #!/bin/bash
  2. # Check for required packages
  3. if ! [ -x "$(command -v gnunet-namestore)" ]; then
  4. echo 'bind/named is not installed' >&2
  5. exit 1
  6. fi
  7. # Check if gnunet is running
  8. gnunet-arm -I 2&>1 /dev/null
  9. ret=$?
  10. if [ 0 -ne $ret ]; then
  11. echo 'gnunet services are not running'
  12. exit 1
  13. fi
  14. ## GNUNET part
  15. # Check if identity exists and delets and readds it to get rid of entries in zone
  16. gnunet-identity -d | grep randomtestingid 2>&1 /dev/null
  17. ret=$?
  18. if [ 0 -ne $ret ]; then
  19. gnunet-identity -D randomtestingid
  20. gnunet-identity -C randomtestingid
  21. fi
  22. function minimize_ttl {
  23. ttl=10000000
  24. arr=$1
  25. # parse each element and update ttl to smallest one
  26. for i in "${arr[@]}"
  27. do
  28. currttl=$(echo -n "$i" | cut -d' ' -f1)
  29. if [ "$currttl" -lt "$ttl" ]
  30. then
  31. ttl=$currttl
  32. fi
  33. done
  34. echo "$ttl"
  35. }
  36. function get_record_type {
  37. arr=$1
  38. typ=$(echo -n "${arr[0]}" | cut -d' ' -f2)
  39. echo "$typ"
  40. }
  41. function get_value {
  42. arr=$1
  43. val=$(echo -n "${arr[0]}" | cut -d' ' -f4-)
  44. echo "$val"
  45. }
  46. function testing {
  47. label=$1
  48. records=$2
  49. recordstring=""
  50. typ=$(get_record_type "${records[@]}")
  51. for i in "${records[@]}"
  52. do
  53. recordstring+="-R $i"
  54. done
  55. #echo "$recordstring"
  56. gnunet-namestore -z randomtestingid -n "$label" "$recordstring" 2>&1 /dev/null
  57. if [ 0 -ne $ret ]; then
  58. echo "failed to add record $label: $recordstring"
  59. fi
  60. gnunet-gns -t "$typ" -u foo2.randomtestingid 2>&1 /dev/null
  61. if [ 0 -ne $ret ]; then
  62. echo "record $label could not be found"
  63. fi
  64. }
  65. # TEST CASES
  66. # 1
  67. echo "Testing adding of single A record with -R"
  68. testing test1 "${arr[@]}"
  69. # 2
  70. echo "Testing adding of multiple A records with -R"
  71. declare -a arr=('1200 A n 127.0.0.1' '2400 A n 127.0.0.2')
  72. testing test2 "${arr[@]}"
  73. # 3
  74. echo "Testing adding of multiple different records with -R"
  75. declare -a arr=('1200 A n 127.0.0.1' '2400 AAAA n 2002::')
  76. testing test3 "${arr[@]}"
  77. # 4
  78. echo "Testing adding of single GNS2DNS record with -R"
  79. declare -a arr=('86400 GNS2DNS n gnu.org@127.0.0.1')
  80. testing test4 "${arr[@]}"
  81. # 5
  82. echo "Testing adding of single GNS2DNS shadow record with -R"
  83. declare -a arr=('86409 GNS2DNS s gnu.org@127.0.0.250')
  84. testing test5 "${arr[@]}"
  85. # 6
  86. echo "Testing adding of multiple GNS2DNS record with -R"
  87. declare -a arr=('1 GNS2DNS n gnunet.org@127.0.0.1' '3600 GNS2DNS s gnunet.org@127.0.0.2')
  88. testing test6 "${arr[@]}"
  89. val=$(gnunet-gns -t GNS2DNS -u test6.randomtestingid)
  90. if [[ $val == *"127.0.0.1"* ]]; then
  91. echo "shadow!"
  92. fi
  93. echo "Sleeping to let record expire"
  94. sleep 5
  95. val=$(gnunet-gns -t GNS2DNS -u test6.randomtestingid)
  96. if [[ $val == *"127.0.0.2"* ]]; then
  97. echo "no shadow!"
  98. fi
  99. # 7
  100. echo "Testing adding MX record with -R"
  101. declare -a arr=('3600 MX n 10,mail')
  102. testing test7 "${arr[@]}"
  103. # 8
  104. echo "Testing adding TXT record with -R"
  105. declare -a arr=('3600 TXT n Pretty_Unicorns')
  106. testing test8 "${arr[@]}"
  107. # 8
  108. echo "Testing adding TXT record with -R"
  109. declare -a arr=('3600 SRV n _autodiscover_old._tcp.bfh.ch.')
  110. testing test8 "${arr[@]}"
  111. # CLEANUP
  112. gnunet-identity -D randomtestingid