gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] branch master updated (5f1f5fc8 -> 1954f2de)


From: gnunet
Subject: [taler-merchant] branch master updated (5f1f5fc8 -> 1954f2de)
Date: Wed, 15 Feb 2023 15:54:48 +0100

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

priscilla-huang pushed a change to branch master
in repository merchant.

    from 5f1f5fc8 -new taler option required
     new 98dfff89 stashing my changes for pull
     new 88fa748e pull all the changes in the merchant directory
     new 1954f2de check the pending webhook with web server, test of web server 
is ok

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/include/taler_merchant_testing_lib.h    |  16 +-
 src/testing/Makefile.am                     |   2 +-
 src/testing/test_merchant_api.c             |   9 +-
 src/testing/testing_api_cmd_checkserver.c   | 263 ++++++++++++++++++++++++++++
 src/testing/testing_api_cmd_post_webhooks.c |   4 +-
 src/testing/testing_api_cmd_testserver.c    | 183 +++++++++----------
 6 files changed, 360 insertions(+), 117 deletions(-)
 create mode 100644 src/testing/testing_api_cmd_checkserver.c

diff --git a/src/include/taler_merchant_testing_lib.h 
b/src/include/taler_merchant_testing_lib.h
index 9ac15909..e0ffcccf 100644
--- a/src/include/taler_merchant_testing_lib.h
+++ b/src/include/taler_merchant_testing_lib.h
@@ -1793,6 +1793,8 @@ TALER_TESTING_cmd_testserver (const char *label,
  * This function is used to check the web server
  *
  * @param label command label
+ * @param ref_operation reference to command to the previous set server status 
operation.
+ * @param index index to know which web server we check.
  * @param url of the webhook
  * @param http_method of the webhook
  * @param header of the webhook
@@ -1801,12 +1803,8 @@ TALER_TESTING_cmd_testserver (const char *label,
  */
 struct TALER_TESTING_Command
 TALER_TESTING_cmd_checkserver (const char *label,
-                               char *url,
-                               char *http_method,
-                               char *header,
-                               char *body,
-                               uint16_t port);
-
+                               const char *ref_operation,
+                               unsigned int index);
 
 /* ****** Specific traits supported by this component ******* */
 
@@ -1854,8 +1852,8 @@ TALER_TESTING_cmd_checkserver (const char *label,
   op (template_id, const char *) \
   op (template_contract, const json_t) \
   op (event_type, const char *)   \
-  op (url, const char *) \
   op (webhook_id, const char *) \
+  op (url, const char *) \
   op (http_method, const char *)   \
   op (header_template, const char *)   \
   op (body_template, const char *)   \
@@ -1872,6 +1870,10 @@ TALER_TESTING_cmd_checkserver (const char *label,
   op (paths, const char *) \
   op (payto_uris, const char *) \
   op (amounts, const struct TALER_Amount) \
+  op (urls, char *) \
+  op (http_methods, char *)   \
+  op (http_header, char *)   \
+  op (http_body, char *)   \
   op (planchet_secrets, const struct TALER_PlanchetMasterSecretP)
 
 
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am
index 74a818b7..7caaa7ea 100644
--- a/src/testing/Makefile.am
+++ b/src/testing/Makefile.am
@@ -70,7 +70,6 @@ libtalermerchanttesting_la_SOURCES = \
   testing_api_cmd_patch_template.c \
   testing_api_cmd_patch_webhook.c \
   testing_api_cmd_refund_order.c \
-   \
   testing_api_cmd_tip_authorize.c \
   testing_api_cmd_tip_pickup.c \
   testing_api_cmd_wallet_get_order.c \
@@ -78,6 +77,7 @@ libtalermerchanttesting_la_SOURCES = \
   testing_api_cmd_wallet_post_orders_refund.c \
   testing_api_cmd_webhook.c \
   testing_api_cmd_testserver.c \
+  testing_api_cmd_checkserver.c \
   testing_api_helpers.c \
   testing_api_traits.c
 
diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c
index 1d8a4d96..7200e86b 100644
--- a/src/testing/test_merchant_api.c
+++ b/src/testing/test_merchant_api.c
@@ -1,6 +1,6 @@
 /*
   This file is part of TALER
-  Copyright (C) 2014-2022 Taler Systems SA
+  Copyright (C) 2014-2023 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
@@ -438,11 +438,8 @@ run (void *cls,
     /* Check webhook did anything: have a command that inspects traits of the 
testserver
      and check if the traits have the right values set! */
     TALER_TESTING_cmd_checkserver ("check-http-server-for-webhooks",
-                                   "http://localhost:12345/";,
-                                   "POST",
-                                   "Authorization: EFEHYJS",
-                                   "5.0 EUR",
-                                   12345),
+                                   "launch-http-server-for-webhooks",
+                                   0),
     /* Here we expect to run into a timeout, as we do not pay this one */
     TALER_TESTING_cmd_wallet_poll_order_conclude2 ("poll-order-1x-conclude",
                                                    MHD_HTTP_PAYMENT_REQUIRED,
diff --git a/src/testing/testing_api_cmd_checkserver.c 
b/src/testing/testing_api_cmd_checkserver.c
new file mode 100644
index 00000000..1414bd1d
--- /dev/null
+++ b/src/testing/testing_api_cmd_checkserver.c
@@ -0,0 +1,263 @@
+/*
+  This file is part of TALER
+  Copyright (C) 2023 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 testing/testing_api_cmd_checkserver.c
+ * @brief Implement a CMD to run an Checkserver service for faking the 
legitimation service
+ * @author Priscilla HUANG
+ */
+#include "platform.h"
+#include "taler/taler_json_lib.h"
+#include <gnunet/gnunet_curl_lib.h>
+#include "taler/taler_testing_lib.h"
+#include "taler/taler_mhd_lib.h"
+#include "taler_merchant_testing_lib.h"
+#include "taler_merchant_service.h"
+#include <taler/taler_exchange_service.h>
+
+
+/**
+ * State for a "check_aml_decision" CMD.
+ */
+struct CheckState
+{
+  /**
+   * Handle to the "testserver" service.
+   */
+  struct MHD_Daemon *mhd;
+
+  /**
+   * Our interpreter.
+   */
+  struct TALER_TESTING_Interpreter *is;
+
+  /**
+   * Index to know which web server we check.
+   */
+  unsigned int index;
+
+  /**
+   * Reference to command to the previous set server status operation.
+   */
+  const char *ref_operation;
+
+  /**
+   * Expected method of the pending webhook.
+   */
+  char *expected_method;
+
+  /**
+   * Expected url of the pending webhook.
+   */
+  char *expected_url;
+
+  /**
+   * Expected header of the pending webhook.
+   */
+  char *expected_header;
+
+  /**
+   * Expected body of the pending webhook.
+   */
+  char *expected_body;
+
+};
+
+/**
+ * Run the command.
+ *
+ * @param cls closure.
+ * @param cmd the command to execute.
+ * @param is the interpreter state.
+ */
+static void
+checkserver_run (void *cls,
+                 const struct TALER_TESTING_Command *cmd,
+                 struct TALER_TESTING_Interpreter *is)
+{
+  struct CheckState *cs = cls;
+  const struct TALER_TESTING_Command *ref;
+  (void) cmd;
+  cs->is = is;
+
+  ref = TALER_TESTING_interpreter_lookup_command (is,
+                                                  cs->ref_operation);
+
+
+  if (NULL == ref)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  "ref NULL\n");
+    GNUNET_break (0);
+    TALER_TESTING_interpreter_fail (is);
+    return;
+  }
+
+  char **expected_url;
+  if (GNUNET_OK !=
+      TALER_TESTING_get_trait_urls (ref,
+                                    cs->index,
+                                    &expected_url))
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  "Trait url does not work\n");
+      GNUNET_break (0);
+      TALER_TESTING_interpreter_fail (is);
+      return;
+    }
+  if (NULL == *expected_url)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  "Trait for url is NULL!?\n");
+      GNUNET_break (0);
+      TALER_TESTING_interpreter_fail (is);
+      return;
+    }
+
+  if (0 != strcmp (cs->expected_url,
+                   *expected_url))
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  "URL does not match: `%s' != `%s'\n",
+                  cs->expected_url,
+                  *expected_url);
+      TALER_TESTING_interpreter_fail (is);
+      return;
+    }
+
+  char **expected_http_method;
+
+  if (GNUNET_OK !=
+      TALER_TESTING_get_trait_http_methods (ref,
+                                            cs->index,
+                                            &expected_http_method))
+    TALER_TESTING_interpreter_fail (is);
+  if (0 != strcmp (cs->expected_method,
+                   *expected_http_method))
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  "http_method does not match\n");
+      TALER_TESTING_interpreter_fail (is);
+      return;
+    }
+
+
+  char **expected_header;
+
+  if (GNUNET_OK !=
+      TALER_TESTING_get_trait_http_header (ref,
+                                           cs->index,
+                                           &expected_header))
+    TALER_TESTING_interpreter_fail (is);
+  if ( ( (NULL == cs->expected_header) && (NULL != *expected_header)) ||
+       ( (NULL != cs->expected_header) && (NULL == expected_header)) ||
+       ( (NULL != cs->expected_header) &&
+         (0 != strcmp (cs->expected_header,
+                       *expected_header)) ) )
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  "header does not match: `%s' != `%s'\n",
+                  cs->expected_header,
+                  *expected_header);
+        TALER_TESTING_interpreter_fail (is);
+        return;
+    }
+
+  char **expected_body;
+
+  if (GNUNET_OK !=
+      TALER_TESTING_get_trait_http_body (ref,
+                                         cs->index,
+                                         &expected_body))
+    TALER_TESTING_interpreter_fail (is);
+  if ( ( (NULL == cs->expected_body) && (NULL != *expected_body)) ||
+       ( (NULL != cs->expected_body) && (NULL == expected_body)) ||
+       ( (NULL != cs->expected_body) &&
+         (0 != strcmp (cs->expected_body,
+                       *expected_body) ) ) )
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  "body does not match : `%s' and `%s'\n",
+                  cs->expected_body,
+                  *expected_body);
+      TALER_TESTING_interpreter_fail (is);
+      return;
+    }
+
+  TALER_TESTING_interpreter_next (is);
+}
+
+
+/**
+ * This function is used to check the web server
+ *
+ * @param label command label
+ * @param ref_operation reference to command to the previous set server status 
operation.
+ * @param index index to know which web server we check.
+ * @param url of the webhook
+ * @param http_method of the webhook
+ * @param header of the webhook
+ * @param body of the webhook
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_checkserver2 (const char *label,
+                                const char *ref_operation,
+                                unsigned int index,
+                                char *expected_url,
+                                char *expected_method,
+                                char *expected_header,
+                                char *expected_body)
+{
+  struct CheckState *cs;
+
+  cs = GNUNET_new (struct CheckState);
+  cs->ref_operation = ref_operation;
+  cs->index = index;
+  cs->expected_url = expected_url;
+  cs->expected_method = expected_method;
+  cs->expected_header = expected_header;
+  cs->expected_body = expected_body;
+
+  {
+    struct TALER_TESTING_Command cmd = {
+      .cls = cs,
+      .label = label,
+      .run = &checkserver_run
+    };
+
+    return cmd;
+  }
+}
+
+
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_checkserver (const char *label,
+                               const char *ref_operation,
+                               unsigned int index)
+{
+  return TALER_TESTING_cmd_checkserver2 (label,
+                                         ref_operation,
+                                         index,
+                                         "/",
+                                         "POST",
+                                         "EFEHYJS-Bakery",
+                                         "5.0 EUR");
+}
+
+/* end of testing_api_cmd_checkserver.c */
diff --git a/src/testing/testing_api_cmd_post_webhooks.c 
b/src/testing/testing_api_cmd_post_webhooks.c
index 2a16a990..924a474a 100644
--- a/src/testing/testing_api_cmd_post_webhooks.c
+++ b/src/testing/testing_api_cmd_post_webhooks.c
@@ -270,8 +270,8 @@ TALER_TESTING_cmd_merchant_post_webhooks (const char *label,
     event_type,
     "http://localhost:12345/";,
     "POST",
-    "Authorization: EFEHYJS",
-    "{{amount.val}}.{{amount.frac}} {{amount.currency}}",
+    "Taler-test-header: EFEHYJS-Bakery",
+    "5.0 EUR",
     http_status);
 }
 
