test_plugin_rest_identity.sh 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #!/usr/bin/bash
  2. #First, start gnunet-arm and the rest-service.
  3. #Exit 0 means success, exit 1 means failed test
  4. identity_link="http://localhost:7776/identity"
  5. wrong_link="http://localhost:7776/identityandmore"
  6. curl_get () {
  7. #$1 is link
  8. #$2 is grep
  9. cache="$(curl -v "$1" 2>&1 | grep "$2")"
  10. #echo $cache
  11. if [ "" == "$cache" ]
  12. then
  13. exit 1
  14. fi
  15. }
  16. curl_post () {
  17. #$1 is link
  18. #$2 is data
  19. #$3 is grep
  20. cache="$(curl -v -X "POST" "$1" --data "$2" 2>&1 | grep "$3")"
  21. #echo $cache
  22. if [ "" == "$cache" ]
  23. then
  24. exit 1
  25. fi
  26. }
  27. curl_delete () {
  28. #$1 is link
  29. #$2 is grep
  30. cache="$(curl -v -X "DELETE" "$1" 2>&1 | grep "$2")"
  31. #echo $cache
  32. if [ "" == "$cache" ]
  33. then
  34. exit 1
  35. fi
  36. }
  37. curl_put () {
  38. #$1 is link
  39. #$2 is data
  40. #$3 is grep
  41. cache="$(curl -v -X "PUT" "$1" --data "$2" 2>&1 | grep "$3")"
  42. #echo $cache
  43. if [ "" == "$cache" ]
  44. then
  45. exit 1
  46. fi
  47. }
  48. #Test GET
  49. test="$(gnunet-identity -d)"
  50. #if no identity exists
  51. if [ "" == "$test" ]
  52. then
  53. curl_get "$identity_link/all" "error"
  54. gnunet-identity -C "test_plugin_rest_identity"
  55. name="$(gnunet-identity -d | awk 'NR==1{print $1}')"
  56. public="$(gnunet-identity -d | awk 'NR==1{print $3}')"
  57. curl_get "${identity_link}/name/$name" "$public"
  58. curl_get "${identity_link}/name/$public" "error"
  59. curl_get "${identity_link}/name/" "error"
  60. curl_get "${identity_link}/pubkey/$public" "$name"
  61. curl_get "${identity_link}/pubkey/$name" "error"
  62. curl_get "${identity_link}/pubkey/" "error"
  63. gnunet-identity -D "test_plugin_rest_identity"
  64. else
  65. name="$(gnunet-identity -d | awk 'NR==1{print $1}')"
  66. public="$(gnunet-identity -d | awk 'NR==1{print $3}')"
  67. curl_get "${identity_link}/name/$name" "$public"
  68. curl_get "${identity_link}/name/$public" "error"
  69. curl_get "${identity_link}/name/" "error"
  70. curl_get "${identity_link}/pubkey/$public" "$name"
  71. curl_get "${identity_link}/pubkey/$name" "error"
  72. curl_get "${identity_link}/pubkey/" "error"
  73. fi
  74. #Test POST
  75. gnunet-identity -D "test_plugin_rest_identity" > /dev/null 2>&1
  76. gnunet-identity -D "test_plugin_rest_identity1" > /dev/null 2>&1
  77. curl_post "${identity_link}" '{"name":"test_plugin_rest_identity"}' "HTTP/1.1 201 Created"
  78. curl_post "${identity_link}" '{"name":"test_plugin_rest_identity"}' "HTTP/1.1 409"
  79. curl_post "${identity_link}" '{"name":"Test_plugin_rest_identity"}' "HTTP/1.1 409"
  80. curl_post "${identity_link}" '{}' "error"
  81. curl_post "${identity_link}" '' "error"
  82. curl_post "${identity_link}" '{"name":""}' "error"
  83. curl_post "${identity_link}" '{"name":123}' "error"
  84. curl_post "${identity_link}" '{"name":[]}' "error"
  85. curl_post "${identity_link}" '{"name1":"test_plugin_rest_identity"}' "error"
  86. curl_post "${identity_link}" '{"other":""}' "error"
  87. curl_post "${identity_link}" '{"name":"test_plugin_rest_identity1", "other":"test_plugin_rest_identity2"}' "error"
  88. #Test PUT
  89. name="$(gnunet-identity -d | grep "test_plugin_rest_identity" | awk 'NR==1{print $1}')"
  90. public="$(gnunet-identity -d | grep "test_plugin_rest_identity" | awk 'NR==1{print $3}')"
  91. curl_put "${identity_link}/pubkey/$public" '{"newname":"test_plugin_rest_identity1"}' "HTTP/1.1 204"
  92. curl_put "${identity_link}/pubkey/$public" '{"newname":"test_plugin_rest_identity1"}' "HTTP/1.1 409"
  93. curl_put "${identity_link}/pubkey/${public}xx" '{"newname":"test_plugin_rest_identity1"}' "HTTP/1.1 404"
  94. curl_put "${identity_link}/pubkey/" '{"newname":"test_plugin_rest_identity1"}' "HTTP/1.1 404"
  95. curl_put "${identity_link}/pubke" '{"newname":"test_plugin_rest_identity1"}' "error"
  96. curl_put "${identity_link}" '{"newname":"test_plugin_rest_identity1","other":"sdfdsf"}' "error"
  97. curl_put "${identity_link}/pubkey/$name" '{"newname":"test_plugin_rest_identity1"}' "HTTP/1.1 404"
  98. curl_put "${identity_link}/name/test_plugin_rest_identity1" '{"newname":"test_plugin_rest_identity"}' "HTTP/1.1 204"
  99. curl_put "${identity_link}/pubkey/$public" '{"newnam":"test_plugin_rest_identity"}' "error"
  100. curl_put "${identity_link}/name/test_plugin_rest_identity" '{"newname":"test_plugin_rest_identity1"}' "HTTP/1.1 204"
  101. curl_put "${identity_link}/name/test_plugin_rest_identity1" '{"newname":"TEST_plugin_rest_identity1"}' "HTTP/1.1 409"
  102. curl_put "${identity_link}/name/test_plugin_rest_identity1" '{"newname":"test_plugin_rest_identity1"}' "HTTP/1.1 409"
  103. curl_put "${identity_link}/name/test_plugin_rest_identityxxx" '{"newname":"test_plugin_rest_identity"}' "HTTP/1.1 404"
  104. curl_put "${identity_link}/name/test_plugin_rest_identity1" '{"newname":"test_plugin_rest_identity"}' "HTTP/1.1 204"
  105. curl_put "${identity_link}/name/test_plugin_rest_identity" '{"newnam":"test_plugin_rest_identityfail"}' "error"
  106. #Test subsystem
  107. curl_put "${identity_link}/subsystem/test_plugin_rest_identity" '{"subsystem":"namestore"}' "HTTP/1.1 204"
  108. curl_put "${identity_link}/subsystem/test_plugin_rest_identity" '{"subsystem":"namestore"}' "HTTP/1.1 204"
  109. curl_get "${identity_link}/subsystem/namestore" "test_plugin_rest_identity"
  110. public="$(gnunet-identity -d | grep "test_plugin_rest_identity" | awk 'NR==1{print $3}')"
  111. curl_put "${identity_link}/subsystem/$public" '{"subsystem":"namestore"}' "HTTP/1.1 404"
  112. curl_post "${identity_link}" '{"name":"test_plugin_rest_identity1"}' "HTTP/1.1 201 Created"
  113. curl_get "${identity_link}/subsystem/test_plugin_rest_identity_no_subsystem" "error"
  114. curl_put "${identity_link}/subsystem/test_plugin_rest_identity1" '{"subsystem":"test_plugin_rest_identity_no_subsystem"}' "HTTP/1.1 204"
  115. curl_get "${identity_link}/subsystem/test_plugin_rest_identity_no_subsystem" "test_plugin_rest_identity1"
  116. curl_put "${identity_link}/subsystem/test_plugin_rest_identity1" '{"subsyste":"test_plugin_rest_identity_no_subsystem"}' "error"
  117. curl_put "${identity_link}/subsystem/test_plugin_rest_identity1" '{"subsystem":"test_plugin_rest_identity_no_subsystem"}' "HTTP/1.1 204"
  118. #Test DELETE
  119. curl_delete "${identity_link}/name/test_plugin_rest_identity" "HTTP/1.1 204"
  120. curl_get "${identity_link}/name/test_plugin_rest_identity" "error"
  121. curl_delete "${identity_link}/name/TEST_plugin_rest_identity1" "HTTP/1.1 204"
  122. curl_delete "${identity_link}/name/test_plugin_rest_identity1" "HTTP/1.1 404"
  123. curl_get "${identity_link}/name/test_plugin_rest_identity1" "error"
  124. curl_delete "${identity_link}/name/test_plugin_rest_identity_not_found" "HTTP/1.1 404"
  125. curl_post "${identity_link}" '{"name":"test_plugin_rest_identity1"}' "HTTP/1.1 201 Created"
  126. public="$(gnunet-identity -d | grep "test_plugin_rest_identity1" | awk 'NR==1{print $3}')"
  127. curl_delete "${identity_link}/pubkey/$public" "HTTP/1.1 204"
  128. curl_delete "${identity_link}/pubke/$public" "error"
  129. curl_delete "${identity_link}/pubkey/${public}other=232" "HTTP/1.1 404"
  130. #Test wrong_link
  131. curl_get "$wrong_link" "HTTP/1.1 404"
  132. curl_post "$wrong_link" '{"name":"test_plugin_rest_identity"}' "HTTP/1.1 404"
  133. curl_put "$wrong_link/name/test_plugin_rest_identity" '{"newname":"test_plugin_rest_identity1"}' "HTTP/1.1 404"
  134. curl_delete "$wrong_link/name/test_plugin_rest_identity1" "HTTP/1.1 404"
  135. exit 0;