summaryrefslogtreecommitdiff
path: root/src/identity/test_plugin_rest_identity.sh
blob: f391f827f118eea6481a6b4b3a022fb1f61b12b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#!/usr/bin/bash

#First, start gnunet-arm and the rest-service. Make sure, no identity exists
#Exit 0 means success, exit 1 means failed test

#No test for subsystem available

link_to_api="http://localhost:7776/identity"
wrong_link="http://localhost:7776/idenmmmy"
wrong_link2="http://localhost:7776/identityandmore"

#Test GET (multiple identities) for error when no identity exists
#The next test case can be ignored if you have already added identities
cache="$(curl --silent "$link_to_api" | grep "error")"
if [ "" == "$cache" ]
then
    exit 1
fi

#Test POST success code, error response code and error json
#The next test case can be ignored if you have already added an identity with the name Test
cache="$(curl -v -X "POST" "$link_to_api" --data "{\"name\":\"Test\"}" 2>&1 | grep "HTTP/1.1 201")"
if [ "" == "$cache" ]
then
    exit 1
fi

cache="$(curl -v -X "POST" "$link_to_api" --data "{\"name\":\"Test\"}" 2>&1 | grep "HTTP/1.1 409")"
if [ "" == "$cache" ]
then
    exit 1
fi

cache="$(curl -v -X "POST" "$link_to_api" 2>&1 | grep "error")"
if [ "" == "$cache" ]
then
    exit 1
fi

cache="$(curl -v -X "POST" "$link_to_api" --data "wrong" 2>&1 | grep "error")"
if [ "" == "$cache" ]
then
    exit 1
fi

cache="$(curl -v -X "POST" "$link_to_api" --data "[{}]" 2>&1 | grep "error")"
if [ "" == "$cache" ]
then
    exit 1
fi

cache="$(curl -v -X "POST" "$link_to_api" --data "{\"name\":\"Test\",\"other\":\"Test\"}" 2>&1 | grep "error")"
if [ "" == "$cache" ]
then
    exit 1
fi

cache="$(curl -v -X "POST" "$link_to_api" --data "{\"nam\":\"Test\"}" 2>&1 | grep "error")"
if [ "" == "$cache" ]
then
    exit 1
fi

cache="$(curl -v -X "POST" "$link_to_api" --data "{\"name\":123}" 2>&1 | grep "error")"
if [ "" == "$cache" ]
then
    exit 1
fi

cache="$(curl -v -X "POST" "$link_to_api" --data "{\"name\":""}" 2>&1 | grep "error")"
if [ "" == "$cache" ]
then
    exit 1
fi


#Test GET (multiple identities) for success and error json
cache="$(curl --silent "$link_to_api" | grep "error")"
if [ "" != "$cache" ]
then
    exit 1
fi


id="$(gnunet-identity -d | grep "Test - " | sed  "s/Test - //g")"
#Test GET (one identity) for success and error json
#Only lowercase
cache="$(curl --silent "${link_to_api}?name=Test" | grep "error")"
if [ "" == "$cache" ]
then
    exit 1
fi
#Test GET (one identity) for success and error json
cache="$(curl --silent "${link_to_api}?pubkey=$id" | grep "error")"
if [ "" != "$cache" ]
then
    exit 1
fi

#Test DELETE success code, error response code and error json
#echo "Next tests for DELETE will probably fail when POST fails"
cache="$(curl -v -X "DELETE" "${link_to_api}?pubkey=$id" 2>&1 | grep "HTTP/1.1 404")"
if [ "" != "$cache" ]
then
    exit 1
fi

curl --silent -X "POST" "$link_to_api" --data "{\"name\":\"Test\"}"
id="$(gnunet-identity -d | grep "Test - " | sed  "s/Test - //g")"

cache="$(curl -v -X "DELETE" "${link_to_api}?pubkey=df1" 2>&1 | grep "HTTP/1.1 404")"
if [ "" == "$cache" ]
then
    exit 1
