commit ec3f361cc3547bf2fbc48259ce2191926afb9c5e
parent b55506b39509657aba64be1a4e22c5bf32c934f9
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date: Thu, 15 Mar 2018 11:19:25 +0100
malforming /history response body, and avoid extracting
error codes from NULL responses.
Diffstat:
3 files changed, 48 insertions(+), 11 deletions(-)
diff --git a/src/lib/merchant_api_history.c b/src/lib/merchant_api_history.c
@@ -99,7 +99,17 @@ history_raw_cb (void *cls,
switch (response_code)
{
case 0:
- break;
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "/history returned response code 0\n");
+ /**
+ * The response was malformed or didn't have the
+ * application/json header.
+ */
+ ho->cb (ho->cb_cls,
+ response_code,
+ TALER_EC_INVALID_RESPONSE,
+ json);
+ return;
case MHD_HTTP_OK:
ho->cb (ho->cb_cls,
MHD_HTTP_OK,
@@ -124,6 +134,7 @@ history_raw_cb (void *cls,
response_code = 0;
break;
}
+
ho->cb (ho->cb_cls,
response_code,
TALER_JSON_get_error_code (json),
diff --git a/src/lib/test_merchant_api_twisted.c b/src/lib/test_merchant_api_twisted.c
@@ -296,6 +296,15 @@ run (void *cls,
#endif
+ /**** Covering /history lib ****/
+
+ /**
+ * Changing the response code to a unexpected
+ * one. NOTE: this is unexpected to the *lib*
+ * code, that is then expected to trigger some
+ * emergency behaviour, like setting the response
+ * code to zero before calling the callback.
+ */
TALER_TESTING_cmd_hack_response_code
("twist-history",
PROXY_MERCHANT_CONFIG_FILE,
@@ -304,7 +313,24 @@ run (void *cls,
TALER_TESTING_cmd_history ("history-0",
twister_merchant_url,
is->ctx,
- MHD_HTTP_GONE,
+ 0,
+ GNUNET_TIME_UNIT_ZERO_ABS,
+ 1, // nresult
+ 10, // start
+ 10), // nrows
+ /**
+ * Making the returned response malformed, in order
+ * to make the JSON downloader+parser fail and call
+ * the lib passing a response code as zero.
+ */
+ TALER_TESTING_cmd_malform_response
+ ("malform-history",
+ PROXY_MERCHANT_CONFIG_FILE),
+
+ TALER_TESTING_cmd_history ("history-1",
+ twister_merchant_url,
+ is->ctx,
+ 0, // also works with MHD_HTTP_GONE
GNUNET_TIME_UNIT_ZERO_ABS,
1, // nresult
10, // start
diff --git a/src/lib/testing_api_cmd_history.c b/src/lib/testing_api_cmd_history.c
@@ -158,16 +158,16 @@ history_cb (void *cls,
hs->ho = NULL;
- /* 410 is a convenience status that is used to
- * trigger the "unexpected response code" in the
- * lib, that should then result in a 0 status code
- * passed here to the callback. */
- if (MHD_HTTP_GONE == hs->http_status)
- {
- if (0 != http_status)
+
+ if (hs->http_status != http_status)
TALER_TESTING_FAIL (hs->is);
-
- TALER_TESTING_interpreter_next (hs->is);
+
+ if (0 == hs->http_status)
+ {
+ /* 0 was caused intentionally by the tests,
+ * move on without further checking. */
+ TALER_TESTING_interpreter_next (hs->is);
+ return;
}
nresult = json_array_size (json);