diff options
author | Carlos Garcia Campos <cgarcia@igalia.com> | 2022-09-01 10:50:20 +0200 |
---|---|---|
committer | Carlos Garcia Campos <cgarcia@igalia.com> | 2022-09-01 10:50:20 +0200 |
commit | a044e347489ac6ccf4b51553d2e56c4ac42c6332 (patch) | |
tree | a8532a6d0619ba549f7a6c236bcfd3c453565fc2 | |
parent | 20643a063ba7e55c62d7324cd7448e6bb3f18ad8 (diff) | |
download | libsoup-a044e347489ac6ccf4b51553d2e56c4ac42c6332.tar.gz |
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.
-rw-r--r-- | tests/http2-test.c | 41 |
1 files changed, 41 insertions, 0 deletions
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" @@ -961,6 +962,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, GHashTable *params) @@ -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, |