summaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2024-02-24 13:13:31 +0100
committerChristian Grothoff <christian@grothoff.org>2024-02-24 13:13:31 +0100
commita84dbc0e60adbc27f4f98a024c469dd51df8f817 (patch)
treed72418611e5e675ccdf0b7f3f996c6190200701e /src/testing
parentbfb86da296a788d4b96ac55fd9b06c58e34cd98e (diff)
downloadmerchant-a84dbc0e60adbc27f4f98a024c469dd51df8f817.tar.gz
merchant-a84dbc0e60adbc27f4f98a024c469dd51df8f817.tar.bz2
merchant-a84dbc0e60adbc27f4f98a024c469dd51df8f817.zip
add (working) test for repurchase detection
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/test_merchant_api.c83
-rw-r--r--src/testing/testing_api_cmd_merchant_get_order.c127
-rw-r--r--src/testing/testing_api_cmd_post_orders.c44
3 files changed, 224 insertions, 30 deletions
diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c
index 5610b987..cff12442 100644
--- a/src/testing/test_merchant_api.c
+++ b/src/testing/test_merchant_api.c
@@ -1477,7 +1477,86 @@ run (void *cls,
MHD_HTTP_NO_CONTENT),
TALER_TESTING_cmd_end ()
};
+ struct TALER_TESTING_Command repurchase[] = {
+ cmd_transfer_to_exchange (
+ "create-reserve-30x",
+ "EUR:30.06"),
+ cmd_exec_wirewatch (
+ "wirewatch-30x"),
+ TALER_TESTING_cmd_check_bank_admin_transfer (
+ "check_bank_transfer-30x",
+ "EUR:30.06",
+ payer_payto,
+ exchange_payto,
+ "create-reserve-30x"),
+ TALER_TESTING_cmd_withdraw_amount (
+ "withdraw-coin-rep",
+ "create-reserve-30x",
+ "EUR:5",
+ 0,
+ MHD_HTTP_OK),
+ TALER_TESTING_cmd_merchant_post_orders3 (
+ "post-order-repurchase-original",
+ cred.cfg,
+ merchant_url,
+ MHD_HTTP_OK,
+ GNUNET_TIME_relative_to_timestamp (GNUNET_TIME_UNIT_MINUTES),
+ GNUNET_TIME_UNIT_FOREVER_TS,
+ "https://fulfillment.example.com/",
+ "EUR:1.0"),
+ TALER_TESTING_cmd_merchant_pay_order (
+ "repurchase-pay-first",
+ merchant_url,
+ MHD_HTTP_OK,
+ "post-order-repurchase-original",
+ "withdraw-coin-rep",
+ "EUR:1.00",
+ "EUR:0.99",
+ "repurchase-session"),
+ TALER_TESTING_cmd_merchant_get_order3 (
+ "repurchase-check-primary-payment",
+ merchant_url,
+ "post-order-repurchase-original",
+ TALER_MERCHANT_OSC_PAID,
+ "repurchase-session",
+ NULL,
+ MHD_HTTP_OK),
+ TALER_TESTING_cmd_merchant_get_order3 (
+ "repurchase-check-primary-payment-bad-binding",
+ merchant_url,
+ "post-order-repurchase-original",
+ TALER_MERCHANT_OSC_CLAIMED, /* someone else has it! */
+ "wrong-session",
+ NULL,
+ MHD_HTTP_OK),
+ TALER_TESTING_cmd_merchant_post_orders3 (
+ "post-order-repurchase-secondary",
+ cred.cfg,
+ merchant_url,
+ MHD_HTTP_OK,
+ GNUNET_TIME_relative_to_timestamp (GNUNET_TIME_UNIT_MINUTES),
+ GNUNET_TIME_UNIT_FOREVER_TS,
+ "https://fulfillment.example.com/",
+ "EUR:1.0"),
+ TALER_TESTING_cmd_merchant_get_order3 (
+ "repurchase-check-secondary-payment",
+ merchant_url,
+ "post-order-repurchase-secondary",
+ TALER_MERCHANT_OSC_UNPAID,
+ "repurchase-session",
+ NULL,
+ MHD_HTTP_OK),
+ TALER_TESTING_cmd_merchant_get_order3 (
+ "repurchase-check-secondary-payment",
+ merchant_url,
+ "post-order-repurchase-secondary",
+ TALER_MERCHANT_OSC_UNPAID,
+ "repurchase-session",
+ "post-order-repurchase-original",
+ MHD_HTTP_OK),
+ TALER_TESTING_cmd_end ()
+ };
struct TALER_TESTING_Command commands[] = {
/* general setup */
@@ -1742,6 +1821,7 @@ run (void *cls,
merchant_url,
"product-2",
MHD_HTTP_CONFLICT),
+#if 1
TALER_TESTING_cmd_batch ("pay",
pay),
TALER_TESTING_cmd_batch ("double-spending",
@@ -1758,6 +1838,9 @@ run (void *cls,
webhooks),
TALER_TESTING_cmd_batch ("auth",
auth),
+#endif
+ TALER_TESTING_cmd_batch ("repurchase",
+ repurchase),
/**
* End the suite.
*/
diff --git a/src/testing/testing_api_cmd_merchant_get_order.c b/src/testing/testing_api_cmd_merchant_get_order.c
index f30c43ad..1b235c93 100644
--- a/src/testing/testing_api_cmd_merchant_get_order.c
+++ b/src/testing/testing_api_cmd_merchant_get_order.c
@@ -94,6 +94,23 @@ struct MerchantGetOrderState
unsigned int forgets_length;
/**
+ * Set to a session ID, if we should pass one as part
+ * of the request.
+ */
+ const char *session_id;
+
+ /**
+ * Set if we expect to be referred to another equivalent order which was
+ * already paid by the wallet under this @e session_id.
+ */
+ const char *repurchase_order_ref;
+
+ /**
+ * True if we should pass the 'allow_refunded_for_repurchase' flag.
+ */
+ bool allow_refunded_for_repurchase;
+
+ /**
* Whether the order was refunded or not.
*/
bool refunded;
@@ -413,6 +430,31 @@ merchant_get_order_cb (
const char *order_id;
const struct TALER_ClaimTokenP *claim_token;
+ if (NULL != gos->repurchase_order_ref)
+ {
+ const struct TALER_TESTING_Command *rep_cmd;
+ const char *rep_id;
+ const char *ri;
+
+ rep_cmd = TALER_TESTING_interpreter_lookup_command (
+ gos->is,
+ gos->repurchase_order_ref);
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_order_id (rep_cmd,
+ &rep_id))
+ {
+ TALER_TESTING_FAIL (gos->is);
+ }
+ ri = osr->details.ok.details.unpaid.already_paid_order_id;
+ if ( (NULL == ri) ||
+ (0 !=
+ strcmp (ri,
+ rep_id)) )
+ {
+ TALER_TESTING_FAIL (gos->is);
+ }
+ }
+
if (GNUNET_OK !=
TALER_MERCHANT_parse_pay_uri (
osr->details.ok.details.unpaid.taler_pay_uri,
@@ -535,7 +577,7 @@ merchant_get_order_run (void *cls,
TALER_TESTING_interpreter_get_context (is),
gos->merchant_url,
order_id,
- NULL,
+ gos->session_id,
GNUNET_TIME_UNIT_ZERO,
&merchant_get_order_cb,
gos);
@@ -574,13 +616,14 @@ merchant_get_order_cleanup (void *cls,
struct TALER_TESTING_Command
-TALER_TESTING_cmd_merchant_get_order (const char *label,
- const char *merchant_url,
- const char *order_reference,
- enum TALER_MERCHANT_OrderStatusCode osc,
- bool refunded,
- unsigned int http_status,
- ...)
+TALER_TESTING_cmd_merchant_get_order (
+ const char *label,
+ const char *merchant_url,
+ const char *order_reference,
+ enum TALER_MERCHANT_OrderStatusCode osc,
+ bool refunded,
+ unsigned int http_status,
+ ...)
{
struct MerchantGetOrderState *gos;
@@ -618,16 +661,17 @@ TALER_TESTING_cmd_merchant_get_order (const char *label,
struct TALER_TESTING_Command
-TALER_TESTING_cmd_merchant_get_order2 (const char *label,
- const char *merchant_url,
- const char *order_reference,
- enum TALER_MERCHANT_OrderStatusCode osc,
- bool wired,
- const char **transfers,
- bool refunded,
- const char **refunds,
- const char **forgets,
- unsigned int http_status)
+TALER_TESTING_cmd_merchant_get_order2 (
+ const char *label,
+ const char *merchant_url,
+ const char *order_reference,
+ enum TALER_MERCHANT_OrderStatusCode osc,
+ bool wired,
+ const char **transfers,
+ bool refunded,
+ const char **refunds,
+ const char **forgets,
+ unsigned int http_status)
{
struct MerchantGetOrderState *gos;
@@ -678,6 +722,38 @@ TALER_TESTING_cmd_merchant_get_order2 (const char *label,
}
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_merchant_get_order3 (
+ const char *label,
+ const char *merchant_url,
+ const char *order_reference,
+ enum TALER_MERCHANT_OrderStatusCode osc,
+ const char *session_id,
+ const char *repurchase_order_ref,
+ unsigned int expected_http_status)
+{
+ struct MerchantGetOrderState *gos;
+
+ gos = GNUNET_new (struct MerchantGetOrderState);
+ gos->merchant_url = merchant_url;
+ gos->order_reference = order_reference;
+ gos->osc = osc;
+ gos->session_id = session_id;
+ gos->repurchase_order_ref = repurchase_order_ref;
+ gos->http_status = expected_http_status;
+ {
+ struct TALER_TESTING_Command cmd = {
+ .cls = gos,
+ .label = label,
+ .run = &merchant_get_order_run,
+ .cleanup = &merchant_get_order_cleanup
+ };
+
+ return cmd;
+ }
+}
+
+
struct MerchantPollOrderConcludeState
{
/**
@@ -892,14 +968,12 @@ merchant_poll_order_start_cleanup (void *cls,
}
-/**
- * Start a long poll for GET /private/orders/$ORDER_ID.
- */
struct TALER_TESTING_Command
-TALER_TESTING_cmd_poll_order_start (const char *label,
- const char *merchant_url,
- const char *order_id,
- struct GNUNET_TIME_Relative timeout)
+TALER_TESTING_cmd_poll_order_start (
+ const char *label,
+ const char *merchant_url,
+ const char *order_id,
+ struct GNUNET_TIME_Relative timeout)
{
struct MerchantPollOrderStartState *pos;
@@ -987,9 +1061,6 @@ merchant_poll_order_conclude_cleanup (void *cls,
}
-/**
- * Complete a long poll for GET /private/orders/$ORDER_ID.
- */
struct TALER_TESTING_Command
TALER_TESTING_cmd_poll_order_conclude (const char *label,
unsigned int http_status,
diff --git a/src/testing/testing_api_cmd_post_orders.c b/src/testing/testing_api_cmd_post_orders.c
index 72fe0b11..9fdf5a6a 100644
--- a/src/testing/testing_api_cmd_post_orders.c
+++ b/src/testing/testing_api_cmd_post_orders.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2023 Taler Systems SA
+ Copyright (C) 2014-2024 Taler Systems SA
TALER is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as
@@ -687,7 +687,6 @@ TALER_TESTING_cmd_merchant_post_orders_no_claim (
ps->http_status = http_status;
ps->expected_order_id = order_id;
ps->merchant_url = merchant_url;
- ps->with_claim = false;
{
struct TALER_TESTING_Command cmd = {
.cls = ps,
@@ -786,3 +785,44 @@ TALER_TESTING_cmd_merchant_post_orders2 (
return cmd;
}
}
+
+
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_merchant_post_orders3 (
+ const char *label,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *merchant_url,
+ unsigned int http_status,
+ struct GNUNET_TIME_Timestamp refund_deadline,
+ struct GNUNET_TIME_Timestamp pay_deadline,
+ const char *fulfillment_url,
+ const char *amount)
+{
+ struct OrdersState *ps;
+
+ ps = GNUNET_new (struct OrdersState);
+ ps->cfg = cfg;
+ make_order_json (NULL,
+ refund_deadline,
+ pay_deadline,
+ amount,
+ &ps->order_terms);
+ GNUNET_assert (0 ==
+ json_object_set_new (ps->order_terms,
+ "fulfillment_url",
+ json_string (fulfillment_url)));
+ ps->http_status = http_status;
+ ps->merchant_url = merchant_url;
+ ps->with_claim = true;
+ {
+ struct TALER_TESTING_Command cmd = {
+ .cls = ps,
+ .label = label,
+ .run = &orders_run,
+ .cleanup = &orders_cleanup,
+ .traits = &orders_traits
+ };
+
+ return cmd;
+ }
+}