aboutsummaryrefslogtreecommitdiff
path: root/src/identity/test_plugin_rest_identity.sh
diff options
context:
space:
mode:
Diffstat (limited to 'src/identity/test_plugin_rest_identity.sh')
-rwxr-xr-xsrc/identity/test_plugin_rest_identity.sh216
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
8link_to_api="http://localhost:7776/identity"
9wrong_link="http://localhost:7776/idenmmmy"
10wrong_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
14cache="$(curl --silent "$link_to_api" | grep "error")"
15if [ "" == "$cache" ]
16then
17 exit 1
18fi
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
22cache="$(curl -v -X "POST" "$link_to_api" --data "{\"name\":\"Test\"}" 2>&1 | grep "HTTP/1.1 201")"
23if [ "" == "$cache" ]
24then
25 exit 1
26fi
27
28cache="$(curl -v -X "POST" "$link_to_api" --data "{\"name\":\"Test\"}" 2>&1 | grep "HTTP/1.1 409")"
29if [ "" == "$cache" ]
30then
31 exit 1
32fi
33
34cache="$(curl -v -X "POST" "$link_to_api" 2>&1 | grep "error")"
35if [ "" == "$cache" ]
36then
37 exit 1
38fi
39
40cache="$(curl -v -X "POST" "$link_to_api" --data "wrong" 2>&1 | grep "error")"
41if [ "" == "$cache" ]
42then
43 exit 1
44fi
45
46cache="$(curl -v -X "POST" "$link_to_api" --data "[{}]" 2>&1 | grep "error")"
47if [ "" == "$cache" ]
48then
49 exit 1
50fi
51
52cache="$(curl -v -X "POST" "$link_to_api" --data "{\"name\":\"Test\",\"other\":\"Test\"}" 2>&1 | grep "error")"
53if [ "" == "$cache" ]
54then
55 exit 1
56fi
57
58cache="$(curl -v -X "POST" "$link_to_api" --data "{\"nam\":\"Test\"}" 2>&1 | grep "error")"
59if [ "" == "$cache" ]
60then
61 exit 1
62fi
63
64cache="$(curl -v -X "POST" "$link_to_api" --data "{\"name\":123}" 2>&1 | grep "error")"
65if [ "" == "$cache" ]
66then
67 exit 1
68fi
69
70cache="$(curl -v -X "POST" "$link_to_api" --data "{\"name\":""}" 2>&1 | grep "error")"
71if [ "" == "$cache" ]
72then
73 exit 1
74fi
75
76
77#Test GET (multiple identities) for success and error json
78cache="$(curl --silent "$link_to_api" | grep "error")"
79if [ "" != "$cache" ]
80then
81 exit 1
82fi
83
84
85id="$(gnunet-identity -d | grep "Test - " | sed "s/Test - //g")"
86#Test GET (one identity) for success and error json
87cache="$(curl --silent "${link_to_api}?pubkey=$id" | grep "error")"
88if [ "" != "$cache" ]
89then
90 exit 1
91fi
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"
96cache="$(curl -v -X "DELETE" "${link_to_api}?pubkey=$id" 2>&1 | grep "HTTP/1.1 404")"
97if [ "" != "$cache" ]
98then
99 exit 1
100fi
101
102curl --silent -X "POST" "$link_to_api" --data "{\"name\":\"Test\"}"
103id="$(gnunet-identity -d | grep "Test - " | sed "s/Test - //g")"
104
105cache="$(curl -v -X "DELETE" "${link_to_api}?pubkey=df1" 2>&1 | grep "HTTP/1.1 404")"
106if [ "" == "$cache" ]
107then
108 exit 1
109fi
110
111cache="$(curl -v -X "DELETE" "${link_to_api}?pubke=$id" 2>&1 | grep "error")"
112if [ "" == "$cache" ]
113then
114 exit 1
115fi
116
117#Test PUT success code, error response codes and error json
118cache="$(curl -v -X "PUT" "${link_to_api}" --data "{\"newname\":\"NewTest\",\"pubkey\":\"${id}\"}" 2>&1 | grep "HTTP/1.1 204")"
119if [ "" == "$cache" ]
120then
121 exit 1
122fi
123
124cache="$(curl -v -X "PUT" "${link_to_api}" --data "{\"newname\":\"NewNewTest\",\"pubkey\":\"${id}1\"}" 2>&1 | grep "HTTP/1.1 404")"
125if [ "" == "$cache" ]
126then
127 exit 1
128fi
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
138cache="$(curl -v -X "PUT" "$link_to_api" 2>&1 | grep "error")"
139if [ "" == "$cache" ]
140then
141 exit 1
142fi
143
144cache="$(curl -v -X "PUT" "$link_to_api" --data "wrong" 2>&1 | grep "error")"
145if [ "" == "$cache" ]
146then
147 exit 1
148fi
149
150cache="$(curl -v -X "PUT" "$link_to_api" --data "[{}]" 2>&1 | grep "error")"
151if [ "" == "$cache" ]
152then
153 exit 1
154fi
155
156cache="$(curl -v -X "PUT" "$link_to_api" --data "{\"newname\":\"Test\",\"other\":\"Test\",\"pubkey\":\"${id}\"}" 2>&1 | grep "error")"
157if [ "" == "$cache" ]
158then
159 exit 1
160fi
161
162cache="$(curl -v -X "PUT" "$link_to_api" --data "{\"newnam\":\"Test\",\"pubkey\":\"${id}\"}" 2>&1 | grep "error")"
163if [ "" == "$cache" ]
164then
165 exit 1
166fi
167
168cache="$(curl -v -X "PUT" "$link_to_api" --data "{\"newname\":\"Test\",\"pubke\":\"${id}\"}" 2>&1 | grep "error")"
169if [ "" == "$cache" ]
170then
171 exit 1
172fi
173
174cache="$(curl -v -X "PUT" "$link_to_api" --data "{\"newname\":123,\"pubkey\":\"${id}\"}" 2>&1 | grep "error")"
175if [ "" == "$cache" ]
176then
177 exit 1
178fi
179
180cache="$(curl -v -X "PUT" "$link_to_api" --data "{\"newname\":"",\"pubkey\":\"${id}\"}" 2>&1 | grep "error")"
181if [ "" == "$cache" ]
182then
183 exit 1
184fi
185#TODO Missing subsystem test
186
187#Missing OPTIONS success - nothing can really go wrong here
188
189#Test wrong url
190cache="$(curl -v "$wrong_link" 2>&1 | grep "HTTP/1.1 404")"
191if [ "" == "$cache" ]
192then
193 exit 1
194fi
195
196cache="$(curl -X "PUT" -v "$wrong_link" --data "{\"newname\":\"Testing\",\"pubkey\":\"${id}\"}" 2>&1 | grep "HTTP/1.1 404")"
197if [ "" == "$cache" ]
198then
199 exit 1
200fi
201
202cache="$(curl -X "POST" -v "$wrong_link?pubkey=$id" --data "{\"name\":\"Test\"}" 2>&1 | grep "HTTP/1.1 404")"
203if [ "" == "$cache" ]
204then
205 exit 1
206fi
207
208cache="$(curl -X "DELETE" -v "${wrong_link}?pubkey=$id" 2>&1 | grep "HTTP/1.1 404")"
209if [ "" == "$cache" ]
210then
211 exit 1
212fi
213
214gnunet-identity -D NewTest
215
216exit 0