gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] branch master updated: lib code/tests for claim token


From: gnunet
Subject: [taler-merchant] branch master updated: lib code/tests for claim token
Date: Wed, 29 Jul 2020 08:24:34 +0200

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

jonathan-buchanan pushed a commit to branch master
in repository merchant.

The following commit(s) were added to refs/heads/master by this push:
     new cf42868  lib code/tests for claim token
cf42868 is described below

commit cf42868740b7481d2ebaac4ca0a152fbd9e97a95
Author: Jonathan Buchanan <jonathan.russ.buchanan@gmail.com>
AuthorDate: Wed Jul 29 02:23:55 2020 -0400

    lib code/tests for claim token
---
 src/include/taler_merchant_service.h      |  9 ++++++++-
 src/lib/merchant_api_post_order_claim.c   | 17 ++++++++++++++---
 src/lib/merchant_api_post_orders.c        | 31 ++++++++++++++++++++++++++++---
 src/testing/test_merchant_api_twisted.c   | 28 +++++++++++++++++++++++-----
 src/testing/testing_api_cmd_claim_order.c |  9 +++++++++
 src/testing/testing_api_cmd_post_orders.c | 16 +++++++++++++++-
 6 files changed, 97 insertions(+), 13 deletions(-)

diff --git a/src/include/taler_merchant_service.h 
b/src/include/taler_merchant_service.h
index 8779f09..783520c 100644
--- a/src/include/taler_merchant_service.h
+++ b/src/include/taler_merchant_service.h
@@ -1114,12 +1114,15 @@ struct TALER_MERCHANT_PostOrdersOperation;
  * @param cls closure
  * @param hr HTTP response details
  * @param order_id order id of the newly created order
