gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] 248/277: deeper checks on GET /private/orders


From: gnunet
Subject: [taler-merchant] 248/277: deeper checks on GET /private/orders
Date: Sun, 05 Jul 2020 20:52:41 +0200

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

grothoff pushed a commit to branch master
in repository merchant.

commit 4ce3a78d0071035a66cfb889c23fe9a9d731086f
Author: Jonathan Buchanan <jonathan.russ.buchanan@gmail.com>
AuthorDate: Tue Jun 23 23:32:53 2020 -0400

    deeper checks on GET /private/orders
---
 .../taler-merchant-httpd_private-get-orders.c      |  2 +-
 src/include/taler_merchant_testing_lib.h           | 29 +++----
 src/testing/test_merchant_api.c                    | 24 +++---
 src/testing/testing_api_cmd_get_orders.c           | 71 +++++++++++++++--
 src/testing/testing_api_cmd_get_reserves.c         | 90 ++++++++++------------
 5 files changed, 132 insertions(+), 84 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_private-get-orders.c 
b/src/backend/taler-merchant-httpd_private-get-orders.c
index 05d518f..608d276 100644
--- a/src/backend/taler-merchant-httpd_private-get-orders.c
+++ b/src/backend/taler-merchant-httpd_private-get-orders.c
@@ -338,7 +338,7 @@ TMH_private_get_orders (const struct TMH_RequestHandler *rh,
                                                  "start");
     if (NULL == start_row_str)
     {
-      of.start_row = UINT64_MAX;
+      of.start_row = INT64_MAX;
     }
     else
     {
diff --git a/src/include/taler_merchant_testing_lib.h 
b/src/include/taler_merchant_testing_lib.h
index e96d5fe..af14955 100644
--- a/src/include/taler_merchant_testing_lib.h
+++ b/src/include/taler_merchant_testing_lib.h
@@ -442,12 +442,16 @@ TALER_TESTING_cmd_merchant_post_orders (const char *label,
  * @param merchant_url base URL of the merchant serving the
  *        GET /orders request.
  * @param http_status expected HTTP response code.
+ * @param ... NULL-terminated list of labels (const char *) of
+ *        reserve (commands) we expect to be returned in the list
+ *        (assuming @a http_code is #MHD_HTTP_OK)
  * @return the command.
  */
 struct TALER_TESTING_Command
 TALER_TESTING_cmd_merchant_get_orders (const char *label,
                                        const char *merchant_url,
-                                       unsigned int http_status);
+                                       unsigned int http_status,
+                                       ...);
 
 
 /**
@@ -708,29 +712,16 @@ TALER_TESTING_cmd_merchant_get_reserve_with_tips (const 
char *label,
  * @param label command label.
  * @param merchant_url url to the merchant.
  * @param http_status expected HTTP response code.
+ * @param ... NULL-terminated list of labels (const char *) of
+ *        reserve (commands) we expect to be returned in the list
+ *        (assuming @a http_code is #MHD_HTTP_OK)
  */
 struct TALER_TESTING_Command
 TALER_TESTING_cmd_merchant_get_reserves (const char *label,
                                          const char *merchant_url,
-                                         unsigned int http_status);
-
+                                         unsigned int http_status,
+                                         ...);
 
-/**
- * Define a "GET /reserves" CMD
- *
- * @param label command label.
- * @param merchant_url url to the merchant.
- * @param reserve_refs a NULL-terminated list of references to
- *        commands that created reserves.
- * @param http_status expected HTTP response code.
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_merchant_get_reserves_with_reserves (const char *label,
-                                                       const char 
*merchant_url,
-                                                       const char *reserve_refs
-                                                       [],
-                                                       unsigned int
-                                                       http_status);
 
 /**
  * Define a "DELETE reserve" CMD.
diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c
index 0a150a9..1752ab1 100644
--- a/src/testing/test_merchant_api.c
+++ b/src/testing/test_merchant_api.c
@@ -57,9 +57,6 @@ static const char *pickup_amounts_2[] = {"EUR:0.01", NULL};
 
 static const char *pickup_refs[] = {"pickup-tip-1", "pickup-tip-4", NULL};
 
-static const char *reserve_refs[] = {"create-reserve-tip-1",
-                                     "create-reserve-tip-2", NULL};
-
 /**
  * Payto URI of the customer (payer).
  */
@@ -263,6 +260,10 @@ run (void *cls,
                                        "create-reserve-1",
                                        "EUR:5",
                                        MHD_HTTP_OK),
+    TALER_TESTING_cmd_merchant_get_orders ("get-orders-empty",
+                                           merchant_url,
+                                           MHD_HTTP_OK,
+                                           NULL),
     /**
      * Check the reserve is depleted.
      */
@@ -284,7 +285,9 @@ run (void *cls,
                          \"value\":\"{EUR:5}\"} ] }"),
     TALER_TESTING_cmd_merchant_get_orders ("get-orders-1",
                                            merchant_url,
-                                           MHD_HTTP_OK),
+                                           MHD_HTTP_OK,
+                                           "create-proposal-1",
+                                           NULL),
     TALER_TESTING_cmd_wallet_get_order ("get-order-wallet-1",
                                         merchant_url,
                                         "create-proposal-1",
@@ -698,7 +701,8 @@ run (void *cls,
                                 MHD_HTTP_OK),
     TALER_TESTING_cmd_merchant_get_reserves ("get-reserves-1",
                                              merchant_url,
-                                             MHD_HTTP_OK),
+                                             MHD_HTTP_OK,
+                                             NULL),
     TALER_TESTING_cmd_merchant_get_reserve ("get-reserve-1",
                                             merchant_url,
                                             MHD_HTTP_OK,
@@ -788,10 +792,12 @@ run (void *cls,
                                           pickup_amounts_1,
                                           TALER_EC_TIP_PICKUP_TIP_ID_UNKNOWN),
 
-    TALER_TESTING_cmd_merchant_get_reserves_with_reserves ("get-reserves-2",
-                                                           merchant_url,
-                                                           reserve_refs,
-                                                           MHD_HTTP_OK),
+    TALER_TESTING_cmd_merchant_get_reserves ("get-reserves-2",
+                                             merchant_url,
+                                             MHD_HTTP_OK,
+                                             "create-reserve-tip-1",
+                                             "create-reserve-tip-2",
+                                             NULL),
 
     TALER_TESTING_cmd_merchant_delete_reserve ("delete-reserve-tip-1",
                                                merchant_url,
diff --git a/src/testing/testing_api_cmd_get_orders.c 
b/src/testing/testing_api_cmd_get_orders.c
index 93469fd..d4073b0 100644
--- a/src/testing/testing_api_cmd_get_orders.c
+++ b/src/testing/testing_api_cmd_get_orders.c
@@ -54,6 +54,16 @@ struct GetOrdersState
    */
   unsigned int http_status;
 
+  /**
+   * A NULL-terminated array of CMD labels that created orders.
+   */
+  const char **orders;
+
+  /**
+   * The length of @e orders.
+   */
+  unsigned int orders_length;
+
 };
 
 
@@ -68,7 +78,6 @@ get_orders_cb (void *cls,
                unsigned int orders_length,
                const struct TALER_MERCHANT_OrderEntry orders[])
 {
-  /* FIXME, deeper checks should be implemented here. */
   struct GetOrdersState *gos = cls;
 
   gos->ogh = NULL;
@@ -85,8 +94,43 @@ get_orders_cb (void *cls,
   switch (hr->http_status)
   {
   case MHD_HTTP_OK:
-    // FIXME: use gis->instance_reference here to
-    // check if the data returned matches that from the POST / PATCH
+    if (orders_length != gos->orders_length)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  "Number of orders found does not match\n");
+      TALER_TESTING_interpreter_fail (gos->is);
+      return;
+    }
+    for (unsigned int i = 0; i < orders_length; ++i)
+    {
+      const struct TALER_TESTING_Command *order_cmd;
+
+      order_cmd = TALER_TESTING_interpreter_lookup_command (
+        gos->is,
+        gos->orders[i]);
+
+      {
+        const char *order_id;
+        if (GNUNET_OK !=
+            TALER_TESTING_get_trait_order_id (order_cmd,
+                                              0,
+                                              &order_id))
+        {
+          GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                      "Could not fetch order id\n");
+          TALER_TESTING_interpreter_fail (gos->is);
+          return;
+        }
+        if (0 != strcmp (orders[i].order_id,
+                         order_id))
+        {
+          GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                      "Order id does not match\n");
+          TALER_TESTING_interpreter_fail (gos->is);
+          return;
+        }
+      }
+    }
     break;
   default:
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -136,7 +180,7 @@ get_orders_cleanup (void *cls,
   if (NULL != gos->ogh)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                "GET /instances/$ID operation did not complete\n");
