[libsoup/carlosgc/http2-protocol-errors] http2-test: add invalid header received test
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup/carlosgc/http2-protocol-errors] http2-test: add invalid header received test
- Date: Thu, 1 Sep 2022 08:51:58 +0000 (UTC)
commit a044e347489ac6ccf4b51553d2e56c4ac42c6332
Author: Carlos Garcia Campos <cgarcia igalia com>
Date: Thu Sep 1 10:50:20 2022 +0200
http2-test: add invalid header received test
Check we now get an HTTP/2 protocol error when an ivalid header value is
received from the server.
tests/http2-test.c | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
---
diff --git a/tests/http2-test.c b/tests/http2-test.c
index c11b245e..12012c3b 100644
--- a/tests/http2-test.c
+++ b/tests/http2-test.c
@@ -20,6 +20,7 @@
#include "test-utils.h"
#include "soup-connection.h"
#include "soup-message-private.h"
+#include "soup-message-headers-private.h"
#include "soup-server-message-private.h"
#include "soup-body-input-stream-http2.h"
@@ -960,6 +961,31 @@ do_invalid_header_test (Test *test, gconstpointer data)
}
}
+static void
+do_invalid_header_received_test (Test *test, gconstpointer data)
+{
+ gboolean async = GPOINTER_TO_INT (data);
+ GUri *uri;
+ SoupMessage *msg;
+ GBytes *response;
+ GError *error = NULL;
+
+ uri = g_uri_parse_relative (base_uri, "/invalid-header", SOUP_HTTP_URI_FLAGS, NULL);
+ msg = soup_message_new_from_uri (SOUP_METHOD_GET, uri);
+
+ if (async)
+ response = soup_test_session_async_send (test->session, msg, NULL, &error);
+ else
+ response = soup_session_send_and_read (test->session, msg, NULL, &error);
+
+ g_assert_null (response);
+ g_error_matches (error, G_IO_ERROR, G_IO_ERROR_FAILED);
+ g_assert_cmpstr (error->message, ==, "HTTP/2 Error: PROTOCOL_ERROR");
+ g_clear_error (&error);
+ g_uri_unref (uri);
+ g_object_unref (msg);
+}
+
static void
content_sniffed (SoupMessage *msg,
char *content_type,
@@ -1178,6 +1204,13 @@ server_handler (SoupServer *server,
soup_server_message_set_response (msg, "text/plain",
SOUP_MEMORY_STATIC,
"Authenticated", 13);
+ } else if (strcmp (path, "/invalid-header") == 0) {
+ SoupMessageHeaders *response_headers;
+
+ response_headers = soup_server_message_get_response_headers (msg);
+ /* Use soup_message_headers_append_common to skip the validation check. */
+ soup_message_headers_append_common (response_headers, SOUP_HEADER_CONTENT_TYPE, "\r");
+ soup_server_message_set_status (msg, SOUP_STATUS_OK, NULL);
}
}
@@ -1305,6 +1338,14 @@ main (int argc, char **argv)
setup_session,
do_invalid_header_test,
teardown_session);
+ g_test_add ("/http2/invalid-header-received/async", Test, GINT_TO_POINTER (TRUE),
+ setup_session,
+ do_invalid_header_received_test,
+ teardown_session);
+ g_test_add ("/http2/invalid-header-received/sync", Test, GINT_TO_POINTER (FALSE),
+ setup_session,
+ do_invalid_header_received_test,
+ teardown_session);
g_test_add ("/http2/sniffer/async", Test, NULL,
setup_session,
do_sniffer_async_test,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]