+ * @param token the claim token generated by the merchant (NULL if
+ *        it wasn't generated).
  */
 typedef void
 (*TALER_MERCHANT_PostOrdersCallback) (
   void *cls,
   const struct TALER_MERCHANT_HttpResponse *hr,
-  const char *order_id);
+  const char *order_id,
+  const struct TALER_ClaimTokenP *token);
 
 
 /**
@@ -1176,6 +1179,7 @@ struct TALER_MERCHANT_InventoryProduct
  * @param inventory_products products to add to the order from the inventory
  * @param lock_uuids_length length of the @a uuids array
  * @param uuids array of UUIDs with locks on @a inventory_products
+ * @param create_token whether to create a claim token
  * @param cb the callback to call when a reply for this request is available
  * @param cb_cls closure for @a cb
  * @return a handle for this request, NULL on error
@@ -1191,6 +1195,7 @@ TALER_MERCHANT_orders_post2 (
   const struct TALER_MERCHANT_InventoryProduct inventory_products[],
   unsigned int uuids_length,
   const struct GNUNET_Uuid uuids[],
+  bool create_token,
   TALER_MERCHANT_PostOrdersCallback cb,
   void *cb_cls);
 
@@ -1809,6 +1814,7 @@ typedef void
  * @param backend_url base URL of the merchant backend
  * @param order_id order id used to perform the lookup
  * @param nonce nonce to use to claim the proposal
+ * @param claim_token the token used to verify the claim
  * @param cb callback which will work the response gotten from the backend
  * @param cb_cls closure to pass to @a cb
  * @return handle for this handle, NULL upon errors
@@ -1818,6 +1824,7 @@ TALER_MERCHANT_order_claim (struct GNUNET_CURL_Context 
*ctx,
                             const char *backend_url,
                             const char *order_id,
                             const struct GNUNET_CRYPTO_EddsaPublicKey *nonce,
+                            const struct TALER_ClaimTokenP *claim_token,
                             TALER_MERCHANT_OrderClaimCallback cb,
                             void *cb_cls);
 
diff --git a/src/lib/merchant_api_post_order_claim.c 
b/src/lib/merchant_api_post_order_claim.c
index 08e4f77..5ec2e24 100644
--- a/src/lib/merchant_api_post_order_claim.c
+++ b/src/lib/merchant_api_post_order_claim.c
@@ -166,13 +166,16 @@ handle_post_order_claim_finished (void *cls,
 
 
 /**
- * Calls the GET /proposal API at the backend.  That is,
- * retrieve a proposal data by providing its transaction id.
+ * Calls the POST /orders/$ID/claim API at the backend.  That is,
+ * retrieve the final contract terms including the client nonce.
+ *
+ * This is a PUBLIC API for wallets.
  *
  * @param ctx execution context
  * @param backend_url base URL of the merchant backend
  * @param order_id order id used to perform the lookup
- * @param nonce nonce used to perform the lookup
+ * @param nonce nonce to use to claim the proposal
+ * @param claim_token the token used to verify the claim
  * @param cb callback which will work the response gotten from the backend
  * @param cb_cls closure to pass to @a cb
  * @return handle for this handle, NULL upon errors
@@ -182,6 +185,7 @@ TALER_MERCHANT_order_claim (struct GNUNET_CURL_Context *ctx,
                             const char *backend_url,
                             const char *order_id,
                             const struct GNUNET_CRYPTO_EddsaPublicKey *nonce,
+                            const struct TALER_ClaimTokenP *claim_token,
                             TALER_MERCHANT_OrderClaimCallback cb,
                             void *cb_cls)
 {
@@ -196,6 +200,13 @@ TALER_MERCHANT_order_claim (struct GNUNET_CURL_Context 
*ctx,
     GNUNET_break (0);
     return NULL;
   }
+  if (NULL != claim_token)
+  {
+    GNUNET_assert (0 ==
+                   json_object_set_new (req_obj,
+                                        "token",
+                                        GNUNET_JSON_from_data_auto 
(claim_token)));
+  }
   och = GNUNET_new (struct TALER_MERCHANT_OrderClaimHandle);
   och->ctx = ctx;
   och->cb = cb;
diff --git a/src/lib/merchant_api_post_orders.c 
b/src/lib/merchant_api_post_orders.c
index f1617aa..1dafeb7 100644
--- a/src/lib/merchant_api_post_orders.c
+++ b/src/lib/merchant_api_post_orders.c
@@ -87,14 +87,23 @@ handle_post_order_finished (void *cls,
 {
   struct TALER_MERCHANT_PostOrdersOperation *po = cls;
   const char *order_id = NULL;
+  struct TALER_ClaimTokenP token;
   const json_t *json = response;
   struct TALER_MERCHANT_HttpResponse hr = {
     .http_status = (unsigned int) response_code,
     .reply = json
   };
+  bool has_token = ((NULL != json_object_get (json,
+                                              "token")) &&
+                    (false == json_is_null (json_object_get (json,
+                                                             "token"))));
   struct GNUNET_JSON_Specification spec[] = {
     GNUNET_JSON_spec_string ("order_id",
                              &order_id),
+    (!has_token) ?
+      GNUNET_JSON_spec_end () :
+      GNUNET_JSON_spec_fixed_auto ("token",
+                                   &token),
     GNUNET_JSON_spec_end ()
   };
 
@@ -161,9 +170,15 @@ handle_post_order_finished (void *cls,
     GNUNET_break_op (0);
     break;
   }
-  po->cb (po->cb_cls,
-          &hr,
-          order_id);
+  {
+    const struct TALER_ClaimTokenP *token_ptr = &token;
+    if (!has_token)
+      token_ptr = NULL;
+    po->cb (po->cb_cls,
+            &hr,
+            order_id,
+            token_ptr);
+  }
   if (MHD_HTTP_OK == response_code)
     GNUNET_JSON_parse_free (spec);
   TALER_MERCHANT_orders_post_cancel (po);
@@ -201,6 +216,7 @@ TALER_MERCHANT_orders_post (struct GNUNET_CURL_Context *ctx,
                                       NULL,
                                       0,
                                       NULL,
+                                      true,
                                       cb,
                                       cb_cls);
 }
@@ -220,6 +236,7 @@ TALER_MERCHANT_orders_post (struct GNUNET_CURL_Context *ctx,
  * @param inventory_products products to add to the order from the inventory
  * @param lock_uuids_length length of the @a uuids array
  * @param uuids array of UUIDs with locks on @a inventory_products
+ * @param create_token whether to create a claim token
  * @param cb the callback to call when a reply for this request is available
  * @param cb_cls closure for @a cb
  * @return a handle for this request, NULL on error
@@ -235,6 +252,7 @@ TALER_MERCHANT_orders_post2 (
   const struct TALER_MERCHANT_InventoryProduct inventory_products[],
   unsigned int uuids_length,
   const struct GNUNET_Uuid uuids[],
+  bool create_token,
   TALER_MERCHANT_PostOrdersCallback cb,
   void *cb_cls)
 {
@@ -316,6 +334,13 @@ TALER_MERCHANT_orders_post2 (
                                         "lock_uuids",
                                         ua));
   }
+  if (true != create_token)
+  {
+    GNUNET_assert (0 ==
+                   json_object_set_new (req,
+                                        "create_token",
+                                        json_boolean (create_token)));
+  }
   eh = curl_easy_init ();
   GNUNET_assert (NULL != eh);
   if (GNUNET_OK != TALER_curl_easy_post (&po->post_ctx,
diff --git a/src/testing/test_merchant_api_twisted.c 
b/src/testing/test_merchant_api_twisted.c
index 3304f4d..6b0ea36 100644
--- a/src/testing/test_merchant_api_twisted.c
+++ b/src/testing/test_merchant_api_twisted.c
@@ -354,17 +354,35 @@ run (void *cls,
                                        "create-reserve-1",
                                        "EUR:5",
                                        MHD_HTTP_OK),
-    TALER_TESTING_cmd_merchant_post_orders ("create-proposal-1",
+
+    TALER_TESTING_cmd_merchant_post_orders_no_claim (
+      "create-proposal-1",
+      merchant_url,
+      MHD_HTTP_OK,
+      "1",
+      GNUNET_TIME_UNIT_ZERO_ABS,
+      GNUNET_TIME_UNIT_FOREVER_ABS,
+      "EUR:6.0"),
+    TALER_TESTING_cmd_flip_upload ("hack-claim-token",
+                                   PROXY_MERCHANT_CONFIG_FILE,
+                                   "token"),
+    TALER_TESTING_cmd_merchant_claim_order (
+      "claim-1-incorrect-claim-token",
+      twister_merchant_url,
+      MHD_HTTP_CONFLICT,
+      "create-proposal-1",
+      NULL),
+    TALER_TESTING_cmd_merchant_post_orders ("create-proposal-2",
                                             merchant_url,
                                             MHD_HTTP_OK,
-                                            "1",
+                                            "2",
                                             GNUNET_TIME_UNIT_ZERO_ABS,
                                             GNUNET_TIME_UNIT_FOREVER_ABS,
                                             "EUR:6.0"),
-    TALER_TESTING_cmd_merchant_pay_order ("deposit-1",
+    TALER_TESTING_cmd_merchant_pay_order ("deposit-2",
                                           merchant_url,
                                           MHD_HTTP_NOT_ACCEPTABLE,
-                                          "create-proposal-1",
+                                          "create-proposal-2",
                                           "withdraw-coin-1",
                                           "EUR:5",
                                           "EUR:4.99",
@@ -373,7 +391,7 @@ run (void *cls,
                                         PROXY_EXCHANGE_CONFIG_FILE),
     TALER_TESTING_cmd_merchant_order_abort ("pay-abort-1",
                                             merchant_url,
-                                            "deposit-1",
+                                            "deposit-2",
                                             MHD_HTTP_INTERNAL_SERVER_ERROR),
     TALER_TESTING_cmd_end ()
   };
diff --git a/src/testing/testing_api_cmd_claim_order.c 
b/src/testing/testing_api_cmd_claim_order.c
index f47ddcc..ab95f59 100644
--- a/src/testing/testing_api_cmd_claim_order.c
+++ b/src/testing/testing_api_cmd_claim_order.c
@@ -187,6 +187,7 @@ order_claim_run (void *cls,
   struct OrderClaimState *pls = cls;
   const char *order_id;
   const struct GNUNET_CRYPTO_EddsaPublicKey *nonce;
+  const struct TALER_ClaimTokenP *claim_token;
   /* Only used if we do NOT use the nonce from traits.  */
   struct GNUNET_CRYPTO_EddsaPublicKey dummy_nonce;
 
