gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] branch master updated: fully implement forget + some te


From: gnunet
Subject: [taler-merchant] branch master updated: fully implement forget + some tests
Date: Tue, 21 Jul 2020 22:45:15 +0200

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

jonathan-buchanan pushed a commit to branch master
in repository merchant.

The following commit(s) were added to refs/heads/master by this push:
     new aeef085  fully implement forget + some tests
aeef085 is described below

commit aeef085a936545f26c5be60b33e2d9e05b862492
Author: Jonathan Buchanan <jonathan.russ.buchanan@gmail.com>
AuthorDate: Tue Jul 21 16:45:06 2020 -0400

    fully implement forget + some tests
---
 ...merchant-httpd_private-patch-orders-ID-forget.c | 112 ++++++---------------
 src/include/taler_merchant_testing_lib.h           |   5 +-
 src/lib/merchant_api_get_config.c                  |   2 +-
 src/testing/test_merchant_api.c                    |  51 +++++++---
 src/testing/testing_api_cmd_post_orders.c          |  75 +++++++-------
 5 files changed, 106 insertions(+), 139 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_private-patch-orders-ID-forget.c 
b/src/backend/taler-merchant-httpd_private-patch-orders-ID-forget.c
index 314e66a..1c33d84 100644
--- a/src/backend/taler-merchant-httpd_private-patch-orders-ID-forget.c
+++ b/src/backend/taler-merchant-httpd_private-patch-orders-ID-forget.c
@@ -28,83 +28,22 @@
 
 
 /**
- * Parse a json path, using the syntax defined in the spec for this method.
- * @param obj the root object the path applies to.
- * @param path the path to find.
+ * Forget part of the contract terms.
  *
- * @return the object pointed to by @e path if it exists, NULL otherwise.
+ * @param cls pointer to the result of the forget operation.
+ * @param object_id name of the object to forget.
+ * @param parent parent of the object at @e object_id.
  */
-static int
-forget_field (json_t *obj,
-              json_t *prev,
-              const char *field)
+static void
+forget (void *cls,
+        const char *object_id,
+        json_t *parent)
 {
-  /* FIXME: Handle nonexistent paths */
-  /* FIXME: If prev is NULL, check that the string starts with $ */
-  char *id = GNUNET_strdup (field);
-  char *next_id = strchr (id,
-                          '.');
-  json_t *next_obj = NULL;
-  int ret;
-
-  if (NULL != next_id)
-  {
-    *next_id = '\0';
-    next_id++;
-  }
-  else
-  {
-    return TALER_JSON_contract_part_forget (prev,
-                                            id);
-  }
-
-  // Check for bracketed indices
-  char *bracket = strchr (id,
-                          '[');
-  if (NULL != bracket)
-  {
-    char *end_bracket = strchr (bracket,
-                                ']');
-    if (NULL == end_bracket)
-      return GNUNET_SYSERR;
-    *end_bracket = '\0';
-
-    *bracket = '\0';
-    bracket++;
-
-    json_t *arr = json_object_get (obj,
-                                   id);
-    if (0 == strcmp (bracket,
-                     "*"))
-    {
-      /* FIXME: Handle wildcard expansion */
-    }
-    else
-    {
-      unsigned int index;
-      if (1 != sscanf (bracket,
-                       "%u",
-                       &index))
-        return GNUNET_SYSERR;
-
-      next_obj = json_array_get (arr,
-                                 index);
-    }
-  }
-  else
-  {
-    // No brackets, so just fetch the object by name
-    next_obj = json_object_get (obj,
-                                next_id);
-  }
-
-  ret = forget_field (next_obj,
-                      obj,
-                      next_id);
-
-  GNUNET_free (id);
-
-  return ret;
+  int *res = cls;
+  if (GNUNET_OK !=
+      TALER_JSON_contract_part_forget (parent,
+                                       object_id))
+    *res = GNUNET_SYSERR;
 }
 
 
@@ -170,7 +109,7 @@ TMH_private_patch_orders_ID_forget (const struct 
TMH_RequestHandler *rh,
              ? MHD_YES
              : MHD_NO;
   }
