gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] 207/277: test DELETE /private/reserves/


From: gnunet
Subject: [taler-merchant] 207/277: test DELETE /private/reserves/
Date: Sun, 05 Jul 2020 20:52:00 +0200

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

grothoff pushed a commit to branch master
in repository merchant.

commit 2f853bebd269b51536bc357c9ae76d5aa24b9d3a
Author: Jonathan Buchanan <jonathan.russ.buchanan@gmail.com>
AuthorDate: Sat Jun 13 03:22:22 2020 -0400

    test DELETE /private/reserves/
---
 src/backend/taler-merchant-httpd.c           |   2 +-
 src/include/taler_merchant_testing_lib.h     |  37 ++++
 src/testing/Makefile.am                      |   3 +-
 src/testing/test_merchant_api.c              |  12 ++
 src/testing/testing_api_cmd_delete_reserve.c | 245 +++++++++++++++++++++++++++
 src/testing/testing_api_cmd_post_reserves.c  |  41 ++++-
 6 files changed, 337 insertions(+), 3 deletions(-)

diff --git a/src/backend/taler-merchant-httpd.c 
b/src/backend/taler-merchant-httpd.c
index f9eed14..c9b22dd 100644
--- a/src/backend/taler-merchant-httpd.c
+++ b/src/backend/taler-merchant-httpd.c
@@ -857,7 +857,7 @@ url_handler (void *cls,
     },
     /* DELETE /reserves/$ID: */
     {
-      .url_prefix = "/reserves",
+      .url_prefix = "/reserves/",
       .have_id_segment = true,
       .method = MHD_HTTP_METHOD_DELETE,
       .handler = &TMH_private_delete_reserves_ID
diff --git a/src/include/taler_merchant_testing_lib.h 
b/src/include/taler_merchant_testing_lib.h
index c38ac88..9fb9e57 100644
--- a/src/include/taler_merchant_testing_lib.h
+++ b/src/include/taler_merchant_testing_lib.h
@@ -562,6 +562,7 @@ TALER_TESTING_cmd_merchant_get_transfers (const char *label,
 
 /* ******************* /reserves *************** */
 
+
 /**
  * Define a "POST /reserves" CMD
  *
@@ -581,6 +582,41 @@ TALER_TESTING_cmd_merchant_post_reserves (const char 
*label,
                                           const char *wire_method,
                                           unsigned int http_status);
 
+
+/**
+ * Define a "DELETE reserve" CMD.
+ *
+ * @param label command label.
+ * @param merchant_url base URL of the merchant serving the
+ *        DELETE /reserves/$RESERVE_PUB request.
+ * @param reserve_reference command label of a command providing a reserve
+ * @param http_status expected HTTP response code.
+ * @return the command.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_merchant_delete_reserve (const char *label,
+                                           const char *merchant_url,
+                                           const char *reserve_reference,
+                                           unsigned int http_status);
+
+
+/**
+ * Define a "PURGE reserve" CMD.
+ *
+ * @param label command label.
+ * @param merchant_url base URL of the merchant serving the
+ *        DELETE /reserves/$RESERVE_PUB request.
+ * @param reserve_reference command label of a command providing a reserve
+ * @param http_status expected HTTP response code.
+ * @return the command.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_merchant_purge_reserve (const char *label,
+                                          const char *merchant_url,
+                                          const char *reserve_reference,
+                                          unsigned int http_status);
+
+
 /**
  * Define a get tips CMD.
  *
@@ -595,6 +631,7 @@ TALER_TESTING_cmd_get_tips (const char *label,
                             const char *merchant_url,
                             unsigned int http_status);
 
+
 /* ******************** OLD ******************* */
 
 
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am
index 985db0c..c7becfd 100644
--- a/src/testing/Makefile.am
+++ b/src/testing/Makefile.am
@@ -25,12 +25,13 @@ libtalermerchanttesting_la_SOURCES = \
   testing_api_cmd_get_transfers.c \
   testing_api_cmd_delete_instance.c \
   testing_api_cmd_delete_product.c \
+  testing_api_cmd_delete_reserve.c \
   testing_api_cmd_lock_product.c \
   testing_api_cmd_pay_order.c \
   testing_api_cmd_post_instances.c \
   testing_api_cmd_post_orders.c \
   testing_api_cmd_post_products.c \
-       testing_api_cmd_post_reserves.c \
+  testing_api_cmd_post_reserves.c \
   testing_api_cmd_post_transfers.c \
   testing_api_cmd_patch_instance.c \
   testing_api_cmd_patch_product.c \
diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c
index 5ca5ec6..05ed298 100644
--- a/src/testing/test_merchant_api.c
+++ b/src/testing/test_merchant_api.c
@@ -651,6 +651,18 @@ run (void *cls,
     TALER_TESTING_cmd_get_tips ("get-tips-1",
                                 merchant_url,
                                 MHD_HTTP_OK),
+    TALER_TESTING_cmd_merchant_delete_reserve ("delete-reserve-tip-1",
+                                               merchant_url,
+                                               "create-reserve-tip-1",
+                                               MHD_HTTP_NO_CONTENT),
+    TALER_TESTING_cmd_merchant_purge_reserve ("delete-reserve-tip-1",
+                                              merchant_url,
+                                              "create-reserve-tip-1",
+                                              MHD_HTTP_NO_CONTENT),
+    TALER_TESTING_cmd_merchant_purge_reserve ("delete-reserve-tip-1",
+                                              merchant_url,
+                                              "create-reserve-tip-1",
+                                              MHD_HTTP_NOT_FOUND),
 #if 0
     /* Test tipping.  */
     TALER_TESTING_cmd_admin_add_incoming_with_instance ("create-reserve-tip-1",
diff --git a/src/testing/testing_api_cmd_delete_reserve.c 
b/src/testing/testing_api_cmd_delete_reserve.c
new file mode 100644
index 0000000..fe746d4
--- /dev/null
+++ b/src/testing/testing_api_cmd_delete_reserve.c
@@ -0,0 +1,245 @@
+/*
+  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
+  <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file lib/testing_api_cmd_delete_reserve.c
+ * @brief command to test DELETE /reserves/$RESERVE_PUB
+ * @author Jonathan Buchanan
+ */
+#include "platform.h"
+#include <taler/taler_exchange_service.h>
+#include <taler/taler_testing_lib.h>
+#include "taler_merchant_service.h"
+#include "taler_merchant_testing_lib.h"
+
+
+/**
+ * State of a "DELETE /reserves/$RESERVE_PUB" CMD.
+ */
+struct DeleteReserveState
+{
+
+  /**
+   * Handle for a "DELETE reserve" request.
+   */
+  struct TALER_MERCHANT_ReserveDeleteHandle *rdh;
+
+  /**
+   * The interpreter state.
+   */
+  struct TALER_TESTING_Interpreter *is;
+
+  /**
+   * Base URL of the merchant serving the request.
+   */
+  const char *merchant_url;
+
+  /**
+   * Reference to a command that provides a reserve.
+   */
+  const char *reserve_reference;
+
+  /**
+   * Expected HTTP response code.
+   */
+  unsigned int http_status;
+
+  /**
+   * Use purge, not delete.
+   */
+  bool purge;
+
+};
+
+
+/**
+ * Callback for a DELETE /reserves/$RESERVE_PUB operation.
+ *
+ * @param cls closure for this function
+ */
+static void
+delete_reserve_cb (void *cls,
+                   const struct TALER_MERCHANT_HttpResponse *hr)
+{
+  struct DeleteReserveState *drs = cls;
+
+  drs->rdh = NULL;
+  if (drs->http_status != hr->http_status)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Unexpected response code %u (%d) to command %s\n",
+                hr->http_status,
+                (int) hr->ec,
+                TALER_TESTING_interpreter_get_current_label (drs->is));
+    TALER_TESTING_interpreter_fail (drs->is);
+    return;
+  }
+  switch (hr->http_status)
+  {
+  case MHD_HTTP_NO_CONTENT:
+    break;
+  case MHD_HTTP_NOT_FOUND:
+    break;
+  case MHD_HTTP_CONFLICT:
+    break;
+  default:
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "Unhandled HTTP status.\n");
+  }
+  TALER_TESTING_interpreter_next (drs->is);
+}
+
+
+/**
+ * Run the "DELETE reserve" CMD.
+ *
+ * @param cls closure.
+ * @param cmd command being run now.
+ * @param is interpreter state.
+ */
+static void
+delete_reserve_run (void *cls,
+                    const struct TALER_TESTING_Command *cmd,
+                    struct TALER_TESTING_Interpreter *is)
+{
+  struct DeleteReserveState *drs = cls;
+  const struct TALER_TESTING_Command *reserve_cmd;
+  const struct TALER_ReservePublicKeyP *reserve_pub;
+
+  reserve_cmd = TALER_TESTING_interpreter_lookup_command (
+    is,
+    drs->reserve_reference);
+  if (GNUNET_OK !=
+      TALER_TESTING_get_trait_reserve_pub (reserve_cmd,
+                                           0,
+                                           &reserve_pub))
+    TALER_TESTING_FAIL (is);
+
+  drs->is = is;
+  if (drs->purge)
+    drs->rdh = TALER_MERCHANT_reserve_purge (is->ctx,
+                                             drs->merchant_url,
+                                             reserve_pub,
+                                             &delete_reserve_cb,
+                                             drs);
+  else
+    drs->rdh = TALER_MERCHANT_reserve_delete (is->ctx,
+                                              drs->merchant_url,
+                                              reserve_pub,
+                                              &delete_reserve_cb,
+                                              drs);
+
+  GNUNET_assert (NULL != drs->rdh);
+}
+
+
+/**
+ * Free the state of a "DELETE reserve" CMD, and possibly
+ * cancel a pending operation thereof.
+ *
+ * @param cls closure.
+ * @param cmd command being run.
+ */
+static void
+delete_reserve_cleanup (void *cls,
+                        const struct TALER_TESTING_Command *cmd)
+{
+  struct DeleteReserveState *drs = cls;
+
+  if (NULL != drs->rdh)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "DELETE /reserves/$RESERVE_PUB operation did not complete\n");
+    TALER_MERCHANT_reserve_delete_cancel (drs->rdh);
+  }
+  GNUNET_free (drs);
+}
+
+
+/**
+ * Define a "DELETE reserve" CMD.
+ *
+ * @param label command label.
+ * @param merchant_url base URL of the merchant serving the
+ *        DELETE /reserves/$RESERVE_PUB request.
+ * @param reserve_reference command label of a command providing a reserve
+ * @param http_status expected HTTP response code.
+ * @return the command.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_merchant_delete_reserve (const char *label,
+                                           const char *merchant_url,
+                                           const char *reserve_reference,
+                                           unsigned int http_status)
+{
+  struct DeleteReserveState *drs;
+
+  drs = GNUNET_new (struct DeleteReserveState);
+  drs->merchant_url = merchant_url;
+  drs->reserve_reference = reserve_reference;
+  drs->http_status = http_status;
+  {
+    struct TALER_TESTING_Command cmd = {
+      .cls = drs,
+      .label = label,
+      .run = &delete_reserve_run,
+      .cleanup = &delete_reserve_cleanup
+    };
+
+    return cmd;
+  }
+}
+
+
+/**
+ * Define a "PURGE reserve" CMD.
+ *
+ * @param label command label.
+ * @param merchant_url base URL of the merchant serving the
+ *        DELETE /reserves/$RESERVE_PUB request.
+ * @param reserve_reference command label of a command providing a reserve
+ * @param http_status expected HTTP response code.
+ * @return the command.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_merchant_purge_reserve (const char *label,
+                                          const char *merchant_url,
+                                          const char *reserve_reference,
+                                          unsigned int http_status)
+{
+  struct DeleteReserveState *drs;
+
+  drs = GNUNET_new (struct DeleteReserveState);
+  drs->merchant_url = merchant_url;
+  drs->reserve_reference = reserve_reference;
+  drs->http_status = http_status;
+  drs->purge = true;
+  {
+    struct TALER_TESTING_Command cmd = {
+      .cls = drs,
+      .label = label,
+      .run = &delete_reserve_run,
+      .cleanup = &delete_reserve_cleanup
+    };
+
+    return cmd;
+  }
+}
+
+
+/* end of testing_api_cmd_delete_reserve.c */
diff --git a/src/testing/testing_api_cmd_post_reserves.c 
b/src/testing/testing_api_cmd_post_reserves.c
index 573d004..e9bd63a 100644
--- a/src/testing/testing_api_cmd_post_reserves.c
+++ b/src/testing/testing_api_cmd_post_reserves.c
@@ -66,6 +66,11 @@ struct PostReservesState
    * Expected HTTP response code.
    */
   unsigned int http_status;
