gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-merchant] branch master updated: fix pos_key logic


From: gnunet
Subject: [taler-merchant] branch master updated: fix pos_key logic
Date: Sun, 02 Apr 2023 14:27:33 +0200

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository merchant.

The following commit(s) were added to refs/heads/master by this push:
     new e1ad6029 fix pos_key logic
e1ad6029 is described below

commit e1ad6029c397c93e7b5e2f0e296f3db3b6836158
Author: Christian Grothoff <grothoff@gnunet.org>
AuthorDate: Sun Apr 2 14:27:27 2023 +0200

    fix pos_key logic
---
 .../taler-merchant-httpd_post-orders-ID-pay.c      |  2 +-
 .../taler-merchant-httpd_post-using-templates.c    |  1 -
 src/backenddb/plugin_merchantdb_postgres.c         |  7 +-
 src/lib/merchant_api_post_order_claim.c            |  2 +-
 src/testing/test_merchant_api.c                    | 35 +++++++++-
 src/testing/testing_api_cmd_pay_order.c            | 74 ++++++++++++++++------
 src/testing/testing_api_cmd_post_templates.c       |  2 +
 src/testing/testing_api_cmd_post_using_templates.c |  2 +-
 8 files changed, 97 insertions(+), 28 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_post-orders-ID-pay.c 
