fix use of index in testing_api_cmd_refresh.c

This commit is contained in:
Christian Grothoff 2019-07-15 21:44:03 +02:00
parent a497ccffb6
commit 28f790fac5
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
6 changed files with 115 additions and 77 deletions

View File

@ -1384,7 +1384,9 @@ TALER_TESTING_cmd_refund (const char *label,
* @param label the command label * @param label the command label
* @param expected_response_code expected HTTP status code * @param expected_response_code expected HTTP status code
* @param coin_reference reference to any command which * @param coin_reference reference to any command which
* offers a coin & reserve private key. * offers a coin and reserve private key. May specify
* the index of the coin using "$LABEL#$INDEX" syntax.
* Here, $INDEX must be a non-negative number.
* @param amount denomination to pay back. * @param amount denomination to pay back.
* *
* @return the command. * @return the command.

1
src/lib/.gitignore vendored
View File

@ -1 +1,2 @@
test_auditor_api_version test_auditor_api_version
test_exchange_api_revocation

View File

@ -161,7 +161,7 @@ run (void *cls,
/* Refund coin to original coin */ /* Refund coin to original coin */
TALER_TESTING_cmd_payback ("payback-1", TALER_TESTING_cmd_payback ("payback-1",
MHD_HTTP_OK, MHD_HTTP_OK,
"refresh-melt-1", "refresh-reveal-1",
"EUR:5"), "EUR:5"),
/** /**
* Melt original coin AGAIN * Melt original coin AGAIN
@ -178,7 +178,7 @@ run (void *cls,
/* Make refreshed coin invalid */ /* Make refreshed coin invalid */
TALER_TESTING_cmd_revoke ("revoke-2", TALER_TESTING_cmd_revoke ("revoke-2",
MHD_HTTP_OK, MHD_HTTP_OK,
"refresh-melt-2", "refresh-reveal-2",
CONFIG_FILE), CONFIG_FILE),
/* Make also original coin invalid */ /* Make also original coin invalid */
TALER_TESTING_cmd_revoke ("revoke-3", TALER_TESTING_cmd_revoke ("revoke-3",

View File

@ -124,7 +124,6 @@ payback_cb (void *cls,
const struct TALER_ReservePublicKeyP *reserve_pub, const struct TALER_ReservePublicKeyP *reserve_pub,
const json_t *full_response) const json_t *full_response)
{ {
struct PaybackState *ps = cls; struct PaybackState *ps = cls;
struct TALER_TESTING_Interpreter *is = ps->is; struct TALER_TESTING_Interpreter *is = ps->is;
struct TALER_TESTING_Command *cmd = &is->commands[is->ip]; struct TALER_TESTING_Command *cmd = &is->commands[is->ip];
@ -132,6 +131,9 @@ payback_cb (void *cls,
const struct TALER_ReservePrivateKeyP *reserve_priv; const struct TALER_ReservePrivateKeyP *reserve_priv;
struct TALER_ReservePublicKeyP rp; struct TALER_ReservePublicKeyP rp;
struct TALER_Amount expected_amount; struct TALER_Amount expected_amount;
char *cref;
const char *index;
unsigned int idx;
ps->ph = NULL; ps->ph = NULL;
if (ps->expected_response_code != http_status) if (ps->expected_response_code != http_status)
@ -148,8 +150,37 @@ payback_cb (void *cls,
return; return;
} }
/* We allow command referneces of the form "$LABEL#$INDEX" or
just "$LABEL", which implies the index is 0. Figure out
which one it is. */
index = strchr (ps->coin_reference, '#');
if (NULL == index)
{
idx = 0;
cref = GNUNET_strdup (ps->coin_reference);
}
else
{
cref = GNUNET_strndup (ps->coin_reference,
index - ps->coin_reference);
if (1 != sscanf (index,
"%u",
&idx))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Numeric index (not `%s') required after `#' in command reference of command %s in %s:%u\n",
index,
cmd->label,
__FILE__,
__LINE__);
TALER_TESTING_interpreter_fail (is);
GNUNET_free (cref);
return;
}
}
reserve_cmd = TALER_TESTING_interpreter_lookup_command reserve_cmd = TALER_TESTING_interpreter_lookup_command
(is, ps->coin_reference); (is, cref);
GNUNET_free (cref);
if (NULL == reserve_cmd) if (NULL == reserve_cmd)
{ {
@ -159,7 +190,7 @@ payback_cb (void *cls,
} }
if (GNUNET_OK != TALER_TESTING_get_trait_reserve_priv if (GNUNET_OK != TALER_TESTING_get_trait_reserve_priv
(reserve_cmd, 0, &reserve_priv)) (reserve_cmd, idx, &reserve_priv))
{ {
GNUNET_break (0); GNUNET_break (0);
TALER_TESTING_interpreter_fail (is); TALER_TESTING_interpreter_fail (is);

View File

@ -83,7 +83,7 @@ struct RefreshMeltState
/** /**
* Array of the denomination public keys * Array of the denomination public keys
* corresponding to the @e fresh_amounts. * corresponding to the @e num_fresh_coins;
*/ */
struct TALER_EXCHANGE_DenomPublicKey *fresh_pks; struct TALER_EXCHANGE_DenomPublicKey *fresh_pks;
@ -102,6 +102,11 @@ struct RefreshMeltState
*/ */
size_t refresh_data_length; size_t refresh_data_length;
/**
* Number of fresh coins generated by the melt.
*/
unsigned int num_fresh_coins;
/** /**
* Expected HTTP response code. * Expected HTTP response code.
*/ */
@ -282,7 +287,7 @@ do_reveal_retry (void *cls)
static void static void
reveal_cb (void *cls, reveal_cb (void *cls,
unsigned int http_status, unsigned int http_status,
enum TALER_ErrorCode ec, enum TALER_ErrorCode ec,
unsigned int num_coins, unsigned int num_coins,
const struct TALER_CoinSpendPrivateKeyP *coin_privs, const struct TALER_CoinSpendPrivateKeyP *coin_privs,
const struct TALER_DenominationSignature *sigs, const struct TALER_DenominationSignature *sigs,
@ -340,24 +345,19 @@ reveal_cb (void *cls,
case MHD_HTTP_OK: case MHD_HTTP_OK:
rrs->fresh_coins = GNUNET_new_array rrs->fresh_coins = GNUNET_new_array
(num_coins, struct FreshCoin); (num_coins, struct FreshCoin);
const struct TALER_EXCHANGE_DenomPublicKey *fresh_pks;
if (GNUNET_OK !=
TALER_TESTING_get_trait_denom_pub (melt_cmd,
0,
&fresh_pks))
{
GNUNET_break (0);
TALER_TESTING_interpreter_fail (rrs->is);
return;
}
for (unsigned int i=0; i<num_coins; i++) for (unsigned int i=0; i<num_coins; i++)
{ {
struct FreshCoin *fc = &rrs->fresh_coins[i]; struct FreshCoin *fc = &rrs->fresh_coins[i];
fc->pk = &fresh_pks[i]; if (GNUNET_OK !=
TALER_TESTING_get_trait_denom_pub (melt_cmd,
i,
&fc->pk))
{
GNUNET_break (0);
TALER_TESTING_interpreter_fail (rrs->is);
return;
}
fc->coin_priv = coin_privs[i]; fc->coin_priv = coin_privs[i];
fc->sig.rsa_signature = GNUNET_CRYPTO_rsa_signature_dup fc->sig.rsa_signature = GNUNET_CRYPTO_rsa_signature_dup
(sigs[i].rsa_signature); (sigs[i].rsa_signature);
@ -611,18 +611,18 @@ link_cb (void *cls,
for (unsigned int i=0;i<num_coins;i++) for (unsigned int i=0;i<num_coins;i++)
for (unsigned int j=0;j<num_coins;j++) for (unsigned int j=0;j<num_coins;j++)
{ {
if ( (0 == GNUNET_memcmp if ( (0 == GNUNET_memcmp
(&coin_privs[i], &fc[j].coin_priv)) && (&coin_privs[i], &fc[j].coin_priv)) &&
(0 == GNUNET_CRYPTO_rsa_signature_cmp (0 == GNUNET_CRYPTO_rsa_signature_cmp
(fc[i].sig.rsa_signature, (fc[i].sig.rsa_signature,
sigs[j].rsa_signature)) && sigs[j].rsa_signature)) &&
(0 == GNUNET_CRYPTO_rsa_public_key_cmp (0 == GNUNET_CRYPTO_rsa_public_key_cmp
(fc[i].pk->key.rsa_public_key, (fc[i].pk->key.rsa_public_key,
pubs[j].rsa_public_key)) ) pubs[j].rsa_public_key)) )
{ {
found++; found++;
break; break;
} }
} }
if (found != num_coins) if (found != num_coins)
{ {
@ -883,7 +883,7 @@ refresh_melt_run (void *cls,
for (num_fresh_coins=0; for (num_fresh_coins=0;
NULL != melt_fresh_amounts[num_fresh_coins]; NULL != melt_fresh_amounts[num_fresh_coins];
num_fresh_coins++) ; num_fresh_coins++) ;
rms->num_fresh_coins = num_fresh_coins;
rms->fresh_pks = GNUNET_new_array rms->fresh_pks = GNUNET_new_array
(num_fresh_coins, (num_fresh_coins,
struct TALER_EXCHANGE_DenomPublicKey); struct TALER_EXCHANGE_DenomPublicKey);
@ -935,13 +935,12 @@ refresh_melt_run (void *cls,
return; return;
} }
if (GNUNET_OK != TALER_TESTING_get_trait_denom_pub if (GNUNET_OK != TALER_TESTING_get_trait_denom_pub
(coin_command, 0, &melt_denom_pub)) (coin_command, 0, &melt_denom_pub))
{ {
GNUNET_break (0); GNUNET_break (0);
TALER_TESTING_interpreter_fail (rms->is); TALER_TESTING_interpreter_fail (rms->is);
return; return;
} }
for (unsigned int i=0;i<num_fresh_coins;i++) for (unsigned int i=0;i<num_fresh_coins;i++)
{ {
const struct TALER_EXCHANGE_DenomPublicKey *fresh_pk; const struct TALER_EXCHANGE_DenomPublicKey *fresh_pk;
@ -1035,7 +1034,6 @@ refresh_melt_cleanup (void *cls,
* @param ret[out] result (could be anything). * @param ret[out] result (could be anything).
* @param trait name of the trait. * @param trait name of the trait.
* @param index index number of the object to offer. * @param index index number of the object to offer.
*
* @return #GNUNET_OK on success. * @return #GNUNET_OK on success.
*/ */
static int static int
@ -1046,15 +1044,22 @@ refresh_melt_traits (void *cls,
{ {
struct RefreshMeltState *rms = cls; struct RefreshMeltState *rms = cls;
struct TALER_TESTING_Trait traits[] = { if (index >= rms->num_fresh_coins)
TALER_TESTING_make_trait_denom_pub (0, rms->fresh_pks), {
TALER_TESTING_trait_end () GNUNET_break (0);
}; return GNUNET_SYSERR;
}
{
struct TALER_TESTING_Trait traits[] = {
TALER_TESTING_make_trait_denom_pub (index, &rms->fresh_pks[index]),
TALER_TESTING_trait_end ()
};
return TALER_TESTING_get_trait (traits, return TALER_TESTING_get_trait (traits,
ret, ret,
trait, trait,
index); index);
}
} }
@ -1081,20 +1086,20 @@ TALER_TESTING_cmd_refresh_melt
md.coin_reference = coin_reference; md.coin_reference = coin_reference;
md.amount = amount; md.amount = amount;
rms = GNUNET_new (struct RefreshMeltState); rms = GNUNET_new (struct RefreshMeltState);
rms->melted_coin = md; rms->melted_coin = md;
rms->expected_response_code = expected_response_code; rms->expected_response_code = expected_response_code;
{
struct TALER_TESTING_Command cmd = {
.label = label,
.cls = rms,
.run = &refresh_melt_run,
.cleanup = &refresh_melt_cleanup,
.traits = &refresh_melt_traits
};
struct TALER_TESTING_Command cmd = { return cmd;
.label = label, }
.cls = rms,
.run = &refresh_melt_run,
.cleanup = &refresh_melt_cleanup,
.traits = &refresh_melt_traits
};
return cmd;
} }
@ -1109,7 +1114,6 @@ TALER_TESTING_cmd_refresh_melt
* @param coin_reference reference to a command that will provide * @param coin_reference reference to a command that will provide
* a coin to refresh * a coin to refresh
* @param expected_response_code expected HTTP code * @param expected_response_code expected HTTP code
*
* @return the command. * @return the command.
*/ */
struct TALER_TESTING_Command struct TALER_TESTING_Command
@ -1124,21 +1128,21 @@ TALER_TESTING_cmd_refresh_melt_double
md.coin_reference = coin_reference; md.coin_reference = coin_reference;
md.amount = amount; md.amount = amount;
rms = GNUNET_new (struct RefreshMeltState); rms = GNUNET_new (struct RefreshMeltState);
rms->melted_coin = md; rms->melted_coin = md;
rms->expected_response_code = expected_response_code; rms->expected_response_code = expected_response_code;
rms->double_melt = GNUNET_YES; rms->double_melt = GNUNET_YES;
{
struct TALER_TESTING_Command cmd = {
.label = label,
.cls = rms,
.run = &refresh_melt_run,
.cleanup = &refresh_melt_cleanup,
.traits = &refresh_melt_traits
};
struct TALER_TESTING_Command cmd = { return cmd;
.label = label, }
.cls = rms,
.run = &refresh_melt_run,
.cleanup = &refresh_melt_cleanup,
.traits = &refresh_melt_traits
};
return cmd;
} }
@ -1237,16 +1241,17 @@ TALER_TESTING_cmd_refresh_reveal
rrs = GNUNET_new (struct RefreshRevealState); rrs = GNUNET_new (struct RefreshRevealState);
rrs->melt_reference = melt_reference; rrs->melt_reference = melt_reference;
rrs->expected_response_code = expected_response_code; rrs->expected_response_code = expected_response_code;
{
struct TALER_TESTING_Command cmd = {
.cls = rrs,
.label = label,
.run = &refresh_reveal_run,
.cleanup = &refresh_reveal_cleanup,
.traits = &refresh_reveal_traits
};
struct TALER_TESTING_Command cmd = { return cmd;
.cls = rrs, }
.label = label,
.run = &refresh_reveal_run,
.cleanup = &refresh_reveal_cleanup,
.traits = &refresh_reveal_traits
};
return cmd;
} }

View File

@ -59,7 +59,6 @@ TALER_TESTING_get_trait_denom_pub
* *
* @param index index number to associate to the offered denom pub. * @param index index number to associate to the offered denom pub.
* @param denom_pub denom pub to offer with this trait. * @param denom_pub denom pub to offer with this trait.
*
* @return the trait. * @return the trait.
*/ */
struct TALER_TESTING_Trait struct TALER_TESTING_Trait