gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnunet] branch master updated: -more rest API fixes, test fix


From: gnunet
Subject: [gnunet] branch master updated: -more rest API fixes, test fix
Date: Sun, 23 Oct 2022 15:02:38 +0200

This is an automated email from the git hooks/post-receive script.

martin-schanzenbach pushed a commit to branch master
in repository gnunet.

The following commit(s) were added to refs/heads/master by this push:
     new 9c7255313 -more rest API fixes, test fix
9c7255313 is described below

commit 9c7255313368e04bff09d8dfb1aad537e7121359
Author: Martin Schanzenbach <schanzen@gnunet.org>
AuthorDate: Sun Oct 23 22:01:37 2022 +0900

    -more rest API fixes, test fix
---
 src/gnsrecord/json_gnsrecord.c              | 114 ++++++++++++++--------------
 src/namestore/Makefile.am                   |   5 +-
 src/namestore/plugin_rest_namestore.c       |   2 +-
 src/namestore/test_plugin_rest_namestore.sh |  21 +++--
 4 files changed, 71 insertions(+), 71 deletions(-)

diff --git a/src/gnsrecord/json_gnsrecord.c b/src/gnsrecord/json_gnsrecord.c
index 94916292f..707e88668 100644
--- a/src/gnsrecord/json_gnsrecord.c
+++ b/src/gnsrecord/json_gnsrecord.c
@@ -31,13 +31,13 @@
 #define GNUNET_JSON_GNSRECORD_VALUE "value"
 #define GNUNET_JSON_GNSRECORD_RECORD_DATA "data"
 #define GNUNET_JSON_GNSRECORD_TYPE "record_type"
-#define GNUNET_JSON_GNSRECORD_EXPIRATION_TIME "expiration_time"
+#define GNUNET_JSON_GNSRECORD_RELATIVE_EXPIRATION_TIME "relative_expiration"
+#define GNUNET_JSON_GNSRECORD_ABSOLUTE_EXPIRATION_TIME "absolute_expiration"
 #define GNUNET_JSON_GNSRECORD_FLAG_PRIVATE "is_private"
-#define GNUNET_JSON_GNSRECORD_FLAG_SUPPLEMENTAL "supplemental"
+#define GNUNET_JSON_GNSRECORD_FLAG_SUPPLEMENTAL "is_supplemental"
 #define GNUNET_JSON_GNSRECORD_FLAG_RELATIVE "is_relative_expiration"
-#define GNUNET_JSON_GNSRECORD_FLAG_SHADOW "shadow"
+#define GNUNET_JSON_GNSRECORD_FLAG_SHADOW "is_shadow"
 #define GNUNET_JSON_GNSRECORD_RECORD_NAME "record_name"