diff --git a/src/testing/testing_api_cmd_testserver.c 
b/src/testing/testing_api_cmd_testserver.c
index 77f0e692..d06ce824 100644
--- a/src/testing/testing_api_cmd_testserver.c
+++ b/src/testing/testing_api_cmd_testserver.c
@@ -1,6 +1,6 @@
 /*
   This file is part of TALER
-  Copyright (C) 2021 Taler Systems SA
+  Copyright (C) 2023 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
@@ -47,57 +47,43 @@ struct TestserverState
    */
   uint16_t port;
 
-  // FIXME: record URL, HTTP method, HTTP headers, HTTP body here!
+  struct RequestCtx **rcs;
+
+  unsigned int rcs_length;
+};
+
+
+struct RequestCtx
+{
   /**
    * URL where we are redirect.
    */
-  const char *url;
+  char *url;
 
   /**
    * http method of the webhook.
    */
-  const char *http_method;
+  char *http_method;
 
   /**
    * header of the webhook.
    */
-  const char *header;
+  char *header;
 
   /**
    * body of the webhook.
    */
-  const char *body;
-  // => expose as trait
-};
+  char *body;
 
+  /**
+   * size of the body
+   */
+  size_t body_size;
 
-struct RequestCtx
-{
-  struct MHD_PostProcessor *pp;
+  bool done;
 };
 
 
