aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gns/plugin_rest_gns.c34
-rwxr-xr-xsrc/gns/test_plugin_rest_gns.sh50
2 files changed, 63 insertions, 21 deletions
diff --git a/src/gns/plugin_rest_gns.c b/src/gns/plugin_rest_gns.c
index aae14153d..4be583f73 100644
--- a/src/gns/plugin_rest_gns.c
+++ b/src/gns/plugin_rest_gns.c
@@ -24,6 +24,7 @@
24#include "platform.h" 24#include "platform.h"
25#include "gnunet_rest_plugin.h" 25#include "gnunet_rest_plugin.h"
26#include "gnunet_rest_lib.h" 26#include "gnunet_rest_lib.h"
27#include "gnunet_json_lib.h"
27#include "gnunet_gnsrecord_lib.h" 28#include "gnunet_gnsrecord_lib.h"
28#include "gnunet_gns_service.h" 29#include "gnunet_gns_service.h"
29#include "microhttpd.h" 30#include "microhttpd.h"
@@ -31,9 +32,9 @@
31 32
32#define GNUNET_REST_API_NS_GNS "/gns" 33#define GNUNET_REST_API_NS_GNS "/gns"
33 34
34#define GNUNET_REST_PARAMETER_GNS_NAME "name" 35#define GNUNET_REST_GNS_PARAM_NAME "name"
35 36
36#define GNUNET_REST_PARAMETER_GNS_RECORD_TYPE "record_type" 37#define GNUNET_REST_GNS_PARAM_RECORD_TYPE "record_type"
37#define GNUNET_REST_GNS_ERROR_UNKNOWN "Unknown Error" 38#define GNUNET_REST_GNS_ERROR_UNKNOWN "Unknown Error"
38 39
39/** 40/**
@@ -203,7 +204,6 @@ handle_gns_response (void *cls,
203 uint32_t rd_count, 204 uint32_t rd_count,
204 const struct GNUNET_GNSRECORD_Data *rd) 205 const struct GNUNET_GNSRECORD_Data *rd)
205{ 206{
206 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "TEST4\n");
207 struct RequestHandle *handle = cls; 207 struct RequestHandle *handle = cls;
208 struct MHD_Response *resp; 208 struct MHD_Response *resp;
209 json_t *result_array; 209 json_t *result_array;
@@ -229,10 +229,7 @@ handle_gns_response (void *cls,
229 continue; 229 continue;
230 } 230 }
231 231
232 record_value = GNUNET_GNSRECORD_value_to_string (rd->record_type, 232 record_obj = GNUNET_JSON_from_gns_record(NULL,&rd[i]);
233 rd->data,
234 rd->data_size);
235 record_obj = json_string(record_value);
236 json_array_append (result_array, record_obj); 233 json_array_append (result_array, record_obj);
237 json_decref (record_obj); 234 json_decref (record_obj);
238 } 235 }
@@ -264,8 +261,8 @@ get_gns_cont (struct GNUNET_REST_RequestHandle *con_handle,
264 char *record_type; 261 char *record_type;
265 char *name; 262 char *name;
266 263
267 GNUNET_CRYPTO_hash (GNUNET_REST_PARAMETER_GNS_NAME, 264 GNUNET_CRYPTO_hash (GNUNET_REST_GNS_PARAM_NAME,
268 strlen (GNUNET_REST_PARAMETER_GNS_NAME), 265 strlen (GNUNET_REST_GNS_PARAM_NAME),
269 &key); 266 &key);
270 if ( GNUNET_NO 267 if ( GNUNET_NO
271 == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map, 268 == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map,
@@ -284,23 +281,19 @@ get_gns_cont (struct GNUNET_REST_RequestHandle *con_handle,
284 } 281 }
285 handle->name = GNUNET_strdup(name); 282 handle->name = GNUNET_strdup(name);
286 283
287 GNUNET_CRYPTO_hash (GNUNET_REST_PARAMETER_GNS_RECORD_TYPE, 284 handle->record_type = UINT32_MAX;
288 strlen (GNUNET_REST_PARAMETER_GNS_RECORD_TYPE), 285 GNUNET_CRYPTO_hash (GNUNET_REST_GNS_PARAM_RECORD_TYPE,
286 strlen (GNUNET_REST_GNS_PARAM_RECORD_TYPE),
289 &key); 287 &key);
290 if ( GNUNET_NO 288 if ( GNUNET_YES
291 == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map, 289 == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map,
292 &key)) 290 &key))
293 { 291 {
294 handle->emsg = GNUNET_strdup("Parameter record_type is missing"); 292 record_type = GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, &key);
295 GNUNET_SCHEDULER_add_now (&do_error, handle); 293 handle->record_type = GNUNET_GNSRECORD_typename_to_number(record_type);
296 return;
297 } 294 }
298 295
299 296
300 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "TEST1\n");
301
302 record_type = GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, &key);
303 handle->record_type = GNUNET_GNSRECORD_typename_to_number(record_type);
304 if(UINT32_MAX == handle->record_type) 297 if(UINT32_MAX == handle->record_type)
305 { 298 {
306 handle->record_type = GNUNET_GNSRECORD_TYPE_ANY; 299 handle->record_type = GNUNET_GNSRECORD_TYPE_ANY;
@@ -313,7 +306,6 @@ get_gns_cont (struct GNUNET_REST_RequestHandle *con_handle,
313 GNUNET_SCHEDULER_add_now (&do_error, handle); 306 GNUNET_SCHEDULER_add_now (&do_error, handle);
314 return; 307 return;
315 } 308 }
316 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "TEST2\n");
317 309
318 handle->gns_lookup = GNUNET_GNS_lookup_with_tld (handle->gns, 310 handle->gns_lookup = GNUNET_GNS_lookup_with_tld (handle->gns,
319 handle->name, 311 handle->name,
diff --git a/src/gns/test_plugin_rest_gns.sh b/src/gns/test_plugin_rest_gns.sh
new file mode 100755
index 000000000..fca35ee2d
--- /dev/null
+++ b/src/gns/test_plugin_rest_gns.sh
@@ -0,0 +1,50 @@
1#!/usr/bin/bash
2
3#First, start gnunet-arm and the rest-service.
4#Exit 0 means success, exit 1 means failed test
5
6gns_link="http://localhost:7776/gns"
7wrong_link="http://localhost:7776/gnsandmore"
8
9curl_get () {
10 #$1 is link
11 #$2 is grep
12 cache="$(curl -v "$1" 2>&1 | grep "$2")"
13 echo $cache
14 if [ "" == "$cache" ]
15 then
16 exit 1
17 fi
18}
19
20gnunet-identity -D "test_plugin_rest_gns" > /dev/null 2>&1
21
22curl_get "$gns_link?name=www.test_plugin_rest_gns" "error"
23
24gnunet-identity -C "test_plugin_rest_gns"
25
26curl_get "$gns_link?name=www.test_plugin_rest_gns" "\[\]"
27
28gnunet-namestore -z "test_plugin_rest_gns" -p -a -n www -e 1d -V 1.1.1.1 -t A
29
30curl_get "$gns_link?name=www.test_plugin_rest_gns" "1.1.1.1"
31
32gnunet-namestore -z "test_plugin_rest_gns" -p -a -n www -e 1d -V 1::1 -t AAAA
33
34curl_get "$gns_link?name=www.test_plugin_rest_gns" "1::1.*1.1.1.1"
35
36gnunet-namestore -z "test_plugin_rest_gns" -p -a -n www -e 1d -V 1.1.1.2 -t A
37
38curl_get "$gns_link?name=www.test_plugin_rest_gns" "1.1.1.2.*1::1.*1.1.1.1"
39curl_get "$gns_link?name=www.test_plugin_rest_gns&record_type=A" "1.1.1.2.*1.1.1.1"
40curl_get "$gns_link?name=www.test_plugin_rest_gns&record_type=AAAA" "1::1"
41curl_get "$gns_link?name=www.test_plugin_rest_gns&record_type=WRONG_TYPE" "1.1.1.2.*1::1.*1.1.1.1"
42
43gnunet-namestore -z "test_plugin_rest_gns" -p -a -n www1 -e 1d -V 1.1.1.1 -t A
44curl_get "$gns_link?name=www1.test_plugin_rest_gns" "1.1.1.1"
45
46gnunet-identity -D "test_plugin_rest_gns"
47
48curl_get "$gns_link?name=www1.test_plugin_rest_gns" "error"
49
50exit 0