summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpriscilla <priscilla.huang@efrei.net>2022-12-05 07:11:28 -0500
committerpriscilla <priscilla.huang@efrei.net>2022-12-05 07:11:55 -0500
commit4d093eb54beda349e95de54421ea44d66476273e (patch)
treeb5d01882e335c6592867b2977131128791e51b43
parent489f6665155d9db9982c3285fe61e818214f18da (diff)
downloadmerchant-4d093eb54beda349e95de54421ea44d66476273e.tar.gz
merchant-4d093eb54beda349e95de54421ea44d66476273e.tar.bz2
merchant-4d093eb54beda349e95de54421ea44d66476273e.zip
update
-rw-r--r--src/include/taler_merchant_service.h4
-rw-r--r--src/include/taler_merchant_testing_lib.h137
-rw-r--r--src/lib/Makefile.am5
-rw-r--r--src/testing/testing_api_cmd_delete_webhook.c180
-rw-r--r--src/testing/testing_api_cmd_get_template.c2
-rw-r--r--src/testing/testing_api_cmd_get_webhook.c278
-rw-r--r--src/testing/testing_api_cmd_get_webhooks.c240
-rw-r--r--src/testing/testing_api_cmd_patch_template.c2
-rw-r--r--src/testing/testing_api_cmd_patch_webhook.c258
-rw-r--r--src/testing/testing_api_cmd_post_templates.c2
-rw-r--r--src/testing/testing_api_cmd_post_webhooks.c279
11 files changed, 1381 insertions, 6 deletions
diff --git a/src/include/taler_merchant_service.h b/src/include/taler_merchant_service.h
index f7e9ebd9..02b91310 100644
--- a/src/include/taler_merchant_service.h
+++ b/src/include/taler_merchant_service.h
@@ -4530,8 +4530,8 @@ typedef void
* @param cb_cls closure for @a cb
* @return the request handle; NULL upon error
*/
-struct TALER_MERCHANT_TemplatesPostHandle *
-TALER_MERCHANT_templates_post (
+struct TALER_MERCHANT_WebhooksPostHandle *
+TALER_MERCHANT_webhooks_post (
struct GNUNET_CURL_Context *ctx,
const char *backend_url,
const char *webhook_id,
diff --git a/src/include/taler_merchant_testing_lib.h b/src/include/taler_merchant_testing_lib.h
index 9a4a8372..a77def75 100644
--- a/src/include/taler_merchant_testing_lib.h
+++ b/src/include/taler_merchant_testing_lib.h
@@ -1599,7 +1599,7 @@ TALER_TESTING_cmd_merchant_get_template (const char *label,
/**
- * Define a "DELETE product" CMD.
+ * Define a "DELETE template" CMD.
*
* @param label command label.
* @param merchant_url base URL of the merchant serving the
@@ -1614,6 +1614,141 @@ TALER_TESTING_cmd_merchant_delete_template (const char *label,
const char *template_id,
unsigned int http_status);
+/* ****** Webhooks ******* */
+
+
+/**
+ * Define a "POST /webhooks" CMD.
+ *
+ * @param label command label.
+ * @param merchant_url base URL of the merchant serving the
+ * POST /webhooks request.
+ * @param webhook_id the ID of the webhook to query
+ * @param event_type event of the webhook
+ * @param url use by the customer
+ * @param http_method use by the merchant
+ * @param header_template of the webhook
+ * @param body_template of the webhook
+ * @param http_status expected HTTP response code.
+ * @return the command.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_merchant_post_webhooks2 (
+ const char *label,
+ const char *merchant_url,
+ const char *webhook_id,
+ const char *event_type,
+ const char *url,
+ const char *http_method,
+ const char *header_template,
+ const char *body_template,
+ unsigned int http_status);
+
+
+/**
+ * Define a "POST /webhooks" CMD, simple version
+ *
+ * @param label command label.
+ * @param merchant_url base URL of the merchant serving the
+ * POST /webhooks request.
+ * @param webhook_id the ID of the webhook to query
+ * @param event_type event of the webhook
+ * @param http_status expected HTTP response code.
+ * @return the command.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_merchant_post_webhooks (const char *label,
+ const char *merchant_url,
+ const char *webhook_id,
+ const char *event_type,
+ unsigned int http_status);
+
+
+/**
+ * Define a "PATCH /webhooks/$ID" CMD.
+ *
+ * @param label command label.
+ * @param merchant_url base URL of the merchant serving the
+ * PATCH /webhook request.
+ * @param webhook_id the ID of the webhook to query
+ * @param event_type event of the webhook
+ * @param url use by the customer
+ * @param http_method use by the merchant
+ * @param header_template of the webhook
+ * @param body_template of the webhook
+ * @param http_status expected HTTP response code.
+ * @return the command.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_merchant_patch_webhook (
+ const char *label,
+ const char *merchant_url,
+ const char *webhook_id,
+ const char *event_type,
+ const char *url,
+ const char *http_method,
+ const char *header_template,
+ const char *body_template,
+ unsigned int http_status);
+
+
+/**
+ * Define a "GET /webhooks" CMD.
+ *
+ * @param label command label.
+ * @param merchant_url base URL of the merchant serving the
+ * GET /webhooks request.
+ * @param http_status expected HTTP response code.
+ * @param ... NULL-terminated list of labels (const char *) of
+ * webhook (commands) we expect to be returned in the list
+ * (assuming @a http_code is #MHD_HTTP_OK)
+ * @return the command.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_merchant_get_webhooks (const char *label,
+ const char *merchant_url,
+ unsigned int http_status,
+ ...);
+
+
+/**
+ * Define a "GET webhook" CMD.
+ *
+ * @param label command label.
+ * @param merchant_url base URL of the merchant serving the
+ * GET /templates/$ID request.
+ * @param webhook_id the ID of the webhook to query
+ * @param http_status expected HTTP response code.
+ * @param webhook_reference reference to a "POST /webhooks" or "PATCH /webhooks/$ID" CMD
+ * that will provide what we expect the backend to return to us
+ * @return the command.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_merchant_get_webhook (const char *label,
+ const char *merchant_url,
+ const char *webhook_id,
+ unsigned int http_status,
+ const char *webhook_reference);
+
+
+
+/**
+ * Define a "DELETE webhook" CMD.
+ *
+ * @param label command label.
+ * @param merchant_url base URL of the merchant serving the
+ * DELETE /webhooks/$ID request.
+ * @param webhook_id the ID of the webhook to query
+ * @param http_status expected HTTP response code.
+ * @return the command.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_merchant_delete_webhook (const char *label,
+ const char *merchant_url,
+ const char *webhook_id,
+ unsigned int http_status);
+
+
/* ****** Specific traits supported by this component ******* */
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index 93870ece..7d212c3b 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -22,6 +22,7 @@ libtalermerchant_la_SOURCES = \
merchant_api_delete_reserve.c \
merchant_api_delete_transfer.c \
merchant_api_delete_template.c \
+ merchant_api_delete_webhook.c \
merchant_api_get_config.c \
merchant_api_get_instance.c \
merchant_api_get_instances.c \
@@ -35,6 +36,8 @@ libtalermerchant_la_SOURCES = \
merchant_api_get_transfers.c \
merchant_api_get_template.c \
merchant_api_get_templates.c \
+ merchant_api_get_webhook.c \
+ merchant_api_get_webhooks.c \
merchant_api_lock_product.c \
merchant_api_merchant_get_order.c \
merchant_api_merchant_get_tip.c \
@@ -42,6 +45,7 @@ libtalermerchant_la_SOURCES = \
merchant_api_patch_order_forget.c \
merchant_api_patch_product.c \
merchant_api_patch_template.c \
+ merchant_api_patch_webhook.c \
merchant_api_post_instance_auth.c \
merchant_api_post_instances.c \
merchant_api_post_orders.c \
@@ -54,6 +58,7 @@ libtalermerchant_la_SOURCES = \
merchant_api_post_reserves.c \
merchant_api_post_transfers.c \
merchant_api_post_templates.c \
+ merchant_api_post_webhooks.c \
merchant_api_tip_authorize.c \
merchant_api_tip_pickup.c \
merchant_api_tip_pickup2.c \
diff --git a/src/testing/testing_api_cmd_delete_webhook.c b/src/testing/testing_api_cmd_delete_webhook.c
new file mode 100644
index 00000000..3648ca1f
--- /dev/null
+++ b/src/testing/testing_api_cmd_delete_webhook.c
@@ -0,0 +1,180 @@
+/*
+ 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 testing_api_cmd_delete_webhook.c
+ * @brief command to test DELETE /webhooks/$ID
+ * @author Priscilla HUANG
+ */
+#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 /webhooks/$ID" CMD.
+ */
+struct DeleteWebhookState
+{
+
+ /**
+ * Handle for a "DELETE webhook" request.
+ */
+ struct TALER_MERCHANT_WebhookDeleteHandle *wdh;
+
+ /**
+ * The interpreter state.
+ */
+ struct TALER_TESTING_Interpreter *is;
+
+ /**
+ * Base URL of the merchant serving the request.
+ */
+ const char *merchant_url;
+
+ /**
+ * ID of the webhook to run DELETE for.
+ */
+ const char *webhook_id;
+
+ /**
+ * Expected HTTP response code.
+ */
+ unsigned int http_status;
+
+};
+
+
+/**
+ * Callback for a /delete/webhooks/$ID operation.
+ *
+ * @param cls closure for this function
+ * @param hr response being processed
+ */
+static void
+delete_webhook_cb (void *cls,
+ const struct TALER_MERCHANT_HttpResponse *hr)
+{
+ struct DeleteWebhookState *dis = cls;
+
+ dis->wdh = NULL;
+ if (dis->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 (dis->is));
+ TALER_TESTING_interpreter_fail (dis->is);
+ return;
+ }
+ switch (hr->http_status)
+ {
+ case MHD_HTTP_NO_CONTENT:
+ break;
+ case MHD_HTTP_UNAUTHORIZED:
+ break;
+ case MHD_HTTP_NOT_FOUND:
+ break;
+ case MHD_HTTP_CONFLICT:
+ break;
+ default:
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Unhandled HTTP status %u for DELETE webhook.\n",
+ hr->http_status);
+ }
+ TALER_TESTING_interpreter_next (dis->is);
+}
+
+
+/**
+ * Run the "DELETE webhook" CMD.
+ *
+ *
+ * @param cls closure.
+ * @param cmd command being run now.
+ * @param is interpreter state.
+ */
+static void
+delete_webhook_run (void *cls,
+ const struct TALER_TESTING_Command *cmd,
+ struct TALER_TESTING_Interpreter *is)
+{
+ struct DeleteWebhookState *dis = cls;
+
+ dis->is = is;
+ dis->wdh = TALER_MERCHANT_webhook_delete (is->ctx,
+ dis->merchant_url,
+ dis->webhook_id,
+ &delete_webhook_cb,
+ dis);
+ GNUNET_assert (NULL != dis->wdh);
+}
+
+
+/**
+ * Free the state of a "DELETE webhook" CMD, and possibly
+ * cancel a pending operation thereof.
+ *
+ * @param cls closure.
+ * @param cmd command being run.
+ */
+static void
+delete_webhook_cleanup (void *cls,
+ const struct TALER_TESTING_Command *cmd)
+{
+ struct DeleteWebhookState *dis = cls;
+
+ if (NULL != dis->wdh)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "DELETE /webhooks/$ID operation did not complete\n");
+ TALER_MERCHANT_webhook_delete_cancel (dis->wdh);
+ }
+ GNUNET_free (dis);
+}
+
+
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_merchant_delete_webhook (const char *label,
+ const char *merchant_url,
+ const char *webhook_id,
+ unsigned int http_status)
+{
+ struct DeleteWebhookState *dis;
+
+ dis = GNUNET_new (struct DeleteWebhookState);
+ dis->merchant_url = merchant_url;
+ dis->template_id = webhook_id;
+ dis->http_status = http_status;
+ {
+ struct TALER_TESTING_Command cmd = {
+ .cls = dis,
+ .label = label,
+ .run = &delete_webhook_run,
+ .cleanup = &delete_webhook_cleanup
+ };
+
+ return cmd;
+ }
+}
+
+
+/* end of testing_api_cmd_delete_webhook.c */
diff --git a/src/testing/testing_api_cmd_get_template.c b/src/testing/testing_api_cmd_get_template.c
index 0865efe1..4e5580da 100644
--- a/src/testing/testing_api_cmd_get_template.c
+++ b/src/testing/testing_api_cmd_get_template.c
@@ -35,7 +35,7 @@ struct GetTemplateState
{
/**
- * Handle for a "GET template request.
+ * Handle for a "GET template" request.
*/
struct TALER_MERCHANT_TemplateGetHandle *igh;
diff --git a/src/testing/testing_api_cmd_get_webhook.c b/src/testing/testing_api_cmd_get_webhook.c
new file mode 100644
index 00000000..44553caa
--- /dev/null
+++ b/src/testing/testing_api_cmd_get_webhook.c
@@ -0,0 +1,278 @@
+/*
+ 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 testing_api_cmd_get_webhook.c
+ * @brief command to test GET /webhooks/$ID
+ * @author Priscilla HUANG
+ */
+#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 "GET webhook" CMD.
+ */
+struct GetWebhookState
+{
+
+ /**
+ * Handle for a "GET webhook" request.
+ */
+ struct TALER_MERCHANT_WebhookGetHandle *igh;
+
+ /**
+ * The interpreter state.
+ */
+ struct TALER_TESTING_Interpreter *is;
+
+ /**
+ * Base URL of the merchant serving the request.
+ */
+ const char *merchant_url;
+
+ /**
+ * ID of the webhook to run GET for.
+ */
+ const char *webhook_id;
+
+ /**
+ * Reference for a POST or PATCH /webhooks CMD (optional).
+ */
+ const char *webhook_reference;
+
+ /**
+ * Expected HTTP response code.
+ */
+ unsigned int http_status;
+
+};
+
+
+/**
+ * Callback for a /get/webhooks/$ID operation.
+ *
+ * @param cls closure for this function
+ * @param hr HTTP response details
+ * @param event_type event of the webhook
+ * @param url use by the customer
+ * @param http_method method use by the merchant
+ * @param header_template of the webhook
+ * @param body_template of the webhook
+ */
+static void
+get_template_cb (void *cls,
+ const struct TALER_MERCHANT_HttpResponse *hr,
+ const char *event_type,
+ const char *url,
+ const char *http_method,
+ const char *header_template,
+ const char *body_template)
+{
+ struct GetWebhookState *gis = cls;
+ const struct TALER_TESTING_Command *webhook_cmd;
+
+ gis->igh = NULL;
+ if (gis->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 (gis->is));
+ TALER_TESTING_interpreter_fail (gis->is);
+ return;
+ }
+ switch (hr->http_status)
+ {
+ case MHD_HTTP_OK:
+ {
+ const char **expected_event_type;
+
+ template_cmd = TALER_TESTING_interpreter_lookup_command (
+ gis->is,
+ gis->webhook_reference);
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_event_type (webhook_cmd,
+ &expected_event_type))
+ TALER_TESTING_interpreter_fail (gis->is);
+ if (0 != strcmp (event_type, ,
+ *expected_event_type))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Event type does not match\n");
+ TALER_TESTING_interpreter_fail (gis->is);
+ return;
+ }
+ }
+ {
+ const char **expected_url;
+
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_url (webhook_cmd,
+ &expected_url))
+ TALER_TESTING_interpreter_fail (gis->is);
+ if (0 != strcmp (url,
+ *expected_url))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "URL does not match\n");
+ TALER_TESTING_interpreter_fail (gis->is);
+ return;
+ }
+ }
+ {
+ const char **expected_http_method;
+
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_http_method (webhook_cmd,
+ &expected_http_method))
+ TALER_TESTING_interpreter_fail (gis->is);
+ if (0 != strcmp (http_method,
+ *expected_http_method))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "http_method does not match\n");
+ TALER_TESTING_interpreter_fail (gis->is);
+ return;
+ }
+ }
+ {
+ const char **expected_header_template;
+
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_header_template (webhook_cmd,
+ &expected_header_template))
+ TALER_TESTING_interpreter_fail (gis->is);
+ if (0 != strcmp (header_template,
+ *expected_header_template))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "header template does not match\n");
+ TALER_TESTING_interpreter_fail (gis->is);
+ return;
+ }
+ }
+ {
+ const char **expected_body_template;
+
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_body_template (webhook_cmd,
+ &expected_body_template))
+ TALER_TESTING_interpreter_fail (gis->is);
+ if (0 != strcmp (body_template,
+ *expected_body_template))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "body template does not match\n");
+ TALER_TESTING_interpreter_fail (gis->is);
+ return;
+ }
+ }
+ break;
+ case MHD_HTTP_UNAUTHORIZED:
+ break;
+ case MHD_HTTP_NOT_FOUND:
+ break;
+ default:
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Unhandled HTTP status.\n");
+ }
+ TALER_TESTING_interpreter_next (gis->is);
+}
+
+
+/**
+ * Run the "GET webhook" CMD.
+ *
+ *
+ * @param cls closure.
+ * @param cmd command being run now.
+ * @param is interpreter state.
+ */
+static void
+get_webhook_run (void *cls,
+ const struct TALER_TESTING_Command *cmd,
+ struct TALER_TESTING_Interpreter *is)
+{
+ struct GetWebhookState *gis = cls;
+
+ gis->is = is;
+ gis->igh = TALER_MERCHANT_webhook_get (is->ctx,
+ gis->merchant_url,
+ gis->webhook_id,
+ &get_webhook_cb,
+ gis);
+ GNUNET_assert (NULL != gis->igh);
+}
+
+
+/**
+ * Free the state of a "GET webhook" CMD, and possibly
+ * cancel a pending operation thereof.
+ *
+ * @param cls closure.
+ * @param cmd command being run.
+ */
+static void
+get_webhook_cleanup (void *cls,
+ const struct TALER_TESTING_Command *cmd)
+{
+ struct GetWebhookState *gis = cls;
+
+ if (NULL != gis->igh)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "GET /webhooks/$ID operation did not complete\n");
+ TALER_MERCHANT_webhook_get_cancel (gis->igh);
+ }
+ GNUNET_free (gis);
+}
+
+
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_merchant_get_webhook (const char *label,
+ const char *merchant_url,
+ const char *webhook_id,
+ unsigned int http_status,
+ const char *webhook_reference)
+{
+ struct GetWebhookState *gis;
+
+ gis = GNUNET_new (struct GetWebhookState);
+ gis->merchant_url = merchant_url;
+ gis->webhook_id = webhook_id;
+ gis->http_status = http_status;
+ gis->webhook_reference = webhook_reference;
+ {
+ struct TALER_TESTING_Command cmd = {
+ .cls = gis,
+ .label = label,
+ .run = &get_webhook_run,
+ .cleanup = &get_webhook_cleanup
+ };
+
+ return cmd;
+ }
+}
+
+
+/* end of testing_api_cmd_get_webhook.c */
diff --git a/src/testing/testing_api_cmd_get_webhooks.c b/src/testing/testing_api_cmd_get_webhooks.c
new file mode 100644
index 00000000..6fca66e2
--- /dev/null
+++ b/src/testing/testing_api_cmd_get_webhooks.c
@@ -0,0 +1,240 @@
+/*
+ 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 testing_api_cmd_get_webhooks.c
+ * @brief command to test GET /webhooks
+ * @author Priscilla HUANG
+ */
+#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 "GET webhooks" CMD.
+ */
+struct GetWebhooksState
+{
+
+ /**
+ * Handle for a "GET webhook" request.
+ */
+ struct TALER_MERCHANT_WebhooksGetHandle *igh;
+
+ /**
+ * The interpreter state.
+ */
+ struct TALER_TESTING_Interpreter *is;
+
+ /**
+ * Base URL of the merchant serving the request.
+ */
+ const char *merchant_url;
+
+ /**
+ * Expected HTTP response code.
+ */
+ unsigned int http_status;
+
+ /**
+ * The list of webhook references.
+ */
+ const char **webhooks;
+
+ /**
+ * Length of @e webhooks.
+ */
+ unsigned int webhooks_length;
+
+};
+
+
+/**
+ * Callback for a GET /webhooks operation.
+ *
+ * @param cls closure for this function
+ * @param hr HTTP response details
+ * @param webhooks_length length of the @a webhooks array
+ * @param webhooks array of webhooks the requested instance offers
+ */
+static void
+get_webhooks_cb (void *cls,
+ const struct TALER_MERCHANT_HttpResponse *hr,
+ unsigned int webhooks_length,
+ const struct TALER_MERCHANT_WebhookEntry webhooks[])
+{
+ struct GetWebhooksState *gis = cls;
+
+ gis->igh = NULL;
+ if (gis->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 (gis->is));
+ TALER_TESTING_interpreter_fail (gis->is);
+ return;
+ }
+ switch (hr->http_status)
+ {
+ case MHD_HTTP_OK:
+ if (webhooks_length != gis->webhooks_length)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Length of webhooks found does not match\n");
+ TALER_TESTING_interpreter_fail (gis->is);
+ return;
+ }
+ for (unsigned int i = 0; i < gis->webhooks_length; ++i)
+ {
+ const struct TALER_TESTING_Command *webhook_cmd;
+
+ webhook_cmd = TALER_TESTING_interpreter_lookup_command (
+ gis->is,
+ gis->webhooks[i]);
+
+ {
+ const char **webhook_id;
+
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_webhook_id (webhook_cmd,
+ &webhook_id))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Could not fetch webhook id\n");
+ TALER_TESTING_interpreter_fail (gis->is);
+ return;
+ }
+ if (0 != strcmp (webhooks[i].webhook_id,
+ *webhook_id))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Webhook id does not match\n");
+ TALER_TESTING_interpreter_fail (gis->is);
+ return;
+ }
+ }
+ }
+ break;
+ case MHD_HTTP_UNAUTHORIZED:
+ break;
+ case MHD_HTTP_NOT_FOUND:
+ /* instance does not exist */
+ break;
+ default:
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Unhandled HTTP status %u (%d).\n",
+ hr->http_status,
+ hr->ec);
+ }
+ TALER_TESTING_interpreter_next (gis->is);
+}
+
+
+/**
+ * Run the "GET /webhooks" CMD.
+ *
+ *
+ * @param cls closure.
+ * @param cmd command being run now.
+ * @param is interpreter state.
+ */
+static void
+get_webhooks_run (void *cls,
+ const struct TALER_TESTING_Command *cmd,
+ struct TALER_TESTING_Interpreter *is)
+{
+ struct GetWebhooksState *gis = cls;
+
+ gis->is = is;
+ gis->igh = TALER_MERCHANT_webhooks_get (is->ctx,
+ gis->merchant_url,
+ &get_webhooks_cb,
+ gis);
+ GNUNET_assert (NULL != gis->igh);
+}
+
+
+/**
+ * Free the state of a "GET webhook" CMD, and possibly
+ * cancel a pending operation thereof.
+ *
+ * @param cls closure.
+ * @param cmd command being run.
+ */
+static void
+get_webhooks_cleanup (void *cls,
+ const struct TALER_TESTING_Command *cmd)
+{
+ struct GetWebhooksState *gis = cls;
+
+ if (NULL != gis->igh)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "GET /webhooks operation did not complete\n");
+ TALER_MERCHANT_webhooks_get_cancel (gis->igh);
+ }
+ GNUNET_array_grow (gis->webhooks,
+ gis->webhooks_length,
+ 0);
+ GNUNET_free (gis);
+}
+
+
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_merchant_get_webhooks (const char *label,
+ const char *merchant_url,
+ unsigned int http_status,
+ ...)
+{
+ struct GetWebhooksState *gis;
+
+ gis = GNUNET_new (struct GetWebhooksState);
+ gis->merchant_url = merchant_url;
+ gis->http_status = http_status;
+ {
+ const char *clabel;
+ va_list ap;
+
+ va_start (ap, http_status);
+ while (NULL != (clabel = va_arg (ap, const char *)))
+ {
+ GNUNET_array_append (gis->webhooks,
+ gis->webhooks_length,
+ clabel);
+ }
+ va_end (ap);
+ }
+ {
+ struct TALER_TESTING_Command cmd = {
+ .cls = gis,
+ .label = label,
+ .run = &get_webhooks_run,
+ .cleanup = &get_webhooks_cleanup
+ };
+
+ return cmd;
+ }
+}
+
+
+/* end of testing_api_cmd_get_webhooks.c */
diff --git a/src/testing/testing_api_cmd_patch_template.c b/src/testing/testing_api_cmd_patch_template.c
index 6c769565..68b5cbaa 100644
--- a/src/testing/testing_api_cmd_patch_template.c
+++ b/src/testing/testing_api_cmd_patch_template.c
@@ -114,7 +114,7 @@ patch_template_cb (void *cls,
break;
default:
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Unhandled HTTP status %u for PATCH /products/ID.\n",
+ "Unhandled HTTP status %u for PATCH /templates/ID.\n",
hr->http_status);
}
TALER_TESTING_interpreter_next (pis->is);
diff --git a/src/testing/testing_api_cmd_patch_webhook.c b/src/testing/testing_api_cmd_patch_webhook.c
new file mode 100644
index 00000000..c11c7fd0
--- /dev/null
+++ b/src/testing/testing_api_cmd_patch_webhook.c
@@ -0,0 +1,258 @@
+/*
+ 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 testing_api_cmd_patch_webhook.c
+ * @brief command to test PATCH /webhook
+ * @author Priscilla HUANG
+ */
+#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 "PATCH /webhook" CMD.
+ */
+struct PatchWebhookState
+{
+
+ /**
+ * Handle for a "GET webhook" request.
+ */
+ struct TALER_MERCHANT_WebhookPatchHandle *iph;
+
+ /**
+ * The interpreter state.
+ */
+ struct TALER_TESTING_Interpreter *is;
+
+ /**
+ * Base URL of the merchant serving the request.
+ */
+ const char *merchant_url;
+
+ /**
+ * ID of the webhook to run GET for.
+ */
+ const char *webhook_id;
+
+ /**
+ * event of the webhook
+ */
+ const char *event_type;
+
+ /**
+ * url use by the customer
+ */
+ const char *url;
+
+ /**
+ * http_method use by the merchant
+ */
+ const char *http_method;
+
+ /**
+ * header of the webhook
+ */
+ const char *header_template;
+
+ /**
+ * body_template of the webhook
+ */
+ const char *body_template;
+
+ /**
+ * Expected HTTP response code.
+ */
+ unsigned int http_status;
+
+};
+
+
+/**
+ * Callback for a PATCH /webhooks/$ID operation.
+ *
+ * @param cls closure for this function
+ * @param hr response being processed
+ */
+static void
+patch_webhook_cb (void *cls,
+ const struct TALER_MERCHANT_HttpResponse *hr)
+{
+ struct PatchWebhookState *pis = cls;
+
+ pis->iph = NULL;
+ if (pis->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 (pis->is));
+ TALER_TESTING_interpreter_fail (pis->is);
+ return;
+ }
+ switch (hr->http_status)
+ {
+ case MHD_HTTP_NO_CONTENT:
+ break;
+ case MHD_HTTP_UNAUTHORIZED:
+ break;
+ case MHD_HTTP_FORBIDDEN:
+ break;
+ case MHD_HTTP_NOT_FOUND:
+ break;
+ case MHD_HTTP_CONFLICT:
+ break;
+ default:
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Unhandled HTTP status %u for PATCH /webhooks/ID.\n",
+ hr->http_status);
+ }
+ TALER_TESTING_interpreter_next (pis->is);
+}
+
+
+/**
+ * Run the "PATCH /webhooks/$ID" CMD.
+ *
+ *
+ * @param cls closure.
+ * @param cmd command being run now.
+ * @param is interpreter state.
+ */
+static void
+patch_webhook_run (void *cls,
+ const struct TALER_TESTING_Command *cmd,
+ struct TALER_TESTING_Interpreter *is)
+{
+ struct PatchWebhookState *pis = cls;
+
+ pis->is = is;
+ pis->iph = TALER_MERCHANT_webhook_patch (is->ctx,
+ pis->merchant_url,
+ pis->webhook_id,
+ pis->event_type,
+ pis->url,
+ pis->http_method,
+ pis->header_template,
+ pis->body_template,
+ &patch_webhook_cb,
+ pis);
+ GNUNET_assert (NULL != pis->iph);
+}
+
+
+/**
+ * Offers information from the PATCH /webhooks CMD state to other
+ * commands.
+ *
+ * @param cls closure
+ * @param[out] ret 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 enum GNUNET_GenericReturnValue
+patch_webhook_traits (void *cls,
+ const void **ret,
+ const char *trait,
+ unsigned int index)
+{
+ struct PatchWebhookState *pws = cls;
+ struct TALER_TESTING_Trait traits[] = {
+ TALER_TESTING_make_trait_event_type (&pws->event_type),
+ TALER_TESTING_make_trait_url (&pws->url),
+ TALER_TESTING_make_trait_http_method (&pws->http_method),
+ TALER_TESTING_make_trait_header_template (&pws->header_template),
+ TALER_TESTING_make_trait_body_template (&pws->body_template),
+ TALER_TESTING_make_trait_webhook_id (&pws->webhook_id),
+ TALER_TESTING_trait_end (),
+ };
+
+ return TALER_TESTING_get_trait (traits,
+ ret,
+ trait,
+ index);
+}
+
+
+/**
+ * Free the state of a "GET webhook" CMD, and possibly
+ * cancel a pending operation thereof.
+ *
+ * @param cls closure.
+ * @param cmd command being run.
+ */
+static void
+patch_webhook_cleanup (void *cls,
+ const struct TALER_TESTING_Command *cmd)
+{
+ struct PatchWebhookState *pis = cls;
+
+ if (NULL != pis->iph)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "PATCH /webhooks/$ID operation did not complete\n");
+ TALER_MERCHANT_webhook_patch_cancel (pis->iph);
+ }
+ GNUNET_free (pis);
+}
+
+
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_merchant_patch_webhook (
+ const char *label,
+ const char *merchant_url,
+ const char *webhook_id,
+ const char *event_type,
+ const char *url,
+ const char *http_method,
+ const char *header_template,
+ const char *body_template,
+ unsigned int http_status)
+{
+ struct PatchWebhookState *pis;
+
+ pis = GNUNET_new (struct PatchWebhookState);
+ pis->merchant_url = merchant_url;
+ pis->webhook_id = webhook_id;
+ pis->http_status = http_status;
+ pis->event_type = event_type;
+ pis->url = url;
+ pis->http_method = http_method;
+ pis->header_template = header_template;
+ pis->body_template = body_template;
+ {
+ struct TALER_TESTING_Command cmd = {
+ .cls = pis,
+ .label = label,
+ .run = &patch_webhook_run,
+ .cleanup = &patch_webhook_cleanup,
+ .traits = &patch_webhook_traits
+ };
+
+ return cmd;
+ }
+}
+
+
+/* end of testing_api_cmd_patch_webhook.c */
diff --git a/src/testing/testing_api_cmd_post_templates.c b/src/testing/testing_api_cmd_post_templates.c
index fea11ad6..4cc5a3bd 100644
--- a/src/testing/testing_api_cmd_post_templates.c
+++ b/src/testing/testing_api_cmd_post_templates.c
@@ -50,7 +50,7 @@ struct PostTemplatesState
const char *merchant_url;
/**
- * ID of the product to run POST for.
+ * ID of the template to run POST for.
*/
const char *template_id;
diff --git a/src/testing/testing_api_cmd_post_webhooks.c b/src/testing/testing_api_cmd_post_webhooks.c
new file mode 100644
index 00000000..83dafa58
--- /dev/null
+++ b/src/testing/testing_api_cmd_post_webhooks.c
@@ -0,0 +1,279 @@
+/*
+ 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 testing_api_cmd_post_webhooks.c
+ * @brief command to test POST /webhooks
+ * @author Priscilla HUANG
+ */
+#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 "POST /webhooks" CMD.
+ */
+struct PostWebhooksState
+{
+
+ /**
+ * Handle for a "GET webhook" request.
+ */
+ struct TALER_MERCHANT_WebhooksPostHandle *iph;
+
+ /**
+ * The interpreter state.
+ */
+ struct TALER_TESTING_Interpreter *is;
+
+ /**
+ * Base URL of the merchant serving the request.
+ */
+ const char *merchant_url;
+
+ /**
+ * ID of the webhook to run POST for.
+ */
+ const char *webhook_id;
+
+ /**
+ * event of the webhook
+ */
+ const char *event_type;
+
+ /**
+ * url use by the customer
+ */
+ const char *url;
+
+ /**
+ * http_method use by the merchant
+ */
+ const char *http_method;
+
+ /**
+ * header of the webhook
+ */
+ const char *header_template;
+
+ /**
+ * body of the webhook
+ */
+ const char *body_template;
+
+ /**
+ * Expected HTTP response code.
+ */
+ unsigned int http_status;
+
+};
+
+
+/**
+ * Callback for a POST /webhooks operation.
+ *
+ * @param cls closure for this function
+ * @param hr response being processed
+ */
+static void
+post_webhooks_cb (void *cls,
+ const struct TALER_MERCHANT_HttpResponse *hr)
+{
+ struct PostWebhooksState *wis = cls;
+
+ wis->iph = NULL;
+ if (wis->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 (wis->is));
+ TALER_TESTING_interpreter_fail (wis->is);
+ return;
+ }
+ switch (hr->http_status)
+ {
+ case MHD_HTTP_NO_CONTENT:
+ break;
+ case MHD_HTTP_UNAUTHORIZED:
+ break;
+ case MHD_HTTP_FORBIDDEN:
+ break;
+ case MHD_HTTP_NOT_FOUND:
+ break;
+ case MHD_HTTP_CONFLICT:
+ break;
+ default:
+ GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Unhandled HTTP status %u for POST /templates.\n",
+ hr->http_status);
+ }
+ TALER_TESTING_interpreter_next (wis->is);
+}
+
+
+/**
+ * Run the "POST /webhooks" CMD.
+ *
+ *
+ * @param cls closure.
+ * @param cmd command being run now.
+ * @param is interpreter state.
+ */
+static void
+post_webhooks_run (void *cls,
+ const struct TALER_TESTING_Command *cmd,
+ struct TALER_TESTING_Interpreter *is)
+{
+ struct PostWebhooksState *wis = cls;
+
+ wis->is = is;
+ wis->iph = TALER_MERCHANT_webhooks_post (is->ctx,
+ wis->merchant_url,
+ wis->webhook_id,
+ wis->event_type,
+ wis->url,
+ wis->http_method,
+ wis->header_template,
+ wis->body_template,
+ &post_webhooks_cb,
+ wis);
+ GNUNET_assert (NULL != wis->iph);
+}
+
+
+/**
+ * Offers information from the POST /webhooks CMD state to other
+ * commands.
+ *
+ * @param cls closure
+ * @param[out] ret 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_webhooks_traits (void *cls,
+ const void **ret,
+ const char *trait,
+ unsigned int index)
+{
+ struct PostWebhooksState *pws = cls;
+ struct TALER_TESTING_Trait traits[] = {
+ TALER_TESTING_make_trait_event_type (&pws->event_type),
+ TALER_TESTING_make_trait_url (&pws->url),
+ TALER_TESTING_make_trait_http_method (&pws->http_method),
+ TALER_TESTING_make_trait_header_template (&pws->header_template),
+ TALER_TESTING_make_trait_body_template (&pws->body_template),
+ TALER_TESTING_make_trait_webhook_id (&pws->webhook_id),
+ TALER_TESTING_trait_end (),
+ };
+
+ return TALER_TESTING_get_trait (traits,
+ ret,
+ trait,
+ index);
+}
+
+
+/**
+ * Free the state of a "POST webhook" CMD, and possibly
+ * cancel a pending operation thereof.
+ *
+ * @param cls closure.
+ * @param cmd command being run.
+ */
+static void
+post_webhooks_cleanup (void *cls,
+ const struct TALER_TESTING_Command *cmd)
+{
+ struct PostWebhooksState *wis = cls;
+
+ if (NULL != wis->iph)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "POST /webhooks operation did not complete\n");
+ TALER_MERCHANT_webhooks_post_cancel (wis->iph);
+ }
+ GNUNET_free (wis);
+}
+
+
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_merchant_post_webhooks2 (
+ const char *label,
+ const char *merchant_url,
+ const char *webhook_id,
+ const char *event_type,
+ const char *url,
+ const char *http_method,
+ const char *header_template,
+ const char *body_template,
+ unsigned int http_status)
+{
+ struct PostWebhooksState *wis;
+
+ wis = GNUNET_new (struct PostWebhooksState);
+ wis->merchant_url = merchant_url;
+ wis->webhook_id = webhook_id;
+ wis->http_status = http_status;
+ wis->event_type = event_type;
+ wis->url = url;
+ wis->http_method = http_method;
+ wis->header_template = header_template;
+ wis->body_template = body_template;
+ {
+ struct TALER_TESTING_Command cmd = {
+ .cls = wis,
+ .label = label,
+ .run = &post_webhooks_run,
+ .cleanup = &post_webhooks_cleanup,
+ .traits = &post_webhooks_traits
+ };
+
+ return cmd;
+ }
+}
+
+
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_merchant_post_webhooks (const char *label,
+ const char *merchant_url,
+ const char *webhook_id,
+ const char *event_type,
+ unsigned int http_status)
+{
+ return TALER_TESTING_cmd_merchant_post_webhooks2 (
+ label,
+ merchant_url,
+ webhook_id,
+ event_type,
+ "https://example.com",
+ "POST",
+ "Authorization:EFEHYJS",
+ "$amount",
+ http_status);
+}
+
+
+/* end of testing_api_cmd_post_webhooks.c */