diff options
Diffstat (limited to 'src/testing/testing_api_cmd_bank_admin_add_incoming.c')
-rw-r--r-- | src/testing/testing_api_cmd_bank_admin_add_incoming.c | 159 |
1 files changed, 79 insertions, 80 deletions
diff --git a/src/testing/testing_api_cmd_bank_admin_add_incoming.c b/src/testing/testing_api_cmd_bank_admin_add_incoming.c index 28f907fda..5c031d0b3 100644 --- a/src/testing/testing_api_cmd_bank_admin_add_incoming.c +++ b/src/testing/testing_api_cmd_bank_admin_add_incoming.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2018-2020 Taler Systems SA + Copyright (C) 2018-2021 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 published by @@ -107,7 +107,7 @@ struct AdminAddIncomingState * the "sender_url" field is set to a 'const char *' and * MUST NOT be free()'ed. */ - struct TALER_EXCHANGE_ReserveHistory reserve_history; + struct TALER_EXCHANGE_ReserveHistoryEntry reserve_history; /** * Set to the wire transfer's unique ID. @@ -117,7 +117,7 @@ struct AdminAddIncomingState /** * Timestamp of the transaction (as returned from the bank). */ - struct GNUNET_TIME_Absolute timestamp; + struct GNUNET_TIME_Timestamp timestamp; /** * Merchant instance. Sometimes used to get the tip reserve @@ -180,8 +180,7 @@ do_retry (void *cls) struct AdminAddIncomingState *fts = cls; fts->retry_task = NULL; - fts->is->commands[fts->is->ip].last_req_time - = GNUNET_TIME_absolute_get (); + TALER_TESTING_touch_cmd (fts->is); admin_add_incoming_run (fts, NULL, fts->is); @@ -194,41 +193,54 @@ do_retry (void *cls) * acceptable. * * @param cls closure with the interpreter state - * @param http_status HTTP response code, #MHD_HTTP_OK (200) for - * successful status request; 0 if the exchange's reply is - * bogus (fails to follow the protocol) - * @param ec taler-specific error code, #TALER_EC_NONE on success - * @param serial_id unique ID of the wire transfer - * @param timestamp time stamp of the transaction made. - * @param json raw response + * @param air response details */ static void confirmation_cb (void *cls, - unsigned int http_status, - enum TALER_ErrorCode ec, - uint64_t serial_id, - struct GNUNET_TIME_Absolute timestamp, - const json_t *json) + const struct TALER_BANK_AdminAddIncomingResponse *air) { struct AdminAddIncomingState *fts = cls; struct TALER_TESTING_Interpreter *is = fts->is; - (void) json; - fts->reserve_history.details.in_details.timestamp = timestamp; - fts->reserve_history.details.in_details.wire_reference = serial_id; fts->aih = NULL; - switch (http_status) + /** + * Test case not caring about the HTTP status code. + * That helps when Fakebank and Libeufin diverge in + * the response status code. An example is the + * /admin/add-incoming: libeufin return ALWAYS '200 OK' + * (see note below) whereas the Fakebank responds with + * '409 Conflict' upon a duplicate reserve public key. + * + * Note: this decision aims at avoiding to put Taler + * logic into the Sandbox; that's because banks DO allow + * their customers to wire the same subject multiple + * times. Hence, instead of triggering any error, libeufin + * bounces the payment back in the same way it does for + * malformed reserve public keys. + */ + if (-1 == (int) fts->expected_http_status) + { + TALER_TESTING_interpreter_next (is); + return; + } + if (air->http_status != fts->expected_http_status) + { + TALER_TESTING_unexpected_status (is, + air->http_status, + fts->expected_http_status); + return; + } + switch (air->http_status) { case MHD_HTTP_OK: - if (fts->expected_http_status != - MHD_HTTP_OK) - { - GNUNET_break (0); - TALER_TESTING_interpreter_fail (is); - return; - } - fts->serial_id = serial_id; - fts->timestamp = timestamp; + fts->reserve_history.details.in_details.timestamp + = air->details.ok.timestamp; + fts->reserve_history.details.in_details.wire_reference + = air->details.ok.serial_id; + fts->serial_id + = air->details.ok.serial_id; + fts->timestamp + = air->details.ok.timestamp; TALER_TESTING_interpreter_next (is); return; case MHD_HTTP_UNAUTHORIZED: @@ -246,35 +258,28 @@ confirmation_cb (void *cls, } break; case MHD_HTTP_CONFLICT: - if (fts->expected_http_status != - MHD_HTTP_CONFLICT) - { - GNUNET_break (0); - TALER_TESTING_interpreter_fail (is); - return; - } TALER_TESTING_interpreter_next (is); return; default: if (0 != fts->do_retry) { fts->do_retry--; - if ( (0 == http_status) || - (TALER_EC_GENERIC_DB_SOFT_FAILURE == ec) || - (MHD_HTTP_INTERNAL_SERVER_ERROR == http_status) ) + if ( (0 == air->http_status) || + (TALER_EC_GENERIC_DB_SOFT_FAILURE == air->ec) || + (MHD_HTTP_INTERNAL_SERVER_ERROR == air->http_status) ) { GNUNET_log ( GNUNET_ERROR_TYPE_INFO, "Retrying fakebank transfer failed with %u/%d\n", - http_status, - (int) ec); + air->http_status, + (int) air->ec); /* on DB conflicts, do not use backoff */ - if (TALER_EC_GENERIC_DB_SOFT_FAILURE == ec) + if (TALER_EC_GENERIC_DB_SOFT_FAILURE == air->ec) fts->backoff = GNUNET_TIME_UNIT_ZERO; else fts->backoff = GNUNET_TIME_randomized_backoff (fts->backoff, MAX_BACKOFF); - fts->is->commands[fts->is->ip].num_tries++; + TALER_TESTING_inc_tries (fts->is); fts->retry_task = GNUNET_SCHEDULER_add_delayed ( fts->backoff, &do_retry, @@ -287,8 +292,8 @@ confirmation_cb (void *cls, GNUNET_break (0); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fakebank returned HTTP status %u/%d\n", - http_status, - (int) ec); + air->http_status, + (int) air->ec); TALER_TESTING_interpreter_fail (is); } @@ -309,6 +314,7 @@ admin_add_incoming_run (void *cls, bool have_public = false; (void) cmd; + fts->is = is; /* Use reserve public key as subject */ if (NULL != fts->reserve_reference) { @@ -326,11 +332,9 @@ admin_add_incoming_run (void *cls, } if (GNUNET_OK != TALER_TESTING_get_trait_reserve_priv (ref, - 0, &reserve_priv)) { if (GNUNET_OK != TALER_TESTING_get_trait_reserve_pub (ref, - 0, &reserve_pub)) { GNUNET_break (0); @@ -361,7 +365,6 @@ admin_add_incoming_run (void *cls, fts->reserve_history.amount = fts->amount; fts->reserve_history.details.in_details.sender_url = (char *) fts->payto_debit_account; /* remember to NOT free this one... */ - fts->is = is; fts->aih = TALER_BANK_admin_add_incoming ( TALER_TESTING_interpreter_get_context (is), @@ -395,9 +398,8 @@ admin_add_incoming_cleanup (void *cls, if (NULL != fts->aih) { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Command %s did not complete\n", - cmd->label); + TALER_TESTING_command_incomplete (fts->is, + cmd->label); TALER_BANK_admin_add_incoming_cancel (fts->aih); fts->aih = NULL; } @@ -420,13 +422,14 @@ admin_add_incoming_cleanup (void *cls, * @param index index number of the object to offer. * @return #GNUNET_OK on success. */ -static int +static enum GNUNET_GenericReturnValue admin_add_incoming_traits (void *cls, const void **ret, const char *trait, unsigned int index) { struct AdminAddIncomingState *fts = cls; + static const char *void_uri = "payto://void/the-exchange"; if (MHD_HTTP_OK != fts->expected_http_status) @@ -435,19 +438,17 @@ admin_add_incoming_traits (void *cls, { struct TALER_TESTING_Trait traits[] = { TALER_TESTING_make_trait_bank_row (&fts->serial_id), - TALER_TESTING_make_trait_payto (TALER_TESTING_PT_DEBIT, - fts->payto_debit_account), + TALER_TESTING_make_trait_debit_payto_uri (fts->payto_debit_account), + TALER_TESTING_make_trait_payto_uri (fts->payto_debit_account), /* Used as a marker, content does not matter */ - TALER_TESTING_make_trait_payto (TALER_TESTING_PT_CREDIT, - "payto://void/the-exchange"), - TALER_TESTING_make_trait_url (TALER_TESTING_UT_EXCHANGE_BANK_ACCOUNT_URL, - fts->exchange_credit_url), - TALER_TESTING_make_trait_amount_obj (0, &fts->amount), - TALER_TESTING_make_trait_absolute_time (0, &fts->timestamp), - TALER_TESTING_make_trait_reserve_priv (0, - &fts->reserve_priv), - TALER_TESTING_make_trait_reserve_pub (0, - &fts->reserve_pub), + TALER_TESTING_make_trait_credit_payto_uri (void_uri), + TALER_TESTING_make_trait_exchange_bank_account_url ( + fts->exchange_credit_url), + TALER_TESTING_make_trait_amount (&fts->amount), + TALER_TESTING_make_trait_timestamp (0, + &fts->timestamp), + TALER_TESTING_make_trait_reserve_priv (&fts->reserve_priv), + TALER_TESTING_make_trait_reserve_pub (&fts->reserve_pub), TALER_TESTING_make_trait_reserve_history (0, &fts->reserve_history), TALER_TESTING_trait_end () @@ -462,17 +463,15 @@ admin_add_incoming_traits (void *cls, { struct TALER_TESTING_Trait traits[] = { TALER_TESTING_make_trait_bank_row (&fts->serial_id), - TALER_TESTING_make_trait_payto (TALER_TESTING_PT_DEBIT, - fts->payto_debit_account), + TALER_TESTING_make_trait_debit_payto_uri (fts->payto_debit_account), /* Used as a marker, content does not matter */ - TALER_TESTING_make_trait_payto (TALER_TESTING_PT_CREDIT, - "payto://void/the-exchange"), - TALER_TESTING_make_trait_url (TALER_TESTING_UT_EXCHANGE_BANK_ACCOUNT_URL, - fts->exchange_credit_url), - TALER_TESTING_make_trait_amount_obj (0, &fts->amount), - TALER_TESTING_make_trait_absolute_time (0, &fts->timestamp), - TALER_TESTING_make_trait_reserve_pub (0, - &fts->reserve_pub), + TALER_TESTING_make_trait_credit_payto_uri (void_uri), + TALER_TESTING_make_trait_exchange_bank_account_url ( + fts->exchange_credit_url), + TALER_TESTING_make_trait_amount (&fts->amount), + TALER_TESTING_make_trait_timestamp (0, + &fts->timestamp), + TALER_TESTING_make_trait_reserve_pub (&fts->reserve_pub), TALER_TESTING_make_trait_reserve_history (0, &fts->reserve_history), TALER_TESTING_trait_end () @@ -543,11 +542,11 @@ make_command (const char *label, struct TALER_TESTING_Command -TALER_TESTING_cmd_admin_add_incoming (const char *label, - const char *amount, - const struct - TALER_BANK_AuthenticationData *auth, - const char *payto_debit_account) +TALER_TESTING_cmd_admin_add_incoming ( + const char *label, + const char *amount, + const struct TALER_BANK_AuthenticationData *auth, + const char *payto_debit_account) { return make_command (label, make_fts (amount, |