aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil <phil.buschmann@tum.de>2018-08-08 23:24:10 +0200
committerPhil <phil.buschmann@tum.de>2018-08-08 23:24:10 +0200
commit0d239903075f518edef85277f13d1b5d303443bf (patch)
tree915dd42806aee47625ffed4bce82be9476e5bd36
parent9eb2df3407246f984f0d85af338bff872d5e6fba (diff)
downloadgnunet-0d239903075f518edef85277f13d1b5d303443bf.tar.gz
gnunet-0d239903075f518edef85277f13d1b5d303443bf.zip
Namestore Rest API finished
-rw-r--r--src/json/json_gnsrecord.c18
-rw-r--r--src/namestore/plugin_rest_namestore.c22
-rwxr-xr-xsrc/namestore/test_plugin_rest_namestore.sh78
3 files changed, 37 insertions, 81 deletions
diff --git a/src/json/json_gnsrecord.c b/src/json/json_gnsrecord.c
index 4f6d30748..7bdf97f06 100644
--- a/src/json/json_gnsrecord.c
+++ b/src/json/json_gnsrecord.c
@@ -54,7 +54,7 @@ parse_gnsrecordobject (void *cls,
54 const char *record_type; 54 const char *record_type;
55 const char *label; 55 const char *label;
56 int flag; 56 int flag;
57 void *rdata; 57 void *rdata = NULL;
58 size_t rdata_size; 58 size_t rdata_size;
59 59
60 GNUNET_assert(NULL != root); 60 GNUNET_assert(NULL != root);
@@ -72,7 +72,7 @@ parse_gnsrecordobject (void *cls,
72 GNUNET_JSON_GNSRECORD_EXPIRATION_TIME, &expiration_time, 72 GNUNET_JSON_GNSRECORD_EXPIRATION_TIME, &expiration_time,
73 GNUNET_JSON_GNSRECORD_FLAG, &flag, 73 GNUNET_JSON_GNSRECORD_FLAG, &flag,
74 GNUNET_JSON_GNSRECORD_LABEL, &label); 74 GNUNET_JSON_GNSRECORD_LABEL, &label);
75 if (GNUNET_SYSERR == unpack_state) 75 if (0 != unpack_state)
76 { 76 {
77 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 77 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
78 "Error json object has a wrong format!\n"); 78 "Error json object has a wrong format!\n");
@@ -82,7 +82,8 @@ parse_gnsrecordobject (void *cls,
82 gnsrecord_object->record_type = GNUNET_GNSRECORD_typename_to_number(record_type); 82 gnsrecord_object->record_type = GNUNET_GNSRECORD_typename_to_number(record_type);
83 if (UINT32_MAX == gnsrecord_object->record_type) 83 if (UINT32_MAX == gnsrecord_object->record_type)
84 { 84 {
85 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,"Unsupported type"); 85 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,"Unsupported type\n");
86 GNUNET_free(gnsrecord_object);
86 return GNUNET_SYSERR; 87 return GNUNET_SYSERR;
87 } 88 }
88 if (GNUNET_OK 89 if (GNUNET_OK
@@ -91,7 +92,8 @@ parse_gnsrecordobject (void *cls,
91 &rdata, 92 &rdata,
92 &rdata_size)) 93 &rdata_size))
93 { 94 {
94 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,"Value invalid for record type"); 95 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,"Value invalid for record type\n");
96 GNUNET_free(gnsrecord_object);
95 return GNUNET_SYSERR; 97 return GNUNET_SYSERR;
96 } 98 }
97 99
@@ -110,7 +112,9 @@ parse_gnsrecordobject (void *cls,
110 } 112 }
111 else 113 else
112 { 114 {
113 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Expiration time invalid"); 115 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Expiration time invalid\n");
116 GNUNET_free_non_null(rdata);
117 GNUNET_free(gnsrecord_object);
114 return GNUNET_SYSERR; 118 return GNUNET_SYSERR;
115 } 119 }
116 // check if flag is a valid enum value 120 // check if flag is a valid enum value
@@ -119,7 +123,9 @@ parse_gnsrecordobject (void *cls,
119 && (GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION != flag) 123 && (GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION != flag)
120 && (GNUNET_GNSRECORD_RF_SHADOW_RECORD) != flag) 124 && (GNUNET_GNSRECORD_RF_SHADOW_RECORD) != flag)
121 { 125 {
122 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Flag invalid"); 126 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Flag invalid\n");
127 GNUNET_free_non_null(rdata);
128 GNUNET_free(gnsrecord_object);
123 return GNUNET_SYSERR; 129 return GNUNET_SYSERR;
124 } 130 }
125 gnsrecord_object->flags = (enum GNUNET_GNSRECORD_Flags)flag; 131 gnsrecord_object->flags = (enum GNUNET_GNSRECORD_Flags)flag;
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
197curl_delete "${namestore_link}?label=test_entry&name=$name" "HTTP/1.1 204" 197curl_delete "${namestore_link}?label=test_entry&name=$name" "HTTP/1.1 204"
198gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY" 198gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY"
199curl_delete "${namestore_link}?label=test_entry&pubkey=$public" "HTTP/1.1 204" 199curl_delete "${namestore_link}?label=test_entry&pubkey=$public" "HTTP/1.1 204"
200gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY"
201curl_delete "${namestore_link}?label=test_entry&pubkey=$name" "HTTP/1.1 404"
200 202
201exit 0;
202
203
204
205#pubkey zone
206#name zone
207curl_post "${namestore_link}" '{"name":"test_plugin_rest_identity"}' "HTTP/1.1 201 Created"
208curl_post "${namestore_link}" '{"name":"test_plugin_rest_identity"}' "HTTP/1.1 409"
209curl_post "${namestore_link}" '{"name":"Test_plugin_rest_identity"}' "HTTP/1.1 409"
210curl_post "${namestore_link}" '{}' "error"
211curl_post "${namestore_link}" '' "error"
212curl_post "${namestore_link}" '{"name":""}' "error"
213curl_post "${namestore_link}" '{"name":123}' "error"
214curl_post "${namestore_link}" '{"name":[]}' "error"
215curl_post "${namestore_link}" '{"name1":"test_plugin_rest_identity"}' "error"
216curl_post "${namestore_link}" '{"other":""}' "error"
217curl_post "${namestore_link}" '{"name":"test_plugin_rest_identity1", "other":"test_plugin_rest_identity2"}' "error"
218
219#Test PUT
220name="$(gnunet-identity -d | grep "test_plugin_rest_identity" | awk 'NR==1{print $1}')"
221public="$(gnunet-identity -d | grep "test_plugin_rest_identity" | awk 'NR==1{print $3}')"
222
223curl_put "${namestore_link}" '{"newname":"test_plugin_rest_identity1","pubkey":"'$public'"}' "HTTP/1.1 204"
224curl_put "${namestore_link}" '{"newname":"test_plugin_rest_identity1","pubkey":"'$public'"}' "HTTP/1.1 409"
225curl_put "${namestore_link}" '{"newname":"test_plugin_rest_identity1","pubkey":"'$public'xx"}' "HTTP/1.1 404"
226curl_put "${namestore_link}" '{"newname":"test_plugin_rest_identity1","pubkey":""}' "HTTP/1.1 404"
227curl_put "${namestore_link}" '{"newname":"test_plugin_rest_identity1","pubke":""}' "HTTP/1.1 404"
228curl_put "${namestore_link}" '{"newname":"test_plugin_rest_identity1","pubke":"","other":"sdfdsf"}' "HTTP/1.1 404"
229curl_put "${namestore_link}" '{"newname":"test_plugin_rest_identity1","pubke":"","name":"sdfdsf"}' "HTTP/1.1 404"
230curl_put "${namestore_link}" '{"newname":"test_plugin_rest_identity","pubke":"","name":"test_plugin_rest_identity1"}' "HTTP/1.1 204"
231curl_put "${namestore_link}" '{"newnam":"test_plugin_rest_identity","pubkey":"'$public'"}' "error"
232curl_put "${namestore_link}" '{"newname":"test_plugin_rest_identity1","name":"test_plugin_rest_identity"}' "HTTP/1.1 204"
233curl_put "${namestore_link}" '{"newname":"TEST_plugin_rest_identity1","name":"test_plugin_rest_identity1"}' "HTTP/1.1 409"
234curl_put "${namestore_link}" '{"newname":"test_plugin_rest_identity1","name":"test_plugin_rest_identity1"}' "HTTP/1.1 409"
235curl_put "${namestore_link}" '{"newname":"test_plugin_rest_identity","name":"test_plugin_rest_identityxxx"}' "HTTP/1.1 404"
236curl_put "${namestore_link}" '{"newname":"test_plugin_rest_identity","name":"test_plugin_rest_identity1"}' "HTTP/1.1 204"
237curl_put "${namestore_link}" '{"newnam":"test_plugin_rest_identityfail","name":"test_plugin_rest_identity"}' "error"
238
239
240#Test subsystem
241curl_put "${identity_link}" '{"subsystem":"namestore","name":"test_plugin_rest_identity"}' "HTTP/1.1 204"
242curl_put "${identity_link}" '{"subsystem":"namestore","name":"test_plugin_rest_identity"}' "HTTP/1.1 204"
243curl_get "${identity_link}?subsystem=namestore" "test_plugin_rest_identity"
244curl_post "${identity_link}" '{"name":"test_plugin_rest_identity1"}' "HTTP/1.1 201 Created"
245public="$(gnunet-identity -d | grep "test_plugin_rest_identity" | awk 'NR==1{print $3}')"
246curl_put "${identity_link}" '{"subsystem":"namestore","pubkey":"'"$public"'"}' "HTTP/1.1 204"
247curl_get "${identity_link}?subsystem=namestore" "test_plugin_rest_identity1"
248curl_get "${identity_link}?subsystem=test_plugin_rest_identity_no_subsystem" "error"
249curl_put "${identity_link}" '{"subsystem":"test_plugin_rest_identity_no_subsystem","name":"test_plugin_rest_identity1"}' "HTTP/1.1 204"
250curl_get "${identity_link}?subsystem=test_plugin_rest_identity_no_subsystem" "test_plugin_rest_identity1"
251
252curl_put "${identity_link}" '{"subsyste":"test_plugin_rest_identity_no_subsystem","name":"test_plugin_rest_identity1"}' "error"
253curl_put "${identity_link}" '{"subsystem":"test_plugin_rest_identity_no_subsystem","name":"Test_plugin_rest_identity1"}' "HTTP/1.1 204"
254
255#Test DELETE
256curl_delete "${identity_link}?name=test_plugin_rest_identity" "HTTP/1.1 204"
257curl_get "${identity_link}?name=test_plugin_rest_identity" "error"
258curl_delete "${identity_link}?name=TEST_plugin_rest_identity1" "HTTP/1.1 404"
259curl_delete "${identity_link}?name=test_plugin_rest_identity1" "HTTP/1.1 204"
260curl_get "${identity_link}?name=test_plugin_rest_identity1" "error"
261curl_delete "${identity_link}?name=test_plugin_rest_identity_not_found" "HTTP/1.1 404"
262curl_post "${identity_link}" '{"name":"test_plugin_rest_identity1"}' "HTTP/1.1 201 Created"
263public="$(gnunet-identity -d | grep "test_plugin_rest_identity1" | awk 'NR==1{print $3}')"
264curl_delete "${identity_link}?pubkey=$public" "HTTP/1.1 204"
265curl_delete "${identity_link}?pubke=$public" "error"
266curl_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
270exit 0; 207exit 0;
208