summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcello Stanisci <stanisci.m@gmail.com>2018-03-15 11:20:59 +0100
committerMarcello Stanisci <stanisci.m@gmail.com>2018-03-15 11:20:59 +0100
commit9cb8e4ad812dd197e1dcbb34ea58f1a99a3f7d1d (patch)
treeb7e15939f5de170495e3408abb32b7cea8dd2661
parent1dd44afd032ed46d38500256222973044e4db95d (diff)
downloadtwister-9cb8e4ad812dd197e1dcbb34ea58f1a99a3f7d1d.tar.gz
twister-9cb8e4ad812dd197e1dcbb34ea58f1a99a3f7d1d.tar.bz2
twister-9cb8e4ad812dd197e1dcbb34ea58f1a99a3f7d1d.zip
body malformation test CMD.
-rw-r--r--src/include/taler_twister_testing_lib.h14
-rwxr-xr-xsrc/test/test_twister.sh15
-rw-r--r--src/twister/taler-twister-service.c3
-rw-r--r--src/twister/testing_api_cmd_exec_client.c125
-rw-r--r--src/twister/twister_api.c2
5 files changed, 158 insertions, 1 deletions
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;
}