-#define GNUNET_JSON_GNSRECORD_NEVER "never"
 
 struct GnsRecordInfo
 {
@@ -82,39 +82,66 @@ cleanup_recordinfo (struct GnsRecordInfo *gnsrecord_info)
 static int
 parse_record (json_t *data, struct GNUNET_GNSRECORD_Data *rd)
 {
-  struct GNUNET_TIME_Absolute abs_expiration_time;
-  struct GNUNET_TIME_Relative rel_expiration_time;
+  struct GNUNET_TIME_Absolute abs_exp;
+  struct GNUNET_TIME_Relative rel_exp;
   const char *value;
   const char *record_type;
-  const char *expiration_time;
   int private;
   int supplemental;
-  int rel_exp;
+  int is_rel_exp;
   int shadow;
   int unpack_state = 0;
+  json_error_t err;
 
   // interpret single gns record
-  unpack_state = json_unpack (data,
-                              "{s:s, s:s, s:s, s:b, s:b, s:b, s:b}",
-                              GNUNET_JSON_GNSRECORD_VALUE,
-                              &value,
-                              GNUNET_JSON_GNSRECORD_TYPE,
-                              &record_type,
-                              GNUNET_JSON_GNSRECORD_EXPIRATION_TIME,
-                              &expiration_time,
-                              GNUNET_JSON_GNSRECORD_FLAG_PRIVATE,
-                              &private,
-                              GNUNET_JSON_GNSRECORD_FLAG_SUPPLEMENTAL,
-                              &supplemental,
-                              GNUNET_JSON_GNSRECORD_FLAG_RELATIVE,
-                              &rel_exp,
-                              GNUNET_JSON_GNSRECORD_FLAG_SHADOW,
-                              &shadow);
+  unpack_state = json_unpack_ex (data,
+                                 &err,
+                                 0,
+                                 "{s:s, s:s, s:i, s:b, s:b, s:b, s:b}",
+                                 GNUNET_JSON_GNSRECORD_VALUE,
+                                 &value,
+                                 GNUNET_JSON_GNSRECORD_TYPE,
+                                 &record_type,
+                                 
GNUNET_JSON_GNSRECORD_RELATIVE_EXPIRATION_TIME,
+                                 &rel_exp.rel_value_us,
+                                 GNUNET_JSON_GNSRECORD_FLAG_PRIVATE,
+                                 &private,
+                                 GNUNET_JSON_GNSRECORD_FLAG_SUPPLEMENTAL,
+                                 &supplemental,
+                                 GNUNET_JSON_GNSRECORD_FLAG_RELATIVE,
+                                 &is_rel_exp,
+                                 GNUNET_JSON_GNSRECORD_FLAG_SHADOW,
+                                 &shadow);
   if (0 != unpack_state)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Error gnsdata object has a wrong format!\n");
-    return GNUNET_SYSERR;
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  "Error gnsdata object has a wrong format: `%s'!\n",
+                  err.text);
+    unpack_state = json_unpack_ex (data,
+                                   &err,
+                                   0,
+                                   "{s:s, s:s, s:I, s:b, s:b, s:b, s:b}",
+                                   GNUNET_JSON_GNSRECORD_VALUE,
+                                   &value,
+                                   GNUNET_JSON_GNSRECORD_TYPE,
+                                   &record_type,
+                                   
GNUNET_JSON_GNSRECORD_ABSOLUTE_EXPIRATION_TIME,
+                                   &abs_exp.abs_value_us,
+                                   GNUNET_JSON_GNSRECORD_FLAG_PRIVATE,
+                                   &private,
+                                   GNUNET_JSON_GNSRECORD_FLAG_SUPPLEMENTAL,
+                                   &supplemental,
+                                   GNUNET_JSON_GNSRECORD_FLAG_RELATIVE,
+                                   &is_rel_exp,
+                                   GNUNET_JSON_GNSRECORD_FLAG_SHADOW,
+                                   &shadow);
+    if ((0 != unpack_state) || (is_rel_exp))
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  "Error gnsdata object has a wrong format: `%s'!\n",
+                  (is_rel_exp) ? "No relative expiration given" : err.text);
+      return GNUNET_SYSERR;
+    }
   }
   rd->record_type = GNUNET_GNSRECORD_typename_to_number (record_type);
   if (UINT32_MAX == rd->record_type)
@@ -131,29 +158,8 @@ parse_record (json_t *data, struct GNUNET_GNSRECORD_Data 
*rd)
     return GNUNET_SYSERR;
   }
 
-  if (0 == strcmp (expiration_time, GNUNET_JSON_GNSRECORD_NEVER))
-  {
-    rd->expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us;
-  }
-  else if ((1 != rel_exp) &&
-           (GNUNET_OK ==
-            GNUNET_STRINGS_fancy_time_to_absolute (expiration_time,
-                                                   &abs_expiration_time)))
-  {
-    rd->expiration_time = abs_expiration_time.abs_value_us;
-  }
-  else if (GNUNET_OK ==
-           GNUNET_STRINGS_fancy_time_to_relative (expiration_time,
-                                                  &rel_expiration_time))
-  {
+  if (is_rel_exp)
     rd->flags |= GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
-    rd->expiration_time = rel_expiration_time.rel_value_us;
-  }
-  else
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Expiration time invalid\n");
-    return GNUNET_SYSERR;
-  }
   if (1 == private)
     rd->flags |= GNUNET_GNSRECORD_RF_PRIVATE;
   if (1 == supplemental)
