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