From d842c14f85352367d9e2d0c868b63e09c206100e Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 13 Jan 2020 00:27:48 +0100 Subject: refactor to make it easier to share init logic for test configurations --- src/benchmark/taler-exchange-benchmark.c | 43 ++- src/include/Makefile.am | 3 +- src/include/taler_testing_bank_lib.h | 266 ----------------- src/include/taler_testing_lib.h | 331 ++++++++++++++++++++-- src/lib/test_auditor_api.c | 205 +++++--------- src/lib/test_bank_api.c | 84 ++---- src/lib/test_bank_api_twisted.c | 30 +- src/lib/test_exchange_api.c | 187 ++++-------- src/lib/test_exchange_api_keys_cherry_picking.c | 14 +- src/lib/test_exchange_api_overlapping_keys_bug.c | 12 +- src/lib/test_exchange_api_twisted.c | 69 ++--- src/lib/testing_api_cmd_bank_admin_add_incoming.c | 1 - src/lib/testing_api_cmd_bank_history_credit.c | 1 - src/lib/testing_api_cmd_bank_history_debit.c | 3 - src/lib/testing_api_cmd_bank_transfer.c | 1 - src/lib/testing_api_cmd_deposit.c | 6 +- src/lib/testing_api_helpers_bank.c | 207 ++++++++++---- src/lib/testing_api_helpers_exchange.c | 189 +++--------- 18 files changed, 724 insertions(+), 928 deletions(-) delete mode 100644 src/include/taler_testing_bank_lib.h diff --git a/src/benchmark/taler-exchange-benchmark.c b/src/benchmark/taler-exchange-benchmark.c index 07ee26062..dd184cc8b 100644 --- a/src/benchmark/taler-exchange-benchmark.c +++ b/src/benchmark/taler-exchange-benchmark.c @@ -35,7 +35,6 @@ #include "taler_bank_service.h" #include "taler_fakebank_lib.h" #include "taler_testing_lib.h" -#include "taler_testing_bank_lib.h" #include "taler_error_codes.h" /* Error codes. */ @@ -94,6 +93,11 @@ enum BenchmarkMode */ static struct TALER_Account exchange_bank_account; +/** + * Configuration of our exchange. + */ +static struct TALER_TESTING_ExchangeConfiguration ec; + /** * Hold information about a user at the bank. */ @@ -318,7 +322,7 @@ run (void *cls, withdraw_label, 0, /* Index of the one withdrawn coin in the traits. */ TALER_TESTING_make_wire_details - (TALER_TESTING_USER_ACCOUNT_NUMBER, + (42 /* FIXME: ugly! */, exchange_bank_account.details.x_taler_bank.hostname), order_enc, GNUNET_TIME_UNIT_ZERO, @@ -435,14 +439,12 @@ launch_fakebank (void *cls) * @param main_cb main function to run per process * @param main_cb_cls closure for @a main_cb * @param config_file configuration file to use - * @param exchange_url exchange URL to use * @return #GNUNET_OK on success */ static int parallel_benchmark (TALER_TESTING_Main main_cb, void *main_cb_cls, - const char *config_file, - const char *exchange_url) + const char *config_file) { int result = GNUNET_OK; pid_t cpids[howmany_clients]; @@ -556,11 +558,11 @@ parallel_benchmark (TALER_TESTING_Main main_cb, /* We always wait for the exchange, no matter if it's running locally or remotely */ - if (0 != TALER_TESTING_wait_exchange_ready (exchange_url)) + if (0 != TALER_TESTING_wait_exchange_ready (ec.exchange_url)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to detect running exchange at `%s'\n", - exchange_url); + ec.exchange_url); GNUNET_OS_process_kill (exchanged, SIGTERM); if ( (MODE_BOTH == mode) || (MODE_CLIENT == mode)) @@ -719,8 +721,6 @@ int main (int argc, char *const *argv) { - char *exchange_url = NULL; - char *auditor_url = NULL; struct GNUNET_CONFIGURATION_Handle *cfg; struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_option_mandatory @@ -836,11 +836,9 @@ main (int argc, { const char *bank_details_section; - GNUNET_CONFIGURATION_iterate_sections - (cfg, - &pick_exchange_account_cb, - &bank_details_section); - + GNUNET_CONFIGURATION_iterate_sections (cfg, + &pick_exchange_account_cb, + &bank_details_section); if (NULL == bank_details_section) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, @@ -903,11 +901,9 @@ main (int argc, GNUNET_OS_process_wait (compute_wire_response); GNUNET_OS_process_destroy (compute_wire_response); - GNUNET_assert - (GNUNET_OK == TALER_TESTING_prepare_exchange - (cfg_filename, - &auditor_url, - &exchange_url)); + GNUNET_assert (GNUNET_OK == + TALER_TESTING_prepare_exchange (cfg_filename, + &ec)); } else { @@ -915,7 +911,7 @@ main (int argc, GNUNET_CONFIGURATION_get_value_string (cfg, "exchange", "BASE_URL", - &exchange_url)) + &ec.exchange_url)) { GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "exchange", @@ -950,16 +946,11 @@ main (int argc, return BAD_CONFIG_FILE; } } - GNUNET_CONFIGURATION_destroy (cfg); result = parallel_benchmark (&run, NULL, - cfg_filename, - exchange_url); - - GNUNET_free_non_null (exchange_url); - GNUNET_free_non_null (auditor_url); + cfg_filename); /* If we're the exchange worker, we're done now. No need to print results */ if (MODE_EXCHANGE == mode) diff --git a/src/include/Makefile.am b/src/include/Makefile.am index ed42006f0..b1068d5d7 100644 --- a/src/include/Makefile.am +++ b/src/include/Makefile.am @@ -30,8 +30,7 @@ talerinclude_HEADERS = \ taler_util.h \ taler_mhd_lib.h \ taler_pq_lib.h \ - taler_signatures.h \ - taler_testing_bank_lib.h + taler_signatures.h endif diff --git a/src/include/taler_testing_bank_lib.h b/src/include/taler_testing_bank_lib.h deleted file mode 100644 index cbd734ff5..000000000 --- a/src/include/taler_testing_bank_lib.h +++ /dev/null @@ -1,266 +0,0 @@ -/* - This file is part of TALER - (C) 2018-2020 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 the Free Software Foundation; either version 3, or - (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public - License along with TALER; see the file COPYING. If not, see - -*/ - -/** - * @file include/taler_testing_bank_lib.h - * @brief API for writing test cases to test banks. - * @author Marcello Stanisci - */ -#ifndef TALER_TESTING_BANK_LIB_H -#define TALER_TESTING_BANK_LIB_H - -#include "taler_util.h" -#include -#include "taler_json_lib.h" -#include -#include "taler_bank_service.h" -#include "taler_testing_lib.h" - - -/* ******** Credentials to log in at the bank ******* */ - -/* Note that the same passwords must be set in the script in - contrib/taler-bank-manage-testing for the tests to work! */ -#define TALER_TESTING_BANK_ACCOUNT_NUMBER 1 -#define TALER_TESTING_BANK_USERNAME "Bank" -#define TALER_TESTING_BANK_PASSWORD "x" -#define TALER_TESTING_EXCHANGE_ACCOUNT_NUMBER 2 -#define TALER_TESTING_EXCHANGE_USERNAME "Exchange" -#define TALER_TESTING_EXCHANGE_PASSWORD "x" -#define TALER_TESTING_USER_ACCOUNT_NUMBER 3 -#define TALER_TESTING_USER_USERNAME "Tor" -#define TALER_TESTING_USER_PASSWORD "x" - - -/* ********************* Helper functions ********************* */ - -/** - * Start the (Python) bank process. Assume the port - * is available and the database is clean. Use the "prepare - * bank" function to do such tasks. - * - * @param config_filename configuration filename. - * @param bank_url base URL of the bank, used by `wget' to check - * that the bank was started right. - * - * @return the process, or NULL if the process could not - * be started. - */ -struct GNUNET_OS_Process * -TALER_TESTING_run_bank (const char *config_filename, - const char *bank_url); - -/** - * Runs the Fakebank by guessing / extracting the portnumber - * from the base URL. - * - * @param bank_url bank's base URL. - * @return the fakebank process handle, or NULL if any - * error occurs. - */ -struct TALER_FAKEBANK_Handle * -TALER_TESTING_run_fakebank (const char *bank_url); - -/** - * Prepare the bank execution. Check if the port is available - * and reset database. - * - * @param config_filename configuration file name. - * - * @return the base url, or NULL upon errors. Must be freed - * by the caller. - */ -char * -TALER_TESTING_prepare_bank (const char *config_filename); - - -/** - * Look for substring in a programs' name. - * - * @param prog program's name to look into - * @param marker chunk to find in @a prog - */ -int -TALER_TESTING_has_in_name (const char *prog, - const char *marker); - -/* ************** Specific interpreter commands ************ */ - -/** - * Make a credit "history" CMD. - * - * @param label command label. - * @param account_url base URL of the account offering the "history" - * operation. - * @param auth login data to use - * @param start_row_reference reference to a command that can - * offer a row identifier, to be used as the starting row - * to accept in the result. - * @param num_results how many rows we want in the result, - * and ascending/descending call - * @return the command. - */ -struct TALER_TESTING_Command -TALER_TESTING_cmd_bank_credits (const char *label, - const char *account_url, - const struct - TALER_BANK_AuthenticationData *auth, - const char *start_row_reference, - long long num_results); - - -/** - * Make a debit "history" CMD. - * - * @param label command label. - * @param account_url base URL of the account offering the "history" - * operation. - * @param auth authentication data - * @param start_row_reference reference to a command that can - * offer a row identifier, to be used as the starting row - * to accept in the result. - * @param num_results how many rows we want in the result. - * @return the command. - */ -struct TALER_TESTING_Command -TALER_TESTING_cmd_bank_debits (const char *label, - const char *account_url, - const struct TALER_BANK_AuthenticationData *auth, - const char *start_row_reference, - long long num_results); - - -/** - * Create transfer command. - * - * @param label command label. - * @param amount amount to transfer. - * @param account_base_url base URL of the account that implements this - * wire transer (which account gives money). - * @param auth authentication data to use - * @param payto_credit_account which account receives money. - * @param wtid wire transfer identifier to use - * @param exchange_base_url exchange URL to use - * @return the command. - */ -struct TALER_TESTING_Command -TALER_TESTING_cmd_transfer (const char *label, - const char *amount, - const char *account_base_url, - const struct TALER_BANK_AuthenticationData *auth, - const char *payto_credit_account, - const struct TALER_WireTransferIdentifierRawP *wtid, - const char *exchange_base_url); - - -/* ***** Commands ONLY for testing (/admin-API) **** */ - -/** - * Create /admin/add-incoming command. - * - * @param label command label. - * @param amount amount to transfer. - * @param exchange_base_url base URL of the exchange account that receives this - * wire transer (which account receives money). - * @param payto_debit_account which account sends money. - * @param auth authentication data - * @return the command. - */ -struct TALER_TESTING_Command -TALER_TESTING_cmd_admin_add_incoming (const char *label, - const char *amount, - const char *exchange_base_url, - const struct - TALER_BANK_AuthenticationData *auth, - const char *payto_debit_account); - - -/** - * Create "fakebank transfer" CMD, letting the caller specify - * a reference to a command that can offer a reserve private key. - * This private key will then be used to construct the subject line - * of the wire transfer. - * - * @param label command label. - * @param amount the amount to transfer. - * @param account_base_url base URL of the account that implements this - * wire transer (which account receives money). - * @param payto_debit_account which account sends money. - * @param auth authentication data - * @param ref reference to a command that can offer a reserve - * private key. - * @return the command. - */ -struct TALER_TESTING_Command -TALER_TESTING_cmd_admin_add_incoming_with_ref (const char *label, - const char *amount, - const char *account_base_url, - const struct - TALER_BANK_AuthenticationData * - auth, - const char *payto_debit_account, - const char *ref); - - -/** - * Create "fakebank transfer" CMD, letting the caller specifying - * the merchant instance. This version is useful when a tip - * reserve should be topped up, in fact the interpreter will need - * the "tipping instance" in order to get the instance public key - * and make a wire transfer subject out of it. - * - * @param label command label. - * @param amount amount to transfer. - * @param account_base_url base URL of the account that implements this - * wire transer (which account receives money). - * @param payto_debit_account which account sends money. - * @param auth authentication data - * @param instance the instance that runs the tipping. Under this - * instance, the configuration file will provide the private - * key of the tipping reserve. This data will then used to - * construct the wire transfer subject line. - * @param config_filename configuration file to use. - * @return the command. - */ -struct TALER_TESTING_Command -TALER_TESTING_cmd_admin_add_incoming_with_instance (const char *label, - const char *amount, - const char *account_base_url, - const struct - TALER_BANK_AuthenticationData - *auth, - const char * - payto_debit_account, - const char *instance, - const char *config_filename); - - -/** - * Modify a fakebank transfer command to enable retries when the - * reserve is not yet full or we get other transient errors from - * the fakebank. - * - * @param cmd a fakebank transfer command - * @return the command with retries enabled - */ -struct TALER_TESTING_Command -TALER_TESTING_cmd_admin_add_incoming_retry (struct TALER_TESTING_Command cmd); - - -#endif diff --git a/src/include/taler_testing_lib.h b/src/include/taler_testing_lib.h index aa3b537d7..8f432e08a 100644 --- a/src/include/taler_testing_lib.h +++ b/src/include/taler_testing_lib.h @@ -30,6 +30,8 @@ #include "taler_exchange_service.h" #include #include "taler_json_lib.h" +#include "taler_bank_service.h" +#include "taler_wire_lib.h" #include @@ -55,33 +57,46 @@ TALER_TESTING_make_trait_uint64 (3, data) +// FIXME: replace these! #define TALER_TESTING_GET_TRAIT_CREDIT_ACCOUNT(cmd,out) \ TALER_TESTING_get_trait_string (cmd, 4, out) +// FIXME: replace these! #define TALER_TESTING_MAKE_TRAIT_CREDIT_ACCOUNT(data) \ TALER_TESTING_make_trait_string (4, data) +// FIXME: replace these! #define TALER_TESTING_GET_TRAIT_DEBIT_ACCOUNT(cmd,out) \ TALER_TESTING_get_trait_string (cmd, 5, out) +// FIXME: replace these! #define TALER_TESTING_MAKE_TRAIT_DEBIT_ACCOUNT(data) \ TALER_TESTING_make_trait_string (5, data) /** - * Allocate and return a piece of wire-details. Combines - * the @a account_no and the @a bank_url to a - * @a payto://-URL and adds some salt to create the JSON. + * Create an x-taler-bank payto:// URL from a @a bank_url + * and an @a account_name. * - * @param account_no account number - * @param bank_url the bank_url + * @param bank_url the bank URL + * @param account_name the account name + * @return payto:// URL + */ +char * +TALER_TESTING_make_xtalerbank_payto (const char *bank_url, + const char *account_name); + + +/** + * Allocate and return a piece of wire-details. Combines + * a @a payto -URL and adds some salt to create the JSON. * + * @param payto payto://-URL to encapsulate * @return JSON describing the account, including the * payto://-URL of the account, must be manually decref'd */ json_t * -TALER_TESTING_make_wire_details (unsigned long long account_no, - const char *bank_url); +TALER_TESTING_make_wire_details (const char *payto); /** @@ -96,6 +111,28 @@ TALER_TESTING_find_pk (const struct TALER_EXCHANGE_Keys *keys, const struct TALER_Amount *amount); +/** + * Configuration data for an exchange. + */ +struct TALER_TESTING_ExchangeConfiguration +{ + /** + * Exchange base URL as it appears in the configuration. Note + * that it might differ from the one where the exchange actually + * listens from. + */ + char *exchange_url; + + /** + * Auditor base URL as it appears in the configuration. Note + * that it might differ from the one where the auditor actually + * listens from. + */ + char *auditor_url; + +}; + + /** * Prepare launching an exchange. Checks that the configured * port is available, runs taler-exchange-keyup, @@ -103,19 +140,14 @@ TALER_TESTING_find_pk (const struct TALER_EXCHANGE_Keys *keys, * launch the exchange process itself. * * @param config_filename configuration file to use - * @param auditor_base_url[out] will be set to the auditor base url, - * if the config has any; otherwise it will be set to - * NULL. - * @param exchange_base_url[out] will be set to the exchange base url, - * if the config has any; otherwise it will be set to - * NULL. + * @param ec[out] will be set to the exchange configuration data * @return #GNUNET_OK on success, #GNUNET_NO if test should be * skipped, #GNUNET_SYSERR on test failure */ int TALER_TESTING_prepare_exchange (const char *config_filename, - char **auditor_base_url, - char **exchange_base_url); + struct TALER_TESTING_ExchangeConfiguration *ec); + /** * "Canonical" cert_cb used when we are connecting to the @@ -245,24 +277,67 @@ TALER_TESTING_run_auditor_exchange (const char *config_filename, /** * Test port in URL string for availability. + * + * @param url URL to extract port from, 80 is default + * @return #GNUNET_OK if the port is free */ int TALER_TESTING_url_port_free (const char *url); +/** + * Configuration data for a bank. + */ +struct TALER_TESTING_BankConfiguration +{ + /** + * Bank base URL. + */ + char *bank_url; + + /** + * Base URL of the exchange's bank account. Basically + * @e bank_url plus the exchange account. + */ + char *exchange_account_url; + + /** + * Authentication data for the exchange user at the bank. + */ + struct TALER_BANK_AuthenticationData exchange_auth; + + /** + * Payto URL of the exchange's account ("2") + */ + char *exchange_payto; + + /** + * Payto URL of a user account ("42") + */ + char *user42_payto; + + /** + * Payto URL of another user's account ("43") + */ + char *user43_payto; + +}; + /** * Prepare launching a fakebank. Check that the configuration * file has the right option, and that the port is avaiable. - * If everything is OK, return the configured URL of the fakebank. + * If everything is OK, return the configuration data of the fakebank. * * @param config_filename configuration file to use * @param config_section which account to use * (must match x-taler-bank) - * @return NULL on error, fakebank URL otherwise + * @param bc[out] set to the bank's configuration data + * @return #GNUNET_OK on success */ -char * +int TALER_TESTING_prepare_fakebank (const char *config_filename, - const char *config_section); + const char *config_section, + struct TALER_TESTING_BankConfiguration *bc); /* ******************* Generic interpreter logic ************ */ @@ -707,9 +782,223 @@ TALER_TESTING_setup_with_auditor_and_exchange (TALER_TESTING_Main main_cb, void *main_cb_cls, const char *config_file); + +/** + * Start the (Python) bank process. Assume the port + * is available and the database is clean. Use the "prepare + * bank" function to do such tasks. + * + * @param config_filename configuration filename. + * @param bank_url base URL of the bank, used by `wget' to check + * that the bank was started right. + * + * @return the process, or NULL if the process could not + * be started. + */ +struct GNUNET_OS_Process * +TALER_TESTING_run_bank (const char *config_filename, + const char *bank_url); + +/** + * Runs the Fakebank by guessing / extracting the portnumber + * from the base URL. + * + * @param bank_url bank's base URL. + * @return the fakebank process handle, or NULL if any + * error occurs. + */ +struct TALER_FAKEBANK_Handle * +TALER_TESTING_run_fakebank (const char *bank_url); + + +/** + * Prepare the bank execution. Check if the port is available + * and reset database. + * + * @param config_filename configuration file name. + * @param bc[out] set to the bank's configuration data + * @return #GNUNET_OK on success + */ +int +TALER_TESTING_prepare_bank (const char *config_filename, + struct TALER_TESTING_BankConfiguration *bc); + + +/** + * Look for substring in a programs' name. + * + * @param prog program's name to look into + * @param marker chunk to find in @a prog + */ +int +TALER_TESTING_has_in_name (const char *prog, + const char *marker); + + /* ************** Specific interpreter commands ************ */ +/** + * Make a credit "history" CMD. + * + * @param label command label. + * @param account_url base URL of the account offering the "history" + * operation. + * @param auth login data to use + * @param start_row_reference reference to a command that can + * offer a row identifier, to be used as the starting row + * to accept in the result. + * @param num_results how many rows we want in the result, + * and ascending/descending call + * @return the command. + */ +struct TALER_TESTING_Command +TALER_TESTING_cmd_bank_credits (const char *label, + const char *account_url, + const struct + TALER_BANK_AuthenticationData *auth, + const char *start_row_reference, + long long num_results); + + +/** + * Make a debit "history" CMD. + * + * @param label command label. + * @param account_url base URL of the account offering the "history" + * operation. + * @param auth authentication data + * @param start_row_reference reference to a command that can + * offer a row identifier, to be used as the starting row + * to accept in the result. + * @param num_results how many rows we want in the result. + * @return the command. + */ +struct TALER_TESTING_Command +TALER_TESTING_cmd_bank_debits (const char *label, + const char *account_url, + const struct TALER_BANK_AuthenticationData *auth, + const char *start_row_reference, + long long num_results); + + +/** + * Create transfer command. + * + * @param label command label. + * @param amount amount to transfer. + * @param account_base_url base URL of the account that implements this + * wire transer (which account gives money). + * @param auth authentication data to use + * @param payto_credit_account which account receives money. + * @param wtid wire transfer identifier to use + * @param exchange_base_url exchange URL to use + * @return the command. + */ +struct TALER_TESTING_Command +TALER_TESTING_cmd_transfer (const char *label, + const char *amount, + const char *account_base_url, + const struct TALER_BANK_AuthenticationData *auth, + const char *payto_credit_account, + const struct TALER_WireTransferIdentifierRawP *wtid, + const char *exchange_base_url); + + +/* ***** Commands ONLY for testing (/admin-API) **** */ + +/** + * Create /admin/add-incoming command. + * + * @param label command label. + * @param amount amount to transfer. + * @param exchange_base_url base URL of the exchange account that receives this + * wire transer (which account receives money). + * @param payto_debit_account which account sends money. + * @param auth authentication data + * @return the command. + */ +struct TALER_TESTING_Command +TALER_TESTING_cmd_admin_add_incoming (const char *label, + const char *amount, + const char *exchange_base_url, + const struct + TALER_BANK_AuthenticationData *auth, + const char *payto_debit_account); + + +/** + * Create "fakebank transfer" CMD, letting the caller specify + * a reference to a command that can offer a reserve private key. + * This private key will then be used to construct the subject line + * of the wire transfer. + * + * @param label command label. + * @param amount the amount to transfer. + * @param account_base_url base URL of the account that implements this + * wire transer (which account receives money). + * @param payto_debit_account which account sends money. + * @param auth authentication data + * @param ref reference to a command that can offer a reserve + * private key. + * @return the command. + */ +struct TALER_TESTING_Command +TALER_TESTING_cmd_admin_add_incoming_with_ref (const char *label, + const char *amount, + const char *account_base_url, + const struct + TALER_BANK_AuthenticationData * + auth, + const char *payto_debit_account, + const char *ref); + + +/** + * Create "fakebank transfer" CMD, letting the caller specifying + * the merchant instance. This version is useful when a tip + * reserve should be topped up, in fact the interpreter will need + * the "tipping instance" in order to get the instance public key + * and make a wire transfer subject out of it. + * + * @param label command label. + * @param amount amount to transfer. + * @param account_base_url base URL of the account that implements this + * wire transer (which account receives money). + * @param payto_debit_account which account sends money. + * @param auth authentication data + * @param instance the instance that runs the tipping. Under this + * instance, the configuration file will provide the private + * key of the tipping reserve. This data will then used to + * construct the wire transfer subject line. + * @param config_filename configuration file to use. + * @return the command. + */ +struct TALER_TESTING_Command +TALER_TESTING_cmd_admin_add_incoming_with_instance (const char *label, + const char *amount, + const char *account_base_url, + const struct + TALER_BANK_AuthenticationData + *auth, + const char * + payto_debit_account, + const char *instance, + const char *config_filename); + + +/** + * Modify a fakebank transfer command to enable retries when the + * reserve is not yet full or we get other transient errors from + * the fakebank. + * + * @param cmd a fakebank transfer command + * @return the command with retries enabled + */ +struct TALER_TESTING_Command +TALER_TESTING_cmd_admin_add_incoming_retry (struct TALER_TESTING_Command cmd); + + /** * Make a "wirewatch" CMD. * @@ -893,7 +1182,7 @@ TALER_TESTING_cmd_status (const char *label, * coins, this parameter selects which one in that array. * This value is currently ignored, as only one-coin * withdrawals are implemented. - * @param wire_details wire details associated with the "deposit" + * @param target_account_payto target account for the "deposit" * request. * @param contract_terms contract terms to be signed over by the * coin. @@ -907,7 +1196,7 @@ struct TALER_TESTING_Command TALER_TESTING_cmd_deposit (const char *label, const char *coin_reference, unsigned int coin_index, - json_t *wire_details, + const char *target_account_payto, const char *contract_terms, struct GNUNET_TIME_Relative refund_deadline, const char *amount, diff --git a/src/lib/test_auditor_api.c b/src/lib/test_auditor_api.c index 53a48a2aa..eb3813492 100644 --- a/src/lib/test_auditor_api.c +++ b/src/lib/test_auditor_api.c @@ -33,7 +33,6 @@ #include #include "taler_bank_service.h" #include "taler_fakebank_lib.h" -#include "taler_testing_bank_lib.h" #include "taler_testing_lib.h" #include "taler_testing_auditor_lib.h" @@ -47,55 +46,14 @@ "test_auditor_api_expire_reserve_now.conf" /** - * URL of the fakebank. Obtained from CONFIG_FILE's - * "exchange-wire-test:BANK_URI" option. + * Exchange configuration data. */ -static char *fakebank_url; +static struct TALER_TESTING_ExchangeConfiguration ec; /** - * Auditor base URL as it appears in the configuration. Note - * that it might differ from the one where the exchange actually - * listens from. + * Bank configuration data. */ -static char *auditor_url; - -/** - * Exchange base URL as it appears in the configuration. Note - * that it might differ from the one where the exchange actually - * listens from. - */ -static char *exchange_url; - -/** - * URL of the exchange's account at the bank. Obtained from CONFIG_FILE's - * "exchange-wire-test:BANK_URI" option plus the exchange account. - */ -static char *exchange_account_url; // FIXME: initialize! - -/** - * Account number of the exchange at the bank. - */ -#define EXCHANGE_ACCOUNT_NO "2" // FIXME: used? - -/** - * Payto URL of the user's account. - */ -static char *user_account_payto; // FIXME: initialize! - -/** - * Payto URL of the user's account. - */ -static char *user2_account_payto; // FIXME: initialize! (43!) - -/** - * Payto URL of the exchange's account. - */ -static char *exchange_account_payto; // FIXME: initialize! - -/** - * Credentials for talking to the bank. - */ -static struct TALER_BANK_AuthenticationData auth; // FIXME: initialize! +static struct TALER_TESTING_BankConfiguration bc; /** * Execute the taler-exchange-wirewatch command with @@ -123,10 +81,10 @@ static struct TALER_BANK_AuthenticationData auth; // FIXME: initialize! * @param amount amount to transfer, i.e. "EUR:1" */ #define CMD_TRANSFER_TO_EXCHANGE(label,amount) \ - TALER_TESTING_cmd_admin_add_incoming (label, amount, \ - exchange_account_url, \ - &auth, \ - user_account_payto) + TALER_TESTING_cmd_admin_add_incoming (label, amount, \ + bc.exchange_account_url, \ + &bc.exchange_auth, \ + bc.user42_payto) /** * Run the taler-auditor. @@ -186,8 +144,7 @@ run (void *cls, TALER_TESTING_cmd_deposit ("deposit-simple", "withdraw-coin-1", 0, - TALER_TESTING_make_wire_details (42, - fakebank_url), + bc.user42_payto, "{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}", GNUNET_TIME_UNIT_ZERO, "EUR:5", @@ -221,8 +178,7 @@ run (void *cls, TALER_TESTING_cmd_deposit ("refresh-deposit-partial", "refresh-withdraw-coin-1", 0, - TALER_TESTING_make_wire_details (42, - fakebank_url), + bc.user42_payto, "{\"items\":[{\"name\":\"ice\",\"value\":\"EUR:1\"}]}", GNUNET_TIME_UNIT_ZERO, "EUR:1", @@ -246,8 +202,7 @@ run (void *cls, TALER_TESTING_cmd_deposit ("refresh-deposit-refreshed-1b", "refresh-reveal-1", 3, - TALER_TESTING_make_wire_details (43, - fakebank_url), + bc.user43_payto, "{\"items\":[{\"name\":\"ice cream\",\"value\":3}]}", GNUNET_TIME_UNIT_ZERO, "EUR:0.1", @@ -268,78 +223,78 @@ run (void *cls, * Check all the transfers took place. */ TALER_TESTING_cmd_check_bank_transfer - ("check_bank_transfer-499c", exchange_url, - "EUR:4.98", exchange_account_payto, user_account_payto), + ("check_bank_transfer-499c", ec.exchange_url, + "EUR:4.98", bc.exchange_payto, bc.user42_payto), TALER_TESTING_cmd_check_bank_transfer - ("check_bank_transfer-99c1", exchange_url, - "EUR:0.98", exchange_account_payto, user_account_payto), + ("check_bank_transfer-99c1", ec.exchange_url, + "EUR:0.98", bc.exchange_payto, bc.user42_payto), TALER_TESTING_cmd_check_bank_transfer - ("check_bank_transfer-99c", exchange_url, - "EUR:0.08", exchange_account_payto, user2_account_payto), + ("check_bank_transfer-99c", ec.exchange_url, + "EUR:0.08", bc.exchange_payto, bc.user43_payto), TALER_TESTING_cmd_check_bank_transfer - ("check_bank_transfer-aai-1", exchange_url, - "EUR:5.01", user_account_payto, exchange_account_payto), + ("check_bank_transfer-aai-1", ec.exchange_url, + "EUR:5.01", bc.user42_payto, bc.exchange_payto), TALER_TESTING_cmd_check_bank_transfer - ("check_bank_transfer-aai-2", exchange_url, - "EUR:5.01", user_account_payto, exchange_account_payto), + ("check_bank_transfer-aai-2", ec.exchange_url, + "EUR:5.01", bc.user42_payto, bc.exchange_payto), /* The following transactions got originated within * the "massive deposit confirms" batch. */ TALER_TESTING_cmd_check_bank_transfer ("check-massive-transfer", - exchange_url, + ec.exchange_url, "EUR:10.10", - user_account_payto, exchange_account_payto), + bc.user42_payto, bc.exchange_payto), TALER_TESTING_cmd_check_bank_transfer ("check-massive-transfer-1", - exchange_url, + ec.exchange_url, "EUR:0.98", - exchange_account_payto, user2_account_payto), + bc.exchange_payto, bc.user43_payto), TALER_TESTING_cmd_check_bank_transfer ("check-massive-transfer-2", - exchange_url, + ec.exchange_url, "EUR:0.98", - exchange_account_payto, user2_account_payto), + bc.exchange_payto, bc.user43_payto), TALER_TESTING_cmd_check_bank_transfer ("check-massive-transfer-3", - exchange_url, + ec.exchange_url, "EUR:0.98", - exchange_account_payto, user2_account_payto), + bc.exchange_payto, bc.user43_payto), TALER_TESTING_cmd_check_bank_transfer ("check-massive-transfer-4", - exchange_url, + ec.exchange_url, "EUR:0.98", - exchange_account_payto, user2_account_payto), + bc.exchange_payto, bc.user43_payto), TALER_TESTING_cmd_check_bank_transfer ("check-massive-transfer-5", - exchange_url, + ec.exchange_url, "EUR:0.98", - exchange_account_payto, user2_account_payto), + bc.exchange_payto, bc.user43_payto), TALER_TESTING_cmd_check_bank_transfer ("check-massive-transfer-6", - exchange_url, + ec.exchange_url, "EUR:0.98", - exchange_account_payto, user2_account_payto), + bc.exchange_payto, bc.user43_payto), TALER_TESTING_cmd_check_bank_transfer ("check-massive-transfer-7", - exchange_url, + ec.exchange_url, "EUR:0.98", - exchange_account_payto, user2_account_payto), + bc.exchange_payto, bc.user43_payto), TALER_TESTING_cmd_check_bank_transfer ("check-massive-transfer-8", - exchange_url, + ec.exchange_url, "EUR:0.98", - exchange_account_payto, user2_account_payto), + bc.exchange_payto, bc.user43_payto), TALER_TESTING_cmd_check_bank_transfer ("check-massive-transfer-9", - exchange_url, + ec.exchange_url, "EUR:0.98", - exchange_account_payto, user2_account_payto), + bc.exchange_payto, bc.user43_payto), TALER_TESTING_cmd_check_bank_transfer ("check-massive-transfer-10", - exchange_url, + ec.exchange_url, "EUR:0.98", - exchange_account_payto, user2_account_payto), + bc.exchange_payto, bc.user43_payto), TALER_TESTING_cmd_check_bank_empty ("check_bank_empty"), TALER_TESTING_cmd_end () }; @@ -355,10 +310,10 @@ run (void *cls, CMD_EXEC_WIREWATCH ("wirewatch-unaggregated"), /* "consume" reserve creation transfer. */ TALER_TESTING_cmd_check_bank_transfer ("check_bank_transfer-unaggregated", - exchange_url, + ec.exchange_url, "EUR:5.01", - user_account_payto, - exchange_account_payto), + bc.user42_payto, + bc.exchange_payto), TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-unaggregated", "create-reserve-unaggregated", "EUR:5", @@ -366,9 +321,7 @@ run (void *cls, TALER_TESTING_cmd_deposit ("deposit-unaggregated", "withdraw-coin-unaggregated", 0, - TALER_TESTING_make_wire_details - (43, - fakebank_url), + bc.user43_payto, "{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}", GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_YEARS, @@ -404,8 +357,7 @@ run (void *cls, TALER_TESTING_cmd_deposit ("deposit-refund-1", "withdraw-coin-r1", 0, - TALER_TESTING_make_wire_details (42, - fakebank_url), + bc.user42_payto, "{\"items\":[{\"name\":\"ice\",\"value\":\"EUR:5\"}]}", GNUNET_TIME_UNIT_MINUTES, "EUR:5", @@ -423,8 +375,7 @@ run (void *cls, TALER_TESTING_cmd_deposit ("deposit-refund-2", "withdraw-coin-r1", 0, - TALER_TESTING_make_wire_details (42, - fakebank_url), + bc.user42_payto, "{\"items\":[{\"name\":\"more\",\"value\":\"EUR:5\"}]}", GNUNET_TIME_UNIT_ZERO, "EUR:4.99", @@ -510,8 +461,7 @@ run (void *cls, TALER_TESTING_cmd_deposit ("payback-deposit-partial", "payback-withdraw-coin-2a", 0, - TALER_TESTING_make_wire_details (42, - fakebank_url), + bc.user42_payto, "{\"items\":[{\"name\":\"more ice cream\",\"value\":1}]}", GNUNET_TIME_UNIT_ZERO, "EUR:0.5", @@ -581,9 +531,7 @@ run (void *cls, ("massive-deposit-1", "massive-withdraw-1", 0, - TALER_TESTING_make_wire_details - (43, - fakebank_url), + bc.user43_payto, "{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}", GNUNET_TIME_UNIT_ZERO, "EUR:1", @@ -592,9 +540,7 @@ run (void *cls, ("massive-deposit-2", "massive-withdraw-2", 0, - TALER_TESTING_make_wire_details - (43, - fakebank_url), + bc.user43_payto, "{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}", GNUNET_TIME_UNIT_ZERO, "EUR:1", @@ -603,9 +549,7 @@ run (void *cls, ("massive-deposit-3", "massive-withdraw-3", 0, - TALER_TESTING_make_wire_details - (43, - fakebank_url), + bc.user43_payto, "{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}", GNUNET_TIME_UNIT_ZERO, "EUR:1", @@ -614,9 +558,7 @@ run (void *cls, ("massive-deposit-4", "massive-withdraw-4", 0, - TALER_TESTING_make_wire_details - (43, - fakebank_url), + bc.user43_payto, "{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}", GNUNET_TIME_UNIT_ZERO, "EUR:1", @@ -625,9 +567,7 @@ run (void *cls, ("massive-deposit-5", "massive-withdraw-5", 0, - TALER_TESTING_make_wire_details - (43, - fakebank_url), + bc.user43_payto, "{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}", GNUNET_TIME_UNIT_ZERO, "EUR:1", @@ -636,9 +576,7 @@ run (void *cls, ("massive-deposit-6", "massive-withdraw-6", 0, - TALER_TESTING_make_wire_details - (43, - fakebank_url), + bc.user43_payto, "{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}", GNUNET_TIME_UNIT_ZERO, "EUR:1", @@ -647,9 +585,7 @@ run (void *cls, ("massive-deposit-7", "massive-withdraw-7", 0, - TALER_TESTING_make_wire_details - (43, - fakebank_url), + bc.user43_payto, "{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}", GNUNET_TIME_UNIT_ZERO, "EUR:1", @@ -658,9 +594,7 @@ run (void *cls, ("massive-deposit-8", "massive-withdraw-8", 0, - TALER_TESTING_make_wire_details - (43, - fakebank_url), + bc.user43_payto, "{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}", GNUNET_TIME_UNIT_ZERO, "EUR:1", @@ -669,9 +603,7 @@ run (void *cls, ("massive-deposit-9", "massive-withdraw-9", 0, - TALER_TESTING_make_wire_details - (43, - fakebank_url), + bc.user43_payto, "{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}", GNUNET_TIME_UNIT_ZERO, "EUR:1", @@ -680,9 +612,7 @@ run (void *cls, ("massive-deposit-10", "massive-withdraw-10", 0, - TALER_TESTING_make_wire_details - (43, - fakebank_url), + bc.user43_payto, "{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}", GNUNET_TIME_UNIT_ZERO, "EUR:1", @@ -727,7 +657,7 @@ run (void *cls, TALER_TESTING_run_with_fakebank (is, commands, - fakebank_url); + bc.bank_url); } @@ -741,19 +671,18 @@ main (int argc, GNUNET_log_setup ("test-auditor-api", "INFO", NULL); - if (NULL == (fakebank_url - /* Check fakebank port is available and config cares - * about bank url. */ - = TALER_TESTING_prepare_fakebank (CONFIG_FILE, - "account-2"))) + /* Check fakebank port is available and get configuration data. */ + if (GNUNET_OK != + TALER_TESTING_prepare_fakebank (CONFIG_FILE, + "account-2", + &bc)) return 77; TALER_TESTING_cleanup_files (CONFIG_FILE); /* @helpers. Run keyup, create tables, ... Note: it * fetches the port number from config in order to see * if it's available. */ switch (TALER_TESTING_prepare_exchange (CONFIG_FILE, - &auditor_url, - &exchange_url)) + &ec)) { case GNUNET_SYSERR: GNUNET_break (0); diff --git a/src/lib/test_bank_api.c b/src/lib/test_bank_api.c index bb62aead8..9e7236591 100644 --- a/src/lib/test_bank_api.c +++ b/src/lib/test_bank_api.c @@ -32,36 +32,20 @@ #include #include #include "taler_testing_lib.h" -#include "taler_testing_bank_lib.h" - +// FIXME: rename config file to make it clear it is associated with a test! #define CONFIG_FILE "bank.conf" /** - * Fakebank URL. - */ -static char *bank_url; - -/** - * Account URL. - */ -static char *account_url; - -/** - * payto://-URL of another account. + * Bank configuration data. */ -static char *payto_url; +static struct TALER_TESTING_BankConfiguration bc; /** * Handle to the Py-bank daemon. */ static struct GNUNET_OS_Process *bankd; -/** - * Authentication data to use. - */ -static struct TALER_BANK_AuthenticationData auth; - /** * Flag indicating whether the test is running against the * Fakebank. Set up at runtime. @@ -81,40 +65,40 @@ run (void *cls, struct TALER_WireTransferIdentifierRawP wtid; struct TALER_TESTING_Command commands[] = { TALER_TESTING_cmd_bank_credits ("history-0", - account_url, - &auth, + bc.exchange_account_url, + &bc.exchange_auth, NULL, 1), TALER_TESTING_cmd_admin_add_incoming ("debit-1", "KUDOS:5.01", - account_url, - &auth, - payto_url), + bc.exchange_account_url, + &bc.exchange_auth, + bc.user42_payto), TALER_TESTING_cmd_bank_credits ("history-1c", - account_url, - &auth, + bc.exchange_account_url, + &bc.exchange_auth, NULL, 5), TALER_TESTING_cmd_bank_debits ("history-1d", - account_url, - &auth, + bc.exchange_account_url, + &bc.exchange_auth, NULL, 5), TALER_TESTING_cmd_admin_add_incoming ("debit-2", "KUDOS:3.21", - account_url, - &auth, - payto_url), + bc.exchange_account_url, + &bc.exchange_auth, + bc.user42_payto), TALER_TESTING_cmd_transfer ("credit-2", "KUDOS:3.22", - account_url, - &auth, - payto_url, + bc.exchange_account_url, + &bc.exchange_auth, + bc.user42_payto, &wtid, "http://exchange.example.com/"), TALER_TESTING_cmd_bank_debits ("history-2b", - account_url, - &auth, + bc.exchange_account_url, + &bc.exchange_auth, NULL, 5), TALER_TESTING_cmd_end () @@ -123,20 +107,11 @@ run (void *cls, memset (&wtid, 42, sizeof (wtid)); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Bank serves at `%s'\n", - bank_url); - GNUNET_asprintf (&account_url, - "%s/%s", - bank_url, - "alice"); - GNUNET_asprintf (&payto_url, - "payto://x-taler-bank/%s/%s", - bank_url, - "bob"); - // FIXME: init 'auth'! + bc.bank_url); if (GNUNET_YES == with_fakebank) TALER_TESTING_run_with_fakebank (is, commands, - bank_url); + bc.bank_url); else TALER_TESTING_run (is, commands); @@ -155,14 +130,15 @@ main (int argc, GNUNET_log_setup ("test-bank-api", "DEBUG", NULL); - with_fakebank = TALER_TESTING_has_in_name (argv[0], "_with_fakebank"); if (GNUNET_YES == with_fakebank) { TALER_LOG_DEBUG ("Running against the Fakebank.\n"); - if (NULL == (bank_url = TALER_TESTING_prepare_fakebank (CONFIG_FILE, - "account-1"))) + if (GNUNET_OK != + TALER_TESTING_prepare_fakebank (CONFIG_FILE, + "account-1", + &bc)) { GNUNET_break (0); return 77; @@ -171,14 +147,16 @@ main (int argc, else { TALER_LOG_DEBUG ("Running against the Pybank.\n"); - if (NULL == (bank_url = TALER_TESTING_prepare_bank (CONFIG_FILE))) + if (GNUNET_OK != + TALER_TESTING_prepare_bank (CONFIG_FILE, + &bc)) { GNUNET_break (0); return 77; } if (NULL == (bankd = TALER_TESTING_run_bank (CONFIG_FILE, - bank_url))) + bc.bank_url))) { GNUNET_break (0); return 77; @@ -197,9 +175,7 @@ main (int argc, SIGKILL); GNUNET_OS_process_wait (bankd); GNUNET_OS_process_destroy (bankd); - GNUNET_free (bank_url); } - return rv; } diff --git a/src/lib/test_bank_api_twisted.c b/src/lib/test_bank_api_twisted.c index ad8fd71d4..632bf1cbd 100644 --- a/src/lib/test_bank_api_twisted.c +++ b/src/lib/test_bank_api_twisted.c @@ -33,7 +33,6 @@ #include "taler_fakebank_lib.h" #include "taler_testing_lib.h" #include -#include "taler_testing_bank_lib.h" #include /** @@ -47,6 +46,11 @@ */ static int with_fakebank; +/** + * Bank configuration data. + */ +static struct TALER_TESTING_BankConfiguration bc; + /** * (real) Twister URL. Used at startup time to check if it runs. */ @@ -63,11 +67,6 @@ static char *twisted_account_url; */ static struct TALER_BANK_AuthenticationData auth; -/** - * URL of the bank. - */ -static char *bank_url; - /** * Twister process. */ @@ -112,7 +111,7 @@ run (void *cls, if (GNUNET_YES == with_fakebank) TALER_TESTING_run_with_fakebank (is, commands, - bank_url); + bc.bank_url); else TALER_TESTING_run (is, commands); @@ -164,9 +163,10 @@ main (int argc, if (GNUNET_YES == with_fakebank) { TALER_LOG_DEBUG ("Running against the Fakebank.\n"); - if (NULL == (bank_url = TALER_TESTING_prepare_fakebank - (CONFIG_FILE, - "account-1"))) + if (GNUNET_OK != + TALER_TESTING_prepare_fakebank (CONFIG_FILE, + "account-1", + &bc)) { GNUNET_break (0); GNUNET_free (twister_url); @@ -176,8 +176,9 @@ main (int argc, else { TALER_LOG_DEBUG ("Running against the Pybank.\n"); - if (NULL == (bank_url = TALER_TESTING_prepare_bank - (CONFIG_FILE))) + if (GNUNET_OK != + TALER_TESTING_prepare_bank (CONFIG_FILE, + &bc)) { GNUNET_break (0); GNUNET_free (twister_url); @@ -185,11 +186,10 @@ main (int argc, } if (NULL == (bankd = TALER_TESTING_run_bank (CONFIG_FILE, - bank_url))) + bc.bank_url))) { GNUNET_break (0); GNUNET_free (twister_url); - GNUNET_free (bank_url); return 77; } } @@ -210,8 +210,6 @@ main (int argc, } GNUNET_free (twister_url); - GNUNET_free (bank_url); - if (GNUNET_OK == ret) return 0; diff --git a/src/lib/test_exchange_api.c b/src/lib/test_exchange_api.c index 4f9034141..81e54a981 100644 --- a/src/lib/test_exchange_api.c +++ b/src/lib/test_exchange_api.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2014--2019 Taler Systems SA + Copyright (C) 2014--2020 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 @@ -16,15 +16,13 @@ License along with TALER; see the file COPYING. If not, see */ - /** - * @file exchange/test_exchange_api.c + * @file lib/test_exchange_api.c * @brief testcase to test exchange's HTTP API interface * @author Sree Harsha Totakura * @author Christian Grothoff * @author Marcello Stanisci */ - #include "platform.h" #include "taler_util.h" #include "taler_signatures.h" @@ -35,7 +33,6 @@ #include "taler_bank_service.h" #include "taler_fakebank_lib.h" #include "taler_testing_lib.h" -#include "taler_testing_bank_lib.h" /** * Configuration file we use. One (big) configuration is used @@ -46,56 +43,16 @@ #define CONFIG_FILE_EXPIRE_RESERVE_NOW \ "test_exchange_api_expire_reserve_now.conf" -/** - * URL of the fakebank. Obtained from CONFIG_FILE's - * "exchange-wire-test:BANK_URI" option. - */ -static char *fakebank_url; - -/** - * Exchange base URL as it appears in the configuration. Note - * that it might differ from the one where the exchange actually - * listens from. - */ -static char *exchange_url; - -/** - * Auditor base URL as it appears in the configuration. Note - * that it might differ from the one where the auditor actually - * listens from. - */ -static char *auditor_url; - -/** - * URL of the exchange's account at the bank. Obtained from CONFIG_FILE's - * "exchange-wire-test:BANK_URI" option plus the exchange account. - */ -static char *exchange_account_url; // FIXME: initialize! - -/** - * Account number of the exchange at the bank. - */ -#define EXCHANGE_ACCOUNT_NO "2" // FIXME: used? - -/** - * Payto URL of the user's account. - */ -static char *user_account_payto; // FIXME: initialize! - -/** - * Payto URL of the user's account. - */ -static char *user2_account_payto; // FIXME: initialize! (43!) /** - * Payto URL of the exchange's account. + * Exchange configuration data. */ -static char *exchange_account_payto; // FIXME: initialize! +static struct TALER_TESTING_ExchangeConfiguration ec; /** - * Credentials for talking to the bank. + * Bank configuration data. */ -static struct TALER_BANK_AuthenticationData auth; // FIXME: initialize! +static struct TALER_TESTING_BankConfiguration bc; /** @@ -125,9 +82,9 @@ static struct TALER_BANK_AuthenticationData auth; // FIXME: initialize! */ #define CMD_TRANSFER_TO_EXCHANGE(label,amount) \ TALER_TESTING_cmd_admin_add_incoming (label, amount, \ - exchange_account_url, \ - &auth, \ - user_account_payto) + bc.exchange_account_url, \ + &bc.exchange_auth, \ + bc.user42_payto) /** * Main function that will tell the interpreter what commands to @@ -197,8 +154,7 @@ run (void *cls, */ TALER_TESTING_cmd_deposit ("deposit-simple", "withdraw-coin-1", 0, - TALER_TESTING_make_wire_details (42, - fakebank_url), + bc.user42_payto, "{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}", GNUNET_TIME_UNIT_ZERO, "EUR:5", MHD_HTTP_OK), @@ -215,8 +171,7 @@ run (void *cls, */ TALER_TESTING_cmd_deposit ("deposit-double-1", "withdraw-coin-1", 0, - TALER_TESTING_make_wire_details (43, - fakebank_url), + bc.user43_payto, "{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}", GNUNET_TIME_UNIT_ZERO, "EUR:5", MHD_HTTP_CONFLICT), @@ -230,8 +185,7 @@ run (void *cls, * how can a different id be generated? */TALER_TESTING_cmd_deposit ("deposit-double-1", "withdraw-coin-1", 0, - TALER_TESTING_make_wire_details (43, - fakebank_url), + bc.user43_payto, "{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}", GNUNET_TIME_UNIT_ZERO, "EUR:5", MHD_HTTP_CONFLICT), @@ -240,8 +194,7 @@ run (void *cls, */ TALER_TESTING_cmd_deposit ("deposit-double-2", "withdraw-coin-1", 0, - TALER_TESTING_make_wire_details (43, - fakebank_url), + bc.user43_payto, "{\"items\":[{\"name\":\"ice cream\",\"value\":2}]}", GNUNET_TIME_UNIT_ZERO, "EUR:5", MHD_HTTP_CONFLICT), @@ -279,8 +232,7 @@ run (void *cls, */TALER_TESTING_cmd_deposit ("refresh-deposit-partial", "refresh-withdraw-coin-1", 0, - TALER_TESTING_make_wire_details (42, - fakebank_url), + bc.user42_payto, "{\"items\":[{\"name\":\"ice cream\",\ \"value\":\"EUR:1\"}]}", GNUNET_TIME_UNIT_ZERO, "EUR:1", MHD_HTTP_OK), @@ -321,8 +273,7 @@ run (void *cls, TALER_TESTING_cmd_deposit ("refresh-deposit-refreshed-1a", "refresh-reveal-1-idempotency", 0, - TALER_TESTING_make_wire_details (42, - fakebank_url), + bc.user42_payto, "{\"items\":[{\"name\":\"ice cream\",\ \"value\":3}]}", GNUNET_TIME_UNIT_ZERO, "EUR:1", MHD_HTTP_OK), @@ -333,8 +284,7 @@ run (void *cls, TALER_TESTING_cmd_deposit ("refresh-deposit-refreshed-1b", "refresh-reveal-1", 3, - TALER_TESTING_make_wire_details (43, - fakebank_url), + bc.user43_payto, "{\"items\":[{\"name\":\"ice cream\",\ \"value\":3}]}", GNUNET_TIME_UNIT_ZERO, "EUR:0.1", MHD_HTTP_OK), @@ -390,32 +340,32 @@ run (void *cls, * Check all the transfers took place. */ TALER_TESTING_cmd_check_bank_transfer - ("check_bank_transfer-499c", exchange_url, - "EUR:4.98", exchange_account_payto, user_account_payto), + ("check_bank_transfer-499c", ec.exchange_url, + "EUR:4.98", bc.exchange_payto, bc.user42_payto), TALER_TESTING_cmd_check_bank_transfer - ("check_bank_transfer-99c1", exchange_url, - "EUR:0.98", exchange_account_payto, user_account_payto), + ("check_bank_transfer-99c1", ec.exchange_url, + "EUR:0.98", bc.exchange_payto, bc.user42_payto), TALER_TESTING_cmd_check_bank_transfer - ("check_bank_transfer-99c2", exchange_url, - "EUR:0.98", exchange_account_payto, user_account_payto), + ("check_bank_transfer-99c2", ec.exchange_url, + "EUR:0.98", bc.exchange_payto, bc.user42_payto), TALER_TESTING_cmd_check_bank_transfer - ("check_bank_transfer-99c", exchange_url, - "EUR:0.08", exchange_account_payto, user2_account_payto), + ("check_bank_transfer-99c", ec.exchange_url, + "EUR:0.08", bc.exchange_payto, bc.user43_payto), TALER_TESTING_cmd_check_bank_transfer - ("check_bank_transfer-aai-1", exchange_url, - "EUR:5.01", user_account_payto, exchange_account_payto), + ("check_bank_transfer-aai-1", ec.exchange_url, + "EUR:5.01", bc.user42_payto, bc.exchange_payto), /** * NOTE: the old test-suite had this "check bank transfer" * command with debit account == 424. */ TALER_TESTING_cmd_check_bank_transfer - ("check_bank_transfer-aai-2", exchange_url, - "EUR:5.01", user_account_payto, exchange_account_payto), + ("check_bank_transfer-aai-2", ec.exchange_url, + "EUR:5.01", bc.user42_payto, bc.exchange_payto), TALER_TESTING_cmd_check_bank_empty ("check_bank_empty"), @@ -454,9 +404,9 @@ run (void *cls, /* "consume" reserve creation transfer. */ TALER_TESTING_cmd_check_bank_transfer ("check_bank_transfer-unaggregated", - exchange_url, + ec.exchange_url, "EUR:5.01", - user_account_payto, exchange_account_payto), + bc.user42_payto, bc.exchange_payto), TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-unaggregated", @@ -468,9 +418,7 @@ run (void *cls, ("deposit-unaggregated", "withdraw-coin-unaggregated", 0, - TALER_TESTING_make_wire_details - (43, - fakebank_url), + bc.user43_payto, "{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}", GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_YEARS, @@ -513,8 +461,7 @@ run (void *cls, */ TALER_TESTING_cmd_deposit ("deposit-refund-1", "withdraw-coin-r1", 0, - TALER_TESTING_make_wire_details (42, - fakebank_url), + bc.user42_payto, "{\"items\":[{\"name\":\"ice cream\"," "\"value\":\"EUR:5\"}]}", GNUNET_TIME_UNIT_MINUTES, "EUR:5", MHD_HTTP_OK), @@ -533,8 +480,8 @@ run (void *cls, * fakebank and the second to actually check there are not * other transfers around. */TALER_TESTING_cmd_check_bank_transfer - ("check_bank_transfer-pre-refund", exchange_url, - "EUR:5.01", user_account_payto, exchange_account_payto), + ("check_bank_transfer-pre-refund", ec.exchange_url, + "EUR:5.01", bc.user42_payto, bc.exchange_payto), TALER_TESTING_cmd_check_bank_empty ("check_bank_transfer-pre-refund"), @@ -558,8 +505,7 @@ run (void *cls, * 1 ct deposit fee) */ TALER_TESTING_cmd_deposit ("deposit-refund-2", "withdraw-coin-r1", 0, - TALER_TESTING_make_wire_details (42, - fakebank_url), + bc.user42_payto, "{\"items\":[{\"name\":\"more ice cream\"," "\"value\":\"EUR:5\"}]}", GNUNET_TIME_UNIT_ZERO, "EUR:4.99", MHD_HTTP_OK), @@ -575,8 +521,8 @@ run (void *cls, * Check that deposit did run. */ TALER_TESTING_cmd_check_bank_transfer - ("check_bank_transfer-pre-refund", exchange_url, - "EUR:4.97", exchange_account_payto, user_account_payto), + ("check_bank_transfer-pre-refund", ec.exchange_url, + "EUR:4.97", bc.exchange_payto, bc.user42_payto), /** * Run failing refund, as past deadline & aggregation. @@ -603,14 +549,13 @@ run (void *cls, MHD_HTTP_OK), TALER_TESTING_cmd_check_bank_transfer - ("check_bank_transfer-aai-3b", exchange_url, - "EUR:5.01", user_account_payto, exchange_account_payto), + ("check_bank_transfer-aai-3b", ec.exchange_url, + "EUR:5.01", bc.user42_payto, bc.exchange_payto), TALER_TESTING_cmd_deposit ("deposit-refund-1b", "withdraw-coin-rb", 0, - TALER_TESTING_make_wire_details (42, - fakebank_url), + bc.user42_payto, "{\"items\":[{\"name\":\"ice cream\"," "\"value\":\"EUR:5\"}]}", GNUNET_TIME_UNIT_ZERO, "EUR:5", MHD_HTTP_OK), @@ -723,17 +668,17 @@ run (void *cls, TALER_TESTING_cmd_check_bank_transfer ("check_bank_short-lived_transfer", - exchange_url, + ec.exchange_url, "EUR:5.01", - user_account_payto, - exchange_account_payto), + bc.user42_payto, + bc.exchange_payto), TALER_TESTING_cmd_check_bank_transfer ("check_bank_short-lived_reimburse", - exchange_url, + ec.exchange_url, "EUR:5", - exchange_account_payto, - user_account_payto), + bc.exchange_payto, + bc.user42_payto), /** * Fill reserve with EUR:2.02, as withdraw fee is 1 ct per @@ -762,8 +707,7 @@ run (void *cls, TALER_TESTING_cmd_deposit ("payback-deposit-partial", "payback-withdraw-coin-2a", 0, - TALER_TESTING_make_wire_details (42, - fakebank_url), + bc.user42_payto, "{\"items\":[{\"name\":\"more ice cream\",\"value\":1}]}", GNUNET_TIME_UNIT_ZERO, "EUR:0.5", MHD_HTTP_OK), @@ -785,8 +729,7 @@ run (void *cls, TALER_TESTING_cmd_deposit ("payback-deposit-revoked", "payback-withdraw-coin-2b", 0, - TALER_TESTING_make_wire_details (42, - fakebank_url), + bc.user42_payto, "{\"items\":[{\"name\":\"more ice cream\",\"value\":1}]}", GNUNET_TIME_UNIT_ZERO, "EUR:1", MHD_HTTP_NOT_FOUND), @@ -800,9 +743,7 @@ run (void *cls, ("payback-deposit-partial-after-payback", "payback-withdraw-coin-2a", 0, - TALER_TESTING_make_wire_details - (42, - fakebank_url), + bc.user42_payto, "{\"items\":[{\"name\":\"extra ice cream\",\"value\":1}]}", GNUNET_TIME_UNIT_ZERO, "EUR:0.5", @@ -822,14 +763,14 @@ run (void *cls, /* check that we are empty before the rejection test */ TALER_TESTING_cmd_check_bank_transfer - ("check_bank_transfer-pr1", exchange_url, - "EUR:5.01", user_account_payto, exchange_account_payto), + ("check_bank_transfer-pr1", ec.exchange_url, + "EUR:5.01", bc.user42_payto, bc.exchange_payto), TALER_TESTING_cmd_check_bank_transfer - ("check_bank_transfer-pr2", exchange_url, - "EUR:2.02", user_account_payto, exchange_account_payto), + ("check_bank_transfer-pr2", ec.exchange_url, + "EUR:2.02", bc.user42_payto, bc.exchange_payto), TALER_TESTING_cmd_check_bank_transfer - ("check_bank_transfer-pr3", exchange_url, - "EUR:1.01", user_account_payto, exchange_account_payto), + ("check_bank_transfer-pr3", ec.exchange_url, + "EUR:1.01", bc.user42_payto, bc.exchange_payto), TALER_TESTING_cmd_check_bank_empty ("check-empty-again"), @@ -859,8 +800,7 @@ run (void *cls, */TALER_TESTING_cmd_deposit ("deposit-partial", "withdraw-coin-1", 0, - TALER_TESTING_make_wire_details (42, - fakebank_url), + bc.user42_payto, "{\"items\":[{\"name\":\"ice cream\",\ \"value\":\"EUR:1\"}]}", GNUNET_TIME_UNIT_ZERO, "EUR:1", MHD_HTTP_OK), @@ -1008,7 +948,7 @@ run (void *cls, TALER_TESTING_run_with_fakebank (is, commands, - fakebank_url); + bc.bank_url); } @@ -1022,19 +962,18 @@ main (int argc, GNUNET_log_setup ("test-exchange-api", "INFO", NULL); - if (NULL == (fakebank_url - /* Check fakebank port is available and config cares - * about bank url. */ - = TALER_TESTING_prepare_fakebank (CONFIG_FILE, - "account-2"))) + /* Check fakebank port is available and get config */ + if (GNUNET_OK != + TALER_TESTING_prepare_fakebank (CONFIG_FILE, + "account-2", + &bc)) return 77; TALER_TESTING_cleanup_files (CONFIG_FILE); /* @helpers. Run keyup, create tables, ... Note: it * fetches the port number from config in order to see * if it's available. */ switch (TALER_TESTING_prepare_exchange (CONFIG_FILE, - &auditor_url, - &exchange_url)) + &ec)) { case GNUNET_SYSERR: GNUNET_break (0); diff --git a/src/lib/test_exchange_api_keys_cherry_picking.c b/src/lib/test_exchange_api_keys_cherry_picking.c index 8805e7c56..12ee26e60 100644 --- a/src/lib/test_exchange_api_keys_cherry_picking.c +++ b/src/lib/test_exchange_api_keys_cherry_picking.c @@ -17,7 +17,7 @@ */ /** - * @file exchange-lib/test_exchange_api_keys_cherry_picking.c + * @file lib/test_exchange_api_keys_cherry_picking.c * @brief testcase to test exchange's /keys cherry picking ability * @author Marcello Stanisci * @author Christian Grothoff @@ -84,14 +84,9 @@ #define JAN2030 "2030-01-01" /** - * Exchange base URL; mainly purpose is to make the compiler happy. + * Exchange configuration data. */ -static char *exchange_url; - -/** - * Auditor base URL; mainly purpose is to make the compiler happy. - */ -static char *auditor_url; +static struct TALER_TESTING_ExchangeConfiguration ec; /** @@ -239,8 +234,7 @@ main (int argc, * fetches the port number from config in order to see * if it's available. */ switch (TALER_TESTING_prepare_exchange (CONFIG_FILE, - &auditor_url, - &exchange_url)) + &ec)) { case GNUNET_SYSERR: GNUNET_break (0); diff --git a/src/lib/test_exchange_api_overlapping_keys_bug.c b/src/lib/test_exchange_api_overlapping_keys_bug.c index a5ddac516..c6cd17cbd 100644 --- a/src/lib/test_exchange_api_overlapping_keys_bug.c +++ b/src/lib/test_exchange_api_overlapping_keys_bug.c @@ -55,14 +55,9 @@ "test_exchange_api_keys_cherry_picking_extended_2.conf" /** - * Exchange base URL; mainly purpose is to make the compiler happy. + * Exchange configuration data. */ -static char *exchange_url; - -/** - * Auditor base URL; mainly purpose is to make the compiler happy. - */ -static char *auditor_url; +static struct TALER_TESTING_ExchangeConfiguration ec; /** @@ -106,8 +101,7 @@ main (int argc, * fetches the port number from config in order to see * if it's available. */ switch (TALER_TESTING_prepare_exchange (CONFIG_FILE, - &auditor_url, - &exchange_url)) + &ec)) { case GNUNET_SYSERR: GNUNET_break (0); diff --git a/src/lib/test_exchange_api_twisted.c b/src/lib/test_exchange_api_twisted.c index d9faec4ad..d935ca8e0 100644 --- a/src/lib/test_exchange_api_twisted.c +++ b/src/lib/test_exchange_api_twisted.c @@ -33,7 +33,6 @@ #include "taler_bank_service.h" #include "taler_fakebank_lib.h" #include "taler_testing_lib.h" -#include "taler_testing_bank_lib.h" #include #include @@ -49,47 +48,20 @@ static char *twister_url; /** - * URL of the fakebank. Obtained from CONFIG_FILE's - * "exchange-wire-test:BANK_URI" option. + * Exchange configuration data. */ -static char *fakebank_url; +static struct TALER_TESTING_ExchangeConfiguration ec; /** - * Exchange base URL. + * Bank configuration data. */ -static char *exchange_url; - -/** - * Auditor URL, unused but needed to achieve compilation. - */ -static char *auditor_url; +static struct TALER_TESTING_BankConfiguration bc; /** * Twister process. */ static struct GNUNET_OS_Process *twisterd; -/** - * URL of the exchange's account at the bank. Obtained from CONFIG_FILE's - * "exchange-wire-test:BANK_URI" option plus the exchange account. - */ -static char *exchange_account_url; // FIXME: initialize! - -/** - * Account number of the exchange at the bank. - */ -#define EXCHANGE_ACCOUNT_NO "2" // FIXME: used? - -/** - * Payto URL of the user's account. - */ -static char *user_account_payto; // FIXME: initialize! - -/** - * Credentials for talking to the bank. - */ -static struct TALER_BANK_AuthenticationData auth; // FIXME: initialize! - /** * Execute the taler-exchange-wirewatch command with @@ -119,9 +91,9 @@ static struct TALER_BANK_AuthenticationData auth; // FIXME: initialize! */ #define CMD_TRANSFER_TO_EXCHANGE(label,amount) \ TALER_TESTING_cmd_admin_add_incoming (label, amount, \ - exchange_account_url, \ - &auth, \ - user_account_payto) + bc.exchange_account_url, \ + &bc.exchange_auth, \ + bc.user42_payto) /** @@ -160,9 +132,7 @@ run (void *cls, ("refresh-deposit-partial", "refresh-withdraw-coin", 0, - TALER_TESTING_make_wire_details - (42, - fakebank_url), + bc.user42_payto, "{\"items\":[{\"name\":\"ice cream\",\ \"value\":\"EUR:1\"}]}", GNUNET_TIME_UNIT_ZERO, @@ -212,9 +182,7 @@ run (void *cls, ("deposit-refund-1", "withdraw-coin-r1", 0, - TALER_TESTING_make_wire_details - (42, - fakebank_url), + bc.user42_payto, "{\"items\":[{\"name\":\"ice cream\"," "\"value\":\"EUR:5\"}]}", GNUNET_TIME_UNIT_MINUTES, @@ -251,9 +219,7 @@ run (void *cls, ("deposit-refund-to-fail", "withdraw-coin-r1", 0, /* coin index. */ - TALER_TESTING_make_wire_details - (42, - fakebank_url), + bc.user42_payto, /* This parameter will make any comparison about h_contract_terms fail, when /refund will be handled. So in other words, this is h_contract missmatch. */ @@ -293,7 +259,7 @@ run (void *cls, TALER_TESTING_run_with_fakebank (is, commands, - fakebank_url); + bc.bank_url); } @@ -322,9 +288,10 @@ main (int argc, GNUNET_log_setup ("test-exchange-api-twisted", "DEBUG", NULL); - if (NULL == (fakebank_url = TALER_TESTING_prepare_fakebank - (CONFIG_FILE, - "account-2"))) + if (GNUNET_OK != + TALER_TESTING_prepare_fakebank (CONFIG_FILE, + "account-2", + &bc)) return 77; if (NULL == (twister_url = TALER_TESTING_prepare_twister @@ -334,8 +301,7 @@ main (int argc, TALER_TESTING_cleanup_files (CONFIG_FILE); switch (TALER_TESTING_prepare_exchange (CONFIG_FILE, - &auditor_url, - &exchange_url)) + &ec)) { case GNUNET_SYSERR: GNUNET_break (0); @@ -345,8 +311,7 @@ main (int argc, case GNUNET_OK: - if (NULL == (twisterd = TALER_TESTING_run_twister - (CONFIG_FILE))) + if (NULL == (twisterd = TALER_TESTING_run_twister (CONFIG_FILE))) return 77; ret = TALER_TESTING_setup_with_exchange (&run, diff --git a/src/lib/testing_api_cmd_bank_admin_add_incoming.c b/src/lib/testing_api_cmd_bank_admin_add_incoming.c index 770b2e384..690b78437 100644 --- a/src/lib/testing_api_cmd_bank_admin_add_incoming.c +++ b/src/lib/testing_api_cmd_bank_admin_add_incoming.c @@ -30,7 +30,6 @@ #include "taler_fakebank_lib.h" #include "taler_signatures.h" #include "taler_testing_lib.h" -#include "taler_testing_bank_lib.h" /** diff --git a/src/lib/testing_api_cmd_bank_history_credit.c b/src/lib/testing_api_cmd_bank_history_credit.c index fefb2dda7..92a28c22f 100644 --- a/src/lib/testing_api_cmd_bank_history_credit.c +++ b/src/lib/testing_api_cmd_bank_history_credit.c @@ -26,7 +26,6 @@ #include #include "taler_exchange_service.h" #include "taler_testing_lib.h" -#include "taler_testing_bank_lib.h" #include "taler_fakebank_lib.h" #include "taler_bank_service.h" #include "taler_fakebank_lib.h" diff --git a/src/lib/testing_api_cmd_bank_history_debit.c b/src/lib/testing_api_cmd_bank_history_debit.c index 96f989c04..0b0cc40e1 100644 --- a/src/lib/testing_api_cmd_bank_history_debit.c +++ b/src/lib/testing_api_cmd_bank_history_debit.c @@ -16,19 +16,16 @@ License along with TALER; see the file COPYING. If not, see */ - /** * @file bank-lib/testing_api_cmd_history.c * @brief command to check the /history API from the bank. * @author Marcello Stanisci */ - #include "platform.h" #include "taler_json_lib.h" #include #include "taler_exchange_service.h" #include "taler_testing_lib.h" -#include "taler_testing_bank_lib.h" #include "taler_fakebank_lib.h" #include "taler_bank_service.h" #include "taler_fakebank_lib.h" diff --git a/src/lib/testing_api_cmd_bank_transfer.c b/src/lib/testing_api_cmd_bank_transfer.c index d5a3872ed..575c09c56 100644 --- a/src/lib/testing_api_cmd_bank_transfer.c +++ b/src/lib/testing_api_cmd_bank_transfer.c @@ -30,7 +30,6 @@ #include "taler_fakebank_lib.h" #include "taler_signatures.h" #include "taler_testing_lib.h" -#include "taler_testing_bank_lib.h" /** diff --git a/src/lib/testing_api_cmd_deposit.c b/src/lib/testing_api_cmd_deposit.c index c1c07a016..7c7e4936e 100644 --- a/src/lib/testing_api_cmd_deposit.c +++ b/src/lib/testing_api_cmd_deposit.c @@ -480,7 +480,7 @@ deposit_traits (void *cls, * coins, this parameter selects which one in that array. * This value is currently ignored, as only one-coin * withdrawals are implemented. - * @param wire_details wire details associated with the "deposit" + * @param target_account_payto target account for the "deposit" * request. * @param contract_terms contract terms to be signed over by the * coin. @@ -497,14 +497,16 @@ TALER_TESTING_cmd_deposit (const char *label, const char *coin_reference, unsigned int coin_index, - json_t *wire_details, + const char *target_account_payto, const char *contract_terms, struct GNUNET_TIME_Relative refund_deadline, const char *amount, unsigned int expected_response_code) { struct DepositState *ds; + json_t *wire_details; + wire_details = TALER_TESTING_make_wire_details (target_account_payto); ds = GNUNET_new (struct DepositState); ds->coin_reference = coin_reference; ds->coin_index = coin_index; diff --git a/src/lib/testing_api_helpers_bank.c b/src/lib/testing_api_helpers_bank.c index 64976edbb..52227f7b7 100644 --- a/src/lib/testing_api_helpers_bank.c +++ b/src/lib/testing_api_helpers_bank.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2018 Taler Systems SA + Copyright (C) 2018-2020 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 @@ -16,16 +16,14 @@ License along with TALER; see the file COPYING. If not, see */ - /** * @file bank-lib/testing_api_helpers.c * @brief convenience functions for bank-lib tests. * @author Marcello Stanisci */ - #include "platform.h" #include -#include "taler_testing_bank_lib.h" +#include "taler_testing_lib.h" #include "taler_fakebank_lib.h" @@ -33,29 +31,6 @@ do {GNUNET_break (0); return NULL; } while (0) -/** - * Keep each bank account credentials at index: - * bank account number - 1 - */ -struct TALER_BANK_AuthenticationData AUTHS[] = { - - /* Bank credentials */ - {.method = TALER_BANK_AUTH_BASIC, - .details.basic.username = TALER_TESTING_BANK_USERNAME, - .details.basic.password = TALER_TESTING_BANK_PASSWORD}, - - /* Exchange credentials */ - {.method = TALER_BANK_AUTH_BASIC, - .details.basic.username = TALER_TESTING_EXCHANGE_USERNAME, - .details.basic.password = TALER_TESTING_EXCHANGE_PASSWORD }, - - /* User credentials */ - {.method = TALER_BANK_AUTH_BASIC, - .details.basic.username = TALER_TESTING_USER_USERNAME, - .details.basic.password = TALER_TESTING_USER_PASSWORD } -}; - - /** * Runs the Fakebank by guessing / extracting the portnumber * from the base URL. @@ -244,19 +219,19 @@ TALER_TESTING_run_bank (const char *config_filename, * and reset database. * * @param config_filename configuration file name. - * + * @param bc[out] set to the bank's configuration data * @return the base url, or NULL upon errors. Must be freed * by the caller. */ -char * -TALER_TESTING_prepare_bank (const char *config_filename) +int +TALER_TESTING_prepare_bank (const char *config_filename, + struct TALER_TESTING_BankConfiguration *bc) { struct GNUNET_CONFIGURATION_Handle *cfg; unsigned long long port; struct GNUNET_OS_Process *dbreset_proc; enum GNUNET_OS_ProcessStatusType type; unsigned long code; - char *base_url; char *database; cfg = GNUNET_CONFIGURATION_create (); @@ -265,7 +240,8 @@ TALER_TESTING_prepare_bank (const char *config_filename) GNUNET_CONFIGURATION_load (cfg, config_filename)) { GNUNET_CONFIGURATION_destroy (cfg); - BANK_FAIL (); + GNUNET_break (0); + return GNUNET_SYSERR; } if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, @@ -277,7 +253,8 @@ TALER_TESTING_prepare_bank (const char *config_filename) "bank", "DATABASE"); GNUNET_CONFIGURATION_destroy (cfg); - BANK_FAIL (); + GNUNET_break (0); + return GNUNET_SYSERR; } if (GNUNET_OK != @@ -291,17 +268,21 @@ TALER_TESTING_prepare_bank (const char *config_filename) "HTTP_PORT"); GNUNET_CONFIGURATION_destroy (cfg); GNUNET_free (database); - BANK_FAIL (); + GNUNET_break (0); + return GNUNET_SYSERR; } GNUNET_CONFIGURATION_destroy (cfg); - if (GNUNET_OK != GNUNET_NETWORK_test_port_free - (IPPROTO_TCP, (uint16_t) port)) + if (GNUNET_OK != + GNUNET_NETWORK_test_port_free (IPPROTO_TCP, + (uint16_t) port)) { fprintf (stderr, "Required port %llu not available, skipping.\n", port); - BANK_FAIL (); + GNUNET_break (0); + GNUNET_free (database); + return GNUNET_SYSERR; } /* DB preparation */ @@ -321,7 +302,7 @@ TALER_TESTING_prepare_bank (const char *config_filename) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to flush the bank db.\n"); GNUNET_free (database); - BANK_FAIL (); + return GNUNET_SYSERR; } GNUNET_free (database); @@ -331,31 +312,161 @@ TALER_TESTING_prepare_bank (const char *config_filename) &code)) { GNUNET_OS_process_destroy (dbreset_proc); - BANK_FAIL (); + GNUNET_break (0); + return GNUNET_SYSERR; } if ( (type == GNUNET_OS_PROCESS_EXITED) && (0 != code) ) { fprintf (stderr, "Failed to setup database\n"); - BANK_FAIL (); + GNUNET_break (0); + return GNUNET_SYSERR; } if ( (type != GNUNET_OS_PROCESS_EXITED) || (0 != code) ) { - fprintf (stderr, - "Unexpected error running" - " `taler-bank-manage django flush..'!\n"); - BANK_FAIL (); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Unexpected error running `taler-bank-manage django flush'!\n"); + GNUNET_break (0); + return GNUNET_SYSERR; } - GNUNET_OS_process_destroy (dbreset_proc); - GNUNET_asprintf (&base_url, + GNUNET_asprintf (&bc->bank_url, "http://localhost:%llu/", port); - return base_url; + // FIXME: initialize rest of 'bc': + bc->exchange_account_url = NULL; // FIXME + bc->exchange_auth; // FIXME + bc->exchange_payto = TALER_TESTING_make_xtalerbank_payto (bc->bank_url, "2"); + bc->user42_payto = TALER_TESTING_make_xtalerbank_payto (bc->bank_url, "42"); + bc->user43_payto = TALER_TESTING_make_xtalerbank_payto (bc->bank_url, "43"); + return GNUNET_OK; +} + + +/** + * Prepare launching a fakebank. Check that the configuration + * file has the right option, and that the port is available. + * If everything is OK, return the configuration data of the fakebank. + * + * @param config_filename configuration file to use + * @param config_section which account to use (must match x-taler-bank) + * @param bc[out] set to the bank's configuration data + * @return #GNUNET_OK on success + */ +int +TALER_TESTING_prepare_fakebank (const char *config_filename, + const char *config_section, + struct TALER_TESTING_BankConfiguration *bc) +{ + struct GNUNET_CONFIGURATION_Handle *cfg; + char *payto_url; + char *fakebank_url; + const char *start; + const char *end; + + cfg = GNUNET_CONFIGURATION_create (); + if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, + config_filename)) + return GNUNET_SYSERR; + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_string (cfg, + config_section, + "URL", + &payto_url)) + { + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, + config_section, + "URL"); + GNUNET_CONFIGURATION_destroy (cfg); + return GNUNET_SYSERR; + } + GNUNET_CONFIGURATION_destroy (cfg); + if (0 != strncasecmp (payto_url, + "payto://x-taler-bank/", + strlen ("payto://x-taler-bank/"))) + { + GNUNET_log_config_invalid + (GNUNET_ERROR_TYPE_WARNING, + config_section, + "URL", + "expected `x-taler-bank' payto://-URL"); + GNUNET_CONFIGURATION_destroy (cfg); + GNUNET_free (payto_url); + return GNUNET_SYSERR; + } + start = &payto_url [strlen ("payto://x-taler-bank/")]; + end = strchr (start, + (unsigned char) '/'); + if (NULL == end) + end = &start[strlen (start)]; + fakebank_url = GNUNET_strndup (start, + end - start); + GNUNET_free (payto_url); + if (GNUNET_OK != + TALER_TESTING_url_port_free (fakebank_url)) + { + GNUNET_free (fakebank_url); + return GNUNET_SYSERR; + } + bc->bank_url = fakebank_url; + // FIXME: initialize rest of 'bc': + bc->exchange_account_url = NULL; // FIXME + bc->exchange_auth; // FIXME + bc->exchange_payto = TALER_TESTING_make_xtalerbank_payto (bc->bank_url, "2"); + bc->user42_payto = TALER_TESTING_make_xtalerbank_payto (bc->bank_url, "42"); + bc->user43_payto = TALER_TESTING_make_xtalerbank_payto (bc->bank_url, "43"); + return GNUNET_OK; +} + + +/** + * Create an x-taler-bank payto:// URL from a @a bank_url + * and an @a account_name. + * + * @param bank_url the bank URL + * @param account_name the account name + * @return payto:// URL + */ +char * +TALER_TESTING_make_xtalerbank_payto (const char *bank_url, + const char *account_name) +{ + char *payto; + int ends_slash; + + if (0 < strlen (bank_url)) + ends_slash = '/' == bank_url[strlen (bank_url) - 1]; + else + ends_slash = 0; + GNUNET_asprintf (&payto, + (ends_slash) + ? "payto://x-taler-bank/%s%s" + : "payto://x-taler-bank/%s/%s", + bank_url, + account_name); + return payto; +} + + +/** + * Allocate and return a piece of wire-details. Combines + * a @a payto -URL and adds some salt to create the JSON. + * + * @param payto payto://-URL to encapsulate + * @return JSON describing the account, including the + * payto://-URL of the account, must be manually decref'd + */ +json_t * +TALER_TESTING_make_wire_details (const char *payto) +{ + return json_pack ("{s:s, s:s}", + "url", payto, + "salt", + "test-salt (must be constant for aggregation tests)"); } -/* end of testing_api_helpers.c */ +/* end of testing_api_helpers_bank.c */ diff --git a/src/lib/testing_api_helpers_exchange.c b/src/lib/testing_api_helpers_exchange.c index cc8430784..1fed38d1b 100644 --- a/src/lib/testing_api_helpers_exchange.c +++ b/src/lib/testing_api_helpers_exchange.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2018 Taler Systems SA + Copyright (C) 2018-2020 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 @@ -339,15 +339,9 @@ TALER_TESTING_auditor_db_reset (const char *config_filename) struct SignInfo { /** - * Set to the base URL of the exchange. To be free'd - * by the caller. + * Members will be set to the exchange configuration. */ - char *exchange_base_url; - - /** - * Set to the auditor's base URL. To be free'd by the caller. - */ - char *auditor_base_url; + struct TALER_TESTING_ExchangeConfiguration *ec; /** * Name of the configuration file to use. @@ -379,17 +373,18 @@ sign_keys_for_exchange (void *cls, char *test_home_dir; char *signed_keys_out; char *exchange_master_pub; + int ret; if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "exchange", "BASE_URL", - &si->exchange_base_url)) + &si->ec->exchange_url)) { GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, "exchange", "BASE_URL"); - si->exchange_base_url = NULL; + si->ec->exchange_url = NULL; return GNUNET_NO; } @@ -397,14 +392,14 @@ sign_keys_for_exchange (void *cls, GNUNET_CONFIGURATION_get_value_string (cfg, "auditor", "BASE_URL", - &si->auditor_base_url)) + &si->ec->auditor_url)) { GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, "auditor", "BASE_URL"); - GNUNET_free (si->exchange_base_url); - si->exchange_base_url = NULL; - si->auditor_base_url = NULL; + GNUNET_free (si->ec->exchange_url); + si->ec->exchange_url = NULL; + si->ec->auditor_url = NULL; return GNUNET_SYSERR; } @@ -417,11 +412,8 @@ sign_keys_for_exchange (void *cls, GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "paths", "TALER_TEST_HOME"); - GNUNET_free (si->exchange_base_url); - GNUNET_free (si->auditor_base_url); - si->exchange_base_url = NULL; - si->auditor_base_url = NULL; - return GNUNET_SYSERR; + ret = GNUNET_SYSERR; + goto fail; } GNUNET_asprintf (&signed_keys_out, @@ -438,42 +430,42 @@ sign_keys_for_exchange (void *cls, GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "exchange", "MASTER_PUBLIC_KEY"); - GNUNET_free (si->exchange_base_url); - GNUNET_free (si->auditor_base_url); - si->exchange_base_url = NULL; - si->auditor_base_url = NULL; GNUNET_free (signed_keys_out); - return GNUNET_SYSERR; + ret = GNUNET_SYSERR; + goto fail; } if (GNUNET_OK != TALER_TESTING_run_auditor_exchange (si->config_filename, exchange_master_pub, - si->exchange_base_url, + si->ec->exchange_url, GNUNET_NO)) { - GNUNET_free (si->exchange_base_url); - GNUNET_free (si->auditor_base_url); - si->exchange_base_url = NULL; - si->auditor_base_url = NULL; - return GNUNET_NO; + GNUNET_free (signed_keys_out); + ret = GNUNET_NO; + goto fail; } if (GNUNET_OK != TALER_TESTING_run_auditor_sign (si->config_filename, exchange_master_pub, - si->auditor_base_url, + si->ec->auditor_url, si->auditor_sign_input_filename, signed_keys_out)) { - GNUNET_free (si->exchange_base_url); - GNUNET_free (si->auditor_base_url); - si->exchange_base_url = NULL; - si->auditor_base_url = NULL; - return GNUNET_NO; + GNUNET_free (signed_keys_out); + GNUNET_free (exchange_master_pub); + ret = GNUNET_NO; + goto fail; } GNUNET_free (signed_keys_out); GNUNET_free (exchange_master_pub); return GNUNET_OK; +fail: + GNUNET_free (si->ec->exchange_url); + GNUNET_free (si->ec->auditor_url); + si->ec->exchange_url = NULL; + si->ec->auditor_url = NULL; + return ret; } @@ -484,24 +476,17 @@ sign_keys_for_exchange (void *cls, * launch the exchange process itself. * * @param config_filename configuration file to use - * @param auditor_base_url[out] will be set to the auditor base url, - * if the config has any; otherwise it will be set to - * NULL. - * @param exchange_base_url[out] will be set to the exchange base url, - * if the config has any; otherwise it will be set to - * NULL. + * @param ec[out] will be set to the exchange configuration data * @return #GNUNET_OK on success, #GNUNET_NO if test should be * skipped, #GNUNET_SYSERR on test failure */ int TALER_TESTING_prepare_exchange (const char *config_filename, - char **auditor_base_url, - char **exchange_base_url) + struct TALER_TESTING_ExchangeConfiguration *ec) { struct SignInfo si = { .config_filename = config_filename, - .exchange_base_url = NULL, - .auditor_base_url = NULL, + .ec = ec, .auditor_sign_input_filename = "auditor.in" }; @@ -520,8 +505,6 @@ TALER_TESTING_prepare_exchange (const char *config_filename, &sign_keys_for_exchange, &si)) return GNUNET_NO; - *exchange_base_url = si.exchange_base_url; - *auditor_base_url = si.auditor_base_url; return GNUNET_OK; } @@ -946,6 +929,9 @@ TALER_TESTING_setup_with_auditor_and_exchange (TALER_TESTING_Main main_cb, /** * Test port in URL string for availability. + * + * @param url URL to extract port from, 80 is default + * @return #GNUNET_OK if the port is free */ int TALER_TESTING_url_port_free (const char *url) @@ -972,109 +958,4 @@ TALER_TESTING_url_port_free (const char *url) } -/** - * Allocate and return a piece of wire-details. Combines - * the @a account_no and the @a bank_url to a - * @a payto://-URL and adds some salt to create the JSON. - * - * @param account_no account number - * @param bank_url the bank_url (FIXME/WARNING: shouldn't this be a _hostname_ ??) - * @return JSON describing the account, including the - * payto://-URL of the account, must be manually decref'd - */ -json_t * -TALER_TESTING_make_wire_details (unsigned long long account_no, - const char *bank_url) -{ - char *payto; - json_t *ret; - int ends_slash; - - if (0 < strlen (bank_url)) - ends_slash = '/' == bank_url[strlen (bank_url) - 1]; - else - ends_slash = 0; - - GNUNET_asprintf (&payto, - (ends_slash) - ? "payto://x-taler-bank/%s%llu" - : "payto://x-taler-bank/%s/%llu", - bank_url, - account_no); - ret = json_pack ("{s:s, s:s}", - "url", payto, - "salt", - "test-salt (must be constant for aggregation tests)"); - GNUNET_free (payto); - return ret; -} - - -/** - * Prepare launching a fakebank. Check that the configuration - * file has the right option, and that the port is available. - * If everything is OK, return the configured URL of the fakebank. - * - * @param config_filename configuration file to use - * @param config_section which account to use (must match x-taler-bank) - * @return NULL on error, fakebank URL otherwise - */ -char * -TALER_TESTING_prepare_fakebank (const char *config_filename, - const char *config_section) -{ - struct GNUNET_CONFIGURATION_Handle *cfg; - char *payto_url; - char *fakebank_url; - const char *start; - const char *end; - - cfg = GNUNET_CONFIGURATION_create (); - if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, - config_filename)) - return NULL; - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_string (cfg, - config_section, - "URL", - &payto_url)) - { - GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, - config_section, - "URL"); - GNUNET_CONFIGURATION_destroy (cfg); - return NULL; - } - GNUNET_CONFIGURATION_destroy (cfg); - if (0 != strncasecmp (payto_url, - "payto://x-taler-bank/", - strlen ("payto://x-taler-bank/"))) - { - GNUNET_log_config_invalid - (GNUNET_ERROR_TYPE_WARNING, - config_section, - "URL", - "expected `x-taler-bank' payto://-URL"); - GNUNET_CONFIGURATION_destroy (cfg); - GNUNET_free (payto_url); - return NULL; - } - start = &payto_url [strlen ("payto://x-taler-bank/")]; - end = strchr (start, - (unsigned char) '/'); - if (NULL == end) - end = &start[strlen (start)]; - fakebank_url = GNUNET_strndup (start, - end - start); - GNUNET_free (payto_url); - if (GNUNET_OK != - TALER_TESTING_url_port_free (fakebank_url)) - { - GNUNET_free (fakebank_url); - return NULL; - } - return fakebank_url; -} - - /* end of testing_api_helpers.c */ -- cgit v1.2.3