diff options
Diffstat (limited to 'src/testing')
-rw-r--r-- | src/testing/.gitignore | 2 | ||||
-rw-r--r-- | src/testing/Makefile.am | 10 | ||||
-rw-r--r-- | src/testing/test_sync_api.c | 153 | ||||
-rw-r--r-- | src/testing/test_sync_api.conf | 102 | ||||
-rw-r--r-- | src/testing/test_sync_api_home/.config/taler/exchange/account-2.json | 4 | ||||
-rw-r--r-- | src/testing/test_sync_api_home/.local/share/taler/exchange/offline-keys/master.priv | 1 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_backup_download.c | 43 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_backup_upload.c | 193 | ||||
-rw-r--r-- | src/testing/testing_api_helpers.c | 196 | ||||
-rw-r--r-- | src/testing/testing_api_trait_account_priv.c | 73 | ||||
-rw-r--r-- | src/testing/testing_api_trait_account_pub.c | 73 | ||||
-rw-r--r-- | src/testing/testing_api_trait_hash.c | 73 | ||||
-rw-r--r-- | src/testing/testing_api_traits.c | 31 |
13 files changed, 203 insertions, 751 deletions
diff --git a/src/testing/.gitignore b/src/testing/.gitignore index 89ebda4..c81b1be 100644 --- a/src/testing/.gitignore +++ b/src/testing/.gitignore @@ -13,3 +13,5 @@ test_sync_api_home/.local/share/taler/exchange/offline-keys/secm_tofus.pub test_sync_api_home/.local/share/taler/taler-exchange-secmod-eddsa/ test_sync_api_home/.local/share/taler/taler-exchange-secmod-rsa/ +test_sync_api.conf.edited +libeufin-bank.pid diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am index 13ff35f..0fd3d03 100644 --- a/src/testing/Makefile.am +++ b/src/testing/Makefile.am @@ -15,10 +15,7 @@ libsynctesting_la_LDFLAGS = \ libsynctesting_la_SOURCES = \ testing_api_cmd_backup_download.c \ testing_api_cmd_backup_upload.c \ - testing_api_helpers.c \ - testing_api_trait_account_pub.c \ - testing_api_trait_account_priv.c \ - testing_api_trait_hash.c + testing_api_traits.c libsynctesting_la_LIBADD = \ $(top_builddir)/src/lib/libsync.la \ -ltalermerchant \ @@ -32,6 +29,8 @@ libsynctesting_la_LIBADD = \ -ltalertesting \ $(XLIB) +AM_TESTS_ENVIRONMENT=export SYNC_PREFIX=$${SYNC_PREFIX:-@libdir@};export PATH=$${SYNC_PREFIX:-@prefix@}/bin:$$PATH; + check_PROGRAMS = \ test_sync_api @@ -40,8 +39,7 @@ TESTS = \ EXTRA_DIST = \ test_sync_api.conf \ - test_sync_api_home/.config/taler/exchange/account-2.json \ - test_sync_api_home/.local/share/taler/exchange/offline-keys/master.priv + test_sync_api_home/.local/share/taler/exchange-offline/master.priv test_sync_api_SOURCES = \ test_sync_api.c diff --git a/src/testing/test_sync_api.c b/src/testing/test_sync_api.c index a05b39a..f4e7d51 100644 --- a/src/testing/test_sync_api.c +++ b/src/testing/test_sync_api.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2014-2020 Taler Systems SA + Copyright (C) 2014-2023 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 @@ -80,32 +80,17 @@ static char *merchant_payto; /** * Configuration of the bank. */ -static struct TALER_TESTING_BankConfiguration bc; - -/** - * Configuration of the exchange. - */ -static struct TALER_TESTING_ExchangeConfiguration ec; +static struct TALER_TESTING_Credentials cred; /** * Merchant base URL. */ -static char *merchant_url; +static const char *merchant_url = "http://localhost:8080/"; /** * Sync base URL. */ -static char *sync_url; - -/** - * Merchant process. - */ -static struct GNUNET_OS_Process *merchantd; - -/** - * Sync-httpd process. - */ -static struct GNUNET_OS_Process *syncd; +static const char *sync_url = "http://localhost:8084/"; /** @@ -136,7 +121,7 @@ cmd_transfer_to_exchange (const char *label, { return TALER_TESTING_cmd_admin_add_incoming (label, amount, - &bc.exchange_auth, + &cred.ba, payer_payto); } @@ -152,28 +137,26 @@ run (void *cls, struct TALER_TESTING_Interpreter *is) { struct TALER_TESTING_Command commands[] = { - /* general setup */ - TALER_TESTING_cmd_auditor_add ("add-auditor-OK", - MHD_HTTP_NO_CONTENT, - false), - TALER_TESTING_cmd_wire_add ("add-wire-account", - "payto://x-taler-bank/localhost/2", - MHD_HTTP_NO_CONTENT, - false), - TALER_TESTING_cmd_exec_offline_sign_keys ("offline-sign-future-keys", - CONFIG_FILE), - TALER_TESTING_cmd_exec_offline_sign_fees ("offline-sign-fees", - CONFIG_FILE, - "EUR:0.01", - "EUR:0.01"), - TALER_TESTING_cmd_check_keys_pull_all_keys ("refetch /keys", - 1), + TALER_TESTING_cmd_system_start ("start-taler", + CONFIG_FILE, + "-efms", + "-u", "exchange-account-exchange", + NULL), + TALER_TESTING_cmd_get_exchange ("get-exchange", + cred.cfg, + NULL, + true, + true), TALER_TESTING_cmd_merchant_post_instances ("instance-create-default", merchant_url, "default", - merchant_payto, - "EUR", MHD_HTTP_NO_CONTENT), + TALER_TESTING_cmd_merchant_post_account ( + "instance-create-default-account", + merchant_url, + merchant_payto, + NULL, NULL, + MHD_HTTP_OK), /** * Move money to the exchange's bank account. @@ -188,10 +171,12 @@ run (void *cls, TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-1", "create-reserve-1", "EUR:5", + 0, MHD_HTTP_OK), TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-2", "create-reserve-1", "EUR:5", + 0, MHD_HTTP_OK), /* Failed download: no backup exists */ SYNC_TESTING_cmd_backup_nx ("backup-download-nx", @@ -270,9 +255,8 @@ run (void *cls, TALER_TESTING_cmd_end () }; - TALER_TESTING_run_with_fakebank (is, - commands, - bc.exchange_auth.wire_gateway_url); + TALER_TESTING_run (is, + commands); } @@ -280,76 +264,23 @@ int main (int argc, char *const *argv) { - unsigned int ret; - /* These environment variables get in the way... */ - unsetenv ("XDG_DATA_HOME"); - unsetenv ("XDG_CONFIG_HOME"); - - GNUNET_log_setup ("test-sync-api", - "DEBUG", - NULL); - if (GNUNET_OK != - TALER_TESTING_prepare_fakebank (CONFIG_FILE, - "exchange-account-exchange", - &bc)) - return 77; - payer_payto = ("payto://x-taler-bank/localhost/" USER_ACCOUNT_NAME); - exchange_payto = ("payto://x-taler-bank/localhost/" EXCHANGE_ACCOUNT_NAME); - merchant_payto = ("payto://x-taler-bank/localhost/" MERCHANT_ACCOUNT_NAME); - if (NULL == - (merchant_url = TALER_TESTING_prepare_merchant (CONFIG_FILE))) - return 77; - TALER_TESTING_cleanup_files (CONFIG_FILE); - - if (NULL == - (sync_url = SYNC_TESTING_prepare_sync (CONFIG_FILE))) - return 77; - - TALER_TESTING_cleanup_files (CONFIG_FILE); - - switch (TALER_TESTING_prepare_exchange (CONFIG_FILE, - GNUNET_YES, - &ec)) - { - case GNUNET_SYSERR: - GNUNET_break (0); - return 1; - case GNUNET_NO: - return 77; - - case GNUNET_OK: - - if (NULL == (merchantd = - TALER_TESTING_run_merchant (CONFIG_FILE, - merchant_url))) - return 1; - - if (NULL == (syncd = - SYNC_TESTING_run_sync (CONFIG_FILE, - sync_url))) - return 1; - - ret = TALER_TESTING_setup_with_exchange (&run, - NULL, - CONFIG_FILE); - - GNUNET_OS_process_kill (merchantd, SIGTERM); - GNUNET_OS_process_kill (syncd, SIGTERM); - GNUNET_OS_process_wait (merchantd); - GNUNET_OS_process_wait (syncd); - GNUNET_OS_process_destroy (merchantd); - GNUNET_OS_process_destroy (syncd); - GNUNET_free (merchant_url); - GNUNET_free (sync_url); - - if (GNUNET_OK != ret) - return 1; - break; - default: - GNUNET_break (0); - return 1; - } - return 0; + (void) argc; + payer_payto = + "payto://x-taler-bank/localhost/" USER_ACCOUNT_NAME "?receiver-name=user"; + exchange_payto = + "payto://x-taler-bank/localhost/" EXCHANGE_ACCOUNT_NAME + "?receiver-name=exchange"; + merchant_payto = + "payto://x-taler-bank/localhost/" MERCHANT_ACCOUNT_NAME + "?receiver-name=merchant"; + return TALER_TESTING_main (argv, + "DEBUG", + CONFIG_FILE, + "exchange-account-exchange", + TALER_TESTING_BS_FAKEBANK, + &cred, + &run, + NULL); } diff --git a/src/testing/test_sync_api.conf b/src/testing/test_sync_api.conf index 54d2af7..3a0d655 100644 --- a/src/testing/test_sync_api.conf +++ b/src/testing/test_sync_api.conf @@ -1,84 +1,54 @@ # This file is in the public domain. # [PATHS] -# Persistent data storage for the testcase TALER_TEST_HOME = test_sync_api_home/ TALER_RUNTIME_DIR = ${TMPDIR:-${TMP:-/tmp}}/${USER:-}/taler-system-runtime/ - -# Persistent data storage TALER_DATA_HOME = $TALER_HOME/.local/share/taler/ - -# Configuration files TALER_CONFIG_HOME = $TALER_HOME/.config/taler/ - -# Cached data, no big deal if lost TALER_CACHE_HOME = $TALER_HOME/.cache/taler/ [taler] -# What currency do we use? CURRENCY = EUR CURRENCY_ROUND_UNIT = EUR:0.01 [taler-helper-crypto-rsa] -# Reduce from 1 year to speed up test LOOKAHEAD_SIGN = 24 days [taler-helper-crypto-eddsa] -# Reduce from 1 year to speed up test LOOKAHEAD_SIGN = 24 days -# Reduce from 12 weeks to ensure we have multiple DURATION = 14 days [bank] HTTP_PORT = 8082 -# Sync config +[libeufin-bank] +CURRENCY = EUR +PORT = 8082 + +[libeufin-bankdb-postgres] +CONFIG = postgres:///synccheck +SQL_DIR = $DATADIR/sql/ [sync] -# Which port do we run the *sync* backend on? (HTTP server) PORT = 8084 - -# Where does our payment backend run? Must match PORT under [merchant] -PAYMENT_BACKEND_URL = http://localhost:8080/ - -# Annual fee we charge. +PAYMENT_BACKEND_URL = "http://localhost:8080/" ANNUAL_FEE = EUR:4.99 - -# Upload limit UPLOAD_LIMIT_MB = 1 +SERVE = tcp [syncdb-postgres] CONFIG = postgres:///synccheck - -# Where are the SQL files to setup our tables? -# Important: this MUST end with a "/"! SQL_DIR = $DATADIR/sql/ -########################################## -# Configuration for the merchant backend # -########################################## - [merchant] -# Which port do we run the backend on? (HTTP server) PORT = 8080 - -# How quickly do we want the exchange to send us our money? -# Used only if the frontend does not specify a value. WIRE_TRANSFER_DELAY = 0 s - -# Which plugin (backend) do we use for the DB. DB = postgres - -# Default choice for maximum wire fee. DEFAULT_MAX_WIRE_FEE = EUR:0.10 - -# Default choice for maximum deposit fee. DEFAULT_MAX_DEPOSIT_FEE = EUR:0.10 - -# This specifies which database the postgres backend uses. [merchantdb-postgres] -CONFIG = postgres:///talercheck +CONFIG = postgres:///synccheck # Different instances operated by this merchant: [instance-default] @@ -95,59 +65,29 @@ CURRENCY = EUR [auditor] BASE_URL = http://the.auditor/ -# Auditors must be in sections "auditor-", the rest of the section -# name could be anything. -[auditor-ezb] -# Informal name of the auditor. Just for the user. -NAME = European Central Bank - -# URL of the auditor (especially for in the future, when the -# auditor offers an automated issue reporting system). -# Not really used today. -URL = http://taler.ezb.eu/ - -# This is the important bit: the signing key of the auditor. -PUBLIC_KEY = 9QXF7XY7E9VPV47B5Z806NDFSX2VJ79SVHHD29QEQ3BG31ANHZ60 - -# Which currency is this auditor trusted for? -CURRENCY = EUR - - -################################################### -# Configuration for the exchange for the testcase # -################################################### - [exchange] -# How to access our database +AML_THRESHOLD = EUR:1000000 DB = postgres - -# HTTP port the exchange listens to PORT = 8081 - -# How long are signing keys valid? SIGNKEY_LEGAL_DURATION = 2 years - -# Our public key MASTER_PUBLIC_KEY = EAQTXN8S6QP081WRWG03N8SQ34PX492ATXSSWASJGRXCBP0QM7HG - -# Base URL of the exchange. BASE_URL = "http://localhost:8081/" +STEFAN_ABS = "EUR:5" [exchangedb-postgres] -CONFIG = "postgres:///talercheck" - -[auditordb-postgres] -CONFIG = postgres:///talercheck +CONFIG = "postgres:///synccheck" -# Account of the EXCHANGE [exchange-account-exchange] -# What is the exchange's bank account (with the "Taler Bank" demo system)? -PAYTO_URI = "payto://x-taler-bank/localhost:8082/2" +PAYTO_URI = "payto://x-taler-bank/localhost:8082/2?receiver-name=exchange" ENABLE_DEBIT = YES ENABLE_CREDIT = YES [exchange-accountcredentials-exchange] -WIRE_GATEWAY_URL = "http://localhost:8082/2/" +WIRE_GATEWAY_URL = "http://localhost:8082/accounts/2/taler-wire-gateway/" +WIRE_GATEWAY_AUTH_METHOD = NONE + +[admin-accountcredentials-exchange] +WIRE_GATEWAY_URL = "http://localhost:8082/accounts/2/taler-wire-gateway/" WIRE_GATEWAY_AUTH_METHOD = NONE [coin_eur_ct_1] @@ -160,6 +100,7 @@ fee_deposit = EUR:0.00 fee_refresh = EUR:0.01 fee_refund = EUR:0.01 rsa_keysize = 1024 +cipher = RSA [coin_eur_ct_10] value = EUR:0.10 @@ -171,6 +112,7 @@ fee_deposit = EUR:0.01 fee_refresh = EUR:0.03 fee_refund = EUR:0.01 rsa_keysize = 1024 +cipher = RSA [coin_eur_1] value = EUR:1 @@ -182,6 +124,7 @@ fee_deposit = EUR:0.01 fee_refresh = EUR:0.03 fee_refund = EUR:0.01 rsa_keysize = 1024 +cipher = RSA [coin_eur_5] value = EUR:5 @@ -193,3 +136,4 @@ fee_deposit = EUR:0.01 fee_refresh = EUR:0.03 fee_refund = EUR:0.01 rsa_keysize = 1024 +cipher = RSA diff --git a/src/testing/test_sync_api_home/.config/taler/exchange/account-2.json b/src/testing/test_sync_api_home/.config/taler/exchange/account-2.json deleted file mode 100644 index 567fc91..0000000 --- a/src/testing/test_sync_api_home/.config/taler/exchange/account-2.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "payto_uri": "payto://x-taler-bank/localhost:8082/2", - "master_sig": "AM32QB4RYMWK548PE63PJXJMWSA001TFFWTZZPSSD8HQ8JE4D5V5X8WTSYSX59ANF4YRTRMF5Q4Q12CE2KTA8KQ03CM11YDTK75SJ20" -}
\ No newline at end of file diff --git a/src/testing/test_sync_api_home/.local/share/taler/exchange/offline-keys/master.priv b/src/testing/test_sync_api_home/.local/share/taler/exchange/offline-keys/master.priv deleted file mode 100644 index c20942d..0000000 --- a/src/testing/test_sync_api_home/.local/share/taler/exchange/offline-keys/master.priv +++ /dev/null @@ -1 +0,0 @@ -k;d_U}A.w"!Gv_m"_
\ No newline at end of file diff --git a/src/testing/testing_api_cmd_backup_download.c b/src/testing/testing_api_cmd_backup_download.c index e6bfad4..15ae376 100644 --- a/src/testing/testing_api_cmd_backup_download.c +++ b/src/testing/testing_api_cmd_backup_download.c @@ -17,7 +17,7 @@ <http://www.gnu.org/licenses/> */ /** - * @file lib/testing_api_cmd_backup_download.c + * @file testing/testing_api_cmd_backup_download.c * @brief command to download data to the sync backend service. * @author Christian Grothoff */ @@ -80,40 +80,34 @@ struct BackupDownloadState * Function called with the results of a #SYNC_download(). * * @param cls closure - * @param http_status HTTP status of the request - * @param ud details about the download operation + * @param dd details about the download operation */ static void backup_download_cb (void *cls, - unsigned int http_status, const struct SYNC_DownloadDetails *dd) { struct BackupDownloadState *bds = cls; bds->download = NULL; - if (http_status != bds->http_status) + if (dd->http_status != bds->http_status) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Unexpected response code %u to command %s in %s:%u\n", - http_status, - bds->is->commands[bds->is->ip].label, - __FILE__, - __LINE__); - TALER_TESTING_interpreter_fail (bds->is); + TALER_TESTING_unexpected_status (bds->is, + dd->http_status, + bds->http_status); return; } if (NULL != bds->upload_reference) { - if ( (MHD_HTTP_OK == http_status) && - (0 != GNUNET_memcmp (&dd->curr_backup_hash, + if ( (MHD_HTTP_OK == dd->http_status) && + (0 != GNUNET_memcmp (&dd->details.ok.curr_backup_hash, bds->upload_hash)) ) { GNUNET_break (0); TALER_TESTING_interpreter_fail (bds->is); return; } - if ( (MHD_HTTP_OK == http_status) && - (0 != GNUNET_memcmp (&dd->prev_backup_hash, + if ( (MHD_HTTP_OK == dd->http_status) && + (0 != GNUNET_memcmp (&dd->details.ok.prev_backup_hash, bds->prev_upload_hash)) ) { GNUNET_break (0); @@ -155,27 +149,24 @@ backup_download_run (void *cls, return; } if (GNUNET_OK != - SYNC_TESTING_get_trait_hash (upload_cmd, - SYNC_TESTING_TRAIT_HASH_CURRENT, - &bds->upload_hash)) + TALER_TESTING_get_trait_curr_hash (upload_cmd, + &bds->upload_hash)) { GNUNET_break (0); TALER_TESTING_interpreter_fail (bds->is); return; } if (GNUNET_OK != - SYNC_TESTING_get_trait_hash (upload_cmd, - SYNC_TESTING_TRAIT_HASH_PREVIOUS, - &bds->prev_upload_hash)) + TALER_TESTING_get_trait_prev_hash (upload_cmd, + &bds->prev_upload_hash)) { GNUNET_break (0); TALER_TESTING_interpreter_fail (bds->is); return; } if (GNUNET_OK != - SYNC_TESTING_get_trait_account_pub (upload_cmd, - 0, - &sync_pub)) + TALER_TESTING_get_trait_account_pub (upload_cmd, + &sync_pub)) { GNUNET_break (0); TALER_TESTING_interpreter_fail (bds->is); @@ -183,7 +174,7 @@ backup_download_run (void *cls, } bds->sync_pub = *sync_pub; } - bds->download = SYNC_download (is->ctx, + bds->download = SYNC_download (TALER_TESTING_interpreter_get_context (is), bds->sync_url, &bds->sync_pub, &backup_download_cb, diff --git a/src/testing/testing_api_cmd_backup_upload.c b/src/testing/testing_api_cmd_backup_upload.c index 1491db0..3de4db8 100644 --- a/src/testing/testing_api_cmd_backup_upload.c +++ b/src/testing/testing_api_cmd_backup_upload.c @@ -1,6 +1,6 @@ /* This file is part of SYNC - Copyright (C) 2014-2019 Taler Systems SA + Copyright (C) 2014-2023 Taler Systems SA SYNC is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -17,7 +17,7 @@ <http://www.gnu.org/licenses/> */ /** - * @file lib/testing_api_cmd_backup_upload.c + * @file testing/testing_api_cmd_backup_upload.c * @brief command to upload data to the sync backend service. * @author Christian Grothoff */ @@ -82,7 +82,7 @@ struct BackupUploadState /** * Payment order ID we got back, if any. Otherwise NULL. */ - char *payment_order_id; + const char *payment_order_id; /** * Claim token we got back, if any. Otherwise all zeros. @@ -126,100 +126,90 @@ struct BackupUploadState * Function called with the results of a #SYNC_upload(). * * @param cls closure - * @param ec Taler error code - * @param http_status HTTP status of the request * @param ud details about the upload operation */ static void backup_upload_cb (void *cls, - enum TALER_ErrorCode ec, - unsigned int http_status, const struct SYNC_UploadDetails *ud) { struct BackupUploadState *bus = cls; bus->uo = NULL; - if (http_status != bus->http_status) + if (ud->http_status != bus->http_status) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Unexpected response code %u to command %s in %s:%u\n", - http_status, - bus->is->commands[bus->is->ip].label, - __FILE__, - __LINE__); - TALER_TESTING_interpreter_fail (bus->is); + TALER_TESTING_unexpected_status (bus->is, + ud->http_status, + bus->http_status); return; } - if (NULL != ud) + switch (ud->us) { - switch (ud->us) + case SYNC_US_SUCCESS: + if (0 != GNUNET_memcmp ( + &bus->curr_hash, + ud->details.success.curr_backup_hash)) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (bus->is); + return; + } + break; + case SYNC_US_PAYMENT_REQUIRED: { - case SYNC_US_SUCCESS: - if (0 != GNUNET_memcmp (&bus->curr_hash, - ud->details.curr_backup_hash)) + struct TALER_MERCHANT_PayUriData pd; + + if (GNUNET_OK != + TALER_MERCHANT_parse_pay_uri ( + ud->details.payment_required.payment_request, + &pd)) { GNUNET_break (0); TALER_TESTING_interpreter_fail (bus->is); return; } - break; - case SYNC_US_PAYMENT_REQUIRED: - { - struct TALER_MERCHANT_PayUriData pd; - - if (GNUNET_OK != - TALER_MERCHANT_parse_pay_uri (ud->details.payment_request, - &pd)) - { - GNUNET_break (0); - TALER_TESTING_interpreter_fail (bus->is); - return; - } - bus->payment_order_id = GNUNET_strdup (pd.order_id); - if (NULL != pd.claim_token) - bus->token = *pd.claim_token; - TALER_MERCHANT_parse_pay_uri_free (&pd); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Order ID from Sync service is `%s'\n", - bus->payment_order_id); - memset (&bus->curr_hash, - 0, - sizeof (struct GNUNET_HashCode)); - } - break; - case SYNC_US_CONFLICTING_BACKUP: + bus->payment_order_id = GNUNET_strdup (pd.order_id); + if (NULL != pd.claim_token) + bus->token = *pd.claim_token; + TALER_MERCHANT_parse_pay_uri_free (&pd); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Order ID from Sync service is `%s'\n", + bus->payment_order_id); + memset (&bus->curr_hash, + 0, + sizeof (struct GNUNET_HashCode)); + } + break; + case SYNC_US_CONFLICTING_BACKUP: + { + const struct TALER_TESTING_Command *ref; + const struct GNUNET_HashCode *h; + + ref = TALER_TESTING_interpreter_lookup_command + (bus->is, + bus->last_upload); + GNUNET_assert (NULL != ref); + GNUNET_assert (GNUNET_OK == + TALER_TESTING_get_trait_curr_hash (ref, + &h)); + if (0 != GNUNET_memcmp (h, + &ud->details.recovered_backup. + existing_backup_hash)) { - const struct TALER_TESTING_Command *ref; - const struct GNUNET_HashCode *h; - - ref = TALER_TESTING_interpreter_lookup_command - (bus->is, - bus->last_upload); - GNUNET_assert (NULL != ref); - GNUNET_assert (GNUNET_OK == - SYNC_TESTING_get_trait_hash (ref, - SYNC_TESTING_TRAIT_HASH_CURRENT, - &h)); - if (0 != GNUNET_memcmp (h, - &ud->details.recovered_backup. - existing_backup_hash)) - { - GNUNET_break (0); - TALER_TESTING_interpreter_fail (bus->is); - return; - } + GNUNET_break (0); + TALER_TESTING_interpreter_fail (bus->is); + return; } - case SYNC_US_HTTP_ERROR: - break; - case SYNC_US_CLIENT_ERROR: - GNUNET_break (0); - TALER_TESTING_interpreter_fail (bus->is); - return; - case SYNC_US_SERVER_ERROR: - GNUNET_break (0); - TALER_TESTING_interpreter_fail (bus->is); - return; } + case SYNC_US_HTTP_ERROR: + break; + case SYNC_US_CLIENT_ERROR: + GNUNET_break (0); + TALER_TESTING_interpreter_fail (bus->is); + return; + case SYNC_US_SERVER_ERROR: + GNUNET_break (0); + TALER_TESTING_interpreter_fail (bus->is); + return; } TALER_TESTING_interpreter_next (bus->is); } @@ -257,9 +247,8 @@ backup_upload_run (void *cls, const struct GNUNET_HashCode *h; if (GNUNET_OK == - SYNC_TESTING_get_trait_hash (ref, - SYNC_TESTING_TRAIT_HASH_CURRENT, - &h)) + TALER_TESTING_get_trait_curr_hash (ref, + &h)) { bus->prev_hash = *h; } @@ -268,9 +257,8 @@ backup_upload_run (void *cls, const struct SYNC_AccountPrivateKeyP *priv; if (GNUNET_OK != - SYNC_TESTING_get_trait_account_priv (ref, - 0, - &priv)) + TALER_TESTING_get_trait_account_priv (ref, + &priv)) { GNUNET_break (0); TALER_TESTING_interpreter_fail (bus->is); @@ -282,9 +270,8 @@ backup_upload_run (void *cls, const struct SYNC_AccountPublicKeyP *pub; if (GNUNET_OK != - SYNC_TESTING_get_trait_account_pub (ref, - 0, - &pub)) + TALER_TESTING_get_trait_account_pub (ref, + &pub)) { GNUNET_break (0); TALER_TESTING_interpreter_fail (bus->is); @@ -298,7 +285,6 @@ backup_upload_run (void *cls, if (GNUNET_OK != TALER_TESTING_get_trait_order_id (ref, - 0, &order_id)) { GNUNET_break (0); @@ -327,7 +313,7 @@ backup_upload_run (void *cls, GNUNET_CRYPTO_hash (bus->backup, bus->backup_size, &bus->curr_hash); - bus->uo = SYNC_upload (is->ctx, + bus->uo = SYNC_upload (TALER_TESTING_interpreter_get_context (is), bus->sync_url, &bus->sync_priv, ( ( (NULL != bus->prev_upload) && @@ -375,7 +361,6 @@ backup_upload_cleanup (void *cls, SYNC_upload_cancel (bus->uo); bus->uo = NULL; } - GNUNET_free (bus->payment_order_id); GNUNET_free (bus); } @@ -384,12 +369,12 @@ backup_upload_cleanup (void *cls, * Offer internal data to other commands. * * @param cls closure - * @param ret[out] result (could be anything) + * @param[out] ret result (could be anything) * @param trait name of the trait * @param index index number of the object to extract. * @return #GNUNET_OK on success */ -static int +static enum GNUNET_GenericReturnValue backup_upload_traits (void *cls, const void **ret, const char *trait, @@ -397,29 +382,19 @@ backup_upload_traits (void *cls, { struct BackupUploadState *bus = cls; struct TALER_TESTING_Trait straits[] = { - SYNC_TESTING_make_trait_hash (SYNC_TESTING_TRAIT_HASH_CURRENT, - &bus->curr_hash), - SYNC_TESTING_make_trait_hash (SYNC_TESTING_TRAIT_HASH_PREVIOUS, - &bus->prev_hash), - TALER_TESTING_make_trait_claim_token (0, - &bus->token), - SYNC_TESTING_make_trait_account_pub (0, - &bus->sync_pub), - SYNC_TESTING_make_trait_account_priv (0, - &bus->sync_priv), - TALER_TESTING_make_trait_order_id (0, - bus->payment_order_id), + TALER_TESTING_make_trait_curr_hash (&bus->curr_hash), + TALER_TESTING_make_trait_prev_hash (&bus->prev_hash), + TALER_TESTING_make_trait_claim_token (&bus->token), + TALER_TESTING_make_trait_account_pub (&bus->sync_pub), + TALER_TESTING_make_trait_account_priv (&bus->sync_priv), + TALER_TESTING_make_trait_order_id (bus->payment_order_id), TALER_TESTING_trait_end () }; struct TALER_TESTING_Trait ftraits[] = { - TALER_TESTING_make_trait_claim_token (0, - &bus->token), - SYNC_TESTING_make_trait_account_pub (0, - &bus->sync_pub), - SYNC_TESTING_make_trait_account_priv (0, - &bus->sync_priv), - TALER_TESTING_make_trait_order_id (0, - bus->payment_order_id), + TALER_TESTING_make_trait_claim_token (&bus->token), + TALER_TESTING_make_trait_account_pub (&bus->sync_pub), + TALER_TESTING_make_trait_account_priv (&bus->sync_priv), + TALER_TESTING_make_trait_order_id (bus->payment_order_id), TALER_TESTING_trait_end () }; diff --git a/src/testing/testing_api_helpers.c b/src/testing/testing_api_helpers.c deleted file mode 100644 index a83c391..0000000 --- a/src/testing/testing_api_helpers.c +++ /dev/null @@ -1,196 +0,0 @@ -/* - This file is part of SYNC - Copyright (C) 2014-2019 Taler Systems SA - - SYNC 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. - - SYNC is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - SYNCABILITY 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 SYNC; see the file COPYING. If not, see - <http://www.gnu.org/licenses/> -*/ -/** - * @file lib/testing_api_helpers.c - * @brief helper functions for test library. - * @author Christian Grothoff - * @author Marcello Stanisci - */ -#include "platform.h" -#include <taler/taler_testing_lib.h> -#include "sync_testing_lib.h" -#include <gnunet/gnunet_curl_lib.h> - - -/** - * Start the sync backend process. Assume the port - * is available and the database is clean. Use the "prepare - * sync" function to do such tasks. - * - * @param config_filename configuration filename. - * - * @return the process, or NULL if the process could not - * be started. - */ -struct GNUNET_OS_Process * -SYNC_TESTING_run_sync (const char *config_filename, - const char *sync_url) -{ - struct GNUNET_OS_Process *sync_proc; - unsigned int iter; - char *wget_cmd; - - sync_proc - = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL, - NULL, NULL, NULL, - "sync-httpd", - "sync-httpd", - "--log=INFO", - "-c", config_filename, - NULL); - if (NULL == sync_proc) - { - GNUNET_break (0); - return NULL; - } - GNUNET_asprintf (&wget_cmd, - "wget -q -t 1 -T 1" - " %s" - " -o /dev/null -O /dev/null", - sync_url); - - /* give child time to start and bind against the socket */ - fprintf (stderr, - "Waiting for `sync-httpd' to be ready\n"); - iter = 0; - do - { - if (10 == iter) - { - fprintf (stderr, - "Failed to launch" - " `sync-httpd' (or `wget')\n"); - GNUNET_OS_process_kill (sync_proc, - SIGTERM); - GNUNET_OS_process_wait (sync_proc); - GNUNET_OS_process_destroy (sync_proc); - GNUNET_break (0); - return NULL; - } - fprintf (stderr, ".\n"); - sleep (1); - iter++; - } - while (0 != system (wget_cmd)); - GNUNET_free (wget_cmd); - fprintf (stderr, "\n"); - return sync_proc; -} - - -/** - * Prepare the sync execution. Create tables and check if - * the port is available. - * - * @param config_filename configuration filename. - * @return the base url, or NULL upon errors. Must be freed - * by the caller. - */ -char * -SYNC_TESTING_prepare_sync (const char *config_filename) -{ - struct GNUNET_CONFIGURATION_Handle *cfg; - unsigned long long port; - struct GNUNET_OS_Process *dbinit_proc; - enum GNUNET_OS_ProcessStatusType type; - unsigned long code; - char *base_url; - - cfg = GNUNET_CONFIGURATION_create (); - if (GNUNET_OK != - GNUNET_CONFIGURATION_load (cfg, - config_filename)) - { - GNUNET_break (0); - return NULL; - } - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_number (cfg, - "sync", - "PORT", - &port)) - { - GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, - "sync", - "PORT"); - GNUNET_CONFIGURATION_destroy (cfg); - GNUNET_break (0); - return NULL; - } - GNUNET_CONFIGURATION_destroy (cfg); - if (GNUNET_OK != - GNUNET_NETWORK_test_port_free (IPPROTO_TCP, - (uint16_t) port)) - { - fprintf (stderr, - "Required port %llu not available, skipping.\n", - port); - GNUNET_break (0); - return NULL; - } - - /* DB preparation */ - if (NULL == (dbinit_proc = GNUNET_OS_start_process ( - GNUNET_OS_INHERIT_STD_ALL, - NULL, NULL, NULL, - "sync-dbinit", - "sync-dbinit", - "-c", config_filename, - "-r", - NULL))) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to run sync-dbinit." - " Check your PATH.\n"); - GNUNET_break (0); - return NULL; - } - - if (GNUNET_SYSERR == - GNUNET_OS_process_wait_status (dbinit_proc, - &type, - &code)) - { - GNUNET_OS_process_destroy (dbinit_proc); - GNUNET_break (0); - return NULL; - } - if ( (type == GNUNET_OS_PROCESS_EXITED) && - (0 != code) ) - { - fprintf (stderr, - "Failed to setup database\n"); - GNUNET_break (0); - return NULL; - } - if ( (type != GNUNET_OS_PROCESS_EXITED) || - (0 != code) ) - { - fprintf (stderr, - "Unexpected error running" - " `sync-dbinit'!\n"); - GNUNET_break (0); - return NULL; - } - GNUNET_OS_process_destroy (dbinit_proc); - GNUNET_asprintf (&base_url, - "http://localhost:%llu/", - port); - return base_url; -} diff --git a/src/testing/testing_api_trait_account_priv.c b/src/testing/testing_api_trait_account_priv.c deleted file mode 100644 index b8bfb5b..0000000 --- a/src/testing/testing_api_trait_account_priv.c +++ /dev/null @@ -1,73 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2019 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 Privlic License for more details. - - You should have received a copy of the GNU General Privlic - License along with TALER; see the file COPYING. If not, see - <http://www.gnu.org/licenses/> -*/ -/** - * @file lib/testing_api_trait_account_priv.c - * @brief traits to offer a account_priv - * @author Christian Grothoff - */ -#include "platform.h" -#include "sync_service.h" -#include "sync_testing_lib.h" - -#define SYNC_TESTING_TRAIT_ACCOUNT_PRIV "sync-account_priv" - - -/** - * Obtain an account private key from @a cmd. - * - * @param cmd command to extract the private key from. - * @param index the private key's index number. - * @param n[out] set to the private key coming from @a cmd. - * @return #GNUNET_OK on success. - */ -int -SYNC_TESTING_get_trait_account_priv - (const struct TALER_TESTING_Command *cmd, - unsigned int index, - const struct SYNC_AccountPrivateKeyP **priv) -{ - return cmd->traits (cmd->cls, - (const void **) priv, - SYNC_TESTING_TRAIT_ACCOUNT_PRIV, - index); -} - - -/** - * Offer an account private key. - * - * @param index usually zero - * @param priv the account_priv to offer. - * @return #GNUNET_OK on success. - */ -struct TALER_TESTING_Trait -SYNC_TESTING_make_trait_account_priv - (unsigned int index, - const struct SYNC_AccountPrivateKeyP *priv) -{ - struct TALER_TESTING_Trait ret = { - .index = index, - .trait_name = SYNC_TESTING_TRAIT_ACCOUNT_PRIV, - .ptr = (const void *) priv - }; - return ret; -} - - -/* end of testing_api_trait_account_priv.c */ diff --git a/src/testing/testing_api_trait_account_pub.c b/src/testing/testing_api_trait_account_pub.c deleted file mode 100644 index 9fecb18..0000000 --- a/src/testing/testing_api_trait_account_pub.c +++ /dev/null @@ -1,73 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2019 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 - <http://www.gnu.org/licenses/> -*/ -/** - * @file lib/testing_api_trait_account_pub.c - * @brief traits to offer a account_pub - * @author Christian Grothoff - */ -#include "platform.h" -#include "sync_service.h" -#include "sync_testing_lib.h" - -#define SYNC_TESTING_TRAIT_ACCOUNT_PUB "sync-account_pub" - - -/** - * Obtain an account public key from @a cmd. - * - * @param cmd command to extract the public key from. - * @param index the public key's index number. - * @param n[out] set to the public key coming from @a cmd. - * @return #GNUNET_OK on success. - */ -int -SYNC_TESTING_get_trait_account_pub - (const struct TALER_TESTING_Command *cmd, - unsigned int index, - const struct SYNC_AccountPublicKeyP **pub) -{ - return cmd->traits (cmd->cls, - (const void **) pub, - SYNC_TESTING_TRAIT_ACCOUNT_PUB, - index); -} - - -/** - * Offer an account public key. - * - * @param index usually zero - * @param h the account_pub to offer. - * @return #GNUNET_OK on success. - */ -struct TALER_TESTING_Trait -SYNC_TESTING_make_trait_account_pub - (unsigned int index, - const struct SYNC_AccountPublicKeyP *h) -{ - struct TALER_TESTING_Trait ret = { - .index = index, - .trait_name = SYNC_TESTING_TRAIT_ACCOUNT_PUB, - .ptr = (const void *) h - }; - return ret; -} - - -/* end of testing_api_trait_account_pub.c */ diff --git a/src/testing/testing_api_trait_hash.c b/src/testing/testing_api_trait_hash.c deleted file mode 100644 index 10b10d8..0000000 --- a/src/testing/testing_api_trait_hash.c +++ /dev/null @@ -1,73 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2019 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 - <http://www.gnu.org/licenses/> -*/ -/** - * @file lib/testing_api_trait_hash.c - * @brief traits to offer a hash - * @author Christian Grothoff - */ -#include "platform.h" -#include "sync_service.h" -#include "sync_testing_lib.h" - -#define SYNC_TESTING_TRAIT_HASH "sync-hash" - - -/** - * Obtain a hash from @a cmd. - * - * @param cmd command to extract the number from. - * @param index the number's index number. - * @param n[out] set to the number coming from @a cmd. - * @return #GNUNET_OK on success. - */ -int -SYNC_TESTING_get_trait_hash - (const struct TALER_TESTING_Command *cmd, - unsigned int index, - const struct GNUNET_HashCode **h) -{ - return cmd->traits (cmd->cls, - (const void **) h, - SYNC_TESTING_TRAIT_HASH, - index); -} - - -/** - * Offer a hash. - * - * @param index the number's index number. - * @param h the hash to offer. - * @return #GNUNET_OK on success. - */ -struct TALER_TESTING_Trait -SYNC_TESTING_make_trait_hash - (unsigned int index, - const struct GNUNET_HashCode *h) -{ - struct TALER_TESTING_Trait ret = { - .index = index, - .trait_name = SYNC_TESTING_TRAIT_HASH, - .ptr = (const void *) h - }; - return ret; -} - - -/* end of testing_api_trait_hash.c */ diff --git a/src/testing/testing_api_traits.c b/src/testing/testing_api_traits.c new file mode 100644 index 0000000..808cfd9 --- /dev/null +++ b/src/testing/testing_api_traits.c @@ -0,0 +1,31 @@ +/* + This file is part of TALER + Copyright (C) 2024 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 + <http://www.gnu.org/licenses/> +*/ +/** + * @file testing/testing_api_traits.c + * @brief trait implementation + * @author Christian Grothoff + */ +#include "platform.h" +#include "sync_testing_lib.h" + + +SYNC_TESTING_SIMPLE_TRAITS (TALER_TESTING_MAKE_IMPL_SIMPLE_TRAIT) + + +/* end of testing_api_traits.c */ |