diff options
Diffstat (limited to 'src/identity/test_plugin_rest_identity.sh')
-rwxr-xr-x | src/identity/test_plugin_rest_identity.sh | 371 |
1 files changed, 155 insertions, 216 deletions
diff --git a/src/identity/test_plugin_rest_identity.sh b/src/identity/test_plugin_rest_identity.sh index f391f827f..22a7a53c6 100755 --- a/src/identity/test_plugin_rest_identity.sh +++ b/src/identity/test_plugin_rest_identity.sh | |||
@@ -1,222 +1,161 @@ | |||
1 | #!/usr/bin/bash | 1 | #!/usr/bin/bash |
2 | 2 | ||
3 | #First, start gnunet-arm and the rest-service. Make sure, no identity exists | 3 | #First, start gnunet-arm and the rest-service. |
4 | #Exit 0 means success, exit 1 means failed test | 4 | #Exit 0 means success, exit 1 means failed test |
5 | 5 | ||
6 | #No test for subsystem available | 6 | #No test for subsystem available |
7 | 7 | ||
8 | link_to_api="http://localhost:7776/identity" | 8 | identity_link="http://localhost:7776/identity" |
9 | wrong_link="http://localhost:7776/idenmmmy" | 9 | wrong_link="http://localhost:7776/identityandmore" |
10 | wrong_link2="http://localhost:7776/identityandmore" | 10 | |
11 | 11 | ||
12 | #Test GET (multiple identities) for error when no identity exists | 12 | curl_get () { |
13 | #The next test case can be ignored if you have already added identities | 13 | #$1 is link |
14 | cache="$(curl --silent "$link_to_api" | grep "error")" | 14 | #$2 is grep |
15 | if [ "" == "$cache" ] | 15 | cache="$(curl -v "$1" 2>&1 | grep "$2")" |
16 | then | 16 | #echo $cache |
17 | exit 1 | 17 | if [ "" == "$cache" ] |
18 | fi | 18 | then |
19 | 19 | exit 1 | |
20 | #Test POST success code, error response code and error json | 20 | fi |
21 | #The next test case can be ignored if you have already added an identity with the name Test | 21 | } |
22 | cache="$(curl -v -X "POST" "$link_to_api" --data "{\"name\":\"Test\"}" 2>&1 | grep "HTTP/1.1 201")" | 22 | |
23 | if [ "" == "$cache" ] | 23 | curl_post () { |
24 | then | 24 | #$1 is link |
25 | exit 1 | 25 | #$2 is data |
26 | fi | 26 | #$3 is grep |
27 | 27 | cache="$(curl -v -X "POST" "$1" --data "$2" 2>&1 | grep "$3")" | |
28 | cache="$(curl -v -X "POST" "$link_to_api" --data "{\"name\":\"Test\"}" 2>&1 | grep "HTTP/1.1 409")" | 28 | #echo $cache |
29 | if [ "" == "$cache" ] | 29 | if [ "" == "$cache" ] |
30 | then | 30 | then |
31 | exit 1 | 31 | exit 1 |
32 | fi | 32 | fi |
33 | 33 | } | |
34 | cache="$(curl -v -X "POST" "$link_to_api" 2>&1 | grep "error")" | 34 | |
35 | if [ "" == "$cache" ] | 35 | curl_delete () { |
36 | then | 36 | #$1 is link |
37 | exit 1 | 37 | #$2 is grep |
38 | fi | 38 | cache="$(curl -v -X "DELETE" "$1" 2>&1 | grep "$2")" |
39 | 39 | #echo $cache | |
40 | cache="$(curl -v -X "POST" "$link_to_api" --data "wrong" 2>&1 | grep "error")" | 40 | if [ "" == "$cache" ] |
41 | if [ "" == "$cache" ] | 41 | then |
42 | then | 42 | exit 1 |
43 | exit 1 | 43 | fi |
44 | fi | 44 | } |
45 | 45 | ||
46 | cache="$(curl -v -X "POST" "$link_to_api" --data "[{}]" 2>&1 | grep "error")" | 46 | curl_put () { |
47 | if [ "" == "$cache" ] | 47 | #$1 is link |
48 | then | 48 | #$2 is data |
49 | exit 1 | 49 | #$3 is grep |
50 | fi | 50 | cache="$(curl -v -X "PUT" "$1" --data "$2" 2>&1 | grep "$3")" |
51 | 51 | #echo $cache | |
52 | cache="$(curl -v -X "POST" "$link_to_api" --data "{\"name\":\"Test\",\"other\":\"Test\"}" 2>&1 | grep "error")" | 52 | if [ "" == "$cache" ] |
53 | if [ "" == "$cache" ] | 53 | then |
54 | then | 54 | exit 1 |
55 | exit 1 | 55 | fi |
56 | fi | 56 | } |
57 | 57 | ||
58 | cache="$(curl -v -X "POST" "$link_to_api" --data "{\"nam\":\"Test\"}" 2>&1 | grep "error")" | 58 | #Test GET |
59 | if [ "" == "$cache" ] | 59 | test="$(gnunet-identity -d)" |
60 | then | 60 | #if no identity exists |
61 | exit 1 | 61 | if [ "" == "$test" ] |
62 | fi | 62 | then |
63 | 63 | curl_get "$identity_link" "error" | |
64 | cache="$(curl -v -X "POST" "$link_to_api" --data "{\"name\":123}" 2>&1 | grep "error")" | 64 | gnunet-identity -C "test_plugin_rest_identity" |
65 | if [ "" == "$cache" ] | 65 | name="$(gnunet-identity -d | awk 'NR==1{print $1}')" |
66 | then | 66 | public="$(gnunet-identity -d | awk 'NR==1{print $3}')" |
67 | exit 1 | 67 | |
68 | fi | 68 | curl_get "${identity_link}?name=$name" "$public" |
69 | 69 | curl_get "${identity_link}?name=" "error" | |
70 | cache="$(curl -v -X "POST" "$link_to_api" --data "{\"name\":""}" 2>&1 | grep "error")" | 70 | curl_get "${identity_link}?name=$public" "error" |
71 | if [ "" == "$cache" ] | 71 | |
72 | then | 72 | curl_get "${identity_link}?pubkey=$public" "$name" |
73 | exit 1 | 73 | curl_get "${identity_link}?pubkey=$name" "error" |
74 | fi | 74 | curl_get "${identity_link}?pubkey=" "error" |
75 | 75 | ||
76 | 76 | gnunet-identity -D "test_plugin_rest_identity" | |
77 | #Test GET (multiple identities) for success and error json | 77 | else |
78 | cache="$(curl --silent "$link_to_api" | grep "error")" | 78 | name="$(gnunet-identity -d | awk 'NR==1{print $1}')" |
79 | if [ "" != "$cache" ] | 79 | public="$(gnunet-identity -d | awk 'NR==1{print $3}')" |
80 | then | 80 | |
81 | exit 1 | 81 | curl_get "${identity_link}?name=$name" "$public" |
82 | fi | 82 | curl_get "${identity_link}?name=" "error" |
83 | 83 | curl_get "${identity_link}?name=$public" "error" | |
84 | 84 | ||
85 | id="$(gnunet-identity -d | grep "Test - " | sed "s/Test - //g")" | 85 | curl_get "${identity_link}?pubkey=$public" "$name" |
86 | #Test GET (one identity) for success and error json | 86 | curl_get "${identity_link}?pubkey=$name" "error" |
87 | #Only lowercase | 87 | curl_get "${identity_link}?pubkey=" "error" |
88 | cache="$(curl --silent "${link_to_api}?name=Test" | grep "error")" | 88 | fi |
89 | if [ "" == "$cache" ] | 89 | |
90 | then | 90 | #Test POST |
91 | exit 1 | 91 | gnunet-identity -D "test_plugin_rest_identity" > /dev/null 2>&1 |
92 | fi | 92 | gnunet-identity -D "test_plugin_rest_identity1" > /dev/null 2>&1 |
93 | #Test GET (one identity) for success and error json | 93 | |
94 | cache="$(curl --silent "${link_to_api}?pubkey=$id" | grep "error")" | 94 | curl_post "${identity_link}" '{"name":"test_plugin_rest_identity"}' "HTTP/1.1 201 Created" |
95 | if [ "" != "$cache" ] | 95 | curl_post "${identity_link}" '{"name":"test_plugin_rest_identity"}' "HTTP/1.1 409" |
96 | then | 96 | curl_post "${identity_link}" '{"name":"Test_plugin_rest_identity"}' "HTTP/1.1 409" |
97 | exit 1 | 97 | curl_post "${identity_link}" '{}' "error" |
98 | fi | 98 | curl_post "${identity_link}" '' "error" |
99 | 99 | curl_post "${identity_link}" '{"name":""}' "error" | |
100 | #Test DELETE success code, error response code and error json | 100 | curl_post "${identity_link}" '{"name":123}' "error" |
101 | #echo "Next tests for DELETE will probably fail when POST fails" | 101 | curl_post "${identity_link}" '{"name":[]}' "error" |
102 | cache="$(curl -v -X "DELETE" "${link_to_api}?pubkey=$id" 2>&1 | grep "HTTP/1.1 404")" | 102 | curl_post "${identity_link}" '{"name1":"test_plugin_rest_identity"}' "error" |
103 | if [ "" != "$cache" ] | 103 | curl_post "${identity_link}" '{"other":""}' "error" |
104 | then | 104 | curl_post "${identity_link}" '{"name":"test_plugin_rest_identity1", "other":"test_plugin_rest_identity2"}' "error" |
105 | exit 1 | 105 | |
106 | fi | 106 | #Test PUT |
107 | 107 | name="$(gnunet-identity -d | grep "test_plugin_rest_identity" | awk 'NR==1{print $1}')" | |
108 | curl --silent -X "POST" "$link_to_api" --data "{\"name\":\"Test\"}" | 108 | public="$(gnunet-identity -d | grep "test_plugin_rest_identity" | awk 'NR==1{print $3}')" |
109 | id="$(gnunet-identity -d | grep "Test - " | sed "s/Test - //g")" | 109 | |
110 | 110 | curl_put "${identity_link}" '{"newname":"test_plugin_rest_identity1","pubkey":"'$public'"}' "HTTP/1.1 204" | |
111 | cache="$(curl -v -X "DELETE" "${link_to_api}?pubkey=df1" 2>&1 | grep "HTTP/1.1 404")" | 111 | curl_put "${identity_link}" '{"newname":"test_plugin_rest_identity1","pubkey":"'$public'"}' "HTTP/1.1 409" |
112 | if [ "" == "$cache" ] | 112 | curl_put "${identity_link}" '{"newname":"test_plugin_rest_identity1","pubkey":"'$public'xx"}' "HTTP/1.1 404" |
113 | then | 113 | curl_put "${identity_link}" '{"newname":"test_plugin_rest_identity1","pubkey":""}' "HTTP/1.1 404" |
114 | exit 1 | 114 | curl_put "${identity_link}" '{"newname":"test_plugin_rest_identity1","pubke":""}' "HTTP/1.1 404" |
115 | fi | 115 | curl_put "${identity_link}" '{"newname":"test_plugin_rest_identity1","pubke":"","other":"sdfdsf"}' "HTTP/1.1 404" |
116 | 116 | curl_put "${identity_link}" '{"newname":"test_plugin_rest_identity1","pubke":"","name":"sdfdsf"}' "HTTP/1.1 404" | |
117 | cache="$(curl -v -X "DELETE" "${link_to_api}?pubke=$id" 2>&1 | grep "error")" | 117 | curl_put "${identity_link}" '{"newname":"test_plugin_rest_identity","pubke":"","name":"test_plugin_rest_identity1"}' "HTTP/1.1 204" |
118 | if [ "" == "$cache" ] | 118 | curl_put "${identity_link}" '{"newnam":"test_plugin_rest_identity","pubkey":"'$public'"}' "error" |
119 | then | 119 | curl_put "${identity_link}" '{"newname":"test_plugin_rest_identity1","name":"test_plugin_rest_identity"}' "HTTP/1.1 204" |
120 | exit 1 | 120 | curl_put "${identity_link}" '{"newname":"TEST_plugin_rest_identity1","name":"test_plugin_rest_identity1"}' "HTTP/1.1 409" |
121 | fi | 121 | curl_put "${identity_link}" '{"newname":"test_plugin_rest_identity1","name":"test_plugin_rest_identity1"}' "HTTP/1.1 409" |
122 | 122 | curl_put "${identity_link}" '{"newname":"test_plugin_rest_identity","name":"test_plugin_rest_identityxxx"}' "HTTP/1.1 404" | |
123 | #Test PUT success code, error response codes and error json | 123 | curl_put "${identity_link}" '{"newname":"test_plugin_rest_identity","name":"test_plugin_rest_identity1"}' "HTTP/1.1 204" |
124 | cache="$(curl -v -X "PUT" "${link_to_api}" --data "{\"newname\":\"NewTest\",\"pubkey\":\"${id}\"}" 2>&1 | grep "HTTP/1.1 204")" | 124 | curl_put "${identity_link}" '{"newnam":"test_plugin_rest_identityfail","name":"test_plugin_rest_identity"}' "error" |
125 | if [ "" == "$cache" ] | 125 | |
126 | then | 126 | |
127 | exit 1 | 127 | #Test subsystem |
128 | fi | 128 | curl_put "${identity_link}" '{"subsystem":"namestore","name":"test_plugin_rest_identity"}' "HTTP/1.1 204" |
129 | 129 | curl_put "${identity_link}" '{"subsystem":"namestore","name":"test_plugin_rest_identity"}' "HTTP/1.1 204" | |
130 | cache="$(curl -v -X "PUT" "${link_to_api}" --data "{\"newname\":\"NewNewTest\",\"pubkey\":\"${id}1\"}" 2>&1 | grep "HTTP/1.1 404")" | 130 | curl_get "${identity_link}?subsystem=namestore" "test_plugin_rest_identity" |
131 | if [ "" == "$cache" ] | 131 | curl_post "${identity_link}" '{"name":"test_plugin_rest_identity1"}' "HTTP/1.1 201 Created" |
132 | then | 132 | public="$(gnunet-identity -d | grep "test_plugin_rest_identity" | awk 'NR==1{print $3}')" |
133 | exit 1 | 133 | curl_put "${identity_link}" '{"subsystem":"namestore","pubkey":"'"$public"'"}' "HTTP/1.1 204" |
134 | fi | 134 | curl_get "${identity_link}?subsystem=namestore" "test_plugin_rest_identity1" |
135 | 135 | curl_get "${identity_link}?subsystem=test_plugin_rest_identity_no_subsystem" "error" | |
136 | # feature: you can rename your identity with its own name. | 136 | curl_put "${identity_link}" '{"subsystem":"test_plugin_rest_identity_no_subsystem","name":"test_plugin_rest_identity1"}' "HTTP/1.1 204" |
137 | # cache="$(curl -v -X "PUT" "$link_to_api" --data "{\"newname\":\"NewTest\",\"pubkey\":\"${id}\"}" 2>&1 | grep "error")" | 137 | curl_get "${identity_link}?subsystem=test_plugin_rest_identity_no_subsystem" "test_plugin_rest_identity1" |
138 | # if [ "" == "$cache" ] | 138 | |
139 | # then | 139 | curl_put "${identity_link}" '{"subsyste":"test_plugin_rest_identity_no_subsystem","name":"test_plugin_rest_identity1"}' "error" |
140 | # exit 1 | 140 | curl_put "${identity_link}" '{"subsystem":"test_plugin_rest_identity_no_subsystem","name":"Test_plugin_rest_identity1"}' "HTTP/1.1 204" |
141 | # fi | 141 | |
142 | 142 | #Test DELETE | |
143 | 143 | curl_delete "${identity_link}?name=test_plugin_rest_identity" "HTTP/1.1 204" | |
144 | cache="$(curl -v -X "PUT" "$link_to_api" 2>&1 | grep "error")" | 144 | curl_get "${identity_link}?name=test_plugin_rest_identity" "error" |
145 | if [ "" == "$cache" ] | 145 | curl_delete "${identity_link}?name=TEST_plugin_rest_identity1" "HTTP/1.1 404" |
146 | then | 146 | curl_delete "${identity_link}?name=test_plugin_rest_identity1" "HTTP/1.1 204" |
147 | exit 1 | 147 | curl_get "${identity_link}?name=test_plugin_rest_identity1" "error" |
148 | fi | 148 | curl_delete "${identity_link}?name=test_plugin_rest_identity_not_found" "HTTP/1.1 404" |
149 | 149 | curl_post "${identity_link}" '{"name":"test_plugin_rest_identity1"}' "HTTP/1.1 201 Created" | |
150 | cache="$(curl -v -X "PUT" "$link_to_api" --data "wrong" 2>&1 | grep "error")" | 150 | public="$(gnunet-identity -d | grep "test_plugin_rest_identity1" | awk 'NR==1{print $3}')" |
151 | if [ "" == "$cache" ] | 151 | curl_delete "${identity_link}?pubkey=$public" "HTTP/1.1 204" |
152 | then | 152 | curl_delete "${identity_link}?pubke=$public" "error" |
153 | exit 1 | 153 | curl_delete "${identity_link}?pubkey=$public&other=232" "HTTP/1.1 404" |
154 | fi | 154 | |
155 | 155 | #Test wrong_link | |
156 | cache="$(curl -v -X "PUT" "$link_to_api" --data "[{}]" 2>&1 | grep "error")" | 156 | curl_get "$wrong_link" "HTTP/1.1 404" |
157 | if [ "" == "$cache" ] | 157 | curl_post "$wrong_link" '{"name":"test_plugin_rest_identity"}' "HTTP/1.1 404" |
158 | then | 158 | curl_put "$wrong_link" '{"newname":"test_plugin_rest_identity1","name":"test_plugin_rest_identity"}' "HTTP/1.1 404" |
159 | exit 1 | 159 | curl_delete "$wrong_link?name=test_plugin_rest_identity1" "HTTP/1.1 404" |
160 | fi | 160 | |
161 | 161 | exit 0; | |
162 | cache="$(curl -v -X "PUT" "$link_to_api" --data "{\"newname\":\"Test\",\"other\":\"Test\",\"pubkey\":\"${id}\"}" 2>&1 | grep "error")" | ||
163 | if [ "" == "$cache" ] | ||
164 | then | ||
165 | exit 1 | ||
166 | fi | ||
167 | |||
168 | cache="$(curl -v -X "PUT" "$link_to_api" --data "{\"newnam\":\"Test\",\"pubkey\":\"${id}\"}" 2>&1 | grep "error")" | ||
169 | if [ "" == "$cache" ] | ||
170 | then | ||
171 | exit 1 | ||
172 | fi | ||
173 | |||
174 | cache="$(curl -v -X "PUT" "$link_to_api" --data "{\"newname\":\"Test\",\"pubke\":\"${id}\"}" 2>&1 | grep "error")" | ||
175 | if [ "" == "$cache" ] | ||
176 | then | ||
177 | exit 1 | ||
178 | fi | ||
179 | |||
180 | cache="$(curl -v -X "PUT" "$link_to_api" --data "{\"newname\":123,\"pubkey\":\"${id}\"}" 2>&1 | grep "error")" | ||
181 | if [ "" == "$cache" ] | ||
182 | then | ||
183 | exit 1 | ||
184 | fi | ||
185 | |||
186 | cache="$(curl -v -X "PUT" "$link_to_api" --data "{\"newname\":"",\"pubkey\":\"${id}\"}" 2>&1 | grep "error")" | ||
187 | if [ "" == "$cache" ] | ||
188 | then | ||
189 | exit 1 | ||
190 | fi | ||
191 | #TODO Missing subsystem test | ||
192 | |||
193 | #Missing OPTIONS success - nothing can really go wrong here | ||
194 | |||
195 | #Test wrong url | ||
196 | cache="$(curl -v "$wrong_link" 2>&1 | grep "HTTP/1.1 404")" | ||
197 | if [ "" == "$cache" ] | ||
198 | then | ||
199 | exit 1 | ||
200 | fi | ||
201 | |||
202 | cache="$(curl -X "PUT" -v "$wrong_link" --data "{\"newname\":\"Testing\",\"pubkey\":\"${id}\"}" 2>&1 | grep "HTTP/1.1 404")" | ||
203 | if [ "" == "$cache" ] | ||
204 | then | ||
205 | exit 1 | ||
206 | fi | ||
207 | |||
208 | cache="$(curl -X "POST" -v "$wrong_link?pubkey=$id" --data "{\"name\":\"Test\"}" 2>&1 | grep "HTTP/1.1 404")" | ||
209 | if [ "" == "$cache" ] | ||
210 | then | ||
211 | exit 1 | ||
212 | fi | ||
213 | |||
214 | cache="$(curl -X "DELETE" -v "${wrong_link}?pubkey=$id" 2>&1 | grep "HTTP/1.1 404")" | ||
215 | if [ "" == "$cache" ] | ||
216 | then | ||
217 | exit 1 | ||
218 | fi | ||
219 | |||
220 | gnunet-identity -D NewTest | ||
221 | |||
222 | exit 0 | ||