gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-twister] 30/34: body malformation test CMD.


From: gnunet
Subject: [GNUnet-SVN] [taler-twister] 30/34: body malformation test CMD.
Date: Sat, 17 Mar 2018 01:58:21 +0100

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

marcello pushed a commit to branch master
in repository twister.

commit 9cb8e4ad812dd197e1dcbb34ea58f1a99a3f7d1d
Author: Marcello Stanisci <address@hidden>
AuthorDate: Thu Mar 15 11:20:59 2018 +0100

    body malformation test CMD.
---
 src/include/taler_twister_testing_lib.h   |  14 ++++
 src/test/test_twister.sh                  |  15 ++++
 src/twister/taler-twister-service.c       |   3 +-
 src/twister/testing_api_cmd_exec_client.c | 125 ++++++++++++++++++++++++++++++
 src/twister/twister_api.c                 |   2 +
 5 files changed, 158 insertions(+), 1 deletion(-)

diff --git a/src/include/taler_twister_testing_lib.h 
b/src/include/taler_twister_testing_lib.h
index e0fa0ca..7c84483 100644
--- a/src/include/taler_twister_testing_lib.h
+++ b/src/include/taler_twister_testing_lib.h
@@ -80,4 +80,18 @@ TALER_TESTING_cmd_modify_object (const char *label,
                                  const char *config_filename,
                                  const char *path,
                                  const char *value);
