From 8fd6a4e148a93aab45082cbe159a56be05acd1c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96zg=C3=BCr=20Kesim?= Date: Sat, 23 Dec 2023 13:02:45 +0100 Subject: [wip, #7267] added test to detect age commitment conflict on deposit A new testcase is added to detect same coin_pub with different age commitments during deposit. --- src/testing/test_exchange_api_conflicts.c | 80 ++++++++++++++++++++++++++-- src/testing/testing_api_cmd_batch_withdraw.c | 29 +++++----- 2 files changed, 89 insertions(+), 20 deletions(-) (limited to 'src/testing') diff --git a/src/testing/test_exchange_api_conflicts.c b/src/testing/test_exchange_api_conflicts.c index 89851446f..d26c2faf4 100644 --- a/src/testing/test_exchange_api_conflicts.c +++ b/src/testing/test_exchange_api_conflicts.c @@ -125,7 +125,7 @@ run (void *cls, */ TALER_TESTING_cmd_batch_withdraw_with_conflict ("withdraw-coin-denom-1", "create-reserve-denom", - Conflict_Denom, + true, 0, /* age */ MHD_HTTP_OK, "EUR:1", @@ -140,7 +140,7 @@ run (void *cls, /** * Spend the coin. */ - TALER_TESTING_cmd_deposit ("deposit", + TALER_TESTING_cmd_deposit ("deposit-denom", "withdraw-coin-denom-1", 0, cred.user42_payto, @@ -155,7 +155,77 @@ run (void *cls, "{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}", GNUNET_TIME_UNIT_ZERO, "EUR:4.99", - /* FIXME: this fails for cs denominations! */ + MHD_HTTP_CONFLICT), + TALER_TESTING_cmd_deposit ("deposit-denom-conflict-2", + "withdraw-coin-denom-1", + 2, + cred.user42_payto, + "{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}", + GNUNET_TIME_UNIT_ZERO, + "EUR:9.99", + MHD_HTTP_CONFLICT), + TALER_TESTING_cmd_end () + }; + + struct TALER_TESTING_Command withdraw_conflict_age[] = { + /** + * Move money to the exchange's bank account. + */ + CMD_TRANSFER_TO_EXCHANGE ("create-reserve-age", + "EUR:3.03"), + TALER_TESTING_cmd_check_bank_admin_transfer ("check-create-reserve-age", + "EUR:3.03", + cred.user42_payto, + cred.exchange_payto, + "create-reserve-age"), + /** + * Make a reserve exist, according to the previous + * transfer. + */ + CMD_EXEC_WIREWATCH ("wirewatch-conflict-age"), + /** + * Withdraw EUR:1, EUR:5, EUR:15, but using the same private key each time. + */ + TALER_TESTING_cmd_batch_withdraw_with_conflict ("withdraw-coin-age-1", + "create-reserve-age", + true, + 10, /* age */ + MHD_HTTP_OK, + "EUR:1", + "EUR:1", + "EUR:1", + NULL), + + TALER_TESTING_cmd_end () + }; + + struct TALER_TESTING_Command spend_conflict_age[] = { + /** + * Spend the coin. + */ + TALER_TESTING_cmd_deposit ("deposit-age", + "withdraw-coin-age-1", + 0, + cred.user42_payto, + "{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}", + GNUNET_TIME_UNIT_ZERO, + "EUR:0.99", + MHD_HTTP_OK), + TALER_TESTING_cmd_deposit ("deposit-age-conflict", + "withdraw-coin-age-1", + 1, + cred.user42_payto, + "{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}", + GNUNET_TIME_UNIT_ZERO, + "EUR:0.99", + MHD_HTTP_CONFLICT), + TALER_TESTING_cmd_deposit ("deposit-age-conflict-2", + "withdraw-coin-age-1", + 2, + cred.user42_payto, + "{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}", + GNUNET_TIME_UNIT_ZERO, + "EUR:0.99", MHD_HTTP_CONFLICT), TALER_TESTING_cmd_end () }; @@ -179,6 +249,10 @@ run (void *cls, withdraw_conflict_denom), TALER_TESTING_cmd_batch ("spend-conflict-denom", spend_conflict_denom), + TALER_TESTING_cmd_batch ("withdraw-conflict-age", + withdraw_conflict_age), + TALER_TESTING_cmd_batch ("spend-conflict-age", + spend_conflict_age), /* End the suite. */ TALER_TESTING_cmd_end () }; diff --git a/src/testing/testing_api_cmd_batch_withdraw.c b/src/testing/testing_api_cmd_batch_withdraw.c index a93fadace..744da56c9 100644 --- a/src/testing/testing_api_cmd_batch_withdraw.c +++ b/src/testing/testing_api_cmd_batch_withdraw.c @@ -177,7 +177,7 @@ struct BatchWithdrawState /** * Force a conflict: */ - enum TALER_TESTING_CoinConflictType force_conflict; + bool force_conflict; }; @@ -200,9 +200,10 @@ reserve_batch_withdraw_cb (void *cls, ws->wsh = NULL; if (ws->expected_response_code != wr->hr.http_status) { - TALER_TESTING_unexpected_status (is, - wr->hr.http_status, - ws->expected_response_code); + TALER_TESTING_unexpected_status_with_body (is, + wr->hr.http_status, + ws->expected_response_code, + wr->hr.reply); return; } switch (wr->hr.http_status) @@ -271,7 +272,6 @@ batch_withdraw_run (void *cls, struct TALER_EXCHANGE_WithdrawCoinInput wcis[ws->num_coins]; struct TALER_PlanchetMasterSecretP conflict_ps = {0}; struct TALER_AgeMask mask = {0}; - struct GNUNET_HashCode seed = {0}; (void) cmd; ws->is = is; @@ -307,30 +307,25 @@ batch_withdraw_run (void *cls, if (0 < ws->age) mask = TALER_extensions_get_age_restriction_mask (); - if (Conflict_Denom == ws->force_conflict) + if (ws->force_conflict) TALER_planchet_master_setup_random (&conflict_ps); - if (Conflict_Age == ws->force_conflict) - GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, - &seed, - sizeof(seed)); - for (unsigned int i = 0; inum_coins; i++) { struct CoinState *cs = &ws->coins[i]; struct TALER_EXCHANGE_WithdrawCoinInput *wci = &wcis[i]; - if (Conflict_Denom == ws->force_conflict) + if (ws->force_conflict) cs->ps = conflict_ps; else TALER_planchet_master_setup_random (&cs->ps); if (0 < ws->age) { - if (Conflict_Age != ws->force_conflict) - GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, - &seed, - sizeof(seed)); + struct GNUNET_HashCode seed = {0}; + GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, + &seed, + sizeof(seed)); TALER_age_restriction_commit (&mask, ws->age, &seed, @@ -494,7 +489,7 @@ struct TALER_TESTING_Command TALER_TESTING_cmd_batch_withdraw_with_conflict ( const char *label, const char *reserve_reference, - enum TALER_TESTING_CoinConflictType conflict, + bool conflict, uint8_t age, unsigned int expected_response_code, const char *amount, -- cgit v1.2.3