summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpriscilla <priscilla.huang@efrei.net>2023-02-15 09:54:34 -0500
committerpriscilla <priscilla.huang@efrei.net>2023-02-15 09:54:34 -0500
commit1954f2dee9545c89012dc3215769f044f323dc92 (patch)
tree2e4a7bc1c6184dbd5dfad3f5c12b27403160f57a /src
parent88fa748e8e98829df922e58ffee6c210a598cd7a (diff)
downloadmerchant-1954f2dee9545c89012dc3215769f044f323dc92.tar.gz
merchant-1954f2dee9545c89012dc3215769f044f323dc92.tar.bz2
merchant-1954f2dee9545c89012dc3215769f044f323dc92.zip
check the pending webhook with web server, test of web server is ok
Diffstat (limited to 'src')
-rw-r--r--src/include/taler_merchant_testing_lib.h2
-rw-r--r--src/testing/testing_api_cmd_checkserver.c43
-rw-r--r--src/testing/testing_api_cmd_testserver.c20
3 files changed, 49 insertions, 16 deletions
diff --git a/src/include/taler_merchant_testing_lib.h b/src/include/taler_merchant_testing_lib.h
index 771def10..e0ffcccf 100644
--- a/src/include/taler_merchant_testing_lib.h
+++ b/src/include/taler_merchant_testing_lib.h
@@ -1873,7 +1873,7 @@ TALER_TESTING_cmd_checkserver (const char *label,
op (urls, char *) \
op (http_methods, char *) \
op (http_header, char *) \
- op (http_body, void *) \
+ op (http_body, char *) \
op (planchet_secrets, const struct TALER_PlanchetMasterSecretP)
diff --git a/src/testing/testing_api_cmd_checkserver.c b/src/testing/testing_api_cmd_checkserver.c
index d806f3eb..1414bd1d 100644
--- a/src/testing/testing_api_cmd_checkserver.c
+++ b/src/testing/testing_api_cmd_checkserver.c
@@ -75,7 +75,7 @@ struct CheckState
/**
* Expected body of the pending webhook.
*/
- void *expected_body;
+ char *expected_body;
};
@@ -95,31 +95,48 @@ checkserver_run (void *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\n");
+ "URL does not match: `%s' != `%s'\n",
+ cs->expected_url,
+ *expected_url);
TALER_TESTING_interpreter_fail (is);
return;
}
@@ -155,12 +172,14 @@ checkserver_run (void *cls,
*expected_header)) ) )
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "header does not match\n");
+ "header does not match: `%s' != `%s'\n",
+ cs->expected_header,
+ *expected_header);
TALER_TESTING_interpreter_fail (is);
return;
}
- void **expected_body;
+ char **expected_body;
if (GNUNET_OK !=
TALER_TESTING_get_trait_http_body (ref,
@@ -171,16 +190,20 @@ checkserver_run (void *cls,
( (NULL != cs->expected_body) && (NULL == expected_body)) ||
( (NULL != cs->expected_body) &&
(0 != strcmp (cs->expected_body,
- *expected_body)) ) )
+ *expected_body) ) ) )
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "body does not match\n");
+ "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
*
@@ -199,7 +222,7 @@ TALER_TESTING_cmd_checkserver2 (const char *label,
char *expected_url,
char *expected_method,
char *expected_header,
- void *expected_body)
+ char *expected_body)
{
struct CheckState *cs;
@@ -231,9 +254,9 @@ TALER_TESTING_cmd_checkserver (const char *label,
return TALER_TESTING_cmd_checkserver2 (label,
ref_operation,
index,
- "http://localhost:12345/",
+ "/",
"POST",
- "Taler-test-header: EFEHYJS-Bakery",
+ "EFEHYJS-Bakery",
"5.0 EUR");
}
diff --git a/src/testing/testing_api_cmd_testserver.c b/src/testing/testing_api_cmd_testserver.c
index 7992c6f1..d06ce824 100644
--- a/src/testing/testing_api_cmd_testserver.c
+++ b/src/testing/testing_api_cmd_testserver.c
@@ -73,7 +73,7 @@ struct RequestCtx
/**
* body of the webhook.
*/
- void *body;
+ char *body;
/**
* size of the body
@@ -142,7 +142,8 @@ handler_cb (void *cls,
if (NULL == rc)
{
const char *hdr;
- rc= GNUNET_new (struct RequestCtx);
+
+ rc = GNUNET_new (struct RequestCtx);
*con_cls = rc;
rc->http_method = GNUNET_strdup (method);
hdr = MHD_lookup_connection_value (connection,
@@ -150,11 +151,13 @@ handler_cb (void *cls,
"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",
+ "Webhook called server at `%s' with header `%s'\n",
url,
hdr);
return MHD_YES;
@@ -178,8 +181,11 @@ handler_cb (void *cls,
}
if (0 != *upload_data_size)
{
- rc->body = &upload_data;
+ rc->body = GNUNET_strdup(upload_data);
*upload_data_size = 0;
+ GNUNET_array_append (ts->rcs,
+ ts->rcs_length,
+ rc);
return MHD_YES;
}
body = GNUNET_JSON_PACK (
@@ -253,13 +259,14 @@ testserver_cleanup (void *cls,
struct TestserverState *ser = cls;
(void) cmd;
- for (unsigned int i=0;i<ser->rcs_length;i++)
+ 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,
@@ -294,6 +301,9 @@ traits_testserver (void *cls,
TALER_TESTING_make_trait_http_body (index, &rc->body),
TALER_TESTING_trait_end (),
};
+
+ fprintf (stdout, "\n\nbody %s\n\n", rc->body);
+
return TALER_TESTING_get_trait (traits,
ret,
trait,