diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-07-15 21:44:03 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-07-15 21:44:03 +0200 |
commit | 28f790fac5af5d801d5cb7bd3cdfe53f0ac948d2 (patch) | |
tree | 2b10e8a11883852d0869f96f698ff393666ef290 | |
parent | a497ccffb607c7ac4e6461693630d2d673afff73 (diff) |
fix use of index in testing_api_cmd_refresh.c
-rw-r--r-- | src/include/taler_testing_lib.h | 4 | ||||
-rw-r--r-- | src/lib/.gitignore | 1 | ||||
-rw-r--r-- | src/lib/test_exchange_api_revocation.c | 4 | ||||
-rw-r--r-- | src/lib/testing_api_cmd_payback.c | 37 | ||||
-rw-r--r-- | src/lib/testing_api_cmd_refresh.c | 153 | ||||
-rw-r--r-- | src/lib/testing_api_trait_denom_pub.c | 1 |
6 files changed, 119 insertions, 81 deletions
diff --git a/src/include/taler_testing_lib.h b/src/include/taler_testing_lib.h index 99be529b3..2753b36cb 100644 --- a/src/include/taler_testing_lib.h +++ b/src/include/taler_testing_lib.h @@ -1384,7 +1384,9 @@ TALER_TESTING_cmd_refund (const char *label, * @param label the command label * @param expected_response_code expected HTTP status code * @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. * * @return the command. diff --git a/src/lib/.gitignore b/src/lib/.gitignore index 202684432..77a0f711d 100644 --- a/src/lib/.gitignore +++ b/src/lib/.gitignore @@ -1 +1,2 @@ test_auditor_api_version +test_exchange_api_revocation diff --git a/src/lib/test_exchange_api_revocation.c b/src/lib/test_exchange_api_revocation.c index 08be50203..e2e3e4b4f 100644 --- a/src/lib/test_exchange_api_revocation.c +++ b/src/lib/test_exchange_api_revocation.c @@ -161,7 +161,7 @@ run (void *cls, /* Refund coin to original coin */ TALER_TESTING_cmd_payback ("payback-1", MHD_HTTP_OK, - "refresh-melt-1", + "refresh-reveal-1", "EUR:5"), /** * Melt original coin AGAIN @@ -178,7 +178,7 @@ run (void *cls, /* Make refreshed coin invalid */ TALER_TESTING_cmd_revoke ("revoke-2", MHD_HTTP_OK, - "refresh-melt-2", + "refresh-reveal-2", CONFIG_FILE), /* Make also original coin invalid */ TALER_TESTING_cmd_revoke ("revoke-3", diff --git a/src/lib/testing_api_cmd_payback.c b/src/lib/testing_api_cmd_payback.c index 9b49108cd..ac4fd6419 100644 --- a/src/lib/testing_api_cmd_payback.c +++ b/src/lib/testing_api_cmd_payback.c @@ -124,7 +124,6 @@ payback_cb (void *cls, const struct TALER_ReservePublicKeyP *reserve_pub, const json_t *full_response) { - struct PaybackState *ps = cls; struct TALER_TESTING_Interpreter *is = ps->is; struct TALER_TESTING_Command *cmd = &is->commands[is->ip]; @@ -132,6 +131,9 @@ payback_cb (void *cls, const struct TALER_ReservePrivateKeyP *reserve_priv; struct TALER_ReservePublicKeyP rp; struct TALER_Amount expected_amount; + char *cref; + const char *index; + unsigned int idx; ps->ph = NULL; if (ps->expected_response_code != http_status) @@ -148,8 +150,37 @@ payback_cb (void *cls, 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 - (is, ps->coin_reference); + (is, cref); + GNUNET_free (cref); if (NULL == reserve_cmd) { @@ -159,7 +190,7 @@ payback_cb (void *cls, } if (GNUNET_OK != TALER_TESTING_get_trait_reserve_priv - (reserve_cmd, 0, &reserve_priv)) + (reserve_cmd, idx, &reserve_priv)) { GNUNET_break (0); TALER_TESTING_interpreter_fail (is); diff --git a/src/lib/testing_api_cmd_refresh.c b/src/lib/testing_api_cmd_refresh.c index d0b589b12..3a4de783d 100644 --- a/src/lib/testing_api_cmd_refresh.c +++ b/src/lib/testing_api_cmd_refresh.c @@ -83,7 +83,7 @@ struct RefreshMeltState /** * 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; @@ -103,6 +103,11 @@ struct RefreshMeltState size_t refresh_data_length; /** + * Number of fresh coins generated by the melt. + */ + unsigned int num_fresh_coins; + + /** * Expected HTTP response code. */ unsigned int expected_response_code; @@ -282,7 +287,7 @@ do_reveal_retry (void *cls) static void reveal_cb (void *cls, unsigned int http_status, - enum TALER_ErrorCode ec, + enum TALER_ErrorCode ec, unsigned int num_coins, const struct TALER_CoinSpendPrivateKeyP *coin_privs, const struct TALER_DenominationSignature *sigs, @@ -340,24 +345,19 @@ reveal_cb (void *cls, case MHD_HTTP_OK: rrs->fresh_coins = GNUNET_new_array (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++) { 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->sig.rsa_signature = GNUNET_CRYPTO_rsa_signature_dup (sigs[i].rsa_signature); @@ -611,18 +611,18 @@ link_cb (void *cls, for (unsigned int i=0;i<num_coins;i++) for (unsigned int j=0;j<num_coins;j++) { - if ( (0 == GNUNET_memcmp - (&coin_privs[i], &fc[j].coin_priv)) && - (0 == GNUNET_CRYPTO_rsa_signature_cmp - (fc[i].sig.rsa_signature, - sigs[j].rsa_signature)) && - (0 == GNUNET_CRYPTO_rsa_public_key_cmp - (fc[i].pk->key.rsa_public_key, - pubs[j].rsa_public_key)) ) - { - found++; - break; - } + if ( (0 == GNUNET_memcmp + (&coin_privs[i], &fc[j].coin_priv)) && + (0 == GNUNET_CRYPTO_rsa_signature_cmp + (fc[i].sig.rsa_signature, + sigs[j].rsa_signature)) && + (0 == GNUNET_CRYPTO_rsa_public_key_cmp + (fc[i].pk->key.rsa_public_key, + pubs[j].rsa_public_key)) ) + { + found++; + break; + } } if (found != num_coins) { @@ -883,7 +883,7 @@ refresh_melt_run (void *cls, for (num_fresh_coins=0; NULL != melt_fresh_amounts[num_fresh_coins]; num_fresh_coins++) ; - + rms->num_fresh_coins = num_fresh_coins; rms->fresh_pks = GNUNET_new_array (num_fresh_coins, struct TALER_EXCHANGE_DenomPublicKey); @@ -935,13 +935,12 @@ refresh_melt_run (void *cls, return; } if (GNUNET_OK != TALER_TESTING_get_trait_denom_pub - (coin_command, 0, &melt_denom_pub)) + (coin_command, 0, &melt_denom_pub)) { GNUNET_break (0); TALER_TESTING_interpreter_fail (rms->is); return; } - for (unsigned int i=0;i<num_fresh_coins;i++) { const struct TALER_EXCHANGE_DenomPublicKey *fresh_pk; @@ -1035,7 +1034,6 @@ refresh_melt_cleanup (void *cls, * @param ret[out] result (could be anything). * @param trait name of the trait. * @param index index number of the object to offer. - * * @return #GNUNET_OK on success. */ static int @@ -1046,15 +1044,22 @@ refresh_melt_traits (void *cls, { struct RefreshMeltState *rms = cls; - struct TALER_TESTING_Trait traits[] = { - TALER_TESTING_make_trait_denom_pub (0, rms->fresh_pks), - TALER_TESTING_trait_end () - }; - - return TALER_TESTING_get_trait (traits, - ret, - trait, - index); + if (index >= rms->num_fresh_coins) + { + 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, + ret, + trait, + index); + } } @@ -1081,20 +1086,20 @@ TALER_TESTING_cmd_refresh_melt md.coin_reference = coin_reference; md.amount = amount; - rms = GNUNET_new (struct RefreshMeltState); rms->melted_coin = md; 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 - }; - - return cmd; + { + struct TALER_TESTING_Command 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 * a coin to refresh * @param expected_response_code expected HTTP code - * * @return the command. */ struct TALER_TESTING_Command @@ -1124,21 +1128,21 @@ TALER_TESTING_cmd_refresh_melt_double md.coin_reference = coin_reference; md.amount = amount; - rms = GNUNET_new (struct RefreshMeltState); rms->melted_coin = md; rms->expected_response_code = expected_response_code; 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 - }; - - return cmd; + { + struct TALER_TESTING_Command 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->melt_reference = melt_reference; 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 - }; - - return cmd; + { + struct TALER_TESTING_Command cmd = { + .cls = rrs, + .label = label, + .run = &refresh_reveal_run, + .cleanup = &refresh_reveal_cleanup, + .traits = &refresh_reveal_traits + }; + + return cmd; + } } diff --git a/src/lib/testing_api_trait_denom_pub.c b/src/lib/testing_api_trait_denom_pub.c index 448a262c8..8bc482176 100644 --- a/src/lib/testing_api_trait_denom_pub.c +++ b/src/lib/testing_api_trait_denom_pub.c @@ -59,7 +59,6 @@ TALER_TESTING_get_trait_denom_pub * * @param index index number to associate to the offered denom pub. * @param denom_pub denom pub to offer with this trait. - * * @return the trait. */ struct TALER_TESTING_Trait |