aboutsummaryrefslogtreecommitdiff
path: root/src/identity
diff options
context:
space:
mode:
authorPhil <phil.buschmann@tum.de>2018-07-25 16:59:08 +0200
committerPhil <phil.buschmann@tum.de>2018-07-25 16:59:08 +0200
commit9009fb0aa496cd72ff6f1ea3d20ac4a547055e1b (patch)
treedde1a437bdca9fe056667aaa2749d067dc4f6456 /src/identity
parent8b89bb8b02c8949f3c74ad0668107d184aaa3788 (diff)
downloadgnunet-9009fb0aa496cd72ff6f1ea3d20ac4a547055e1b.tar.gz
gnunet-9009fb0aa496cd72ff6f1ea3d20ac4a547055e1b.zip
-fix identity file
Diffstat (limited to 'src/identity')
-rw-r--r--src/identity/plugin_rest_identity.c59
-rwxr-xr-xsrc/identity/test_plugin_identity_rest.sh252
2 files changed, 30 insertions, 281 deletions
diff --git a/src/identity/plugin_rest_identity.c b/src/identity/plugin_rest_identity.c
index 8d525b950..f1d33b0f3 100644
--- a/src/identity/plugin_rest_identity.c
+++ b/src/identity/plugin_rest_identity.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2012-2015 GNUnet e.V. 3 Copyright (C) 2012-2015 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software: you can redistribute it and/or modify it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19 */ 17 */
20/** 18/**
21 * @author Martin Schanzenbach 19 * @author Martin Schanzenbach
@@ -202,8 +200,9 @@ struct RequestHandle
202 * @param handle Handle to clean up 200 * @param handle Handle to clean up
203 */ 201 */
204static void 202static void
205cleanup_handle (struct RequestHandle *handle) 203cleanup_handle (void *cls)
206{ 204{
205 struct RequestHandle *handle = cls;
207 struct EgoEntry *ego_entry; 206 struct EgoEntry *ego_entry;
208 struct EgoEntry *ego_tmp; 207 struct EgoEntry *ego_tmp;
209 208
@@ -248,20 +247,22 @@ do_error (void *cls)
248{ 247{
249 struct RequestHandle *handle = cls; 248 struct RequestHandle *handle = cls;
250 struct MHD_Response *resp; 249 struct MHD_Response *resp;
251 char *json_error; 250 json_t *json_error = json_object();
251 char *response;
252 252
253 if (NULL == handle->emsg) 253 if (NULL == handle->emsg)
254 handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_UNKNOWN); 254 handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_UNKNOWN);
255 255
256 GNUNET_asprintf (&json_error, "{\"error\": \"%s\"}", handle->emsg); 256 json_object_set_new(json_error,"error", json_string(handle->emsg));
257 257
258 if (0 == handle->response_code) 258 if (0 == handle->response_code)
259 handle->response_code = MHD_HTTP_OK; 259 handle->response_code = MHD_HTTP_OK;
260 260 response = json_dumps (json_error, 0);
261 resp = GNUNET_REST_create_response (json_error); 261 resp = GNUNET_REST_create_response (response);
262 handle->proc (handle->proc_cls, resp, handle->response_code); 262 handle->proc (handle->proc_cls, resp, handle->response_code);
263 cleanup_handle (handle); 263 json_decref(json_error);
264 GNUNET_free(json_error); 264 GNUNET_free(response);
265 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
265} 266}
266 267
267/** 268/**
@@ -306,7 +307,7 @@ ego_get_for_subsystem (void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx,
306 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); 307 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
307 GNUNET_free(result_str); 308 GNUNET_free(result_str);
308 GNUNET_free(public_key_string); 309 GNUNET_free(public_key_string);
309 cleanup_handle (handle); 310 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
310} 311}
311 312
312/** 313/**
@@ -420,7 +421,7 @@ ego_get (struct GNUNET_REST_RequestHandle *con_handle, const char* url,
420 json_decref (json_root); 421 json_decref (json_root);
421 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); 422 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
422 GNUNET_free(result_str); 423 GNUNET_free(result_str);
423 cleanup_handle (handle); 424 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
424} 425}
425 426
426/** 427/**
@@ -444,7 +445,7 @@ do_finished (void *cls, const char *emsg)
444 } 445 }
445 resp = GNUNET_REST_create_response (NULL); 446 resp = GNUNET_REST_create_response (NULL);
446 handle->proc (handle->proc_cls, resp, handle->response_code); 447 handle->proc (handle->proc_cls, resp, handle->response_code);
447 cleanup_handle (handle); 448 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
448} 449}
449 450
450/** 451/**
@@ -530,7 +531,7 @@ ego_edit (struct GNUNET_REST_RequestHandle *con_handle, const char* url,
530 json_decref (data_js); 531 json_decref (data_js);
531 resp = GNUNET_REST_create_response (NULL); 532 resp = GNUNET_REST_create_response (NULL);
532 handle->proc (handle->proc_cls, resp, MHD_HTTP_NOT_FOUND); 533 handle->proc (handle->proc_cls, resp, MHD_HTTP_NOT_FOUND);
533 cleanup_handle (handle); 534 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
534 return; 535 return;
535 } 536 }
536 //This is a rename 537 //This is a rename
@@ -555,7 +556,7 @@ ego_edit (struct GNUNET_REST_RequestHandle *con_handle, const char* url,
555 json_decref (data_js); 556 json_decref (data_js);
556 resp = GNUNET_REST_create_response (NULL); 557 resp = GNUNET_REST_create_response (NULL);
557 handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT); 558 handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT);
558 cleanup_handle (handle); 559 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
559 return; 560 return;
560 } 561 }
561 } 562 }
@@ -677,7 +678,7 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle, const char* url,
677 json_decref (data_js); 678 json_decref (data_js);
678 resp = GNUNET_REST_create_response (NULL); 679 resp = GNUNET_REST_create_response (NULL);
679 handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT); 680 handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT);
680 cleanup_handle (handle); 681 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
681 return; 682 return;
682 } 683 }
683 } 684 }
@@ -732,7 +733,7 @@ ego_delete (struct GNUNET_REST_RequestHandle *con_handle, const char* url,
732 { 733 {
733 resp = GNUNET_REST_create_response (NULL); 734 resp = GNUNET_REST_create_response (NULL);
734 handle->proc (handle->proc_cls, resp, MHD_HTTP_NOT_FOUND); 735 handle->proc (handle->proc_cls, resp, MHD_HTTP_NOT_FOUND);
735 cleanup_handle (handle); 736 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
736 return; 737 return;
737 } 738 }
738 handle->response_code = MHD_HTTP_NO_CONTENT; 739 handle->response_code = MHD_HTTP_NO_CONTENT;
@@ -760,7 +761,7 @@ options_cont (struct GNUNET_REST_RequestHandle *con_handle, const char* url,
760 resp = GNUNET_REST_create_response (NULL); 761 resp = GNUNET_REST_create_response (NULL);
761 MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods); 762 MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods);
762 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); 763 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
763 cleanup_handle (handle); 764 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
764 return; 765 return;
765} 766}
766 767
diff --git a/src/identity/test_plugin_identity_rest.sh b/src/identity/test_plugin_identity_rest.sh
deleted file mode 100755
index d43f4206b..000000000
--- a/src/identity/test_plugin_identity_rest.sh
+++ /dev/null
@@ -1,252 +0,0 @@
1#!/usr/bin/bash
2
3#First, start gnunet-arm and the rest-service. Make sure, no identity exists
4
5link_to_api="http://localhost:7776/identity"
6wrong_link="http://localhost:7776/idenmmmy"
7
8#Test GET (multiple identities) for error when no identity exists
9
10echo "No test for subsystem available"
11echo "The next test case can be ignored if you have already added identities"
12cache="$(curl --silent "$link_to_api" | grep "error")"
13if [ "" == "$cache" ]
14then
15 echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for GET request when missing identity\n"
16else
17 echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for GET request when missing identity\n"
18fi
19
20#Test POST success code, error response code and error json
21echo "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 echo -n -e "[\033[0;31m FAILURE\033[0m ] Error for good POST request\n"
26else
27 echo -n -e "[\033[0;32m SUCCESS\033[0m ] Success for good POST request\n"
28fi
29
30cache="$(curl -v -X "POST" "$link_to_api" --data "{\"name\":\"Test\"}" 2>&1 | grep "HTTP/1.1 409")"
31if [ "" == "$cache" ]
32then
33 echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for duplicate name POST request\n"
34else
35 echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for duplicate name POST request\n"
36fi
37
38cache="$(curl -v -X "POST" "$link_to_api" 2>&1 | grep "error")"
39if [ "" == "$cache" ]
40then
41 echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for no data POST request\n"
42else
43 echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for no data POST request\n"
44fi
45
46cache="$(curl -v -X "POST" "$link_to_api" --data "wrong" 2>&1 | grep "error")"
47if [ "" == "$cache" ]
48then
49 echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for wrong data POST request\n"
50else
51 echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for wrong data POST request\n"
52fi
53
54cache="$(curl -v -X "POST" "$link_to_api" --data "[{}]" 2>&1 | grep "error")"
55if [ "" == "$cache" ]
56then
57 echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for json array input POST request\n"
58else
59 echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for json array input POST request\n"
60fi
61
62cache="$(curl -v -X "POST" "$link_to_api" --data "{\"name\":\"Test\",\"other\":\"Test\"}" 2>&1 | grep "error")"
63if [ "" == "$cache" ]
64then
65 echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for multi element json POST request\n"
66else
67 echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for multi element json POST request\n"
68fi
69
70cache="$(curl -v -X "POST" "$link_to_api" --data "{\"nam\":\"Test\"}" 2>&1 | grep "error")"
71if [ "" == "$cache" ]
72then
73 echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for wrong json POST request\n"
74else
75 echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for wrong json POST request\n"
76fi
77
78cache="$(curl -v -X "POST" "$link_to_api" --data "{\"name\":123}" 2>&1 | grep "error")"
79if [ "" == "$cache" ]
80then
81 echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for wrong json type POST request\n"
82else
83 echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for wrong json type POST request\n"
84fi
85
86cache="$(curl -v -X "POST" "$link_to_api" --data "{\"name\":""}" 2>&1 | grep "error")"
87if [ "" == "$cache" ]
88then
89 echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for no name POST request\n"
90else
91 echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for no name POST request\n"
92fi
93
94
95#Test GET (multiple identities) for success and error json
96cache="$(curl --silent "$link_to_api" | grep "error")"
97if [ "" == "$cache" ]
98then
99 echo -n -e "[\033[0;32m SUCCESS\033[0m ] Success for good GET request (multiple identities)\n"
100else
101 echo -n -e "[\033[0;31m FAILURE\033[0m ] Error for good GET request (multiple identities)\n"
102fi
103
104
105id="$(gnunet-identity -d | grep "Test - " | sed "s/Test - //g")"
106#Test GET (one identity) for success and error json
107cache="$(curl --silent "${link_to_api}/$id" | grep "error")"
108if [ "" == "$cache" ]
109then
110 echo -n -e "[\033[0;32m SUCCESS\033[0m ] Success for good GET request (one identity)\n"
111else
112 echo -n -e "[\033[0;31m FAILURE\033[0m ] Error for good GET request (one identity)\n"
113fi
114
115
116#Test DELETE success code, error response code and error json
117echo "Next tests for DELETE will probably fail when POST fails"
118cache="$(curl -v -X "DELETE" "${link_to_api}/$id" 2>&1 | grep "HTTP/1.1 404")"
119if [ "" == "$cache" ]
120then
121 echo -n -e "[\033[0;32m SUCCESS\033[0m ] Success for good DELETE request\n"
122else
123 echo -n -e "[\033[0;31m FAILURE\033[0m ] Error for good DELETE request\n"
124fi
125
126curl --silent -X "POST" "$link_to_api" --data "{\"name\":\"Test\"}"
127id="$(gnunet-identity -d | grep "Test - " | sed "s/Test - //g")"
128
129cache="$(curl -v -X "DELETE" "${link_to_api}/df1" 2>&1 | grep "HTTP/1.1 404")"
130if [ "" == "$cache" ]
131then
132 echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for wrong DELETE request\n"
133else
134 echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for wrong DELETE request\n"
135fi
136
137#Test PUT success code, error response codes and error json
138cache="$(curl -v -X "PUT" "${link_to_api}/$id" --data "{\"newname\":\"NewTest\"}" 2>&1 | grep "HTTP/1.1 204")"
139if [ "" == "$cache" ]
140then
141 echo -n -e "[\033[0;31m FAILURE\033[0m ] Error for good PUT request\n"
142else
143 echo -n -e "[\033[0;32m SUCCESS\033[0m ] Success for good PUT request\n"
144fi
145
146cache="$(curl -v -X "PUT" "${link_to_api}/${id}1" --data "{\"newname\":\"NewNewTest\"}" 2>&1 | grep "HTTP/1.1 404")"
147if [ "" == "$cache" ]
148then
149 echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for wrong identity PUT request\n"
150else
151 echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for wrong identity PUT request\n"
152fi
153
154cache="$(curl -v -X "PUT" "$link_to_api/$id" --data "{\"newname\":\"NewTest\"}" 2>&1 | grep "error")"
155if [ "" == "$cache" ]
156then
157 echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for duplicate name PUT request\n"
158else
159 echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for duplicate name PUT request\n"
160fi
161
162cache="$(curl -v -X "PUT" "$link_to_api/$id" 2>&1 | grep "error")"
163if [ "" == "$cache" ]
164then
165 echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for no data PUT request\n"
166else
167 echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for no data PUT request\n"
168fi
169
170cache="$(curl -v -X "PUT" "$link_to_api/$id" --data "wrong" 2>&1 | grep "error")"
171if [ "" == "$cache" ]
172then
173 echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for wrong data PUT request\n"
174else
175 echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for wrong data PUT request\n"
176fi
177
178cache="$(curl -v -X "PUT" "$link_to_api/$id" --data "[{}]" 2>&1 | grep "error")"
179if [ "" == "$cache" ]
180then
181 echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for json array input PUT request\n"
182else
183 echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for json array input PUT request\n"
184fi
185
186cache="$(curl -v -X "PUT" "$link_to_api/$id" --data "{\"newname\":\"Test\",\"other\":\"Test\"}" 2>&1 | grep "error")"
187if [ "" == "$cache" ]
188then
189 echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for multi element json PUT request\n"
190else
191 echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for multi element json PUT request\n"
192fi
193
194cache="$(curl -v -X "PUT" "$link_to_api/$id" --data "{\"newnam\":\"Test\"}" 2>&1 | grep "error")"
195if [ "" == "$cache" ]
196then
197 echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for wrong json PUT request\n"
198else
199 echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for wrong json PUT request\n"
200fi
201
202cache="$(curl -v -X "PUT" "$link_to_api/$id" --data "{\"newname\":123}" 2>&1 | grep "error")"
203if [ "" == "$cache" ]
204then
205 echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for wrong json type PUT request\n"
206else
207 echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for wrong json type PUT request\n"
208fi
209
210cache="$(curl -v -X "PUT" "$link_to_api/$id" --data "{\"newname\":""}" 2>&1 | grep "error")"
211if [ "" == "$cache" ]
212then
213 echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for no name PUT request\n"
214else
215 echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for no name PUT request\n"
216fi
217#TODO Missing subsystem test
218
219#Missing OPTIONS success - nothing can really go wrong here
220
221#Test wrong url
222cache="$(curl -v "$wrong_link" 2>&1 | grep "HTTP/1.1 404")"
223if [ "" == "$cache" ]
224then
225 echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for wrong url GET request \n"
226else
227 echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for wrong url GET request \n"
228fi
229
230cache="$(curl -X "PUT" -v "$wrong_link/$id" --data "{\"newname\":\"Testing\"}" 2>&1 | grep "HTTP/1.1 404")"
231if [ "" == "$cache" ]
232then
233 echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for wrong url GET request \n"
234else
235 echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for wrong url GET request \n"
236fi
237
238cache="$(curl -X "POST" -v "$wrong_link/$id" --data "{\"name\":\"Test\"}" 2>&1 | grep "HTTP/1.1 404")"
239if [ "" == "$cache" ]
240then
241 echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for wrong url POST request \n"
242else
243 echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for wrong url POST request \n"
244fi
245
246cache="$(curl -X "DELETE" -v "${wrong_link}/$id" 2>&1 | grep "HTTP/1.1 404")"
247if [ "" == "$cache" ]
248then
249 echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for wrong url DELETE request \n"
250else
251 echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for wrong url DELETE request \n"
252fi