diff options
m--------- | contrib/wallet-core | 0 | ||||
-rw-r--r-- | src/include/taler_merchant_testing_lib.h | 103 | ||||
-rw-r--r-- | src/testing/test_merchant_api.c | 83 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_merchant_get_order.c | 127 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_post_orders.c | 44 |
5 files changed, 302 insertions, 55 deletions
diff --git a/contrib/wallet-core b/contrib/wallet-core -Subproject 8b867205faf742df8c2352d4cb2a6604305e406 +Subproject ae088de54c086613a52cd6dd8d88f6535634c42 diff --git a/src/include/taler_merchant_testing_lib.h b/src/include/taler_merchant_testing_lib.h index cb7e6042..3bab73e6 100644 --- a/src/include/taler_merchant_testing_lib.h +++ b/src/include/taler_merchant_testing_lib.h @@ -574,6 +574,33 @@ TALER_TESTING_cmd_merchant_post_orders2 ( /** + * Create an order with a specific fulfillment URL. + * Does not claim the order. + * + * @param label command label + * @param cfg configuration to use + * @param merchant_url base URL of the merchant serving + * the proposal request + * @param http_status expected HTTP status + * @param refund_deadline the deadline for refunds on this order + * @param pay_deadline the deadline for payment on this order + * @param fulfillment_url the fulfillment URL to use + * @param amount the amount this order is for + * @return the command + */ +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); + + +/** * Define a "GET /orders" CMD. * * @param label command label. @@ -737,13 +764,14 @@ TALER_TESTING_cmd_wallet_poll_order_conclude2 ( * this parameter is ignored. */ 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, + ...); /** @@ -770,16 +798,40 @@ TALER_TESTING_cmd_merchant_get_order (const char *label, * @param http_status expected HTTP response code for the request. */ 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); + + +/** + * Define a GET /private/orders/$ORDER_ID CMD. + * + * @param label the command label + * @param merchant_url base URL of the merchant which will + * serve the request. + * @param order_reference reference to a command that created an order. + * @param osc expected order status + * @param session_id session ID the payment must be bound to + * @param repurchase_order_ref command of a paid equivalent order the merchant should be refering us to, or NULL + * @param expected_http_status expected HTTP response code for the request. + */ +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); /** @@ -836,14 +888,15 @@ TALER_TESTING_cmd_merchant_claim_order (const char *label, * @return the command */ struct TALER_TESTING_Command -TALER_TESTING_cmd_merchant_pay_order (const char *label, - const char *merchant_url, - unsigned int http_status, - const char *proposal_reference, - const char *coin_reference, - const char *amount_with_fee, - const char *amount_without_fee, - const char *session_id); +TALER_TESTING_cmd_merchant_pay_order ( + const char *label, + const char *merchant_url, + unsigned int http_status, + const char *proposal_reference, + const char *coin_reference, + const char *amount_with_fee, + const char *amount_without_fee, + const char *session_id); /** 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; + } +} |