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.
*/ */
@ -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);
for (unsigned int i=0; i<num_coins; i++)
const struct TALER_EXCHANGE_DenomPublicKey *fresh_pks; {
struct FreshCoin *fc = &rrs->fresh_coins[i];
if (GNUNET_OK != if (GNUNET_OK !=
TALER_TESTING_get_trait_denom_pub (melt_cmd, TALER_TESTING_get_trait_denom_pub (melt_cmd,
0, i,
&fresh_pks)) &fc->pk))
{ {
GNUNET_break (0); GNUNET_break (0);
TALER_TESTING_interpreter_fail (rrs->is); TALER_TESTING_interpreter_fail (rrs->is);
return; return;
} }
for (unsigned int i=0; i<num_coins; i++)
{
struct FreshCoin *fc = &rrs->fresh_coins[i];
fc->pk = &fresh_pks[i];
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);
@ -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);
@ -941,7 +941,6 @@ refresh_melt_run (void *cls,
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,8 +1044,14 @@ refresh_melt_traits (void *cls,
{ {
struct RefreshMeltState *rms = cls; struct RefreshMeltState *rms = cls;
if (index >= rms->num_fresh_coins)
{
GNUNET_break (0);
return GNUNET_SYSERR;
}
{
struct TALER_TESTING_Trait traits[] = { struct TALER_TESTING_Trait traits[] = {
TALER_TESTING_make_trait_denom_pub (0, rms->fresh_pks), TALER_TESTING_make_trait_denom_pub (index, &rms->fresh_pks[index]),
TALER_TESTING_trait_end () TALER_TESTING_trait_end ()
}; };
@ -1055,6 +1059,7 @@ refresh_melt_traits (void *cls,
ret, ret,
trait, trait,
index); index);
}
} }
@ -1081,11 +1086,10 @@ 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 = { struct TALER_TESTING_Command cmd = {
.label = label, .label = label,
.cls = rms, .cls = rms,
@ -1095,6 +1099,7 @@ TALER_TESTING_cmd_refresh_melt
}; };
return cmd; 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,12 +1128,11 @@ 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 = { struct TALER_TESTING_Command cmd = {
.label = label, .label = label,
.cls = rms, .cls = rms,
@ -1139,6 +1142,7 @@ TALER_TESTING_cmd_refresh_melt_double
}; };
return cmd; return cmd;
}
} }
@ -1237,7 +1241,7 @@ 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 = { struct TALER_TESTING_Command cmd = {
.cls = rrs, .cls = rrs,
.label = label, .label = label,
@ -1247,6 +1251,7 @@ TALER_TESTING_cmd_refresh_reveal
}; };
return cmd; 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