-static MHD_RESULT
-handle_post (void *cls,
-             enum MHD_ValueKind kind,
-             const char *key,
-             const char *filename,
-             const char *content_type,
-             const char *transfer_encoding,
-             const char *data,
-             uint64_t off,
-             size_t size)
-{
-  (void) kind;
-  (void) filename;
-  (void) content_type;
-  (void) transfer_encoding;
-  (void) off;
-
-  return MHD_YES;
-}
-
-
 /**
  * A client has requested the given url using the given method
  * (#MHD_HTTP_METHOD_GET, #MHD_HTTP_METHOD_PUT,
@@ -148,11 +134,34 @@ handler_cb (void *cls,
             size_t *upload_data_size,
             void **con_cls)
 {
+  struct TestserverState *ts = cls;
   struct RequestCtx *rc = *con_cls;
   json_t *body;
 
-  (void) cls;
   (void) version;
+  if (NULL == rc)
+  {
+    const char *hdr;
+
+    rc = GNUNET_new (struct RequestCtx);
+    *con_cls = rc;
+    rc->http_method = GNUNET_strdup (method);
+    hdr = MHD_lookup_connection_value (connection,
+                                       MHD_HEADER_KIND,
+                                       "Taler-test-header");
+    if (NULL != hdr)
+      rc->header = GNUNET_strdup (hdr);
+    if (NULL != hdr)
+      rc->url = GNUNET_strdup (url);
+    GNUNET_array_append (ts->rcs,
+                         ts->rcs_length,
+                         rc);
+    fprintf (stderr,
+             "Webhook called server at `%s' with header `%s'\n",
+             url,
+             hdr);
+    return MHD_YES;
+  }
   if (0 == strcasecmp (method,
                        MHD_HTTP_METHOD_GET))
   {
@@ -170,27 +179,15 @@ handler_cb (void *cls,
     GNUNET_break (0);
     return MHD_NO;
   }
-  if (NULL == rc)
-  {
-    rc = GNUNET_new (struct RequestCtx);
-    *con_cls = rc;
-    rc->pp = MHD_create_post_processor (connection,
-                                        12345,
-                                        &handle_post,
-                                        rc);
-    return MHD_YES;
-  }
   if (0 != *upload_data_size)
   {
-    MHD_RESULT ret;
-
-    ret = MHD_post_process (rc->pp,
-                            upload_data,
-                            *upload_data_size);
+    rc->body = GNUNET_strdup(upload_data);
     *upload_data_size = 0;
-    return ret;
+    GNUNET_array_append (ts->rcs,
+                         ts->rcs_length,
+                         rc);
+    return MHD_YES;
   }
-
   body = GNUNET_JSON_PACK (
     GNUNET_JSON_pack_string ("something",
                              "good"));
@@ -213,7 +210,7 @@ cleanup (void *cls,
   (void) toe;
   if (NULL == rc)
     return;
-  GNUNET_free (rc);
+  rc->done = true;
 }
 
 
@@ -262,6 +259,19 @@ testserver_cleanup (void *cls,
   struct TestserverState *ser = cls;
 
   (void) cmd;
+  for (unsigned int i=0;i<ser->rcs_length-1;i++)
+  {
+    struct RequestCtx *rc = ser->rcs[i];
+
+    GNUNET_free (rc->url);
+    GNUNET_free (rc->http_method);
+    GNUNET_free (rc->header);
+    GNUNET_free (rc->body);
+    GNUNET_free (rc);
+  }
+  GNUNET_array_grow (ser->rcs,
+                     ser->rcs_length,
+                     0);
   if (NULL != ser->mhd)
   {
     MHD_stop_daemon (ser->mhd);
@@ -278,73 +288,42 @@ traits_testserver (void *cls,
                    unsigned int index)
 {
   struct TestserverState *ser = cls;
-  struct TALER_TESTING_Trait traits[] = {
-    TALER_TESTING_make_trait_url (&ser->url),
-    TALER_TESTING_make_trait_http_method (&ser->http_method),
-    TALER_TESTING_make_trait_header_template (&ser->header),
-    TALER_TESTING_make_trait_body_template (&ser->body),
-    TALER_TESTING_trait_end (),
-  };
-
-  return TALER_TESTING_get_trait (traits,
-                                  ret,
-                                  trait,
-                                  index);
-}
 
-/**
- * This function is used to start the web server.
- *
- * @param label command label
- * @param port is the port of the web server
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_testserver (const char *label,
-                              uint16_t port)
-{
-  struct TestserverState *ser;
+  if (index >= ser->rcs_length)
+    return MHD_NO;
 
-  ser = GNUNET_new (struct TestserverState);
-  ser->port = port;
   {
-    struct TALER_TESTING_Command cmd = {
-      .cls = ser,
-      .label = label,
-      .run = &testserver_run,
-      .cleanup = &testserver_cleanup,
-      .traits = &traits_testserver
+    struct RequestCtx *rc = ser->rcs[index];
+    struct TALER_TESTING_Trait traits[] = {
+      TALER_TESTING_make_trait_urls (index, &rc->url),
+      TALER_TESTING_make_trait_http_methods (index, &rc->http_method),
+      TALER_TESTING_make_trait_http_header (index, &rc->header),
+      TALER_TESTING_make_trait_http_body (index, &rc->body),
+      TALER_TESTING_trait_end (),
     };
 
-    return cmd;
+    fprintf (stdout, "\n\nbody %s\n\n", rc->body);
+
+    return TALER_TESTING_get_trait (traits,
+                                    ret,
+                                    trait,
+                                    index);
   }
 }
 
-
 /**
- * This function is used to check the web server
+ * This function is used to start the web server.
  *
  * @param label command label
- * @param url of the webhook
- * @param http_method of the webhook
- * @param header of the webhook
- * @param body of the webhook
  * @param port is the port of the web server
  */
 struct TALER_TESTING_Command
-TALER_TESTING_cmd_checkserver (const char *label,
-                               char *url,
-                               char *http_method,
-                               char *header,
-                               char *body,
-                               uint16_t port)
+TALER_TESTING_cmd_testserver (const char *label,
+                              uint16_t port)
 {
   struct TestserverState *ser;
 
   ser = GNUNET_new (struct TestserverState);
-  ser->url = url;
-  ser->http_method = http_method;
-  ser->header = header;
-  ser->body = body;
   ser->port = port;
   {
     struct TALER_TESTING_Command cmd = {
@@ -352,6 +331,7 @@ TALER_TESTING_cmd_checkserver (const char *label,
       .label = label,
       .run = &testserver_run,
       .cleanup = &testserver_cleanup,
+      .traits = &traits_testserver
     };
 
     return cmd;
@@ -359,4 +339,5 @@ TALER_TESTING_cmd_checkserver (const char *label,
 }
 
 
-/* end of testing_api_cmd_testserver.c */
+/* end of testing_api_cmd_checkserver.c */
+

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