summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-10-21 11:28:26 +0200
committerChristian Grothoff <christian@grothoff.org>2020-10-21 11:28:26 +0200
commit1d630504c359a40e0aeb27ab333583bfcd8d3f74 (patch)
treedb9080d14c17faac7bd5a2865e976b049af7b2ed
parent3a74de266c9724c6b804244e14870cd017e8a721 (diff)
downloadmerchant-1d630504c359a40e0aeb27ab333583bfcd8d3f74.tar.gz
merchant-1d630504c359a40e0aeb27ab333583bfcd8d3f74.tar.bz2
merchant-1d630504c359a40e0aeb27ab333583bfcd8d3f74.zip
implement test for long polling with repurchase detection (fixes #6581)
-rw-r--r--src/include/taler_merchant_testing_lib.h41
-rw-r--r--src/testing/test_merchant_api.c34
-rw-r--r--src/testing/testing_api_cmd_post_orders.c61
-rw-r--r--src/testing/testing_api_cmd_wallet_get_order.c85
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 708d4d2f..8cd23d9d 100644
--- a/src/include/taler_merchant_testing_lib.h
+++ b/src/include/taler_merchant_testing_lib.h
@@ -646,6 +646,29 @@ TALER_TESTING_cmd_wallet_poll_order_start (
/**
+ * 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.
*
* @param label the command label
@@ -662,6 +685,24 @@ TALER_TESTING_cmd_wallet_poll_order_conclude (
/**
+ * 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.
*
* @param label the command label
diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c
index 07e6b61b..790bee43 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 6977269d..ff266b1a 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 2f595315..7251d891 100644
--- a/src/testing/testing_api_cmd_wallet_get_order.c
+++ b/src/testing/testing_api_cmd_wallet_get_order.c
@@ -332,6 +332,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.
*/
struct GNUNET_SCHEDULER_Task *task;
@@ -376,6 +381,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.
*/
struct GNUNET_TIME_Relative timeout;
@@ -406,6 +416,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?
*/
bool wait_for_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 */