fi

cache="$(curl -v -X "DELETE" "${link_to_api}?pubke=$id" 2>&1 | grep "error")"
if [ "" == "$cache" ]
then
    exit 1
fi

#Test PUT success code, error response codes and error json
cache="$(curl -v -X "PUT" "${link_to_api}" --data "{\"newname\":\"NewTest\",\"pubkey\":\"${id}\"}" 2>&1 | grep "HTTP/1.1 204")"
if [ "" == "$cache" ]
then
    exit 1
fi

cache="$(curl -v -X "PUT" "${link_to_api}" --data "{\"newname\":\"NewNewTest\",\"pubkey\":\"${id}1\"}" 2>&1 | grep "HTTP/1.1 404")"
if [ "" == "$cache" ]
then
    exit 1
fi

# feature: you can rename your identity with its own name.
# cache="$(curl -v -X "PUT" "$link_to_api" --data "{\"newname\":\"NewTest\",\"pubkey\":\"${id}\"}" 2>&1 | grep "error")"
# if [ "" == "$cache" ]
# then
#     exit 1
# fi


cache="$(curl -v -X "PUT" "$link_to_api" 2>&1 | grep "error")"
if [ "" == "$cache" ]
then
    exit 1
fi

cache="$(curl -v -X "PUT" "$link_to_api" --data "wrong" 2>&1 | grep "error")"
if [ "" == "$cache" ]
then
    exit 1
fi

cache="$(curl -v -X "PUT" "$link_to_api" --data "[{}]" 2>&1 | grep "error")"
if [ "" == "$cache" ]
then
    exit 1
fi

cache="$(curl -v -X "PUT" "$link_to_api" --data "{\"newname\":\"Test\",\"other\":\"Test\",\"pubkey\":\"${id}\"}" 2>&1 | grep "error")"
if [ "" == "$cache" ]
then
    exit 1
fi

cache="$(curl -v -X "PUT" "$link_to_api" --data "{\"newnam\":\"Test\",\"pubkey\":\"${id}\"}" 2>&1 | grep "error")"
if [ "" == "$cache" ]
then
    exit 1
fi

cache="$(curl -v -X "PUT" "$link_to_api" --data "{\"newname\":\"Test\",\"pubke\":\"${id}\"}" 2>&1 | grep "error")"
if [ "" == "$cache" ]
then
    exit 1
fi

cache="$(curl -v -X "PUT" "$link_to_api" --data "{\"newname\":123,\"pubkey\":\"${id}\"}" 2>&1 | grep "error")"
if [ "" == "$cache" ]
then
    exit 1
fi

cache="$(curl -v -X "PUT" "$link_to_api" --data "{\"newname\":"",\"pubkey\":\"${id}\"}" 2>&1 | grep "error")"
if [ "" == "$cache" ]
then
    exit 1
fi
#TODO Missing subsystem test

#Missing OPTIONS success - nothing can really go wrong here

#Test wrong url
cache="$(curl -v "$wrong_link" 2>&1 | grep "HTTP/1.1 404")"
if [ "" == "$cache" ]
then
    exit 1
fi

cache="$(curl -X "PUT" -v "$wrong_link" --data "{\"newname\":\"Testing\",\"pubkey\":\"${id}\"}" 2>&1 | grep "HTTP/1.1 404")"
if [ "" == "$cache" ]
then
    exit 1
fi

cache="$(curl -X "POST" -v "$wrong_link?pubkey=$id" --data "{\"name\":\"Test\"}" 2>&1 | grep "HTTP/1.1 404")"
if [ "" == "$cache" ]
then
    exit 1
fi

cache="$(curl -X "DELETE" -v "${wrong_link}?pubkey=$id" 2>&1 | grep "HTTP/1.1 404")"
if [ "" == "$cache" ]
then
    exit 1
fi

gnunet-identity -D NewTest

exit 0