@@ -260,8 +266,8 @@ clean_gnsrecordobject (void *cls, struct 
GNUNET_JSON_Specification *spec)
  */
 struct GNUNET_JSON_Specification
 GNUNET_GNSRECORD_JSON_spec_gnsrecord (struct GNUNET_GNSRECORD_Data **rd,
-                            unsigned int *rd_count,
-                            char **name)
+                                      unsigned int *rd_count,
+                                      char **name)
 {
   struct GnsRecordInfo *gnsrecord_info = GNUNET_new (struct GnsRecordInfo);
 
@@ -289,8 +295,8 @@ GNUNET_GNSRECORD_JSON_spec_gnsrecord (struct 
GNUNET_GNSRECORD_Data **rd,
  */
 json_t *
 GNUNET_GNSRECORD_JSON_from_gnsrecord (const char*rname,
-                            const struct GNUNET_GNSRECORD_Data *rd,
-                            unsigned int rd_count)
+                                      const struct GNUNET_GNSRECORD_Data *rd,
+                                      unsigned int rd_count)
 {
   struct GNUNET_TIME_Absolute abs_exp;
   struct GNUNET_TIME_Relative rel_exp;
@@ -387,5 +393,3 @@ GNUNET_GNSRECORD_JSON_from_gnsrecord (const char*rname,
   }
   return data;
 }
-
-
diff --git a/src/namestore/Makefile.am b/src/namestore/Makefile.am
index 4b4839f2a..2a1558e09 100644
--- a/src/namestore/Makefile.am
+++ b/src/namestore/Makefile.am
@@ -519,9 +519,8 @@ check_SCRIPTS = \
   test_namestore_delete.sh \
   test_namestore_zonefile_import.sh
 
-# FIXME
-#check_SCRIPTS += \
-#  test_plugin_rest_namestore.sh
+check_SCRIPTS += \
+  test_plugin_rest_namestore.sh
 
 EXTRA_DIST = \
   test_common.c \
diff --git a/src/namestore/plugin_rest_namestore.c 
b/src/namestore/plugin_rest_namestore.c
index 05495c23b..2618b4ca0 100644
--- a/src/namestore/plugin_rest_namestore.c
+++ b/src/namestore/plugin_rest_namestore.c
@@ -339,7 +339,7 @@ do_error (void *cls)
   if (0 != handle->ec)
     emsg = GNUNET_strdup (GNUNET_ErrorCode_get_hint (handle->ec));
   json_object_set_new (json_error, "error", json_string (emsg));
-
+  json_object_set_new (json_error, "error_code", json_integer (handle->ec));
   response_code = GNUNET_ErrorCode_get_http_status (handle->ec);
   if (0 == response_code)
     response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
diff --git a/src/namestore/test_plugin_rest_namestore.sh 
b/src/namestore/test_plugin_rest_namestore.sh
index cd4162abe..4f117db8b 100755
--- a/src/namestore/test_plugin_rest_namestore.sh
+++ b/src/namestore/test_plugin_rest_namestore.sh
@@ -92,37 +92,34 @@ curl_get "${namestore_link}/$public" "error"
 gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf
 
 #Test POST with NAME
-curl_post "${namestore_link}/$name" '{"data": 
[{"value":"000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8", 
"record_type":"PKEY", "expiration_time":"1d","is_private": false, 
"is_relative_expiration": false, "supplemental": false, "shadow": 
false}],"record_name":"test_entry"}' "HTTP/1.1 204 No Content"
+curl_post "${namestore_link}/$name" '{"data": 
[{"value":"000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8", 
"record_type":"PKEY", "relative_expiration": 86400000000, 
"is_relative_expiration": false, "is_supplemental": false, "is_shadow": false, 
"is_private": false}],"record_name":"test_entry"}' "HTTP/1.1 204 No Content"
 gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > 
/dev/null 2>&1
 
 # invalid values
-curl_post "${namestore_link}/$name" '{"data": 
[{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRGxxx", 
"record_type":"PKEY", "expiration_time":"1d","is_private": false, 
"is_relative_expiration": false, "supplemental": false, "shadow": 
false}],"record_name":"test_entry"}' "error"
+curl_post "${namestore_link}/$name" '{"data": 
[{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRGxxx", 
"record_type":"PKEY", "relative_expiration": 86400000000, 
"is_relative_expiration": false, "is_supplemental": false, "is_shadow": false, 
"is_private": false}],"record_name":"test_entry"}' "error"
 gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > 
/dev/null 2>&1
 
 
-curl_post "${namestore_link}/$name" '{"data": [{"value":"", 
"record_type":"PKEY", 
"expiration_time":"1d","flag":0,"record_name"}]:"test_entry"}' "error"
+curl_post "${namestore_link}/$name" '{"data": [{"value":"", 
"record_type":"PKEY", "relative_expiration": 
86400000000,"flag":0,"record_name"}]:"test_entry"}' "error"
 gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > 
