From 06010ba8681aa588c977410e0ae6f32879435432 Mon Sep 17 00:00:00 2001 From: Jonathan Buchanan Date: Tue, 16 Jun 2020 21:44:18 -0400 Subject: fix/test for POST tips//pickup --- src/backend/taler-merchant-httpd.c | 9 +++++++++ .../taler-merchant-httpd_post-tips-ID-pickup.c | 23 +++++++++++++++------- src/lib/merchant_api_tip_pickup2.c | 2 +- src/testing/test_merchant_api.c | 18 ++++++++++++++++- src/testing/testing_api_cmd_get_reserve.c | 23 ++++++++++++++++++++++ src/testing/testing_api_cmd_post_reserves.c | 1 + 6 files changed, 67 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c index 721861ca..b8791225 100644 --- a/src/backend/taler-merchant-httpd.c +++ b/src/backend/taler-merchant-httpd.c @@ -58,6 +58,7 @@ #include "taler-merchant-httpd_post-orders-ID-abort.h" #include "taler-merchant-httpd_post-orders-ID-claim.h" #include "taler-merchant-httpd_post-orders-ID-pay.h" +#include "taler-merchant-httpd_post-tips-ID-pickup.h" /** @@ -973,6 +974,14 @@ url_handler (void *cls, .have_id_segment = true, .handler = &TMH_get_tips_ID }, + /* POST /tips/$ID/pickup: */ + { + .url_prefix = "/tips/", + .method = MHD_HTTP_METHOD_POST, + .have_id_segment = true, + .url_suffix = "pickup", + .handler = &TMH_post_tips_ID_pickup + }, { NULL } diff --git a/src/backend/taler-merchant-httpd_post-tips-ID-pickup.c b/src/backend/taler-merchant-httpd_post-tips-ID-pickup.c index bf1e3297..bba73d48 100644 --- a/src/backend/taler-merchant-httpd_post-tips-ID-pickup.c +++ b/src/backend/taler-merchant-httpd_post-tips-ID-pickup.c @@ -514,6 +514,8 @@ compute_total_requested (void *cls, } } pc->tr_initialized = true; + MHD_resume_connection (pc->connection); + TMH_trigger_daemon (); /* we resumed, kick MHD */ } @@ -576,7 +578,6 @@ TMH_post_tips_ID_pickup (const struct TMH_RequestHandler *rh, struct PickupContext *pc = hc->ctx; char *exchange_url; struct TALER_Amount total_authorized; - struct TALER_Amount total_requested; struct TALER_Amount total_picked_up; struct TALER_Amount total_remaining; struct GNUNET_TIME_Absolute expiration; @@ -672,7 +673,7 @@ TMH_post_tips_ID_pickup (const struct TMH_RequestHandler *rh, sizeof (pc->tip_id)); for (unsigned int i = 0; iplanchets_length; i++) { - struct TALER_PlanchetDetail *pd = &pc->planchets[index]; + struct TALER_PlanchetDetail *pd = &pc->planchets[i]; GNUNET_CRYPTO_hash_context_read (hc, &pd->denom_pub_hash, @@ -711,6 +712,7 @@ TMH_post_tips_ID_pickup (const struct TMH_RequestHandler *rh, return reply_lookup_tip_failed (connection, qs); MHD_suspend_connection (connection); + pc->connection = connection; pc->tt = GNUNET_SCHEDULER_add_delayed (EXCHANGE_TIMEOUT, &do_timeout, pc); @@ -747,6 +749,10 @@ RETRY: } { struct GNUNET_CRYPTO_RsaSignature *sigs[GNUNET_NZL (pc->planchets_length)]; + memset (sigs, + 0, + sizeof (struct GNUNET_CRYPTO_RsaSignature *) * GNUNET_NZL ( + pc->planchets_length)); qs = TMH_db->lookup_pickup (TMH_db->cls, hc->instance->settings.id, @@ -801,7 +807,10 @@ RETRY: GNUNET_assert (0 == json_array_append_new ( blind_sigs, - GNUNET_JSON_from_rsa_signature (sigs[i]))); + json_pack ("{s:o}", + "blind_sig", + GNUNET_JSON_from_rsa_signature ( + sigs[i])))); GNUNET_CRYPTO_rsa_signature_free (sigs[i]); } return TALER_MHD_reply_json_pack ( @@ -867,7 +876,7 @@ RETRY: if (0 > TALER_amount_cmp (&total_remaining, - &total_requested)) + &pc->total_requested)) { GNUNET_break (0); TMH_db->rollback (TMH_db->cls); @@ -877,16 +886,16 @@ RETRY: "requested amount exceeds amount left in tip"); } - GNUNET_assert (0 > + GNUNET_assert (0 < TALER_amount_add (&total_picked_up, &total_picked_up, - &total_requested)); + &pc->total_requested)); qs = TMH_db->insert_pickup (TMH_db->cls, hc->instance->settings.id, &pc->tip_id, &total_picked_up, &pc->pickup_id, - &total_requested); + &pc->total_requested); if (qs < 0) { TMH_db->rollback (TMH_db->cls); diff --git a/src/lib/merchant_api_tip_pickup2.c b/src/lib/merchant_api_tip_pickup2.c index 4e26217c..a9c38114 100644 --- a/src/lib/merchant_api_tip_pickup2.c +++ b/src/lib/merchant_api_tip_pickup2.c @@ -308,7 +308,7 @@ TALER_MERCHANT_tip_pickup2 (struct GNUNET_CURL_Context *ctx, *end = '\0'; GNUNET_snprintf (arg_str, sizeof (arg_str), - "/tips/%s/pickup", + "tips/%s/pickup", tip_str); tpo->url = TALER_url_join (backend_url, arg_str, diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c index c2ed9535..fb230f04 100644 --- a/src/testing/test_merchant_api.c +++ b/src/testing/test_merchant_api.c @@ -642,12 +642,24 @@ run (void *cls, EXCHANGE_URL, "x-taler-bank", MHD_HTTP_OK), + TALER_TESTING_cmd_admin_add_incoming_with_ref ("create-reserve-tip-1-exch", + "EUR:20.04", + &bc.exchange_auth, + payer_payto, + "create-reserve-tip-1"), + cmd_exec_wirewatch ("wirewatch-3"), TALER_TESTING_cmd_tip_authorize ("authorize-tip-1", merchant_url, EXCHANGE_URL, MHD_HTTP_OK, "tip 1", "EUR:5.01"), + TALER_TESTING_cmd_tip_authorize ("authorize-tip-2", + merchant_url, + EXCHANGE_URL, + MHD_HTTP_OK, + "tip 2", + "EUR:5.01"), TALER_TESTING_cmd_get_tips ("get-tips-1", merchant_url, MHD_HTTP_OK), @@ -658,7 +670,11 @@ run (void *cls, merchant_url, MHD_HTTP_OK, "create-reserve-tip-1"), - + TALER_TESTING_cmd_tip_pickup ("pickup-tip-1", + merchant_url, + MHD_HTTP_OK, + "authorize-tip-1", + pickup_amounts_1), TALER_TESTING_cmd_merchant_delete_reserve ("delete-reserve-tip-1", merchant_url, "create-reserve-tip-1", diff --git a/src/testing/testing_api_cmd_get_reserve.c b/src/testing/testing_api_cmd_get_reserve.c index 1cae418e..d617c182 100644 --- a/src/testing/testing_api_cmd_get_reserve.c +++ b/src/testing/testing_api_cmd_get_reserve.c @@ -72,6 +72,11 @@ get_reserve_cb (void *cls, { /* FIXME, deeper checks should be implemented here. */ struct GetReserveState *grs = cls; + const struct TALER_TESTING_Command *reserve_cmd; + + reserve_cmd = TALER_TESTING_interpreter_lookup_command ( + grs->is, + grs->reserve_reference); grs->rgh = NULL; if (grs->http_status != hr->http_status) @@ -89,6 +94,24 @@ get_reserve_cb (void *cls, case MHD_HTTP_OK: // FIXME: use grs->reserve_reference here to // check if the data returned matches that from the POST / PATCH + { + const struct TALER_Amount *initial_amount; + if (GNUNET_OK != + TALER_TESTING_get_trait_amount_obj (reserve_cmd, + 0, + &initial_amount)) + TALER_TESTING_FAIL (grs->is); + if ((GNUNET_OK != TALER_amount_cmp_currency (&rs->merchant_initial_amount, + initial_amount)) || + (0 != TALER_amount_cmp (&rs->merchant_initial_amount, + initial_amount))) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Reserve initial amount does not match\n"); + TALER_TESTING_interpreter_fail (grs->is); + return; + } + } break; default: GNUNET_log (GNUNET_ERROR_TYPE_WARNING, diff --git a/src/testing/testing_api_cmd_post_reserves.c b/src/testing/testing_api_cmd_post_reserves.c index e9bd63a1..3d62d2f6 100644 --- a/src/testing/testing_api_cmd_post_reserves.c +++ b/src/testing/testing_api_cmd_post_reserves.c @@ -142,6 +142,7 @@ post_reserves_traits (void *cls, struct PostReservesState *prs = cls; struct TALER_TESTING_Trait traits[] = { TALER_TESTING_make_trait_reserve_pub (0, prs->reserve_pub), + TALER_TESTING_make_trait_amount_obj (0, &prs->initial_balance), TALER_TESTING_trait_end (), }; -- cgit v1.2.3