merchant

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

commit 4ce3a78d0071035a66cfb889c23fe9a9d731086f
parent d34f954dcaf6d064931d47f0c90576f3b1dbf648
Author: Jonathan Buchanan <jonathan.russ.buchanan@gmail.com>
Date:   Tue, 23 Jun 2020 23:32:53 -0400

deeper checks on GET /private/orders

Diffstat:
Msrc/backend/taler-merchant-httpd_private-get-orders.c | 2+-
Msrc/include/taler_merchant_testing_lib.h | 29++++++++++-------------------
Msrc/testing/test_merchant_api.c | 24+++++++++++++++---------
Msrc/testing/testing_api_cmd_get_orders.c | 71++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
Msrc/testing/testing_api_cmd_get_reserves.c | 90+++++++++++++++++++++++++++++++++++--------------------------------------------
5 files changed, 132 insertions(+), 84 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_private-get-orders.c b/src/backend/taler-merchant-httpd_private-get-orders.c @@ -338,7 +338,7 @@ TMH_private_get_orders (const struct TMH_RequestHandler *rh, "start"); if (NULL == start_row_str) { - of.start_row = UINT64_MAX; + of.start_row = INT64_MAX; } else { diff --git a/src/include/taler_merchant_testing_lib.h b/src/include/taler_merchant_testing_lib.h @@ -442,12 +442,16 @@ TALER_TESTING_cmd_merchant_post_orders (const char *label, * @param merchant_url base URL of the merchant serving the * GET /orders request. * @param http_status expected HTTP response code. + * @param ... NULL-terminated list of labels (const char *) of + * reserve (commands) we expect to be returned in the list + * (assuming @a http_code is #MHD_HTTP_OK) * @return the command. */ struct TALER_TESTING_Command TALER_TESTING_cmd_merchant_get_orders (const char *label, const char *merchant_url, - unsigned int http_status); + unsigned int http_status, + ...); /** @@ -708,29 +712,16 @@ TALER_TESTING_cmd_merchant_get_reserve_with_tips (const char *label, * @param label command label. * @param merchant_url url to the merchant. * @param http_status expected HTTP response code. + * @param ... NULL-terminated list of labels (const char *) of + * reserve (commands) we expect to be returned in the list + * (assuming @a http_code is #MHD_HTTP_OK) */ struct TALER_TESTING_Command TALER_TESTING_cmd_merchant_get_reserves (const char *label, const char *merchant_url, - unsigned int http_status); - + unsigned int http_status, + ...); -/** - * Define a "GET /reserves" CMD - * - * @param label command label. - * @param merchant_url url to the merchant. - * @param reserve_refs a NULL-terminated list of references to - * commands that created reserves. - * @param http_status expected HTTP response code. - */ -struct TALER_TESTING_Command -TALER_TESTING_cmd_merchant_get_reserves_with_reserves (const char *label, - const char *merchant_url, - const char *reserve_refs - [], - unsigned int - http_status); /** * Define a "DELETE reserve" CMD. diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c @@ -57,9 +57,6 @@ static const char *pickup_amounts_2[] = {"EUR:0.01", NULL}; static const char *pickup_refs[] = {"pickup-tip-1", "pickup-tip-4", NULL}; -static const char *reserve_refs[] = {"create-reserve-tip-1", - "create-reserve-tip-2", NULL}; - /** * Payto URI of the customer (payer). */ @@ -263,6 +260,10 @@ run (void *cls, "create-reserve-1", "EUR:5", MHD_HTTP_OK), + TALER_TESTING_cmd_merchant_get_orders ("get-orders-empty", + merchant_url, + MHD_HTTP_OK, + NULL), /** * Check the reserve is depleted. */ @@ -284,7 +285,9 @@ run (void *cls, \"value\":\"{EUR:5}\"} ] }"), TALER_TESTING_cmd_merchant_get_orders ("get-orders-1", merchant_url, - MHD_HTTP_OK), + MHD_HTTP_OK, + "create-proposal-1", + NULL), TALER_TESTING_cmd_wallet_get_order ("get-order-wallet-1", merchant_url, "create-proposal-1", @@ -698,7 +701,8 @@ run (void *cls, MHD_HTTP_OK), TALER_TESTING_cmd_merchant_get_reserves ("get-reserves-1", merchant_url, - MHD_HTTP_OK), + MHD_HTTP_OK, + NULL), TALER_TESTING_cmd_merchant_get_reserve ("get-reserve-1", merchant_url, MHD_HTTP_OK, @@ -788,10 +792,12 @@ run (void *cls, pickup_amounts_1, TALER_EC_TIP_PICKUP_TIP_ID_UNKNOWN), - TALER_TESTING_cmd_merchant_get_reserves_with_reserves ("get-reserves-2", - merchant_url, - reserve_refs, - MHD_HTTP_OK), + TALER_TESTING_cmd_merchant_get_reserves ("get-reserves-2", + merchant_url, + MHD_HTTP_OK, + "create-reserve-tip-1", + "create-reserve-tip-2", + NULL), TALER_TESTING_cmd_merchant_delete_reserve ("delete-reserve-tip-1", merchant_url, diff --git a/src/testing/testing_api_cmd_get_orders.c b/src/testing/testing_api_cmd_get_orders.c @@ -54,6 +54,16 @@ struct GetOrdersState */ unsigned int http_status; + /** + * A NULL-terminated array of CMD labels that created orders. + */ + const char **orders; + + /** + * The length of @e orders. + */ + unsigned int orders_length; + }; @@ -68,7 +78,6 @@ get_orders_cb (void *cls, unsigned int orders_length, const struct TALER_MERCHANT_OrderEntry orders[]) { - /* FIXME, deeper checks should be implemented here. */ struct GetOrdersState *gos = cls; gos->ogh = NULL; @@ -85,8 +94,43 @@ get_orders_cb (void *cls, switch (hr->http_status) { case MHD_HTTP_OK: - // FIXME: use gis->instance_reference here to - // check if the data returned matches that from the POST / PATCH + if (orders_length != gos->orders_length) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Number of orders found does not match\n"); + TALER_TESTING_interpreter_fail (gos->is); + return; + } + for (unsigned int i = 0; i < orders_length; ++i) + { + const struct TALER_TESTING_Command *order_cmd; + + order_cmd = TALER_TESTING_interpreter_lookup_command ( + gos->is, + gos->orders[i]); + + { + const char *order_id; + if (GNUNET_OK != + TALER_TESTING_get_trait_order_id (order_cmd, + 0, + &order_id)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Could not fetch order id\n"); + TALER_TESTING_interpreter_fail (gos->is); + return; + } + if (0 != strcmp (orders[i].order_id, + order_id)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Order id does not match\n"); + TALER_TESTING_interpreter_fail (gos->is); + return; + } + } + } break; default: GNUNET_log (GNUNET_ERROR_TYPE_WARNING, @@ -136,7 +180,7 @@ get_orders_cleanup (void *cls, if (NULL != gos->ogh) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "GET /instances/$ID operation did not complete\n"); + "GET /orders operation did not complete\n"); TALER_MERCHANT_orders_get_cancel (gos->ogh); } GNUNET_free (gos); @@ -150,12 +194,16 @@ get_orders_cleanup (void *cls, * @param merchant_url base URL of the merchant serving the * GET /orders request. * @param http_status expected HTTP response code. + * @param ... NULL-terminated list of labels (const char *) of + * reserve (commands) we expect to be returned in the list + * (assuming @a http_code is #MHD_HTTP_OK) * @return the command. */ struct TALER_TESTING_Command TALER_TESTING_cmd_merchant_get_orders (const char *label, const char *merchant_url, - unsigned int http_status) + unsigned int http_status, + ...) { struct GetOrdersState *gos; @@ -163,6 +211,19 @@ TALER_TESTING_cmd_merchant_get_orders (const char *label, gos->merchant_url = merchant_url; gos->http_status = http_status; { + const char *clabel; + va_list ap; + + va_start (ap, http_status); + while (NULL != (clabel = va_arg (ap, const char *))) + { + GNUNET_array_append (gos->orders, + gos->orders_length, + clabel); + } + va_end (ap); + } + { struct TALER_TESTING_Command cmd = { .cls = gos, .label = label, diff --git a/src/testing/testing_api_cmd_get_reserves.c b/src/testing/testing_api_cmd_get_reserves.c @@ -45,14 +45,14 @@ struct GetReservesState struct TALER_TESTING_Interpreter *is; /** - * Whether to compare the reserves that were found. + * A list of reserves to compare with. */ - bool cmp_reserves; + const char **reserves; /** - * A list of reserves to compare with. + * Length of @e reserve_refs. */ - const char **reserve_refs; + unsigned int reserves_length; /** * Base URL of the merchant serving the request. @@ -89,24 +89,21 @@ get_reserves_cb (void *cls, switch (hr->http_status) { case MHD_HTTP_OK: + if (reserves_length != grs->reserves_length) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Length of reserves found does not match\n"); + TALER_TESTING_interpreter_fail (grs->is); + return; + } // FIXME: check if the data returned matches that from the POST / PATCH - if (! grs->cmp_reserves) - break; for (unsigned int i = 0; i < reserves_length; ++i) { - if (NULL == grs->reserve_refs[i]) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Number of reserves found does not match\n"); - TALER_TESTING_interpreter_fail (grs->is); - return; - } - const struct TALER_TESTING_Command *reserve_cmd; reserve_cmd = TALER_TESTING_interpreter_lookup_command ( grs->is, - grs->reserve_refs[i]); + grs->reserves[i]); { const struct TALER_ReservePublicKeyP *reserve_pub; @@ -114,7 +111,12 @@ get_reserves_cb (void *cls, TALER_TESTING_get_trait_reserve_pub (reserve_cmd, 0, &reserve_pub)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Could not fetch reserve public key\n"); TALER_TESTING_interpreter_fail (grs->is); + return; + } if (0 != GNUNET_memcmp (&reserves[i].reserve_pub, reserve_pub)) { @@ -131,7 +133,12 @@ get_reserves_cb (void *cls, TALER_TESTING_get_trait_amount_obj (reserve_cmd, 0, &initial)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Could not fetch reserve initial balance\n"); TALER_TESTING_interpreter_fail (grs->is); + return; + } if ((GNUNET_OK != TALER_amount_cmp_currency ( &reserves[i].merchant_initial_amount, initial)) || @@ -200,6 +207,9 @@ get_reserves_cleanup (void *cls, "GET /private/reserves operation did not complete\n"); TALER_MERCHANT_reserves_get_cancel (grs->rgh); } + GNUNET_array_grow (grs->reserves, + grs->reserves_length, + 0); GNUNET_free (grs); } @@ -210,54 +220,34 @@ get_reserves_cleanup (void *cls, * @param label command label. * @param merchant_url url to the merchant. * @param http_status expected HTTP response code. + * @param ... NULL-terminated list of labels (const char *) of + * reserve (commands) we expect to be returned in the list + * (assuming @a http_code is #MHD_HTTP_OK) */ struct TALER_TESTING_Command TALER_TESTING_cmd_merchant_get_reserves (const char *label, const char *merchant_url, - unsigned int http_status) + unsigned int http_status, + ...) { struct GetReservesState *grs; grs = GNUNET_new (struct GetReservesState); grs->merchant_url = merchant_url; - grs->cmp_reserves = false; grs->http_status = http_status; { - struct TALER_TESTING_Command cmd = { - .cls = grs, - .label = label, - .run = &get_reserves_run, - .cleanup = &get_reserves_cleanup - }; + const char *clabel; + va_list ap; - return cmd; + va_start (ap, http_status); + while (NULL != (clabel = va_arg (ap, const char *))) + { + GNUNET_array_append (grs->reserves, + grs->reserves_length, + clabel); + } + va_end (ap); } -} - - -/** - * Define a "GET /reserves" CMD - * - * @param label command label. - * @param merchant_url url to the merchant. - * @param reserve_refs a NULL-terminated list of references to - * commands that created reserves. - * @param http_status expected HTTP response code. - */ -struct TALER_TESTING_Command -TALER_TESTING_cmd_merchant_get_reserves_with_reserves (const char *label, - const char *merchant_url, - const char *reserve_refs - [], - unsigned int http_status) -{ - struct GetReservesState *grs; - - grs = GNUNET_new (struct GetReservesState); - grs->merchant_url = merchant_url; - grs->cmp_reserves = true; - grs->reserve_refs = reserve_refs; - grs->http_status = http_status; { struct TALER_TESTING_Command cmd = { .cls = grs,