b/src/backend/taler-merchant-httpd_post-orders-ID-pay.c
index 278bd473..df9bd21e 100644
--- a/src/backend/taler-merchant-httpd_post-orders-ID-pay.c
+++ b/src/backend/taler-merchant-httpd_post-orders-ID-pay.c
@@ -1970,7 +1970,7 @@ generate_success_response (struct PayContext *pc)
     ? NULL
     : TALER_build_pos_confirmation (pc->pos_key,
                                     pc->pos_alg,
-                                    &pc->total_paid,
+                                    &pc->amount,
                                     pc->timestamp);
   resume_pay_with_response (
     pc,
diff --git a/src/backend/taler-merchant-httpd_post-using-templates.c 
b/src/backend/taler-merchant-httpd_post-using-templates.c
index 22a93847..e2fb7d23 100644
--- a/src/backend/taler-merchant-httpd_post-using-templates.c
+++ b/src/backend/taler-merchant-httpd_post-using-templates.c
@@ -118,7 +118,6 @@ TMH_post_using_templates_ID (const struct 
TMH_RequestHandler *rh,
     struct GNUNET_TIME_Relative pay_duration;
     struct TALER_Amount tamount;
     bool no_tamount;
-
     struct GNUNET_JSON_Specification tspec[] = {
       GNUNET_JSON_spec_mark_optional (
         GNUNET_JSON_spec_string ("summary",
diff --git a/src/backenddb/plugin_merchantdb_postgres.c 
b/src/backenddb/plugin_merchantdb_postgres.c
index a5501e1d..b9c18b4f 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -7155,7 +7155,7 @@ postgres_lookup_template (void *cls,
   }
   else
   {
-    uint32_t pos32 = (uint32_t) td->pos_algorithm;
+    uint32_t pos32;
     struct GNUNET_PQ_ResultSpec rs[] = {
       GNUNET_PQ_result_spec_string ("template_description",
                                     &td->template_description),
@@ -7171,13 +7171,16 @@ postgres_lookup_template (void *cls,
                                  &td->template_contract),
       GNUNET_PQ_result_spec_end
     };
+    enum GNUNET_DB_QueryStatus qs;
 
     check_connection (pg);
     td->pos_key = NULL;
-    return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+    qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
                                                      "lookup_template",
                                                      params,
                                                      rs);
+    td->pos_algorithm = (enum TALER_MerchantConfirmationAlgorithm) pos32;
+    return qs;
   }
 }
 
diff --git a/src/lib/merchant_api_post_order_claim.c 
b/src/lib/merchant_api_post_order_claim.c
index 66e58c2a..ebab679a 100644
--- a/src/lib/merchant_api_post_order_claim.c
+++ b/src/lib/merchant_api_post_order_claim.c
@@ -103,7 +103,7 @@ handle_post_order_claim_finished (void *cls,
   };
 
   och->job = NULL;
-  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               "Order claimed with status %u\n",
               (unsigned int) response_code);
 
diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c
index 3cb262cb..b25e7519 100644
--- a/src/testing/test_merchant_api.c
+++ b/src/testing/test_merchant_api.c
@@ -1428,7 +1428,7 @@ run (void *cls,
       merchant_url,
       "template-amount",
       "a different template with an amount",
-      NULL,
+      NULL, /* pos_key */
       TALER_MCA_NONE,
       GNUNET_JSON_PACK (
         GNUNET_JSON_pack_uint64 ("minimum_age", 0),
@@ -1513,6 +1513,39 @@ run (void *cls,
       GNUNET_TIME_UNIT_ZERO_TS,
       GNUNET_TIME_UNIT_FOREVER_TS,
       MHD_HTTP_NOT_FOUND),
+    TALER_TESTING_cmd_merchant_post_templates2 (
+      "post-templates-with-pos-key",
+      merchant_url,
+      "template-key",
+      "a different template with POS KEY",
+      "secret", /* pos_key */
+      TALER_MCA_WITH_PRICE,
+      GNUNET_JSON_PACK (
+        GNUNET_JSON_pack_uint64 ("minimum_age", 0),
+        GNUNET_JSON_pack_time_rel ("pay_duration",
+                                   GNUNET_TIME_UNIT_MINUTES)),
+      MHD_HTTP_NO_CONTENT),
+
+    TALER_TESTING_cmd_merchant_post_using_templates (
+      "using-templates-pos-key",
+      "post-templates-with-pos-key",
+      merchant_url,
+      "1",
+      "summary-1-pos",
+      "EUR:9.98",
+      GNUNET_TIME_UNIT_ZERO_TS,
+      GNUNET_TIME_UNIT_FOREVER_TS,
+      MHD_HTTP_OK),
+    TALER_TESTING_cmd_merchant_pay_order ("pay-with-pos",
+                                          merchant_url,
+                                          MHD_HTTP_OK,
+                                          "using-templates-pos-key",
+                                          "withdraw-coin-xc;withdraw-coin-xd",
+                                          "EUR:4.99",
+                                          "EUR:4.99",
+                                          NULL),
+
+    
     TALER_TESTING_cmd_end ()
   };
 
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
@@ -67,6 +67,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.
    */
@@ -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,
diff --git a/src/testing/testing_api_cmd_post_templates.c 
b/src/testing/testing_api_cmd_post_templates.c
index 15a09125..9c2ef228 100644
--- a/src/testing/testing_api_cmd_post_templates.c
+++ b/src/testing/testing_api_cmd_post_templates.c
@@ -115,6 +115,8 @@ post_templates_cb (void *cls,
     break;
   case MHD_HTTP_NOT_FOUND:
     break;
+  case MHD_HTTP_CONFLICT:
+    break;
   default:
     GNUNET_break (0);
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
diff --git a/src/testing/testing_api_cmd_post_using_templates.c 
b/src/testing/testing_api_cmd_post_using_templates.c
index d5123d5d..e0c9c2e1 100644
--- a/src/testing/testing_api_cmd_post_using_templates.c
+++ b/src/testing/testing_api_cmd_post_using_templates.c
@@ -411,7 +411,7 @@ post_using_templates_traits (void *cls,
     TALER_TESTING_make_trait_merchant_pub (&pts->merchant_pub),
     TALER_TESTING_make_trait_claim_nonce (&pts->nonce),
     TALER_TESTING_make_trait_claim_token (&pts->claim_token),
-    TALER_TESTING_make_trait_template_pos_key (pts->template_pos_key), // 
extract from template creation CMD
+    TALER_TESTING_make_trait_template_pos_key (pts->template_pos_key),
     TALER_TESTING_make_trait_template_pos_alg (pts->template_pos_alg),
     TALER_TESTING_trait_end (),
   };

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]