gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-merchant] 13/22: malforming /history response body,


From: gnunet
Subject: [GNUnet-SVN] [taler-merchant] 13/22: malforming /history response body, and avoid extracting error codes from NULL responses.
Date: Sat, 17 Mar 2018 01:58:38 +0100

This is an automated email from the git hooks/post-receive script.

marcello pushed a commit to branch master
in repository merchant.

commit ec3f361cc3547bf2fbc48259ce2191926afb9c5e
Author: Marcello Stanisci <address@hidden>
AuthorDate: Thu Mar 15 11:19:25 2018 +0100

    malforming /history response body, and avoid extracting
    error codes from NULL responses.
---
 src/lib/merchant_api_history.c      | 13 ++++++++++++-
 src/lib/test_merchant_api_twisted.c | 28 +++++++++++++++++++++++++++-
 src/lib/testing_api_cmd_history.c   | 18 +++++++++---------
 3 files changed, 48 insertions(+), 11 deletions(-)

diff --git a/src/lib/merchant_api_history.c b/src/lib/merchant_api_history.c
index 0a3e01a..3ca8a12 100644
--- 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
index 1d3ee19..18ac0fe 100644
--- 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
index b9763cf..8cad77a 100644
--- 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);

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]