summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2023-02-19 12:31:00 +0100
committerChristian Grothoff <christian@grothoff.org>2023-02-19 12:31:00 +0100
commit20d9b03ac6e98b0453d8fa068a84e37ea952f302 (patch)
treef633f46f92d1c0cf9884b3ed2e3bf58f35e5625c /src
parentc0cbc4e86218c790b612df737dc85f4760658552 (diff)
downloadmerchant-20d9b03ac6e98b0453d8fa068a84e37ea952f302.tar.gz
merchant-20d9b03ac6e98b0453d8fa068a84e37ea952f302.tar.bz2
merchant-20d9b03ac6e98b0453d8fa068a84e37ea952f302.zip
fix bad memory use in new test logic
Diffstat (limited to 'src')
-rw-r--r--src/include/taler_merchant_testing_lib.h3
-rw-r--r--src/testing/testing_api_cmd_checkserver.c53
-rw-r--r--src/testing/testing_api_cmd_testserver.c59
3 files changed, 73 insertions, 42 deletions
diff --git a/src/include/taler_merchant_testing_lib.h b/src/include/taler_merchant_testing_lib.h
index a749b092..1039d2ef 100644
--- a/src/include/taler_merchant_testing_lib.h
+++ b/src/include/taler_merchant_testing_lib.h
@@ -1891,7 +1891,8 @@ TALER_TESTING_cmd_checkserver2 (const char *label,
op (urls, char *) \
op (http_methods, char *) \
op (http_header, char *) \
- op (http_body, char *) \
+ op (http_body, void *) \
+ op (http_body_size, size_t) \
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 55f0b50d..56b05438 100644
--- a/src/testing/testing_api_cmd_checkserver.c
+++ b/src/testing/testing_api_cmd_checkserver.c
@@ -93,10 +93,11 @@ checkserver_run (void *cls,
{
struct CheckState *cs = cls;
const struct TALER_TESTING_Command *ref;
- char **expected_url;
- char **expected_http_method;
- char **expected_header;
- char **expected_body;
+ char **url;
+ char **http_method;
+ char **header;
+ void **body;
+ size_t *body_size;
(void) cmd;
cs->is = is;
@@ -113,7 +114,7 @@ checkserver_run (void *cls,
if (GNUNET_OK !=
TALER_TESTING_get_trait_urls (ref,
cs->index,
- &expected_url))
+ &url))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Trait url does not work\n");
@@ -121,7 +122,7 @@ checkserver_run (void *cls,
TALER_TESTING_interpreter_fail (is);
return;
}
- if (NULL == *expected_url)
+ if (NULL == *url)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Trait for url is NULL!?\n");
@@ -130,22 +131,22 @@ checkserver_run (void *cls,
return;
}
if (0 != strcmp (cs->expected_url,
- *expected_url))
+ *url))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"URL does not match: `%s' != `%s'\n",
cs->expected_url,
- *expected_url);
+ *url);
TALER_TESTING_interpreter_fail (is);
return;
}
if (GNUNET_OK !=
TALER_TESTING_get_trait_http_methods (ref,
cs->index,
- &expected_http_method))
+ &http_method))
TALER_TESTING_interpreter_fail (is);
if (0 != strcmp (cs->expected_method,
- *expected_http_method))
+ *http_method))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"http_method does not match\n");
@@ -155,36 +156,44 @@ checkserver_run (void *cls,
if (GNUNET_OK !=
TALER_TESTING_get_trait_http_header (ref,
cs->index,
- &expected_header))
+ &header))
TALER_TESTING_interpreter_fail (is);
- if ( ( (NULL == cs->expected_header) && (NULL != *expected_header)) ||
- ( (NULL != cs->expected_header) && (NULL == expected_header)) ||
+ if ( ( (NULL == cs->expected_header) && (NULL != *header)) ||
+ ( (NULL != cs->expected_header) && (NULL == header)) ||
( (NULL != cs->expected_header) &&
(0 != strcmp (cs->expected_header,
- *expected_header)) ) )
+ *header)) ) )
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"header does not match: `%s' != `%s'\n",
cs->expected_header,
- *expected_header);
+ *header);
TALER_TESTING_interpreter_fail (is);
return;
}
if (GNUNET_OK !=
TALER_TESTING_get_trait_http_body (ref,
cs->index,
- &expected_body))
+ &body))
TALER_TESTING_interpreter_fail (is);
- if ( ( (NULL == cs->expected_body) && (NULL != *expected_body)) ||
- ( (NULL != cs->expected_body) && (NULL == expected_body)) ||
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_http_body_size (ref,
+ cs->index,
+ &body_size))
+ TALER_TESTING_interpreter_fail (is);
+ if ( ( (NULL == cs->expected_body) && (NULL != *body)) ||
+ ( (NULL != cs->expected_body) && (NULL == body)) ||
( (NULL != cs->expected_body) &&
- (0 != strcmp (cs->expected_body,
- *expected_body) ) ) )
+ ( (*body_size != strlen (cs->expected_body)) ||
+ (0 != memcmp (cs->expected_body,
+ *body,
+ *body_size) ) ) ) )
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "body does not match : `%s' and `%s'\n",
+ "body does not match : `%s' and `%.*s'\n",
cs->expected_body,
- *expected_body);
+ (int) *body_size,
+ (const char *) *body);
TALER_TESTING_interpreter_fail (is);
return;
}
diff --git a/src/testing/testing_api_cmd_testserver.c b/src/testing/testing_api_cmd_testserver.c
index d06ce824..c5a929c0 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.
*/
- char *body;
+ void *body;
/**
* size of the body
@@ -136,7 +136,6 @@ handler_cb (void *cls,
{
struct TestserverState *ts = cls;
struct RequestCtx *rc = *con_cls;
- json_t *body;
(void) version;
if (NULL == rc)
@@ -165,12 +164,14 @@ handler_cb (void *cls,
if (0 == strcasecmp (method,
MHD_HTTP_METHOD_GET))
{
- body = GNUNET_JSON_PACK (
+ json_t *reply;
+
+ reply = GNUNET_JSON_PACK (
GNUNET_JSON_pack_string (
"status",
"success"));
return TALER_MHD_reply_json_steal (connection,
- body,
+ reply,
MHD_HTTP_OK);
}
if (0 != strcasecmp (method,
@@ -181,19 +182,35 @@ handler_cb (void *cls,
}
if (0 != *upload_data_size)
{
- rc->body = GNUNET_strdup(upload_data);
+ void *body;
+
+ body = GNUNET_malloc (rc->body_size + *upload_data_size);
+ memcpy (body,
+ rc->body,
+ rc->body_size);
+ GNUNET_free (rc->body);
+ memcpy (body + rc->body_size,
+ upload_data,
+ *upload_data_size);
+ rc->body = body;
+ rc->body_size += *upload_data_size;
*upload_data_size = 0;
GNUNET_array_append (ts->rcs,
ts->rcs_length,
rc);
return MHD_YES;
}
- body = GNUNET_JSON_PACK (
- GNUNET_JSON_pack_string ("something",
- "good"));
- return TALER_MHD_reply_json_steal (connection,
- body,
- MHD_HTTP_OK);
+
+ {
+ json_t *reply;
+
+ reply = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("something",
+ "good"));
+ return TALER_MHD_reply_json_steal (connection,
+ reply,
+ MHD_HTTP_OK);
+ }
}
@@ -259,7 +276,7 @@ testserver_cleanup (void *cls,
struct TestserverState *ser = cls;
(void) cmd;
- for (unsigned int i=0;i<ser->rcs_length-1;i++)
+ for (unsigned int i = 0; i<ser->rcs_length - 1; i++)
{
struct RequestCtx *rc = ser->rcs[i];
@@ -295,15 +312,19 @@ traits_testserver (void *cls,
{
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_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_make_trait_http_body_size (index,
+ &rc->body_size),
TALER_TESTING_trait_end (),
};
- fprintf (stdout, "\n\nbody %s\n\n", rc->body);
-
return TALER_TESTING_get_trait (traits,
ret,
trait,
@@ -311,6 +332,7 @@ traits_testserver (void *cls,
}
}
+
/**
* This function is used to start the web server.
*
@@ -340,4 +362,3 @@ TALER_TESTING_cmd_testserver (const char *label,
/* end of testing_api_cmd_checkserver.c */
-