diff options
author | Christian Blättler <blatc2@bfh.ch> | 2024-04-26 12:27:44 +0200 |
---|---|---|
committer | Christian Blättler <blatc2@bfh.ch> | 2024-04-26 12:27:44 +0200 |
commit | ceecb31a47c2391bd2edbb2d76632c586e4c839d (patch) | |
tree | 4b3abac2db1f6374b934132fd4c167fd79f82f18 /src | |
parent | 81bb90b4ed036f364fa141c975675912241a01cb (diff) |
build tokens array in test command
Diffstat (limited to 'src')
-rw-r--r-- | src/include/taler_merchant_testing_lib.h | 5 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_pay_order.c | 94 |
2 files changed, 97 insertions, 2 deletions
diff --git a/src/include/taler_merchant_testing_lib.h b/src/include/taler_merchant_testing_lib.h index 5138be31..12d38fb5 100644 --- a/src/include/taler_merchant_testing_lib.h +++ b/src/include/taler_merchant_testing_lib.h @@ -1856,7 +1856,10 @@ TALER_TESTING_cmd_checkserver2 (const char *label, op (http_header, const char) \ op (http_body, const void) \ op (http_body_size, const size_t) \ - op (planchet_secrets, const struct TALER_PlanchetMasterSecretP) + op (planchet_secrets, const struct TALER_PlanchetMasterSecretP) \ + op (token_priv, const struct TALER_TokenUsePrivateKeyP) \ + op (token_issue_sig, const struct TALER_TokenIssueSignatureP) \ + op (token_issue_pub, const struct TALER_TokenIssuePublicKeyP) TALER_MERCHANT_TESTING_SIMPLE_TRAITS (TALER_TESTING_MAKE_DECL_SIMPLE_TRAIT) diff --git a/src/testing/testing_api_cmd_pay_order.c b/src/testing/testing_api_cmd_pay_order.c index f748a06a..071a9a23 100644 --- a/src/testing/testing_api_cmd_pay_order.c +++ b/src/testing/testing_api_cmd_pay_order.c @@ -23,6 +23,7 @@ * @author Christian Grothoff */ #include "platform.h" +#include <gnunet/gnunet_common.h> #include <jansson.h> #include <taler/taler_exchange_service.h> #include <taler/taler_testing_lib.h> @@ -161,6 +162,7 @@ build_coins (struct TALER_MERCHANT_PayCoin **pc, /* Token syntax is "LABEL[/NUMBER]" */ ctok = strchr (token, '/'); + // TODO: Check why this is not used? ci = 0; if (NULL != ctok) { @@ -243,6 +245,93 @@ build_coins (struct TALER_MERCHANT_PayCoin **pc, /** + * Parse the @a pay_references specification and grow the @a tokens + * array with the tokens found, updating @a tokens_num. + * + * @param[in,out] tokens array of tokens found + * @param[in,out] tokens_num length of @a tokens array + * @param[in] pay_references string of ; separated references to pay commands + that issued the tokens. + * @param is interpreter state + * @return #GNUNET_OK on success + */ +static enum GNUNET_GenericReturnValue +build_tokens (struct TALER_MERCHANT_UseToken **tokens, + unsigned int *tokens_num, + char *pay_references, + struct TALER_TESTING_Interpreter *is) +{ + char *ref; + + for (ref = strtok (pay_references, ";"); + NULL != ref; + ref = strtok (NULL, ";")) + { + const struct TALER_TESTING_Command *pay_cmd; + char *slash; + unsigned int index; + struct TALER_MERCHANT_UseToken *token; + + /* Reference syntax is "LABEL[/NUMBER]" */ + slash = strchr (ref, '/'); + index = 0; + if (NULL != slash) + { + *slash = '\0'; + slash++; + if (1 != sscanf (slash, + "%u", + &index)) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + } + + pay_cmd = TALER_TESTING_interpreter_lookup_command (is, ref); + + if (NULL == pay_cmd) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + + GNUNET_array_grow (*tokens, + *tokens_num, + (*tokens_num) + 1); + + token = &((*tokens)[(*tokens_num) - 1]); + + { + const struct TALER_TokenUsePrivateKeyP *token_priv; + const struct TALER_TokenIssueSignatureP *issue_sig; + const struct TALER_TokenIssuePublicKeyP *issue_pub; + + GNUNET_assert (GNUNET_OK == + TALER_TESTING_get_trait_token_priv (pay_cmd, + index, + &token_priv)); + + GNUNET_assert (GNUNET_OK == + TALER_TESTING_get_trait_token_issue_sig (pay_cmd, + index, + &issue_sig)); + + GNUNET_assert (GNUNET_OK == + TALER_TESTING_get_trait_token_issue_pub (pay_cmd, + index, + &issue_pub)); + + token->token_priv = *token_priv; + token->ub_sig = *issue_sig; + token->issue_pub = *issue_pub; + } + } + + return GNUNET_OK; +} + +/** * Function called with the result of a /pay operation. * Checks whether the merchant signature is valid and the * HTTP response code matches our expectation. @@ -456,6 +545,8 @@ pay_run (void *cls, order_id, npay_coins, pay_coins, + 0, + NULL, &pay_cb, ps); GNUNET_array_grow (pay_coins, @@ -625,7 +716,8 @@ TALER_TESTING_cmd_merchant_pay_order (const char *label, amount_with_fee, amount_without_fee, session_id, - -1); + -1, + NULL); } |