diff options
author | Phil <phil.buschmann@tum.de> | 2018-08-08 23:24:10 +0200 |
---|---|---|
committer | Phil <phil.buschmann@tum.de> | 2018-08-08 23:24:10 +0200 |
commit | 0d239903075f518edef85277f13d1b5d303443bf (patch) | |
tree | 915dd42806aee47625ffed4bce82be9476e5bd36 /src/namestore | |
parent | 9eb2df3407246f984f0d85af338bff872d5e6fba (diff) | |
download | gnunet-0d239903075f518edef85277f13d1b5d303443bf.tar.gz gnunet-0d239903075f518edef85277f13d1b5d303443bf.zip |
Namestore Rest API finished
Diffstat (limited to 'src/namestore')
-rw-r--r-- | src/namestore/plugin_rest_namestore.c | 22 | ||||
-rwxr-xr-x | src/namestore/test_plugin_rest_namestore.sh | 78 |
2 files changed, 25 insertions, 75 deletions
diff --git a/src/namestore/plugin_rest_namestore.c b/src/namestore/plugin_rest_namestore.c index 3801431b2..f14707cce 100644 --- a/src/namestore/plugin_rest_namestore.c +++ b/src/namestore/plugin_rest_namestore.c | |||
@@ -641,16 +641,17 @@ namestore_add (struct GNUNET_REST_RequestHandle *con_handle, | |||
641 | { | 641 | { |
642 | handle->emsg = GNUNET_strdup("Invalid data"); | 642 | handle->emsg = GNUNET_strdup("Invalid data"); |
643 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 643 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
644 | GNUNET_free_non_null(gns_record); | 644 | GNUNET_JSON_parse_free(gnsspec); |
645 | json_decref (data_js); | 645 | json_decref (data_js); |
646 | return; | 646 | return; |
647 | } | 647 | } |
648 | handle->rd = gns_record; | ||
649 | |||
648 | name_json = json_object_get(data_js, "label"); | 650 | name_json = json_object_get(data_js, "label"); |
649 | if (!json_is_string(name_json)) | 651 | if (!json_is_string(name_json)) |
650 | { | 652 | { |
651 | handle->emsg = GNUNET_strdup("Missing name"); | 653 | handle->emsg = GNUNET_strdup("Missing name"); |
652 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 654 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
653 | GNUNET_free_non_null(gns_record); | ||
654 | json_decref (data_js); | 655 | json_decref (data_js); |
655 | return; | 656 | return; |
656 | } | 657 | } |
@@ -659,7 +660,6 @@ namestore_add (struct GNUNET_REST_RequestHandle *con_handle, | |||
659 | { | 660 | { |
660 | handle->emsg = GNUNET_strdup("Missing name"); | 661 | handle->emsg = GNUNET_strdup("Missing name"); |
661 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 662 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
662 | GNUNET_free_non_null(gns_record); | ||
663 | json_decref (data_js); | 663 | json_decref (data_js); |
664 | return; | 664 | return; |
665 | } | 665 | } |
@@ -667,12 +667,10 @@ namestore_add (struct GNUNET_REST_RequestHandle *con_handle, | |||
667 | { | 667 | { |
668 | handle->emsg = GNUNET_strdup("Missing name"); | 668 | handle->emsg = GNUNET_strdup("Missing name"); |
669 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 669 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
670 | GNUNET_free_non_null(gns_record); | ||
671 | json_decref (data_js); | 670 | json_decref (data_js); |
672 | return; | 671 | return; |
673 | } | 672 | } |
674 | json_decref (data_js); | 673 | json_decref (data_js); |
675 | handle->rd = gns_record; | ||
676 | 674 | ||
677 | //change zone if pubkey or name specified | 675 | //change zone if pubkey or name specified |
678 | GNUNET_CRYPTO_hash (GNUNET_REST_API_PARAM_PUBKEY, | 676 | GNUNET_CRYPTO_hash (GNUNET_REST_API_PARAM_PUBKEY, |
@@ -711,6 +709,12 @@ namestore_add (struct GNUNET_REST_RequestHandle *con_handle, | |||
711 | { | 709 | { |
712 | handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego); | 710 | handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego); |
713 | } | 711 | } |
712 | if (NULL == handle->zone_pkey) | ||
713 | { | ||
714 | handle->emsg = GNUNET_strdup("No default identity for namestore"); | ||
715 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
716 | return; | ||
717 | } | ||
714 | handle->add_qe = GNUNET_NAMESTORE_records_lookup (handle->ns_handle, | 718 | handle->add_qe = GNUNET_NAMESTORE_records_lookup (handle->ns_handle, |
715 | handle->zone_pkey, | 719 | handle->zone_pkey, |
716 | handle->label_name, | 720 | handle->label_name, |
@@ -813,6 +817,14 @@ namestore_delete (struct GNUNET_REST_RequestHandle *con_handle, | |||
813 | } | 817 | } |
814 | handle->label_name = GNUNET_strdup( | 818 | handle->label_name = GNUNET_strdup( |
815 | GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, &key)); | 819 | GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, &key)); |
820 | |||
821 | if (NULL == handle->zone_pkey) | ||
822 | { | ||
823 | handle->emsg = GNUNET_strdup("No default identity for namestore"); | ||
824 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
825 | return; | ||
826 | } | ||
827 | |||
816 | handle->add_qe = GNUNET_NAMESTORE_records_lookup (handle->ns_handle, | 828 | handle->add_qe = GNUNET_NAMESTORE_records_lookup (handle->ns_handle, |
817 | handle->zone_pkey, | 829 | handle->zone_pkey, |
818 | handle->label_name, | 830 | handle->label_name, |
diff --git a/src/namestore/test_plugin_rest_namestore.sh b/src/namestore/test_plugin_rest_namestore.sh index 7c1e97397..de02dfafc 100755 --- a/src/namestore/test_plugin_rest_namestore.sh +++ b/src/namestore/test_plugin_rest_namestore.sh | |||
@@ -11,7 +11,7 @@ curl_get () { | |||
11 | #$1 is link | 11 | #$1 is link |
12 | #$2 is grep | 12 | #$2 is grep |
13 | cache="$(curl -v "$1" 2>&1 | grep "$2")" | 13 | cache="$(curl -v "$1" 2>&1 | grep "$2")" |
14 | echo $cache | 14 | #echo $cache |
15 | if [ "" == "$cache" ] | 15 | if [ "" == "$cache" ] |
16 | then | 16 | then |
17 | exit 1 | 17 | exit 1 |
@@ -23,7 +23,7 @@ curl_post () { | |||
23 | #$2 is data | 23 | #$2 is data |
24 | #$3 is grep | 24 | #$3 is grep |
25 | cache="$(curl -v -X "POST" "$1" --data "$2" 2>&1 | grep "$3")" | 25 | cache="$(curl -v -X "POST" "$1" --data "$2" 2>&1 | grep "$3")" |
26 | echo $cache | 26 | #echo $cache |
27 | if [ "" == "$cache" ] | 27 | if [ "" == "$cache" ] |
28 | then | 28 | then |
29 | exit 1 | 29 | exit 1 |
@@ -34,7 +34,7 @@ curl_delete () { | |||
34 | #$1 is link | 34 | #$1 is link |
35 | #$2 is grep | 35 | #$2 is grep |
36 | cache="$(curl -v -X "DELETE" "$1" 2>&1 | grep "$2")" | 36 | cache="$(curl -v -X "DELETE" "$1" 2>&1 | grep "$2")" |
37 | echo $cache | 37 | #echo $cache |
38 | if [ "" == "$cache" ] | 38 | if [ "" == "$cache" ] |
39 | then | 39 | then |
40 | exit 1 | 40 | exit 1 |
@@ -197,74 +197,12 @@ gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9 | |||
197 | curl_delete "${namestore_link}?label=test_entry&name=$name" "HTTP/1.1 204" | 197 | curl_delete "${namestore_link}?label=test_entry&name=$name" "HTTP/1.1 204" |
198 | gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY" | 198 | gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY" |
199 | curl_delete "${namestore_link}?label=test_entry&pubkey=$public" "HTTP/1.1 204" | 199 | curl_delete "${namestore_link}?label=test_entry&pubkey=$public" "HTTP/1.1 204" |
200 | gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY" | ||
201 | curl_delete "${namestore_link}?label=test_entry&pubkey=$name" "HTTP/1.1 404" | ||
200 | 202 | ||
201 | exit 0; | ||
202 | |||
203 | |||
204 | |||
205 | #pubkey zone | ||
206 | #name zone | ||
207 | curl_post "${namestore_link}" '{"name":"test_plugin_rest_identity"}' "HTTP/1.1 201 Created" | ||
208 | curl_post "${namestore_link}" '{"name":"test_plugin_rest_identity"}' "HTTP/1.1 409" | ||
209 | curl_post "${namestore_link}" '{"name":"Test_plugin_rest_identity"}' "HTTP/1.1 409" | ||
210 | curl_post "${namestore_link}" '{}' "error" | ||
211 | curl_post "${namestore_link}" '' "error" | ||
212 | curl_post "${namestore_link}" '{"name":""}' "error" | ||
213 | curl_post "${namestore_link}" '{"name":123}' "error" | ||
214 | curl_post "${namestore_link}" '{"name":[]}' "error" | ||
215 | curl_post "${namestore_link}" '{"name1":"test_plugin_rest_identity"}' "error" | ||
216 | curl_post "${namestore_link}" '{"other":""}' "error" | ||
217 | curl_post "${namestore_link}" '{"name":"test_plugin_rest_identity1", "other":"test_plugin_rest_identity2"}' "error" | ||
218 | |||
219 | #Test PUT | ||
220 | name="$(gnunet-identity -d | grep "test_plugin_rest_identity" | awk 'NR==1{print $1}')" | ||
221 | public="$(gnunet-identity -d | grep "test_plugin_rest_identity" | awk 'NR==1{print $3}')" | ||
222 | |||
223 | curl_put "${namestore_link}" '{"newname":"test_plugin_rest_identity1","pubkey":"'$public'"}' "HTTP/1.1 204" | ||
224 | curl_put "${namestore_link}" '{"newname":"test_plugin_rest_identity1","pubkey":"'$public'"}' "HTTP/1.1 409" | ||
225 | curl_put "${namestore_link}" '{"newname":"test_plugin_rest_identity1","pubkey":"'$public'xx"}' "HTTP/1.1 404" | ||
226 | curl_put "${namestore_link}" '{"newname":"test_plugin_rest_identity1","pubkey":""}' "HTTP/1.1 404" | ||
227 | curl_put "${namestore_link}" '{"newname":"test_plugin_rest_identity1","pubke":""}' "HTTP/1.1 404" | ||
228 | curl_put "${namestore_link}" '{"newname":"test_plugin_rest_identity1","pubke":"","other":"sdfdsf"}' "HTTP/1.1 404" | ||
229 | curl_put "${namestore_link}" '{"newname":"test_plugin_rest_identity1","pubke":"","name":"sdfdsf"}' "HTTP/1.1 404" | ||
230 | curl_put "${namestore_link}" '{"newname":"test_plugin_rest_identity","pubke":"","name":"test_plugin_rest_identity1"}' "HTTP/1.1 204" | ||
231 | curl_put "${namestore_link}" '{"newnam":"test_plugin_rest_identity","pubkey":"'$public'"}' "error" | ||
232 | curl_put "${namestore_link}" '{"newname":"test_plugin_rest_identity1","name":"test_plugin_rest_identity"}' "HTTP/1.1 204" | ||
233 | curl_put "${namestore_link}" '{"newname":"TEST_plugin_rest_identity1","name":"test_plugin_rest_identity1"}' "HTTP/1.1 409" | ||
234 | curl_put "${namestore_link}" '{"newname":"test_plugin_rest_identity1","name":"test_plugin_rest_identity1"}' "HTTP/1.1 409" | ||
235 | curl_put "${namestore_link}" '{"newname":"test_plugin_rest_identity","name":"test_plugin_rest_identityxxx"}' "HTTP/1.1 404" | ||
236 | curl_put "${namestore_link}" '{"newname":"test_plugin_rest_identity","name":"test_plugin_rest_identity1"}' "HTTP/1.1 204" | ||
237 | curl_put "${namestore_link}" '{"newnam":"test_plugin_rest_identityfail","name":"test_plugin_rest_identity"}' "error" | ||
238 | |||
239 | |||
240 | #Test subsystem | ||
241 | curl_put "${identity_link}" '{"subsystem":"namestore","name":"test_plugin_rest_identity"}' "HTTP/1.1 204" | ||
242 | curl_put "${identity_link}" '{"subsystem":"namestore","name":"test_plugin_rest_identity"}' "HTTP/1.1 204" | ||
243 | curl_get "${identity_link}?subsystem=namestore" "test_plugin_rest_identity" | ||
244 | curl_post "${identity_link}" '{"name":"test_plugin_rest_identity1"}' "HTTP/1.1 201 Created" | ||
245 | public="$(gnunet-identity -d | grep "test_plugin_rest_identity" | awk 'NR==1{print $3}')" | ||
246 | curl_put "${identity_link}" '{"subsystem":"namestore","pubkey":"'"$public"'"}' "HTTP/1.1 204" | ||
247 | curl_get "${identity_link}?subsystem=namestore" "test_plugin_rest_identity1" | ||
248 | curl_get "${identity_link}?subsystem=test_plugin_rest_identity_no_subsystem" "error" | ||
249 | curl_put "${identity_link}" '{"subsystem":"test_plugin_rest_identity_no_subsystem","name":"test_plugin_rest_identity1"}' "HTTP/1.1 204" | ||
250 | curl_get "${identity_link}?subsystem=test_plugin_rest_identity_no_subsystem" "test_plugin_rest_identity1" | ||
251 | |||
252 | curl_put "${identity_link}" '{"subsyste":"test_plugin_rest_identity_no_subsystem","name":"test_plugin_rest_identity1"}' "error" | ||
253 | curl_put "${identity_link}" '{"subsystem":"test_plugin_rest_identity_no_subsystem","name":"Test_plugin_rest_identity1"}' "HTTP/1.1 204" | ||
254 | |||
255 | #Test DELETE | ||
256 | curl_delete "${identity_link}?name=test_plugin_rest_identity" "HTTP/1.1 204" | ||
257 | curl_get "${identity_link}?name=test_plugin_rest_identity" "error" | ||
258 | curl_delete "${identity_link}?name=TEST_plugin_rest_identity1" "HTTP/1.1 404" | ||
259 | curl_delete "${identity_link}?name=test_plugin_rest_identity1" "HTTP/1.1 204" | ||
260 | curl_get "${identity_link}?name=test_plugin_rest_identity1" "error" | ||
261 | curl_delete "${identity_link}?name=test_plugin_rest_identity_not_found" "HTTP/1.1 404" | ||
262 | curl_post "${identity_link}" '{"name":"test_plugin_rest_identity1"}' "HTTP/1.1 201 Created" | ||
263 | public="$(gnunet-identity -d | grep "test_plugin_rest_identity1" | awk 'NR==1{print $3}')" | ||
264 | curl_delete "${identity_link}?pubkey=$public" "HTTP/1.1 204" | ||
265 | curl_delete "${identity_link}?pubke=$public" "error" | ||
266 | curl_delete "${identity_link}?pubkey=$public&other=232" "HTTP/1.1 404" | ||
267 | 203 | ||
268 | #test default subsystem | 204 | #Test default identity |
205 | #not possible without defining | ||
269 | 206 | ||
270 | exit 0; | 207 | exit 0; |
208 | |||