From ebfa7888c0cbb461cf70a8d809b1d183011713ce Mon Sep 17 00:00:00 2001 From: Jonathan Buchanan Date: Wed, 24 Jun 2020 00:08:31 -0400 Subject: made a testing trait for order claim nonce --- src/include/taler_merchant_testing_lib.h | 31 ++++++++++++ src/testing/Makefile.am | 1 + src/testing/testing_api_cmd_claim_order.c | 13 +++-- src/testing/testing_api_cmd_post_orders.c | 7 +-- src/testing/testing_api_trait_claim_nonce.c | 76 +++++++++++++++++++++++++++++ 5 files changed, 116 insertions(+), 12 deletions(-) create mode 100644 src/testing/testing_api_trait_claim_nonce.c diff --git a/src/include/taler_merchant_testing_lib.h b/src/include/taler_merchant_testing_lib.h index af14955b..3ae227cd 100644 --- a/src/include/taler_merchant_testing_lib.h +++ b/src/include/taler_merchant_testing_lib.h @@ -1243,6 +1243,37 @@ TALER_TESTING_get_trait_merchant_sig ( struct TALER_MerchantSignatureP **merchant_sig); +/** + * Offer an order claim nonce. + * + * @param index which nonce to offer if there are + * multiple on offer. + * @param nonce set to the offered nonce. + * @return the trait + */ +struct TALER_TESTING_Trait +TALER_TESTING_make_trait_claim_nonce (unsigned int index, + const struct + GNUNET_CRYPTO_EddsaPublicKey *nonce); + + +/** + * Obtain an order claim nonce from a @a cmd. + * + * @param cmd command to extract the trait from. + * @param index which nonce to pick if @a + * cmd has multiple on offer + * @param nonce[out] set to the wanted data. + * + * @return #GNUNET_OK on success + */ +int +TALER_TESTING_get_trait_claim_nonce (const struct TALER_TESTING_Command *cmd, + unsigned int index, + const struct + GNUNET_CRYPTO_EddsaPublicKey **nonce); + + /** * Obtain a reference to a proposal command. Any command that * works with proposals, might need to offer their reference to diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am index 1c9fcb26..6e52b33f 100644 --- a/src/testing/Makefile.am +++ b/src/testing/Makefile.am @@ -49,6 +49,7 @@ libtalermerchanttesting_la_SOURCES = \ testing_api_cmd_wallet_get_order.c \ testing_api_cmd_wallet_get_tip.c \ testing_api_helpers.c \ + testing_api_trait_claim_nonce.c \ testing_api_trait_merchant_sig.c \ testing_api_trait_string.c \ testing_api_trait_hash.c \ diff --git a/src/testing/testing_api_cmd_claim_order.c b/src/testing/testing_api_cmd_claim_order.c index 0cdfff0e..f47ddcc5 100644 --- a/src/testing/testing_api_cmd_claim_order.c +++ b/src/testing/testing_api_cmd_claim_order.c @@ -186,11 +186,9 @@ order_claim_run (void *cls, { struct OrderClaimState *pls = cls; const char *order_id; - const struct TALER_MerchantPublicKeyP *nonce; + const struct GNUNET_CRYPTO_EddsaPublicKey *nonce; /* Only used if we do NOT use the nonce from traits. */ - struct TALER_MerchantPublicKeyP dummy_nonce; -#define GET_TRAIT_NONCE(cmd,ptr) \ - TALER_TESTING_get_trait_merchant_pub (cmd, 1, ptr) + struct GNUNET_CRYPTO_EddsaPublicKey dummy_nonce; pls->is = is; if (NULL != pls->order_id) @@ -211,8 +209,9 @@ order_claim_run (void *cls, if (NULL == order_cmd) TALER_TESTING_FAIL (is); if (GNUNET_OK != - GET_TRAIT_NONCE (order_cmd, - &nonce)) + TALER_TESTING_get_trait_claim_nonce (order_cmd, + 0, + &nonce)) { GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, &dummy_nonce, @@ -229,7 +228,7 @@ order_claim_run (void *cls, pls->och = TALER_MERCHANT_order_claim (is->ctx, pls->merchant_url, order_id, - &nonce->eddsa_pub, + nonce, &order_claim_cb, pls); GNUNET_assert (NULL != pls->och); diff --git a/src/testing/testing_api_cmd_post_orders.c b/src/testing/testing_api_cmd_post_orders.c index 8bdd7862..8e1cc3fc 100644 --- a/src/testing/testing_api_cmd_post_orders.c +++ b/src/testing/testing_api_cmd_post_orders.c @@ -115,17 +115,14 @@ orders_traits (void *cls, unsigned int index) { struct OrdersState *ps = cls; - // FIXME: wtf is this? -#define MAKE_TRAIT_NONCE(ptr) \ - TALER_TESTING_make_trait_merchant_pub ( \ - 1, (struct TALER_MerchantPublicKeyP *) (ptr)) + struct TALER_TESTING_Trait traits[] = { TALER_TESTING_make_trait_order_id (0, ps->order_id), TALER_TESTING_make_trait_contract_terms (0, ps->contract_terms), TALER_TESTING_make_trait_h_contract_terms (0, &ps->h_contract_terms), TALER_TESTING_make_trait_merchant_sig (0, &ps->merchant_sig), TALER_TESTING_make_trait_merchant_pub (0, &ps->merchant_pub), - MAKE_TRAIT_NONCE (&ps->nonce), + TALER_TESTING_make_trait_claim_nonce (0, &ps->nonce), TALER_TESTING_trait_end () }; diff --git a/src/testing/testing_api_trait_claim_nonce.c b/src/testing/testing_api_trait_claim_nonce.c new file mode 100644 index 00000000..96494795 --- /dev/null +++ b/src/testing/testing_api_trait_claim_nonce.c @@ -0,0 +1,76 @@ +/* + This file is part of TALER + Copyright (C) 2020 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 3, or + (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public + License along with TALER; see the file COPYING. If not, see + +*/ +/** + * @file lib/testing_api_trait_claim_nonce.c + * @brief offer a trait that is the nonce used to claim an order. + * @author Jonathan Buchanan + */ +#include "platform.h" +#include +#include +#include + +#define TALER_TESTING_TRAIT_CLAIM_NONCE "nonce" + +/** + * Obtain an order claim nonce from a @a cmd. + * + * @param cmd command to extract the trait from. + * @param index which nonce to pick if @a + * cmd has multiple on offer + * @param nonce[out] set to the wanted data. + * + * @return #GNUNET_OK on success + */ +int +TALER_TESTING_get_trait_claim_nonce + (const struct TALER_TESTING_Command *cmd, + unsigned int index, + const struct GNUNET_CRYPTO_EddsaPublicKey **nonce) +{ + return cmd->traits (cmd->cls, + (const void **) nonce, + TALER_TESTING_TRAIT_CLAIM_NONCE, + index); +} + + +/** + * Offer an order claim nonce. + * + * @param index which nonce to offer if there are + * multiple on offer. + * @param nonce set to the offered nonce. + * @return the trait + */ +struct TALER_TESTING_Trait +TALER_TESTING_make_trait_claim_nonce + (unsigned int index, + const struct GNUNET_CRYPTO_EddsaPublicKey *nonce) +{ + struct TALER_TESTING_Trait ret = { + .index = index, + .trait_name = TALER_TESTING_TRAIT_CLAIM_NONCE, + .ptr = (const void *) nonce + }; + return ret; +} + + +/* end of testing_api_trait_claim_nonce.c */ -- cgit v1.2.3