merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

commit eec18999238cf247043e9f9c093b5bcfa1eb87ea
parent e13b13b3041e905feb0e22a3488457c280dbeed2
Author: Jonathan Buchanan <jonathan.russ.buchanan@gmail.com>
Date:   Tue, 14 Jul 2020 03:05:12 -0400

tests for idempotent/conflicting post requests

Diffstat:
Msrc/backend/taler-merchant-httpd_private-post-instances.c | 11++++++-----
Msrc/backend/taler-merchant-httpd_private-post-orders.c | 6+++---
Msrc/backend/taler-merchant-httpd_private-post-products.c | 6++++--
Msrc/testing/test_merchant_api.c | 31+++++++++++++++++++++++++++++++
4 files changed, 44 insertions(+), 10 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_private-post-instances.c b/src/backend/taler-merchant-httpd_private-post-instances.c @@ -69,8 +69,8 @@ accounts_equal (const struct TMH_MerchantInstance *mi, i)); if (NULL == str) return false; - if ( (strcasecmp (uri, - str)) ) + if (0 == strcasecmp (uri, + str)) { if (matches[i]) { @@ -196,13 +196,14 @@ TMH_private_post_instances (const struct TMH_RequestHandler *rh, is.address)) && (1 == json_equal (mi->settings.jurisdiction, is.jurisdiction)) && - (0 == TALER_amount_cmp_currency ( + (GNUNET_OK == TALER_amount_cmp_currency ( &mi->settings.default_max_deposit_fee, &is.default_max_deposit_fee)) && (0 == TALER_amount_cmp (&mi->settings.default_max_deposit_fee, &is.default_max_deposit_fee)) && - (0 == TALER_amount_cmp_currency (&mi->settings.default_max_wire_fee, - &is.default_max_wire_fee)) && + (GNUNET_OK == TALER_amount_cmp_currency ( + &mi->settings.default_max_wire_fee, + &is.default_max_wire_fee)) && (0 == TALER_amount_cmp (&mi->settings.default_max_wire_fee, &is.default_max_wire_fee)) && (mi->settings.default_wire_fee_amortization == diff --git a/src/backend/taler-merchant-httpd_private-post-orders.c b/src/backend/taler-merchant-httpd_private-post-orders.c @@ -218,12 +218,12 @@ execute_transaction (struct TMH_HandlerContext *hc, order_id, pay_deadline, order); - if (qs < 0) + /* qs == 0: order already exists. */ + if (qs <= 0) { TMH_db->rollback (TMH_db->cls); return qs; } - GNUNET_assert (qs > 0); /* Migrate locks from UUIDs to new order: first release old locks */ for (unsigned int i = 0; i<uuids_length; i++) { @@ -428,7 +428,7 @@ execute_order (struct MHD_Connection *connection, if (GNUNET_DB_STATUS_SOFT_ERROR != qs) break; } - if (0 > qs) + if (0 >= qs) { /* Special report if retries insufficient */ if (GNUNET_DB_STATUS_SOFT_ERROR == qs) diff --git a/src/backend/taler-merchant-httpd_private-post-products.c b/src/backend/taler-merchant-httpd_private-post-products.c @@ -50,8 +50,8 @@ products_equal (const struct TALER_MERCHANTDB_ProductDetails *p1, p2->description_i18n)) && (0 == strcmp (p1->unit, p2->unit)) && - (0 == TALER_amount_cmp_currency (&p1->price, - &p2->price)) && + (GNUNET_OK == TALER_amount_cmp_currency (&p1->price, + &p2->price)) && (0 == TALER_amount_cmp (&p1->price, &p2->price)) && (1 == json_equal (p1->taxes, @@ -117,6 +117,8 @@ TMH_private_post_products (const struct TMH_RequestHandler *rh, res = TALER_MHD_parse_json_data (connection, hc->request_body, spec); + pd.total_sold = 0; + pd.total_lost = 0; if (GNUNET_OK != res) return (GNUNET_NO == res) ? MHD_YES diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c @@ -216,6 +216,13 @@ run (void *cls, GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TIME_UNIT_FOREVER_ABS, "EUR:5.0"), + TALER_TESTING_cmd_merchant_post_orders ("create-proposal-1-pre-exists", + merchant_url, + MHD_HTTP_BAD_REQUEST, + "1", + GNUNET_TIME_UNIT_ZERO_ABS, + GNUNET_TIME_UNIT_FOREVER_ABS, + "EUR:5.0"), TALER_TESTING_cmd_poll_orders_conclude ("poll-orders-1-conclude", MHD_HTTP_OK, "poll-orders-1-start"), @@ -997,6 +1004,18 @@ run (void *cls, PAYTO_I1, "EUR", MHD_HTTP_NO_CONTENT), + TALER_TESTING_cmd_merchant_post_instances ("instance-create-i2-idem", + merchant_url, + "i2", + PAYTO_I1, + "EUR", + MHD_HTTP_NO_CONTENT), + TALER_TESTING_cmd_merchant_post_instances ("instance-create-i2-non-idem", + merchant_url, + "i2", + "payto://other-method/", + "EUR", + MHD_HTTP_CONFLICT), TALER_TESTING_cmd_merchant_delete_instance ("instance-delete-i2", merchant_url, "i2", @@ -1026,6 +1045,18 @@ run (void *cls, "a product", "EUR:1", MHD_HTTP_NO_CONTENT), + TALER_TESTING_cmd_merchant_post_products ("post-products-p1-idem", + merchant_url, + "product-1", + "a product", + "EUR:1", + MHD_HTTP_NO_CONTENT), + TALER_TESTING_cmd_merchant_post_products ("post-products-p1-non-idem", + merchant_url, + "product-1", + "a different product", + "EUR:1", + MHD_HTTP_CONFLICT), TALER_TESTING_cmd_merchant_get_products ("get-products-p1", merchant_url, MHD_HTTP_OK,