+
+
+/**
+ * This command makes the next response randomly malformed
+ * (by truncating it).
+ *
+ * @param label command label
+ * @param config_filename configuration filename.
+ *
+ * @return the command
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_malform_response (const char *label,
+                                    const char *config_filename);
 #endif
diff --git a/src/test/test_twister.sh b/src/test/test_twister.sh
index 6703ce1..1413a0d 100755
--- a/src/test/test_twister.sh
+++ b/src/test/test_twister.sh
@@ -24,6 +24,21 @@ if ! test 202 = $status_code; then
   exit 1
 fi
 
+# malform response.
+taler-twister -c ./test_twister.conf --malform
+malformed_body=$(curl -s ${TWISTER_URL})
+
+# check response body has been emptied
+if test '{"hello":[{"this":"browser!"}],"when":"today"}' = \
+    "$malformed_body"; then
+  printf "Response body (%s) has not been emptied as expected\n" \
+    "$malformed_body"
+  kill $web_server_pid
+  kill $twister_service_pid
+  exit 1
+fi
+
+
 # delete object.
 taler-twister -c ./test_twister.conf -d "hello.0"
 emptied_body=$(curl -s ${TWISTER_URL})
diff --git a/src/twister/taler-twister-service.c 
b/src/twister/taler-twister-service.c
index 9ea8151..75e89f6 100644
--- a/src/twister/taler-twister-service.c
+++ b/src/twister/taler-twister-service.c
@@ -1304,7 +1304,7 @@ create_response (void *cls,
 
   if (NULL != hr->json)
   {
-    TALER_LOG_DEBUG ("Returning altered JSON.\n");
+    TALER_LOG_DEBUG ("Parsing final JSON.\n");
     body = json_dumps (hr->json, JSON_COMPACT);
     body_len = strlen (body);
     json_decref (hr->json);
@@ -1770,6 +1770,7 @@ handle_malform (void *cls,
 {
   struct GNUNET_SERVICE_Client *c = cls;
 
+  TALER_LOG_DEBUG ("Flagging response malformation\n");
   malform = GNUNET_YES;
   send_acknowledgement (c);
 }
diff --git a/src/twister/testing_api_cmd_exec_client.c 
b/src/twister/testing_api_cmd_exec_client.c
index 352d05a..a463d34 100644
--- a/src/twister/testing_api_cmd_exec_client.c
+++ b/src/twister/testing_api_cmd_exec_client.c
@@ -70,6 +70,20 @@ struct DeleteObjectState
 };
 
 
+struct MalformResponseState
+{
+  /**
+   * Process handle for the twister CLI client.
+   */
+  struct GNUNET_OS_Process *proc;
+
+  /**
+   * Config file name to pass to the CLI client.
+   */
+  const char *config_filename;
+
+};
+
 struct HackResponseCodeState
 {
   /**
@@ -405,6 +419,117 @@ TALER_TESTING_cmd_delete_object (const char *label,
 
 
 /**
+ * TODO.
+ */
+static void
+malform_response_cleanup
+  (void *cls,
+   const struct TALER_TESTING_Command *cmd)
+{
+  struct MalformResponseState *mrs = cls;
+
+  if (NULL != mrs->proc)
+  {
+    GNUNET_break (0 == GNUNET_OS_process_kill (mrs->proc,
+                                               SIGKILL));
+    GNUNET_OS_process_wait (mrs->proc);
+    GNUNET_OS_process_destroy (mrs->proc);
+    mrs->proc = NULL;
+  }
+  GNUNET_free (mrs);
+}
+
+
+/**
+ * Extract information from a command that is useful for other
+ * commands.
+ *
+ * @param cls closure
+ * @param ret[out] result (could be anything)
+ * @param trait name of the trait
+ * @param selector more detailed information about which object
+ *                 to return in case there were multiple generated
+ *                 by the command
+ * @return #GNUNET_OK on success
+ */
+static int
+malform_response_traits (void *cls,
+                         void **ret,
+                         const char *trait,
+                         unsigned int index)
+{
+
+  struct MalformResponseState *mrs = cls;
+  struct TALER_TESTING_Trait traits[] = {
+    TALER_TESTING_make_trait_process (0, &mrs->proc),
+    TALER_TESTING_trait_end ()
+  };
+
+  return TALER_TESTING_get_trait (traits,
+                                  ret,
+                                  trait,
+                                  index);
+}
+
+
+/**
+ * FIXME: document.
+ */
+static void
+malform_response_run (void *cls,
+                      const struct TALER_TESTING_Command *cmd,
+                      struct TALER_TESTING_Interpreter *is)
+{
+  struct MalformResponseState *mrs = cls;
+
+  mrs->proc = GNUNET_OS_start_process (GNUNET_NO,
+                                       GNUNET_OS_INHERIT_STD_ALL,
+                                       NULL, NULL, NULL,
+                                       "taler-twister",
+                                       "taler-twister",
+                                       "-c", mrs->config_filename,
+                                       "--malform",
+                                       NULL);
+  if (NULL == mrs->proc)
+  {
+    GNUNET_break (0);
+    TALER_TESTING_interpreter_fail (is);
+    return;
+  }
+  TALER_TESTING_wait_for_sigchld (is);
+}
+
+
+/**
+ * This command makes the next response randomly malformed
+ * (by truncating it).
+ *
+ * @param label command label
+ * @param config_filename configuration filename.
+ *
+ * @return the command
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_malform_response (const char *label,
+                                    const char *config_filename)
+{
+  struct MalformResponseState *mrs;
+  struct TALER_TESTING_Command cmd;
+
+  mrs = GNUNET_new (struct MalformResponseState);
+  mrs->config_filename = config_filename;
+
+  cmd.label = label;
+  cmd.run = &malform_response_run;
+  cmd.cleanup = &malform_response_cleanup;
+  cmd.traits = &malform_response_traits;
+  cmd.cls = mrs;
+
+  return cmd;
+
+}
+
+/**
  * This command deletes the JSON object pointed by @a path.
  *
  * @param label command label
diff --git a/src/twister/twister_api.c b/src/twister/twister_api.c
index c05e34b..b81b7b8 100644
--- a/src/twister/twister_api.c
+++ b/src/twister/twister_api.c
@@ -232,6 +232,8 @@ TALER_TWISTER_malform
     (src, TWISTER_MESSAGE_TYPE_MALFORM);
   /* Send message. */
   GNUNET_MQ_send (h->mq, env);
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "Batching a body malformation\n");
   return op;
 }
 

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



reply via email to

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