gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] branch master updated: implement test for long polling


From: gnunet
Subject: [taler-merchant] branch master updated: implement test for long polling with repurchase detection (fixes #6581)
Date: Wed, 21 Oct 2020 11:28:28 +0200

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

grothoff pushed a commit to branch master
in repository merchant.

The following commit(s) were added to refs/heads/master by this push:
     new 1d63050  implement test for long polling with repurchase detection 
(fixes #6581)
1d63050 is described below

commit 1d630504c359a40e0aeb27ab333583bfcd8d3f74
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Wed Oct 21 11:28:26 2020 +0200

    implement test for long polling with repurchase detection (fixes #6581)
---
 src/include/taler_merchant_testing_lib.h       | 41 +++++++++++++
 src/testing/test_merchant_api.c                | 34 ++++++++++-
 src/testing/testing_api_cmd_post_orders.c      | 61 +++++++++---------
 src/testing/testing_api_cmd_wallet_get_order.c | 85 +++++++++++++++++++++++++-
 4 files changed, 186 insertions(+), 35 deletions(-)

diff --git a/src/include/taler_merchant_testing_lib.h 
b/src/include/taler_merchant_testing_lib.h
index 708d4d2..8cd23d9 100644
--- a/src/include/taler_merchant_testing_lib.h
+++ b/src/include/taler_merchant_testing_lib.h
@@ -645,6 +645,29 @@ TALER_TESTING_cmd_wallet_poll_order_start (
   const char *await_refund);
 
 
+/**
+ * Start a long poll for GET /orders/$ORDER_ID.
+ *
+ * @param label the command label
+ * @param merchant_url base URL of the merchant which will
+ *        serve the request.
+ * @param order_ref reference to a command that created an order.
+ * @param timeout how long to wait for the request to complete
+ * @param await_refund NULL to not wait for refund, amount of value
+ *         zero to wait for any refund amount, non-zero to poll
+ *         for refund exceeding the given amount
+ * @param session_id which session ID to use
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_wallet_poll_order_start2 (
+  const char *label,
+  const char *merchant_url,
+  const char *order_ref,
+  struct GNUNET_TIME_Relative timeout,
+  const char *await_refund,
+  const char *session_id);
+
+
 /**
  * Complete a long poll for GET /orders/$ORDER_ID.
  *
@@ -661,6 +684,24 @@ TALER_TESTING_cmd_wallet_poll_order_conclude (
   const char *poll_start_reference);
 
 
+/**
+ * Complete a long poll for GET /orders/$ORDER_ID.
+ *
+ * @param label the command label
+ * @param expected_http_status expected HTTP response code
+ * @param expected_refund_amount refund expected, NULL for no refund expected
+ * @param poll_start_reference reference to the 
#TALER_TESTING_cmd_wallet_poll_order_start command
+ * @param already_paid_order_id ID of an already paid order we expect to get 
returned
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_wallet_poll_order_conclude2 (
+  const char *label,
+  unsigned int expected_http_status,
+  const char *expected_refund_amount,
+  const char *poll_start_reference,
+  const char *already_paid_order_id);
+
+
 /**
  * Define a GET /private/orders/$ORDER_ID CMD.
  *
diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c
index 07e6b61..790bee4 100644
--- a/src/testing/test_merchant_api.c
+++ b/src/testing/test_merchant_api.c
@@ -278,7 +278,7 @@ run (void *cls,
     TALER_TESTING_cmd_merchant_post_orders2 ("create-proposal-1",
                                              merchant_url,
                                              MHD_HTTP_OK,
-                                             "1",
+                                             "1", /* order ID */
                                              GNUNET_TIME_UNIT_ZERO_ABS,
                                              GNUNET_TIME_UNIT_FOREVER_ABS,
                                              true,
@@ -290,7 +290,7 @@ run (void *cls,
     TALER_TESTING_cmd_merchant_post_orders2 ("create-proposal-1-idem",
                                              merchant_url,
                                              MHD_HTTP_OK,
-                                             "1",
+                                             "1", /* order ID */
                                              GNUNET_TIME_UNIT_ZERO_ABS,
                                              GNUNET_TIME_UNIT_FOREVER_ABS,
                                              true,
@@ -299,6 +299,18 @@ run (void *cls,
                                              "",
                                              "",
                                              "create-proposal-1"),
+    TALER_TESTING_cmd_merchant_post_orders2 ("create-proposal-1x",
+                                             merchant_url,
+                                             MHD_HTTP_OK,
+                                             "1x", /* order ID */
+                                             GNUNET_TIME_UNIT_ZERO_ABS,
+                                             GNUNET_TIME_UNIT_FOREVER_ABS,
+                                             true,
+                                             "EUR:5.0",
+                                             "x-taler-bank",
+                                             "",
+                                             "",
+                                             NULL),
     TALER_TESTING_cmd_merchant_claim_order ("reclaim-1",
                                             merchant_url,
                                             MHD_HTTP_OK,
@@ -309,6 +321,11 @@ run (void *cls,
                                             MHD_HTTP_CONFLICT,
                                             NULL,
                                             "1"),
+    TALER_TESTING_cmd_merchant_claim_order ("reclaim-1x",
+                                            merchant_url,
+                                            MHD_HTTP_OK,
+                                            "create-proposal-1x",
+                                            NULL),
     TALER_TESTING_cmd_merchant_post_orders ("create-proposal-1-pre-exists",
                                             merchant_url,
                                             MHD_HTTP_BAD_REQUEST,
@@ -322,6 +339,7 @@ run (void *cls,
     TALER_TESTING_cmd_merchant_get_orders ("get-orders-1",
                                            merchant_url,
                                            MHD_HTTP_OK,
+                                           "create-proposal-1x",
                                            "create-proposal-1",
                                            NULL),
     TALER_TESTING_cmd_wallet_get_order ("get-order-wallet-1",
@@ -342,6 +360,12 @@ run (void *cls,
                                                "create-proposal-1",
                                                GNUNET_TIME_UNIT_MINUTES,
                                                NULL),
+    TALER_TESTING_cmd_wallet_poll_order_start2 ("poll-order-wallet-start-1x",
+                                                merchant_url,
+                                                "create-proposal-1x",
+                                                GNUNET_TIME_UNIT_MINUTES,
+                                                NULL,
+                                                "session-0"),
     TALER_TESTING_cmd_poll_order_start ("poll-order-merchant-1-start",
                                         merchant_url,
                                         "1",
@@ -361,6 +385,11 @@ run (void *cls,
                                                   MHD_HTTP_OK,
                                                   NULL,
                                                   "poll-order-wallet-start-1"),
+    TALER_TESTING_cmd_wallet_poll_order_conclude2 ("poll-order-1x-conclude",
+                                                   MHD_HTTP_OK,
+                                                   NULL,
+                                                   
"poll-order-wallet-start-1x",
+                                                   "1"),
     TALER_TESTING_cmd_merchant_post_orders_paid ("verify-order-1-paid",
                                                  merchant_url,
                                                  "deposit-simple",
@@ -382,6 +411,7 @@ run (void *cls,
     TALER_TESTING_cmd_merchant_get_orders ("get-orders-1-paid",
                                            merchant_url,
                                            MHD_HTTP_OK,
+                                           "create-proposal-1x",
                                            "create-proposal-1",
                                            NULL),
     TALER_TESTING_cmd_merchant_pay_order ("replay-simple",
diff --git a/src/testing/testing_api_cmd_post_orders.c 
b/src/testing/testing_api_cmd_post_orders.c
index 6977269..ff266b1 100644
--- a/src/testing/testing_api_cmd_post_orders.c
+++ b/src/testing/testing_api_cmd_post_orders.c
@@ -682,15 +682,14 @@ make_order_json (const char *order_id,
 
 
 struct TALER_TESTING_Command
-TALER_TESTING_cmd_merchant_post_orders_no_claim (const char *label,
-                                                 const char *merchant_url,
-                                                 unsigned int http_status,
-                                                 const char *order_id,
-                                                 struct GNUNET_TIME_Absolute
-                                                 refund_deadline,
-                                                 struct GNUNET_TIME_Absolute
-                                                 pay_deadline,
-                                                 const char *amount)
+TALER_TESTING_cmd_merchant_post_orders_no_claim (
+  const char *label,
+  const char *merchant_url,
+  unsigned int http_status,
+  const char *order_id,
+  struct GNUNET_TIME_Absolute refund_deadline,
+  struct GNUNET_TIME_Absolute pay_deadline,
+  const char *amount)
 {
   struct OrdersState *ps;
 
@@ -719,15 +718,14 @@ TALER_TESTING_cmd_merchant_post_orders_no_claim (const 
char *label,
 
 
 struct TALER_TESTING_Command
-TALER_TESTING_cmd_merchant_post_orders (const char *label,
-                                        const char *merchant_url,
-                                        unsigned int http_status,
-                                        const char *order_id,
-                                        struct GNUNET_TIME_Absolute
-                                        refund_deadline,
-                                        struct GNUNET_TIME_Absolute
-                                        pay_deadline,
-                                        const char *amount)
+TALER_TESTING_cmd_merchant_post_orders (
+  const char *label,
+  const char *merchant_url,
+  unsigned int http_status,
+  const char *order_id,
+  struct GNUNET_TIME_Absolute refund_deadline,
+  struct GNUNET_TIME_Absolute pay_deadline,
+  const char *amount)
 {
   struct OrdersState *ps;
 
@@ -756,20 +754,19 @@ TALER_TESTING_cmd_merchant_post_orders (const char *label,
 
 
 struct TALER_TESTING_Command
-TALER_TESTING_cmd_merchant_post_orders2 (const char *label,
-                                         const char *merchant_url,
-                                         unsigned int http_status,
-                                         const char *order_id,
-                                         struct GNUNET_TIME_Absolute
-                                         refund_deadline,
-                                         struct GNUNET_TIME_Absolute
-                                         pay_deadline,
-                                         bool claim_token,
-                                         const char *amount,
-                                         const char *payment_target,
-                                         const char *products,
-                                         const char *locks,
-                                         const char *duplicate_of)
+TALER_TESTING_cmd_merchant_post_orders2 (
+  const char *label,
+  const char *merchant_url,
+  unsigned int http_status,
+  const char *order_id,
+  struct GNUNET_TIME_Absolute refund_deadline,
+  struct GNUNET_TIME_Absolute pay_deadline,
+  bool claim_token,
+  const char *amount,
+  const char *payment_target,
+  const char *products,
+  const char *locks,
+  const char *duplicate_of)
 {
   struct OrdersState *ps;
 
diff --git a/src/testing/testing_api_cmd_wallet_get_order.c 
b/src/testing/testing_api_cmd_wallet_get_order.c
index 2f59531..7251d89 100644
--- a/src/testing/testing_api_cmd_wallet_get_order.c
+++ b/src/testing/testing_api_cmd_wallet_get_order.c
@@ -331,6 +331,11 @@ struct WalletPollOrderConcludeState
    */
   const char *start_reference;
 
+  /**
+   * Already paid order ID expected, or NULL for none.
+   */
+  const char *already_paid_order_id;
+
   /**
    * Task to wait for the deadline.
    */
@@ -375,6 +380,11 @@ struct WalletPollOrderStartState
    */
   const char *order_ref;
 
+  /**
+   * Which session ID to poll for.
+   */
+  const char *session_id;
+
   /**
    * How long to wait for server to return a response.
    */
@@ -405,6 +415,11 @@ struct WalletPollOrderStartState
    */
   struct TALER_Amount refund_available;
 
+  /**
+   * Already paid order ID returned, or NULL for none.
+   */
+  char *already_paid_order_id;
+
   /**
    * Should we poll for a refund?
    */
@@ -469,6 +484,26 @@ conclude_task (void *cls)
                 cps->refunded ? "" : "NOT ");
     TALER_TESTING_FAIL (ppc->is);
   }
+  if ( (NULL == ppc->already_paid_order_id)
+       ^ (NULL == cps->already_paid_order_id) )
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Missmatch in already paid order IDs: %s vs %s\n",
+                ppc->already_paid_order_id,
+                cps->already_paid_order_id);
+    TALER_TESTING_FAIL (ppc->is);
+  }
+  if ( (NULL != ppc->already_paid_order_id) &&
+       (0 != strcmp (ppc->already_paid_order_id,
+                     cps->already_paid_order_id) ) )
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Missmatch in already paid order IDs: %s vs %s\n",
+                ppc->already_paid_order_id,
+                cps->already_paid_order_id);
+    TALER_TESTING_FAIL (ppc->is);
+  }
+
   if (cps->refunded)
   {
     if (0 != TALER_amount_cmp (&ppc->expected_refund_amount,
@@ -539,6 +574,8 @@ wallet_poll_order_cb (
     pos->refund_pending = (GNUNET_YES == refund_pending);
     if (NULL != refund_amount)
       pos->refund_available = *refund_amount;
+    if (NULL != already_paid_order_id)
+      pos->already_paid_order_id = GNUNET_strdup (already_paid_order_id);
     break;
   default:
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -597,7 +634,7 @@ wallet_poll_order_start_run (void *cls,
                                               order_id,
                                               h_contract,
                                               pos->timeout,
-                                              NULL,
+                                              pos->session_id,
                                               pos->wait_for_refund
                                               ? &pos->refund_threshold
                                               : NULL,
@@ -632,6 +669,7 @@ wallet_poll_order_start_cleanup (void *cls,
                   pos->is));
     TALER_MERCHANT_wallet_order_get_cancel (pos->ogh);
   }
+  GNUNET_free (pos->already_paid_order_id);
   GNUNET_free (pos);
 }
 
@@ -670,6 +708,29 @@ TALER_TESTING_cmd_wallet_poll_order_start (
 }
 
 
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_wallet_poll_order_start2 (
+  const char *label,
+  const char *merchant_url,
+  const char *order_ref,
+  struct GNUNET_TIME_Relative timeout,
+  const char *await_refund,
+  const char *session_id)
+{
+  struct WalletPollOrderStartState *pos;
+  struct TALER_TESTING_Command cmd;
+
+  cmd = TALER_TESTING_cmd_wallet_poll_order_start (label,
+                                                   merchant_url,
+                                                   order_ref,
+                                                   timeout,
+                                                   await_refund);
+  pos = cmd.cls;
+  pos->session_id = session_id;
+  return cmd;
+}
+
+
 /**
  * Run the "GET order conclude" CMD.
  *
@@ -763,4 +824,26 @@ TALER_TESTING_cmd_wallet_poll_order_conclude (
 }
 
 
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_wallet_poll_order_conclude2 (
+  const char *label,
+  unsigned int expected_http_status,
+  const char *expected_refund_amount,
+  const char *poll_start_reference,
+  const char *already_paid_order_id)
+{
+  struct WalletPollOrderConcludeState *cps;
+  struct TALER_TESTING_Command cmd;
+
+  cmd = TALER_TESTING_cmd_wallet_poll_order_conclude (
+    label,
+    expected_http_status,
+    expected_refund_amount,
+    poll_start_reference);
+  cps = cmd.cls;
+  cps->already_paid_order_id = already_paid_order_id;
+  return cmd;
+}
+
+
 /* end of testing_api_cmd_wallet_get_order.c */

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