gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-merchant] 16/22: be more gentle with unexpected resp


From: gnunet
Subject: [GNUnet-SVN] [taler-merchant] 16/22: be more gentle with unexpected response codes.
Date: Sat, 17 Mar 2018 01:58:41 +0100

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

marcello pushed a commit to branch master
in repository merchant.

commit 66a55b5e35a174912c2a8c0790acafbfd33054d0
Author: Marcello Stanisci <address@hidden>
AuthorDate: Fri Mar 16 01:16:10 2018 +0100

    be more gentle with unexpected response codes.
    
    test cases often *cause* those unexpected codes,
    so they cannot fail upon those situations.
---
 src/backend/taler-merchant-httpd.c          |  2 +-
 src/backend/taler-merchant-httpd_parsing.c  | 42 ++++++++++++++++++-----------
 src/backend/taler-merchant-httpd_proposal.c |  4 ++-
 src/lib/test_merchant_api_twisted.c         | 37 ++++++++++++++++++++++++-
 src/lib/testing_api_cmd_proposal.c          |  7 +++--
 5 files changed, 71 insertions(+), 21 deletions(-)

diff --git a/src/backend/taler-merchant-httpd.c 
b/src/backend/taler-merchant-httpd.c
index 174be2d..017d6a1 100644
--- a/src/backend/taler-merchant-httpd.c
+++ b/src/backend/taler-merchant-httpd.c
@@ -408,7 +408,7 @@ handle_mhd_completion_callback (void *cls,
 
   if (NULL == hc)
     return;
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               "Finished handling request for `%s' with status %d\n",
               hc->rh->url,
               (int) toe);
diff --git a/src/backend/taler-merchant-httpd_parsing.c 
b/src/backend/taler-merchant-httpd_parsing.c
index f04313a..333637c 100644
--- a/src/backend/taler-merchant-httpd_parsing.c
+++ b/src/backend/taler-merchant-httpd_parsing.c
@@ -64,7 +64,7 @@ struct Buffer
 
 
 /**
- * Initialize a buffer.
+ * Initialize a buffer and copy first chunk of data in it.
  *
  * @param buf the buffer to initialize
  * @param data the initial data
@@ -189,7 +189,7 @@ TMH_PARSE_post_cleanup_callback (void *con_cls)
  *               may be parsed in the future (call again);
  *               `*json` will be NULL if we need to be called again,
  *                and non-NULL if we are done.
- *    #GNUNET_NO is request incomplete or invalid
+ *    #GNUNET_NO if request is incomplete or invalid
  *               (error message was generated)
  *    #GNUNET_SYSERR on internal error
  *               (we could not even queue an error message,
@@ -203,7 +203,10 @@ TMH_PARSE_post_json (struct MHD_Connection *connection,
                      json_t **json)
 {
   struct Buffer *r = *con_cls;
-
+  
+  TALER_LOG_DEBUG ("Will parse: %.*s\n",
+                   (int) *upload_data_size,
+                   upload_data);
   *json = NULL;
   if (NULL == *con_cls)
   {
@@ -219,21 +222,27 @@ TMH_PARSE_post_json (struct MHD_Connection *connection,
       *con_cls = NULL;
       buffer_deinit (r);
       GNUNET_free (r);
-      return (MHD_NO ==
-              TMH_RESPONSE_reply_internal_error (connection,
-                                                TALER_EC_PARSER_OUT_OF_MEMORY,
-                                                 "out of memory"))
-        ? GNUNET_SYSERR : GNUNET_NO;
+      /* return GNUNET_SYSERR if this isn't even
+       * able to generate proper error response.  */
+      return (MHD_NO == TMH_RESPONSE_reply_internal_error
+        (connection,
+         TALER_EC_PARSER_OUT_OF_MEMORY,
+         "out of memory")) ? GNUNET_SYSERR : GNUNET_NO;
     }
     /* everything OK, wait for more POST data */
     *upload_data_size = 0;
     *con_cls = r;
     return GNUNET_YES;
   }
