test_plugin_rest_namestore.sh 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #!/bin/sh
  2. trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT
  3. LOCATION=$(which gnunet-config)
  4. if [ -z $LOCATION ]
  5. then
  6. LOCATION="gnunet-config"
  7. fi
  8. $LOCATION --version 1> /dev/null
  9. if test $? != 0
  10. then
  11. echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
  12. exit 77
  13. fi
  14. rm -rf `gnunet-config -c test_namestore_api.conf -f -s paths -o GNUNET_TEST_HOME`
  15. namestore_link="http://localhost:7776/namestore"
  16. wrong_link="http://localhost:7776/namestoreandmore"
  17. curl_get () {
  18. #$1 is link
  19. #$2 is grep
  20. resp=$(curl -v "$1" 2>&1)
  21. cache="$(echo $resp | grep "$2")"
  22. #echo $cache
  23. if [ "" = "$cache" ]
  24. then
  25. echo "Error in get response: $resp, expected $2"
  26. gnunet-arm -e -c test_namestore_api.conf
  27. exit 1
  28. fi
  29. }
  30. curl_post () {
  31. #$1 is link
  32. #$2 is data
  33. #$3 is grep
  34. resp=$(curl -v -X "POST" "$1" --data "$2" 2>&1)
  35. cache="$(echo $resp | grep "$3")"
  36. #echo $cache
  37. if [ "" = "$cache" ]
  38. then
  39. echo "Error in post response: $resp ($2), expected $3"
  40. gnunet-arm -e -c test_namestore_api.conf
  41. exit 1
  42. fi
  43. }
  44. curl_delete () {
  45. #$1 is link
  46. #$2 is grep
  47. resp=$(curl -v -X "DELETE" "$1" 2>&1)
  48. cache="$(echo $resp | grep "$2")"
  49. #echo $cache
  50. if [ "" = "$cache" ]
  51. then
  52. echo "Error in delete response: $resp, expected $2"
  53. gnunet-arm -e -c test_namestore_api.conf
  54. exit 1
  55. fi
  56. }
  57. # curl_put () {
  58. # #$1 is link
  59. # #$2 is data
  60. # #$3 is grep
  61. # cache="$(curl -v -X "PUT" "$1" --data "$2" 2>&1 | grep "$3")"
  62. # #echo $cache
  63. # if [ "" == "$cache" ]
  64. # then
  65. # exit 1
  66. # fi
  67. # }
  68. #Test subsystem default identity
  69. TEST_ID="test"
  70. gnunet-arm -s -c test_namestore_api.conf
  71. gnunet-arm -i rest -c test_namestore_api.conf
  72. #Test GET
  73. gnunet-identity -C $TEST_ID -c test_namestore_api.conf
  74. test="$(gnunet-namestore -D -z $TEST_ID -c test_namestore_api.conf)"
  75. name=$TEST_ID
  76. public="$(gnunet-identity -d -c test_namestore_api.conf | grep $TEST_ID | awk 'NR==1{print $3}')"
  77. echo "$name $public"
  78. valgrind gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8" -t "PKEY" -c test_namestore_api.conf
  79. #curl_get "${namestore_link}" "HTTP/1.1 200 OK"
  80. curl_get "${namestore_link}/$name" "HTTP/1.1 200 OK"
  81. curl_get "${namestore_link}/$public" "error"
  82. gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf
  83. #Test POST with NAME
  84. curl_post "${namestore_link}/$name" '{"data": [{"value":"000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8", "record_type":"PKEY", "expiration_time":"1d","private": false, "relative_expiration": false, "supplemental": false, "shadow": false}],"record_name":"test_entry"}' "HTTP/1.1 204 No Content"
  85. gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1
  86. # invalid values
  87. curl_post "${namestore_link}/$name" '{"data": [{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRGxxx", "record_type":"PKEY", "expiration_time":"1d","private": false, "relative_expiration": false, "supplemental": false, "shadow": false}],"record_name":"test_entry"}' "error"
  88. gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1
  89. curl_post "${namestore_link}/$name" '{"data": [{"value":"", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name"}]:"test_entry"}' "error"
  90. gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1
  91. curl_post "${namestore_link}/$name" '{"data": [{"record_type":"PKEY", "expiration_time":"1d","flag":0}],"record_name":"test_entry"}' "error"
  92. gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1
  93. #expirations
  94. curl_post "${namestore_link}/$name" '{"data": [{"value":"000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8", "record_type":"PKEY", "expiration_time":"0d","private": false, "relative_expiration": true, "supplemental": false, "shadow": false}],"record_name":"test_entry"}' "HTTP/1.1 204"
  95. gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1
  96. curl_post "${namestore_link}/$name" '{"data": [{"value":"000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8", "record_type":"PKEY", "expiration_time":"10000d","private": false, "relative_expiration": true, "supplemental": false, "shadow": false}],"record_name":"test_entry"}' "HTTP/1.1 204"
  97. gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1
  98. curl_post "${namestore_link}/$name" '{"data": [{"value":"000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8", "record_type":"PKEY", "expiration_time":"now","private": false, "relative_expiration": false, "supplemental": false, "shadow": false}],"record_name":"test_entry"}' "error"
  99. gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1
  100. curl_post "${namestore_link}/$name" '{"data": [{"value":"000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8", "record_type":"PKEY", "expiration_time_missing":"1d","private": false, "relative_expiration": false, "supplemental": false, "shadow": false}],"record_name":"test_entry"}' "error"
  101. gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1
  102. #record_name
  103. curl_post "${namestore_link}/$name" '{"data": [{"value":"000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8", "record_type":"PKEY", "expiration_time":"1d","private": false, "relative_expiration": false, "supplemental": false, "shadow": false}],"record_name":""}' "error"
  104. gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1
  105. curl_post "${namestore_link}/$name" '{"data": [{"value":"000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8", "record_type":"PKEY", "expiration_time":"1d","private": false, "relative_expiration": false, "supplemental": false, "shadow": false}],"record_name_missing":"test_entry"}' "error"
  106. gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1
  107. #Test DELETE
  108. gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8" -t "PKEY" -c test_namestore_api.conf
  109. curl_delete "${namestore_link}/$name/test_entry" "HTTP/1.1 204"
  110. curl_delete "${namestore_link}/$name/test_entry" "error"
  111. gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8" -t "PKEY" -c test_namestore_api.conf
  112. curl_delete "${namestore_link}/$public/test_entry" "error"
  113. gnunet-arm -e -c test_namestore_api.conf
  114. exit 0;