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