diff options
author | Carlos Garcia Campos <cgarcia@igalia.com> | 2019-06-27 16:03:21 +0200 |
---|---|---|
committer | Carlos Garcia Campos <carlosgc@gnome.org> | 2019-06-27 16:42:00 +0200 |
commit | 109bb2f692c746bc63a0ade8737b584aecb0b1ad (patch) | |
tree | 079aeddca5bb32f4050a3d3b162f88c4c0bff2bc /tests | |
parent | fd794a952f5a3bdc2adf15e5245a3bffdeeee350 (diff) | |
download | libsoup-109bb2f692c746bc63a0ade8737b584aecb0b1ad.tar.gz |
WebSockets: allow null characters in text messages data
RFC 6455 says that text messages should contains valid UTF-8, and null
characters valid according to RFC 3629. However, we are using
g_utf8_validate(), which considers null characters as errors, to
validate WebSockets text messages. This patch adds an internal
utf8_validate() function based on g_utf8_validate() but allowing null
characters and just returning a gboolean since we are always ignoring
the end parameter in case of errors.
soup_websocket_connection_send_text() assumes the given text is null
terminated, so we need a new public function to allow sending text
messages containing null characters. This patch adds
soup_websocket_connection_send_message() that receives a
SoupWebsocketDataType and GBytes, which is consistent with
SoupWebsocketConnection::message signal.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/websocket-test.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/tests/websocket-test.c b/tests/websocket-test.c index 1f2781af..619b0b29 100644 --- a/tests/websocket-test.c +++ b/tests/websocket-test.c @@ -376,11 +376,13 @@ test_handshake_unsupported_extension (Test *test, } #define TEST_STRING "this is a test" +#define TEST_STRING_WITH_NULL "this is\0 a test" static void test_send_client_to_server (Test *test, gconstpointer data) { + GBytes *sent; GBytes *received = NULL; const char *contents; gsize len; @@ -395,14 +397,23 @@ test_send_client_to_server (Test *test, contents = g_bytes_get_data (received, &len); g_assert_cmpstr (contents, ==, TEST_STRING); g_assert_cmpint (len, ==, strlen (TEST_STRING)); + g_clear_pointer (&received, g_bytes_unref); - g_bytes_unref (received); + sent = g_bytes_new_static (TEST_STRING_WITH_NULL, sizeof (TEST_STRING_WITH_NULL)); + soup_websocket_connection_send_message (test->client, SOUP_WEBSOCKET_DATA_TEXT, sent); + + WAIT_UNTIL (received != NULL); + + g_assert (g_bytes_equal (sent, received)); + g_clear_pointer (&sent, g_bytes_unref); + g_clear_pointer (&received, g_bytes_unref); } static void test_send_server_to_client (Test *test, gconstpointer data) { + GBytes *sent; GBytes *received = NULL; const char *contents; gsize len; @@ -417,8 +428,16 @@ test_send_server_to_client (Test *test, contents = g_bytes_get_data (received, &len); g_assert_cmpstr (contents, ==, TEST_STRING); g_assert_cmpint (len, ==, strlen (TEST_STRING)); + g_clear_pointer (&received, g_bytes_unref); - g_bytes_unref (received); + sent = g_bytes_new_static (TEST_STRING_WITH_NULL, sizeof (TEST_STRING_WITH_NULL)); + soup_websocket_connection_send_message (test->server, SOUP_WEBSOCKET_DATA_TEXT, sent); + + WAIT_UNTIL (received != NULL); + + g_assert (g_bytes_equal (sent, received)); + g_clear_pointer (&sent, g_bytes_unref); + g_clear_pointer (&received, g_bytes_unref); } static void |