+
+  /**
+   * Public key assigned to the reserve
+   */
+  struct TALER_ReservePublicKeyP *reserve_pub;
 };
 
 /**
@@ -111,10 +116,42 @@ post_reserves_cb (void *cls,
                 "Unhandled HTTP status (%d).\n",
                 hr->http_status);
   }
+  prs->reserve_pub = GNUNET_memdup (reserve_pub,
+                                    sizeof (struct TALER_ReservePublicKeyP));
+  GNUNET_assert (NULL != prs->reserve_pub);
   TALER_TESTING_interpreter_next (prs->is);
 }
 
 
+/**
+ * Offers information from the POST /reserves CMD state to other
+ * commands.
+ *
+ * @param cls closure
+ * @param ret[out] result (could be anything)
+ * @param trait name of the trait
+ * @param index index number of the object to extract.
+ * @return #GNUNET_OK on success
+ */
+static int
+post_reserves_traits (void *cls,
+                      const void **ret,
+                      const char *trait,
+                      unsigned int index)
+{
+  struct PostReservesState *prs = cls;
+  struct TALER_TESTING_Trait traits[] = {
+    TALER_TESTING_make_trait_reserve_pub (0, prs->reserve_pub),
+    TALER_TESTING_trait_end (),
+  };
+
+  return TALER_TESTING_get_trait (traits,
+                                  ret,
+                                  trait,
+                                  index);
+}
+
+
 /**
  * Run the "POST /reserves" CMD.
  *
@@ -160,6 +197,7 @@ post_reserves_cleanup (void *cls,
                 "POST /reserves operation did not complete\n");
     TALER_MERCHANT_reserves_post_cancel (prs->prh);
   }
+  GNUNET_free (prs->reserve_pub);
   GNUNET_free (prs);
 }
 
@@ -198,7 +236,8 @@ TALER_TESTING_cmd_merchant_post_reserves (const char *label,
       .cls = prs,
       .label = label,
       .run = &post_reserves_run,
-      .cleanup = &post_reserves_cleanup
+      .cleanup = &post_reserves_cleanup,
+      .traits = &post_reserves_traits
     };
 
     return cmd;

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