+                "GET /orders operation did not complete\n");
     TALER_MERCHANT_orders_get_cancel (gos->ogh);
   }
   GNUNET_free (gos);
@@ -150,18 +194,35 @@ get_orders_cleanup (void *cls,
  * @param merchant_url base URL of the merchant serving the
  *        GET /orders request.
  * @param http_status expected HTTP response code.
+ * @param ... NULL-terminated list of labels (const char *) of
+ *        reserve (commands) we expect to be returned in the list
+ *        (assuming @a http_code is #MHD_HTTP_OK)
  * @return the command.
  */
 struct TALER_TESTING_Command
 TALER_TESTING_cmd_merchant_get_orders (const char *label,
                                        const char *merchant_url,
-                                       unsigned int http_status)
+                                       unsigned int http_status,
+                                       ...)
 {
   struct GetOrdersState *gos;
 
   gos = GNUNET_new (struct GetOrdersState);
   gos->merchant_url = merchant_url;
   gos->http_status = http_status;
+  {
+    const char *clabel;
+    va_list ap;
+
+    va_start (ap, http_status);
+    while (NULL != (clabel = va_arg (ap, const char *)))
+    {
+      GNUNET_array_append (gos->orders,
+                           gos->orders_length,
+                           clabel);
+    }
+    va_end (ap);
+  }
   {
     struct TALER_TESTING_Command cmd = {
       .cls = gos,
diff --git a/src/testing/testing_api_cmd_get_reserves.c 
b/src/testing/testing_api_cmd_get_reserves.c
index 068d7e6..2c543b6 100644
--- a/src/testing/testing_api_cmd_get_reserves.c
+++ b/src/testing/testing_api_cmd_get_reserves.c
@@ -45,14 +45,14 @@ struct GetReservesState
   struct TALER_TESTING_Interpreter *is;
 
   /**
-   * Whether to compare the reserves that were found.
+   * A list of reserves to compare with.
    */
-  bool cmp_reserves;
+  const char **reserves;
 
   /**
-   * A list of reserves to compare with.
+   * Length of @e reserve_refs.
    */
-  const char **reserve_refs;
+  unsigned int reserves_length;
 
   /**
    * Base URL of the merchant serving the request.
@@ -89,24 +89,21 @@ get_reserves_cb (void *cls,
   switch (hr->http_status)
   {
   case MHD_HTTP_OK:
+    if (reserves_length != grs->reserves_length)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  "Length of reserves found does not match\n");
+      TALER_TESTING_interpreter_fail (grs->is);
+      return;
+    }
     // FIXME: check if the data returned matches that from the POST / PATCH
-    if (! grs->cmp_reserves)
-      break;
     for (unsigned int i = 0; i < reserves_length; ++i)
     {
-      if (NULL == grs->reserve_refs[i])
-      {
-        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                    "Number of reserves found does not match\n");
-        TALER_TESTING_interpreter_fail (grs->is);
-        return;
-      }
-
       const struct TALER_TESTING_Command *reserve_cmd;
 
       reserve_cmd = TALER_TESTING_interpreter_lookup_command (
         grs->is,
-        grs->reserve_refs[i]);
+        grs->reserves[i]);
       {
         const struct TALER_ReservePublicKeyP *reserve_pub;
 
@@ -114,7 +111,12 @@ get_reserves_cb (void *cls,
             TALER_TESTING_get_trait_reserve_pub (reserve_cmd,
                                                  0,
                                                  &reserve_pub))
+        {
+          GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                      "Could not fetch reserve public key\n");
           TALER_TESTING_interpreter_fail (grs->is);
+          return;
+        }
         if (0 != GNUNET_memcmp (&reserves[i].reserve_pub,
                                 reserve_pub))
         {
@@ -131,7 +133,12 @@ get_reserves_cb (void *cls,
             TALER_TESTING_get_trait_amount_obj (reserve_cmd,
                                                 0,
                                                 &initial))
+        {
+          GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                      "Could not fetch reserve initial balance\n");
           TALER_TESTING_interpreter_fail (grs->is);
+          return;
+        }
         if ((GNUNET_OK != TALER_amount_cmp_currency (
                &reserves[i].merchant_initial_amount,
                initial)) ||
@@ -200,6 +207,9 @@ get_reserves_cleanup (void *cls,
                 "GET /private/reserves operation did not complete\n");
     TALER_MERCHANT_reserves_get_cancel (grs->rgh);
   }
+  GNUNET_array_grow (grs->reserves,
+                     grs->reserves_length,
+                     0);
   GNUNET_free (grs);
 }
 
@@ -210,54 +220,34 @@ get_reserves_cleanup (void *cls,
  * @param label command label.
  * @param merchant_url url to the merchant.
  * @param http_status expected HTTP response code.
+ * @param ... NULL-terminated list of labels (const char *) of
+ *        reserve (commands) we expect to be returned in the list
+ *        (assuming @a http_code is #MHD_HTTP_OK)
  */
 struct TALER_TESTING_Command
 TALER_TESTING_cmd_merchant_get_reserves (const char *label,
                                          const char *merchant_url,
-                                         unsigned int http_status)
+                                         unsigned int http_status,
+                                         ...)
 {
   struct GetReservesState *grs;
 
   grs = GNUNET_new (struct GetReservesState);
   grs->merchant_url = merchant_url;
-  grs->cmp_reserves = false;
   grs->http_status = http_status;
   {
-    struct TALER_TESTING_Command cmd = {
-      .cls = grs,
-      .label = label,
-      .run = &get_reserves_run,
-      .cleanup = &get_reserves_cleanup
-    };
+    const char *clabel;
+    va_list ap;
 
-    return cmd;
+    va_start (ap, http_status);
+    while (NULL != (clabel = va_arg (ap, const char *)))
+    {
+      GNUNET_array_append (grs->reserves,
+                           grs->reserves_length,
+                           clabel);
+    }
+    va_end (ap);
   }
-}
-
-
-/**
- * Define a "GET /reserves" CMD
- *
- * @param label command label.
- * @param merchant_url url to the merchant.
- * @param reserve_refs a NULL-terminated list of references to
- *        commands that created reserves.
- * @param http_status expected HTTP response code.
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_merchant_get_reserves_with_reserves (const char *label,
-                                                       const char 
*merchant_url,
-                                                       const char *reserve_refs
-                                                       [],
-                                                       unsigned int 
http_status)
-{
-  struct GetReservesState *grs;
-
-  grs = GNUNET_new (struct GetReservesState);
-  grs->merchant_url = merchant_url;
-  grs->cmp_reserves = true;
-  grs->reserve_refs = reserve_refs;
-  grs->http_status = http_status;
   {
     struct TALER_TESTING_Command cmd = {
       .cls = grs,

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