summaryrefslogtreecommitdiff
path: root/src/testing/testing_api_cmd_pay_order.c
diff options
context:
space:
mode:
authorChristian Grothoff <grothoff@gnunet.org>2023-04-02 14:27:27 +0200
committerChristian Grothoff <grothoff@gnunet.org>2023-04-02 14:27:27 +0200
commite1ad6029c397c93e7b5e2f0e296f3db3b6836158 (patch)
tree6fbd0d10841f0bbc5e53949e7c3bb54a12f5c1e6 /src/testing/testing_api_cmd_pay_order.c
parent98ddd97d475d8ea8f382efb0061caaa3134cc124 (diff)
downloadmerchant-e1ad6029c397c93e7b5e2f0e296f3db3b6836158.tar.gz
merchant-e1ad6029c397c93e7b5e2f0e296f3db3b6836158.tar.bz2
merchant-e1ad6029c397c93e7b5e2f0e296f3db3b6836158.zip
fix pos_key logic
Diffstat (limited to 'src/testing/testing_api_cmd_pay_order.c')
-rw-r--r--src/testing/testing_api_cmd_pay_order.c74
1 files changed, 53 insertions, 21 deletions
diff --git a/src/testing/testing_api_cmd_pay_order.c b/src/testing/testing_api_cmd_pay_order.c
index 3a4e0cc7..ac2d9353 100644
--- a/src/testing/testing_api_cmd_pay_order.c
+++ b/src/testing/testing_api_cmd_pay_order.c
@@ -68,6 +68,11 @@ struct PayState
const char *merchant_url;
/**
+ * Total amount to be paid.
+ */
+ struct TALER_Amount total_amount;
+
+ /**
* Amount to be paid, plus the deposit fee.
*/
const char *amount_with_fee;
@@ -102,10 +107,6 @@ struct PayState
*/
enum TALER_MerchantConfirmationAlgorithm pos_alg;
- /**
- * This variable is for the verification of the payment.
- */
- const char *pos_confirmation;
};
@@ -254,20 +255,42 @@ pay_cb (void *cls,
if (MHD_HTTP_OK == pr->hr.http_status)
{
ps->merchant_sig = pr->details.success.merchant_sig;
-#if FIXME
- // FIXME: check if pr->details.success.pos_confirmation;
- // for that, get pos_secret from ps->proposal_reference CMD and amount from pay/order creation cmd using traits
- struct TALER_Amount amount_with_fee;
- GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount (ps->amount_with_fee,
- &amount_with_fee));
- // FIXME: crashes here, because ps->pos_key is NULL
- ps->pos_confirmation = TALER_build_pos_confirmation (ps->pos_key,
- ps->pos_alg,
- &amount_with_fee,
- GNUNET_TIME_timestamp_get());
- ps->pos_confirmation = pr->details.success.pos_confirmation;
-#endif
+ if (NULL != ps->pos_key)
+ {
+ char *pc;
+ bool found = false;
+
+ if (NULL == pr->details.success.pos_confirmation)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (ps->is);
+ return;
+ }
+ pc = TALER_build_pos_confirmation (ps->pos_key,
+ ps->pos_alg,
+ &ps->total_amount,
+ GNUNET_TIME_timestamp_get());
+ /* Check if *any* of our TOTP codes overlaps
+ with any of the returned TOTP codes. */
+ for (const char *tok = strtok (pc, "\n");
+ NULL != tok;
+ tok = strtok (NULL, "\n"))
+ {
+ if (NULL != strstr (pr->details.success.pos_confirmation,
+ tok))
+ {
+ found = true;
+ break;
+ }
+ }
+ GNUNET_free (pc);
+ if (! found)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (ps->is);
+ return;
+ }
+ }
}
TALER_TESTING_interpreter_next (ps->is);
}
@@ -295,13 +318,14 @@ pay_run (void *cls,
struct TALER_MerchantPublicKeyP merchant_pub;
struct TALER_MerchantWireHashP h_wire;
const struct TALER_PrivateContractHashP *h_proposal;
- struct TALER_Amount total_amount;
struct TALER_Amount max_fee;
const char *error_name = NULL;
unsigned int error_line = 0;
struct TALER_MERCHANT_PayCoin *pay_coins;
unsigned int npay_coins;
const struct TALER_MerchantSignatureP *merchant_sig;
+ const char **pos_key_ptr;
+ const enum TALER_MerchantConfirmationAlgorithm *alg_ptr;
ps->is = is;
proposal_cmd = TALER_TESTING_interpreter_lookup_command (
@@ -317,6 +341,14 @@ pay_run (void *cls,
TALER_TESTING_FAIL (is);
if (NULL == contract_terms)
TALER_TESTING_FAIL (is);
+ if (GNUNET_OK ==
+ TALER_TESTING_get_trait_template_pos_key (proposal_cmd,
+ &pos_key_ptr))
+ ps->pos_key = *pos_key_ptr;
+ if (GNUNET_OK ==
+ TALER_TESTING_get_trait_template_pos_alg (proposal_cmd,
+ &alg_ptr))
+ ps->pos_alg = *alg_ptr;
{
/* Get information that needs to be put verbatim in the
* deposit permission */
@@ -334,7 +366,7 @@ pay_run (void *cls,
GNUNET_JSON_spec_fixed_auto ("h_wire",
&h_wire),
TALER_JSON_spec_amount_any ("amount",
- &total_amount),
+ &ps->total_amount),
TALER_JSON_spec_amount_any ("max_fee",
&max_fee),
/* FIXME oec: parse minimum age, use data later? */
@@ -397,7 +429,7 @@ pay_run (void *cls,
ps->merchant_url,
ps->session_id,
h_proposal,
- &total_amount,
+ &ps->total_amount,
&max_fee,
&merchant_pub,
merchant_sig,