twister

HTTP fault injector for testing
Log | Files | Refs | README | LICENSE

commit 8fbd7583ac35df5e8f8af5088544e5360b59ed77
parent 600c003c034fac5b15866a24ab5274192ede8840
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date:   Thu, 22 Mar 2018 16:41:45 +0100

implement char-flipper.

Diffstat:
Msrc/test/test_twister.sh | 2+-
Msrc/twister/taler-twister-service.c | 75++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 75 insertions(+), 2 deletions(-)

diff --git a/src/test/test_twister.sh b/src/test/test_twister.sh @@ -46,7 +46,7 @@ flip_field=$(echo $flip_body | tr -d '"}{' | awk -F, '{print $2}' | awk -F: '{pr # check if pointed object was flipped. if test "$flip_field" = 'today'; then - printf "Response body (%s) has not been flipped as expected\n" "$flip_body" + printf "Response body (%s vs. %s) has not been flipped as expected\n" "$flip_body" "$flip_field" kill $web_server_pid kill $twister_service_pid exit 1 diff --git a/src/twister/taler-twister-service.c b/src/twister/taler-twister-service.c @@ -895,7 +895,12 @@ walk_response_object (const char *path, last_token = strrchr (path_dup, '.') + 1; /* Give first nondelim char. */ token = strtok (path_dup, "."); - element = hr->json; + + if (NULL == (element = hr->json)) + { + TALER_LOG_ERROR ("Attempting to walk a non JSON response!\n"); + return GNUNET_SYSERR; + } while (last_token != token) { @@ -1014,6 +1019,67 @@ modify_object (struct MHD_Connection *con, return; } +static void +flip_object (struct MHD_Connection *con, + struct HttpRequest *hr) +{ + char *target; + json_t *parent; + + if (GNUNET_OK != walk_response_object (flip_path, + &parent, + &target, + hr)) + return; + + /* here, element is the parent of the element to be deleted. */ + int ret_flip = -1; + json_t *child = NULL; + const char *current_value; + char *current_value_flip; + uint32_t index; + + if (json_is_object (parent)) + child = json_object_get (parent, target); + + if (json_is_array (parent)) + child = json_array_get + (parent, (unsigned int) strtoul (target, + NULL, + 10)); + + /* json walker is such that at this point the + * child's parent is always a object or array. */ + GNUNET_assert (NULL != child); + + current_value = json_string_value (child); + + #warning When free this? + current_value_flip = GNUNET_strdup (current_value); + index = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, + strlen (current_value_flip)); + + /* flip the LSB. */ + current_value_flip[index] ^= 1; + if (0 == json_string_set + (child, + (const char *) current_value_flip)) + ret_flip = GNUNET_YES; + + if (-1 == ret_flip) + TALER_LOG_WARNING ("Could not flip '%s'\n", target); + else + TALER_LOG_INFO ("Flipped to %s, from %s\n", + current_value_flip, + current_value); + + flip_path[0] = '\0'; + GNUNET_free (target); + return; +} + + + /** * Delete object within the proxied response. * Always queues a response; only deletes the object if it is @@ -1351,6 +1417,13 @@ create_response (void *cls, hack_response_code = 0; /* reset for next request */ } + if ('\0' != flip_path[0]) + { + TALER_LOG_DEBUG ("Will flip path: %s\n", + flip_path); + flip_object (con, hr); + } + if ('\0' != delete_path[0]) { TALER_LOG_DEBUG ("Will delete path: %s\n",