-  if ( !(json_is_array (fields)))
+  if (! (json_is_array (fields)))
   {
     json_decref (contract_terms);
     json_decref (fields);
@@ -184,8 +123,9 @@ TMH_private_patch_orders_ID_forget (const struct 
TMH_RequestHandler *rh,
     size_t index;
     json_t *value;
     json_array_foreach (fields, index, value) {
-      int forget_status;
-      if ( !(json_is_string (value)))
+      int forget_status = GNUNET_OK;
+      int expand_status;
+      if (! (json_is_string (value)))
       {
         json_decref (contract_terms);
         json_decref (fields);
@@ -194,10 +134,10 @@ TMH_private_patch_orders_ID_forget (const struct 
TMH_RequestHandler *rh,
                                            
TALER_EC_FORGET_PATH_SYNTAX_INCORRECT,
                                            "field isn't a string");
       }
-      // Check that the field starts with "$."
-      forget_status = forget_field (contract_terms,
-                                    NULL,
-                                    json_string_value (value));
+      expand_status = TALER_JSON_expand_path (contract_terms,
+                                              json_string_value (value),
+                                              &forget,
+                                              &forget_status);
       if (GNUNET_SYSERR == forget_status)
       {
         /* We tried to forget a field that isn't forgettable */
@@ -208,6 +148,16 @@ TMH_private_patch_orders_ID_forget (const struct 
TMH_RequestHandler *rh,
                                            
TALER_EC_FORGET_PATH_NOT_FORGETTABLE,
                                            "field isn't forgettable");
       }
+      if (GNUNET_SYSERR == expand_status)
+      {
+        /* One of the paths was malformed and couldn't be expanded */
+        json_decref (contract_terms);
+        json_decref (fields);
+        return TALER_MHD_reply_with_error (connection,
+                                           MHD_HTTP_BAD_REQUEST,
+                                           
TALER_EC_FORGET_PATH_SYNTAX_INCORRECT,
+                                           "malformed path");
+      }
     }
   }
 
diff --git a/src/include/taler_merchant_testing_lib.h 
b/src/include/taler_merchant_testing_lib.h
index 889c425..68978c9 100644
--- a/src/include/taler_merchant_testing_lib.h
+++ b/src/include/taler_merchant_testing_lib.h
@@ -532,8 +532,6 @@ TALER_TESTING_cmd_merchant_post_orders_no_claim (const char 
*label,
  *        "[product_id]/[quantity];...".
  * @param locks a string of references to lock product commands that should
  *        be formatted as "[lock_1];[lock_2];...".
- * @param ... a NULL-terminated list of paths that should be marked as
- *        forgettable in the contract terms.
  * @return the command
  */
 struct TALER_TESTING_Command
@@ -548,8 +546,7 @@ TALER_TESTING_cmd_merchant_post_orders2 (const char *label,
                                          const char *amount,
                                          const char *payment_target,
                                          const char *products,
-                                         const char *locks,
-                                         ...);
+                                         const char *locks);
 
 
 /**
diff --git a/src/lib/merchant_api_get_config.c 
b/src/lib/merchant_api_get_config.c
index 722d1f0..6a74e90 100644
--- a/src/lib/merchant_api_get_config.c
+++ b/src/lib/merchant_api_get_config.c
@@ -33,7 +33,7 @@
  * Which version of the Taler protocol is implemented
  * by this library?  Used to determine compatibility.
  */
-#define MERCHANT_PROTOCOL_CURRENT 0
+#define MERCHANT_PROTOCOL_CURRENT 1
 
 /**
  * How many configs are we backwards compatible with?
diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c
index b0ac230..7837774 100644
--- a/src/testing/test_merchant_api.c
+++ b/src/testing/test_merchant_api.c
@@ -262,9 +262,7 @@ run (void *cls,
                                              "EUR:5.0",
                                              "x-taler-bank",
                                              "",
-                                             "",
-                                             "max_fee",
-                                             NULL),
+                                             ""),
     TALER_TESTING_cmd_merchant_claim_order ("reclaim-1",
                                             merchant_url,
                                             MHD_HTTP_OK,
@@ -313,12 +311,12 @@ run (void *cls,
                                           "withdraw-coin-1",
                                           "EUR:5",
                                           "EUR:4.99"),
-    TALER_TESTING_cmd_merchant_forget_order ("forget-p3",
+    TALER_TESTING_cmd_merchant_forget_order ("forget-1",
                                              merchant_url,
                                              MHD_HTTP_OK,
                                              "create-proposal-1",
                                              NULL,
-                                             "$.max_fee",
+                                             "$.dummy_obj",
                                              NULL),
     TALER_TESTING_cmd_merchant_forget_order ("forget-unforgettable",
                                              merchant_url,
@@ -327,15 +325,44 @@ run (void *cls,
                                              NULL,
                                              "$.amount",
                                              NULL),
+    TALER_TESTING_cmd_merchant_forget_order ("forget-order-nx",
+                                             merchant_url,
+                                             MHD_HTTP_NOT_FOUND,
+                                             NULL,
+                                             "nx-order",
+                                             "$.dummy_obj",
+                                             NULL),
+    TALER_TESTING_cmd_merchant_forget_order ("forget-order-array-elem",
+                                             merchant_url,
+                                             MHD_HTTP_OK,
+                                             "create-proposal-1",
+                                             NULL,
+                                             "$.dummy_array[0].item",
+                                             NULL),
+    TALER_TESTING_cmd_merchant_forget_order ("forget-order-array-wc",
+                                             merchant_url,
+                                             MHD_HTTP_OK,
+                                             "create-proposal-1",
+                                             NULL,
+                                             "$.dummy_array[*].item",
+                                             NULL),
+    TALER_TESTING_cmd_merchant_forget_order ("forget-order-malformed",
+                                             merchant_url,
+                                             MHD_HTTP_BAD_REQUEST,
+                                             "create-proposal-1",
+                                             NULL,
+                                             "$.dummy_array[abc].item",
+                                             NULL),
     TALER_TESTING_cmd_poll_order_conclude ("poll-order-merchant-1-conclude",
                                            MHD_HTTP_OK,
                                            "poll-order-merchant-1-start"),
+    /*
     TALER_TESTING_cmd_wallet_get_order ("get-order-wallet-1-2",
                                         merchant_url,
                                         "create-proposal-1",
                                         true,
                                         false,
-                                        MHD_HTTP_OK),
+                                        MHD_HTTP_OK),*/
     /*TALER_TESTING_cmd_merchant_get_order ("get-order-merchant-1-2",
                                           merchant_url,
                                           "create-proposal-1",
@@ -415,8 +442,7 @@ run (void *cls,
                                              "EUR:5.0",
                                              "unsupported-wire-method",
                                              "product-3/2",
-                                             "",
-                                             NULL),
+                                             ""),
     TALER_TESTING_cmd_merchant_post_orders2 ("create-proposal-p3-pd-nx",
                                              merchant_url,
                                              MHD_HTTP_NOT_FOUND,
@@ -426,8 +452,7 @@ run (void *cls,
                                              "EUR:5.0",
                                              "x-taler-bank",
                                              "unknown-product/2",
-                                             "",
-                                             NULL),
+                                             ""),
     TALER_TESTING_cmd_merchant_post_orders2 (
       "create-proposal-p3-not-enough-stock",
       merchant_url,
@@ -438,8 +463,7 @@ run (void *cls,
       "EUR:5.0",
       "x-taler-bank",
       "product-3/24",
-      "",
-      NULL),
+      ""),
     TALER_TESTING_cmd_merchant_post_orders2 ("create-proposal-p3",
                                              merchant_url,
                                              MHD_HTTP_OK,
@@ -449,8 +473,7 @@ run (void *cls,
                                              "EUR:5.0",
                                              "x-taler-bank",
                                              "product-3/3",
-                                             "lock-product-p3",
-                                             NULL),
+                                             "lock-product-p3"),
     TALER_TESTING_cmd_merchant_delete_order ("delete-order-1",
                                              merchant_url,
                                              "1",
diff --git a/src/testing/testing_api_cmd_post_orders.c 
b/src/testing/testing_api_cmd_post_orders.c
index 2090c0a..8936985 100644
--- a/src/testing/testing_api_cmd_post_orders.c
+++ b/src/testing/testing_api_cmd_post_orders.c
@@ -521,6 +521,24 @@ orders_cleanup (void *cls,
 }
 
 
+/**
+ * Mark part of the contract terms as possible to forget.
+ *
+ * @param cls pointer to the result of the forget operation.
+ * @param object_id name of the object to forget.
+ * @param parent parent of the object at @e object_id.
+ */
+static void
+mark_forgettable (void *cls,
+                  const char *object_id,
+                  json_t *parent)
+{
+  GNUNET_assert (GNUNET_OK ==
+                 TALER_JSON_contract_mark_forgettable (parent,
+                                                       object_id));
+}
+
+
 /**
  * Constructs the json for a POST order request.
  *
@@ -528,8 +546,6 @@ orders_cleanup (void *cls,
  * @param refund_deadline the deadline for refunds on this order.
  * @param pay_deadline the deadline for payment on this order.
  * @param amount the amount this order is for.
- * @param forgettable a list of paths to mark as forgettable.
- * @param forgettable_length length of @e forgettable.
  * @param order[out] where to write the json string.
  */
 static void
@@ -537,8 +553,6 @@ make_order_json (const char *order_id,
                  struct GNUNET_TIME_Absolute refund_deadline,
                  struct GNUNET_TIME_Absolute pay_deadline,
                  const char *amount,
-                 const char **forgettable,
-                 unsigned int forgettable_length,
                  char **order)
 {
   struct GNUNET_TIME_Absolute refund = refund_deadline;
@@ -549,22 +563,32 @@ make_order_json (const char *order_id,
   GNUNET_TIME_round_abs (&refund);
   GNUNET_TIME_round_abs (&pay);
 
-  /* FIXME: support deeper paths */
-
+  /* Include required fields and some dummy objects to test forgetting. */
   contract_terms = json_pack (
-    "{s:s, s:s?, s:s, s:s, s:o, s:o, s:s}",
+    "{s:s, s:s?, s:s, s:s, s:o, s:o, s:s, s:[{s:s}, {s:s}, {s:s}]}",
     "summary", "merchant-lib testcase",
     "order_id", order_id,
     "amount", amount,
     "fulfillment_url", "https://example.com";,
     "refund_deadline", GNUNET_JSON_from_time_abs (refund),
     "pay_deadline", GNUNET_JSON_from_time_abs (pay),
-    "max_fee", "EUR:1.0"
+    "dummy_obj", "EUR:1.0",
+    "dummy_array", /* For testing forgetting parts of arrays */
+    "item", "speakers",
+    "item", "headphones",
+    "item", "earbuds"
     );
 
-  for (unsigned int i = 0; i < forgettable_length; ++i)
-    TALER_JSON_contract_mark_forgettable (contract_terms,
-                                          forgettable[i]);
+  GNUNET_assert (GNUNET_OK ==
+                 TALER_JSON_expand_path (contract_terms,
+                                         "$.dummy_obj",
+                                         &mark_forgettable,
+                                         NULL));
+  GNUNET_assert (GNUNET_OK ==
+                 TALER_JSON_expand_path (contract_terms,
+                                         "$.dummy_array[*].item",
+                                         &mark_forgettable,
+                                         NULL));
 
   *order = json_dumps (contract_terms, 0);
   json_decref (contract_terms);
@@ -602,8 +626,6 @@ TALER_TESTING_cmd_merchant_post_orders_no_claim (const char 
*label,
                    refund_deadline,
                    pay_deadline,
                    amount,
-                   NULL,
-                   0,
                    &ps->order);
   ps->http_status = http_status;
   ps->merchant_url = merchant_url;
@@ -653,8 +675,6 @@ TALER_TESTING_cmd_merchant_post_orders (const char *label,
                    refund_deadline,
                    pay_deadline,
                    amount,
-                   NULL,
-                   0,
                    &ps->order);
   ps->http_status = http_status;
   ps->merchant_url = merchant_url;
@@ -706,40 +726,17 @@ TALER_TESTING_cmd_merchant_post_orders2 (const char 
*label,
                                          const char *amount,
                                          const char *payment_target,
                                          const char *products,
-                                         const char *locks,
-                                         ...)
+                                         const char *locks)
 {
   struct OrdersState *ps;
 
-  const char **forgettable = NULL;
-  unsigned int forgettable_length = 0;
-  {
-    const char *path;
-    va_list ap;
-
-    va_start (ap, locks);
-    while (NULL != (path = va_arg (ap, const char *)))
-    {
-      GNUNET_array_append (forgettable,
-                           forgettable_length,
-                           path);
-    }
-    va_end (ap);
-  }
-
   ps = GNUNET_new (struct OrdersState);
   make_order_json (order_id,
                    refund_deadline,
                    pay_deadline,
                    amount,
-                   forgettable,
-                   forgettable_length,
                    &ps->order);
 
-  GNUNET_array_grow (forgettable,
-                     forgettable_length,
-                     0);
-
   ps->http_status = http_status;
   ps->merchant_url = merchant_url;
   ps->payment_target = payment_target;

-- 
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]