aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpriscilla <priscilla.huang@efrei.net>2023-02-14 07:27:42 -0500
committerpriscilla <priscilla.huang@efrei.net>2023-02-14 07:27:42 -0500
commit88fa748e8e98829df922e58ffee6c210a598cd7a (patch)
tree98d36f891a6be1c1a644047c0c645cc5028854e9 /src
parent98dfff89fd22c616813bb8c82d62553dd8a26d5d (diff)
pull all the changes in the merchant directory
Diffstat (limited to 'src')
-rw-r--r--src/testing/testing_api_cmd_checkserver.c240
-rw-r--r--src/testing/testing_api_cmd_post_webhooks.c2
2 files changed, 241 insertions, 1 deletions
diff --git a/src/testing/testing_api_cmd_checkserver.c b/src/testing/testing_api_cmd_checkserver.c
new file mode 100644
index 00000000..d806f3eb
--- /dev/null
+++ b/src/testing/testing_api_cmd_checkserver.c
@@ -0,0 +1,240 @@
+/*
+ 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.
+ */
+ void *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_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+
+ char **expected_url;
+
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_urls (ref,
+ cs->index,
+ &expected_url))
+ {
+ TALER_TESTING_interpreter_fail (is);
+ }
+
+ if (0 != strcmp (cs->expected_url,
+ *expected_url))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "URL does not match\n");
+ 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\n");
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+
+ void **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\n");
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+
+}
+
+/**
+ * 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,
+ void *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,
+ "http://localhost:12345/",
+ "POST",
+ "Taler-test-header: 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 099ea755..924a474a 100644
--- a/src/testing/testing_api_cmd_post_webhooks.c
+++ b/src/testing/testing_api_cmd_post_webhooks.c
@@ -268,7 +268,7 @@ TALER_TESTING_cmd_merchant_post_webhooks (const char *label,
merchant_url,
webhook_id,
event_type,
- "https://google.com/",
+ "http://localhost:12345/",
"POST",
"Taler-test-header: EFEHYJS-Bakery",
"5.0 EUR",