summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÖzgür Kesim <oec-taler@kesim.org>2023-12-23 13:02:45 +0100
committerÖzgür Kesim <oec-taler@kesim.org>2023-12-23 13:02:45 +0100
commit8fd6a4e148a93aab45082cbe159a56be05acd1c4 (patch)
treea3d97967cb8d68ab05315a808bef2dc16a40b52e
parenta162761ceb2e1678703b984dfb1608d5144e8b10 (diff)
downloadexchange-8fd6a4e148a93aab45082cbe159a56be05acd1c4.tar.gz
exchange-8fd6a4e148a93aab45082cbe159a56be05acd1c4.tar.bz2
exchange-8fd6a4e148a93aab45082cbe159a56be05acd1c4.zip
[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.
-rw-r--r--src/include/taler_testing_lib.h18
-rw-r--r--src/testing/test_exchange_api_conflicts.c80
-rw-r--r--src/testing/testing_api_cmd_batch_withdraw.c29
3 files changed, 92 insertions, 35 deletions
diff --git a/src/include/taler_testing_lib.h b/src/include/taler_testing_lib.h
index e89779614..1e8ae9d8f 100644
--- a/src/include/taler_testing_lib.h
+++ b/src/include/taler_testing_lib.h
@@ -1079,18 +1079,6 @@ TALER_TESTING_cmd_withdraw_amount (const char *label,
uint8_t age,
unsigned int expected_response_code);
-/**
- * Force a conflict
- * 0: no conflict
- * 1: multiple coins with same private key, different denominations
- * 2: multiple coins with same private key and different age restriction
- */
-enum TALER_TESTING_CoinConflictType
-{
- Conflict_None = 0,
- Conflict_Denom = 1,
- Conflict_Age = 2
-};
/**
* Create a batch withdraw command, letting the caller specify the type of
@@ -1102,7 +1090,7 @@ enum TALER_TESTING_CoinConflictType
*
* @param label command label.
* @param reserve_reference command providing us with a reserve to withdraw from
- * @param conflict type of conflict for the coins
+ * @param conflict if true, enforce a conflict (same priv key, different denom and age commiment)
* @param age if > 0, age restriction applies (same for all coins)
* @param expected_response_code which HTTP response code
* we expect from the exchange.
@@ -1114,7 +1102,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,
@@ -1145,7 +1133,7 @@ TALER_TESTING_cmd_batch_withdraw_with_conflict (
TALER_TESTING_cmd_batch_withdraw_with_conflict ( \
(label), \
(reserve_reference), \
- Conflict_None, \
+ false, \
(age), \
(expected_response_code), \
(amount), \
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; i<ws->num_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,