+
+  /* When zero, upload is over.  */
   if (0 != *upload_data_size)
   {
-    /* We are seeing an old request with more data available. */
+    TALER_LOG_INFO ("Parser asking for more data"
+                    ", current data size is %lu\n",
+                    *upload_data_size);
 
+    /* We are seeing an old request with more data available. */
     if (GNUNET_OK !=
         buffer_append (r,
                        upload_data,
@@ -244,17 +253,19 @@ TMH_PARSE_post_json (struct MHD_Connection *connection,
       *con_cls = NULL;
       buffer_deinit (r);
       GNUNET_free (r);
-      return (MHD_NO ==
-              TMH_RESPONSE_reply_request_too_large (connection))
-        ? GNUNET_SYSERR : GNUNET_NO;
+      return (MHD_NO == TMH_RESPONSE_reply_request_too_large
+        (connection)) ? GNUNET_SYSERR : GNUNET_NO;
     }
+
     /* everything OK, wait for more POST data */
     *upload_data_size = 0;
     return GNUNET_YES;
   }
 
+  TALER_LOG_DEBUG ("About to parse: %.*s\n",
+                   (int) r->fill,
+                   r->data);
   /* We have seen the whole request. */
-
   *json = json_loadb (r->data,
                       r->fill,
                       0,
@@ -263,9 +274,8 @@ TMH_PARSE_post_json (struct MHD_Connection *connection,
   {
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                 "Failed to parse JSON request body\n");
-    return (MHD_YES ==
-            TMH_RESPONSE_reply_invalid_json (connection))
-      ? GNUNET_NO : GNUNET_SYSERR;
+    return (MHD_YES == TMH_RESPONSE_reply_invalid_json
+      (connection)) ? GNUNET_NO : GNUNET_SYSERR;
   }
   buffer_deinit (r);
   GNUNET_free (r);
diff --git a/src/backend/taler-merchant-httpd_proposal.c 
b/src/backend/taler-merchant-httpd_proposal.c
index 64517b3..4d0298b 100644
--- a/src/backend/taler-merchant-httpd_proposal.c
+++ b/src/backend/taler-merchant-httpd_proposal.c
@@ -520,8 +520,10 @@ MH_handler_proposal_put (struct TMH_RequestHandler *rh,
                              &root);
   if (GNUNET_SYSERR == res)
     return MHD_NO;
-  /* the POST's body has to be further fetched */
+
+  /* A error response was already generated */
   if ( (GNUNET_NO == res) ||
+  /* or, need more data to accomplish parsing */
        (NULL == root) )
     return MHD_YES;
 
diff --git a/src/lib/test_merchant_api_twisted.c 
b/src/lib/test_merchant_api_twisted.c
index 1cdb0be..8c02cb4 100644
--- a/src/lib/test_merchant_api_twisted.c
+++ b/src/lib/test_merchant_api_twisted.c
@@ -186,6 +186,41 @@ run (void *cls,
   /**** Covering /proposal lib ****/
 
   /**
+   * Make the merchant return a 400 Bad Request response
+   * due to uploaded body malformation.
+   */
+  TALER_TESTING_cmd_malform_request
+    ("malform-order",
+     PROXY_MERCHANT_CONFIG_FILE),
+
+  TALER_TESTING_cmd_proposal
+    ("create-proposal-0",
+     twister_merchant_url,
+     is->ctx,
+     MHD_HTTP_BAD_REQUEST,
+     /* giving a valid JSON to not make it fail before
+      * data reaches the merchant.  */
+     "{\"not\": \"used\"}",
+     NULL),
+
+    TALER_TESTING_cmd_hack_response_code
+      ("proposal-500",
+       PROXY_MERCHANT_CONFIG_FILE,
+       MHD_HTTP_INTERNAL_SERVER_ERROR),
+
+  TALER_TESTING_cmd_proposal
+    ("create-proposal-1",
+     twister_merchant_url,
+     is->ctx,
+     /* This status code == 0 is gotten via a 500 Internal Server
+      * Error handed to the library.  */
+     MHD_HTTP_INTERNAL_SERVER_ERROR,
+     /* giving a valid JSON to not make it fail before
+      * data reaches the merchant.  */
+     "{\"not\": \"used\"}",
+     NULL),
+
+  /**
    * Cause the PUT /proposal callback to be called
    * with a response code == 0.  We achieve this by malforming
    * the response body.
@@ -196,7 +231,7 @@ run (void *cls,
        PROXY_MERCHANT_CONFIG_FILE),
 
     TALER_TESTING_cmd_proposal
-      ("create-proposal-0",
+      ("create-proposal-2",
        twister_merchant_url,
        is->ctx,
        0,
diff --git a/src/lib/testing_api_cmd_proposal.c 
b/src/lib/testing_api_cmd_proposal.c
index f42dfa8..e066c4c 100644
--- a/src/lib/testing_api_cmd_proposal.c
+++ b/src/lib/testing_api_cmd_proposal.c
@@ -290,12 +290,15 @@ proposal_cb (void *cls,
                   ps->is),
                 s);
     GNUNET_free_non_null (s);
-    TALER_TESTING_interpreter_fail (ps->is);
+    /**
+     * Not failing, as test cases are _supposed_
+     * to create non 200 OK situations.
+     */
+    TALER_TESTING_interpreter_next (ps->is);
   }
   return;
   }
 
-
   if (NULL ==
      (ps->plo = TALER_MERCHANT_proposal_lookup
        (ps->ctx,

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



reply via email to

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