@@ -218,6 +219,13 @@ order_claim_run (void *cls,
                                   sizeof (dummy_nonce));
       nonce = &dummy_nonce;
     }
+    if (GNUNET_OK !=
+        TALER_TESTING_get_trait_claim_token (order_cmd,
+                                             0,
+                                             &claim_token))
+    {
+      TALER_TESTING_FAIL (is);
+    }
 
     if (GNUNET_OK !=
         TALER_TESTING_get_trait_order_id (order_cmd,
@@ -229,6 +237,7 @@ order_claim_run (void *cls,
                                          pls->merchant_url,
                                          order_id,
                                          nonce,
+                                         claim_token,
                                          &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 8936985..119245a 100644
--- a/src/testing/testing_api_cmd_post_orders.c
+++ b/src/testing/testing_api_cmd_post_orders.c
@@ -77,6 +77,11 @@ struct OrdersState
    */
   struct GNUNET_CRYPTO_EddsaPublicKey nonce;
 
+  /**
+   * The claim token
+   */
+  struct TALER_ClaimTokenP *claim_token;
+
   /**
    * URL of the merchant backend.
    */
@@ -143,6 +148,7 @@ orders_traits (void *cls,
     TALER_TESTING_make_trait_merchant_sig (0, &ps->merchant_sig),
     TALER_TESTING_make_trait_merchant_pub (0, &ps->merchant_pub),
     TALER_TESTING_make_trait_claim_nonce (0, &ps->nonce),
+    TALER_TESTING_make_trait_claim_token (0, ps->claim_token),
     TALER_TESTING_trait_end ()
   };
 
@@ -225,11 +231,15 @@ orders_claim_cb (void *cls,
 static void
 order_cb (void *cls,
           const struct TALER_MERCHANT_HttpResponse *hr,
-          const char *order_id)
+          const char *order_id,
+          const struct TALER_ClaimTokenP *claim_token)
 {
   struct OrdersState *ps = cls;
 
   ps->po = NULL;
+  if (NULL != claim_token)
+    ps->claim_token = GNUNET_memdup (claim_token,
+                                     sizeof (struct TALER_ClaimTokenP));
   if (ps->http_status != hr->http_status)
   {
     TALER_LOG_ERROR ("Given vs expected: %u(%d) vs %u\n",
@@ -279,6 +289,7 @@ order_cb (void *cls,
                                              ps->merchant_url,
                                              ps->order_id,
                                              &ps->nonce,
+                                             ps->claim_token,
                                              &orders_claim_cb,
                                              ps)))
     TALER_TESTING_FAIL (ps->is);
@@ -467,6 +478,7 @@ orders_run2 (void *cls,
                                         products,
                                         locks_length,
                                         locks,
+                                        true,
                                         &order_cb,
                                         ps);
   json_decref (order);
@@ -517,6 +529,8 @@ orders_cleanup (void *cls,
   json_decref (ps->contract_terms);
   GNUNET_free (ps->order);
   GNUNET_free_nz ((void *) ps->order_id);
+  if (NULL != ps->claim_token)
+    GNUNET_free (ps->claim_token);
   GNUNET_free (ps);
 }
 

-- 
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]