/dev/null 2>&1
 
-curl_post "${namestore_link}/$name" '{"data": [{"record_type":"PKEY", 
"expiration_time":"1d","flag":0}],"record_name":"test_entry"}' "error"
+curl_post "${namestore_link}/$name" '{"data": [{"record_type":"PKEY", 
"relative_expiration": 86400000000,"flag":0}],"record_name":"test_entry"}' 
"error"
 gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > 
/dev/null 2>&1
 
 #expirations
-curl_post "${namestore_link}/$name" '{"data": 
[{"value":"000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8", 
"record_type":"PKEY", "expiration_time":"0d","is_private": false, 
"is_relative_expiration": true, "supplemental": false, "shadow": 
false}],"record_name":"test_entry"}' "HTTP/1.1 204"
+curl_post "${namestore_link}/$name" '{"data": 
[{"value":"000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8", 
"record_type":"PKEY", "relative_expiration":0, "is_relative_expiration": true, 
"is_supplemental": false, "is_shadow": false, "is_private": 
false}],"record_name":"test_entry"}' "HTTP/1.1 204"
 gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > 
/dev/null 2>&1
 
-curl_post "${namestore_link}/$name" '{"data": 
[{"value":"000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8", 
"record_type":"PKEY", "expiration_time":"10000d","is_private": false, 
"is_relative_expiration": true, "supplemental": false, "shadow": 
false}],"record_name":"test_entry"}' "HTTP/1.1 204"
+curl_post "${namestore_link}/$name" '{"data": 
[{"value":"000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8", 
"record_type":"PKEY", "relative_expiration":864000000000000, 
"is_relative_expiration": true, "is_supplemental": false, "is_shadow": false, 
"is_private": false}],"record_name":"test_entry"}' "HTTP/1.1 204"
 gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > 
/dev/null 2>&1
 
-curl_post "${namestore_link}/$name" '{"data": 
[{"value":"000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8", 
"record_type":"PKEY", "expiration_time":"now","is_private": false, 
"is_relative_expiration": false, "supplemental": false, "shadow": 
false}],"record_name":"test_entry"}' "error"
-gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > 
/dev/null 2>&1
-
-curl_post "${namestore_link}/$name" '{"data": 
[{"value":"000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8", 
"record_type":"PKEY", "expiration_time_missing":"1d","is_private": false, 
"is_relative_expiration": false, "supplemental": false, "shadow": 
false}],"record_name":"test_entry"}' "error"
+curl_post "${namestore_link}/$name" '{"data": 
[{"value":"000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8", 
"record_type":"PKEY", "expiration_time_missing":"1d", "is_relative_expiration": 
false, "is_supplemental": false, "is_shadow": false, "is_private": 
false}],"record_name":"test_entry"}' "error"
 gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > 
/dev/null 2>&1
 
 #record_name
-curl_post "${namestore_link}/$name" '{"data": 
[{"value":"000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8", 
"record_type":"PKEY", "expiration_time":"1d","is_private": false, 
"is_relative_expiration": false, "supplemental": false, "shadow": 
false}],"record_name":""}' "error"
+curl_post "${namestore_link}/$name" '{"data": 
[{"value":"000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8", 
"record_type":"PKEY", "relative_expiration":86400000000, 
"is_relative_expiration": false, "is_supplemental": false, "is_shadow": false, 
"is_private": false}],"record_name":""}' "error"
 gnunet-namestore -z $name -d -n "test_entry"  -c test_namestore_api.conf > 
/dev/null 2>&1
-curl_post "${namestore_link}/$name" '{"data": 
[{"value":"000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8", 
"record_type":"PKEY", "expiration_time":"1d","is_private": false, 
"is_relative_expiration": false, "supplemental": false, "shadow": 
false}],"record_name_missing":"test_entry"}' "error"
+curl_post "${namestore_link}/$name" '{"data": 
[{"value":"000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8", 
"record_type":"PKEY", "relative_expiration":"1d", "is_relative_expiration": 
false, "is_supplemental": false, "is_shadow": false, "is_private": 
false}],"record_name_missing":"test_entry"}' "error"
 gnunet-namestore -z $name -d -n "test_entry"  -c test_namestore_api.conf > 
/dev/null 2>&1
 
 #Test DELETE

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]