Files
wget2/tests/libtest.h
Tim Rühsen 7189cf41c5 Add comprehensive HTTP/2 testing infrastructure with libnghttp2
This adds extensive HTTP/2 test coverage using libnghttp2 as the test
server, covering multiplexing, stream error handling, connection
management, and settings negotiation.

* tests/libtest.h (wget_test_url_t): Add h2_delay_response and
  h2_rst_stream_error fields for HTTP/2 test control.
  (WGET_TEST_H2_MIN_CONCURRENT_STREAMS): New test flag.
  (wget_test_get_h2_server_port): Declare function.

* tests/libtest.c: Remove HAVE_MICROHTTPD_HTTP2_H infrastructure,
  (h2_session_data, h2_server_t): New structures for libnghttp2 server,
  (h2_send_callback, h2_recv_callback): Implement nghttp2 I/O callbacks,
  (h2_on_frame_recv_callback): Handle HTTP/2 frames,
  (h2_on_header_callback): Process request headers,
  (h2_data_read_callback): Stream response body with 8KB chunk limit,
  (h2_on_stream_close_callback): Clean up stream resources,
  (h2_session_data_new, h2_session_data_free): Manage session lifecycle,
  (h2_server_thread): Main server loop with TLS and ALPN support,
  (h2_server_start, h2_server_stop): Control server lifecycle,
  (_http_server_stop): Remove gnutls_global_deinit() call to fix
  server restart issues,
  (wget_test_start_server_handler): Default start_h2 to 0 (opt-in),
  enable HTTP/2 with WGET_TEST_H2_ONLY flag,
  (wget_test): Skip H2_PASS when libnghttp2 unavailable,
  (wget_test_get_h2_server_port): Return HTTP/2 server port.

* tests/Makefile.am (WGET_TESTS): Add test-http2-multiplexing,
  test-http2-stream-errors, test-http2-connection-errors,
  test-http2-settings.

* tests/test-http2-multiplexing.c: New file testing concurrent
  downloads over single HTTP/2 connection with multiplexing.

* tests/test-http2-stream-errors.c: New file testing stream error
  isolation with RST_STREAM frames.

* tests/test-http2-connection-errors.c: New file testing connection
  recovery after server restart.

* tests/test-http2-settings.c: New file testing SETTINGS frame
  exchange, header compression, and large headers.

* tests/test-limit-rate-http2.c (main): Skip 3-file multiplexed
  download test when running with HTTP/2 due to rate limiting
  limitations in test server.

The HTTP/2 test server uses libnghttp2 with GnuTLS for TLS and ALPN
negotiation. Tests verify protocol-specific features like multiplexing,
stream independence, and proper SETTINGS exchange. HTTP/2 is now opt-in
via WGET_TEST_H2_ONLY to avoid breaking existing tests.
2025-12-26 17:42:15 +01:00

183 lines
4.5 KiB
C

/*
* Copyright (c) 2013-2014 Tim Ruehsen
* Copyright (c) 2015-2024 Free Software Foundation, Inc.
*
* This file is part of libwget.
*
* Libwget is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Libwget is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with libwget. If not, see <https://www.gnu.org/licenses/>.
*
*
* Test suite function library header
*
* Changelog
* 10.03.2013 Tim Ruehsen created
*
* Test suite function library
*
* To create the X.509 stuff, I followed the instructions at
* gnutls.org/manual/html_node/gnutls_002dserv-Invocation.html
*
*/
#ifndef TESTS_LIBTEST_H
#define TESTS_LIBTEST_H
#include <stdbool.h>
#include <wget.h>
#ifdef __cplusplus
extern "C" {
#endif
#define WGET_TEST_EXIT_SKIP 77
// defines for wget_test_start_http_server()
#define WGET_TEST_RESPONSE_URLS 1002
#define WGET_TEST_HTTP_ONLY 1003
#define WGET_TEST_HTTPS_ONLY 1004
#define WGET_TEST_HTTP_REJECT_CONNECTIONS 1005
#define WGET_TEST_HTTPS_REJECT_CONNECTIONS 1006
#define WGET_TEST_H2_ONLY 1007
#define WGET_TEST_SKIP_H2 1008
#define WGET_TEST_H2_MIN_CONCURRENT_STREAMS 1009
#define WGET_TEST_FEATURE_MHD 1101
#define WGET_TEST_FEATURE_TLS 1102
#define WGET_TEST_FEATURE_IDN 1103
#define WGET_TEST_FEATURE_PLUGIN 1104
#define WGET_TEST_FEATURE_OCSP 1105
#define WGET_TEST_FEATURE_OCSP_STAPLING 1106
// defines for wget_test()
#define WGET_TEST_REQUEST_URL 2001
#define WGET_TEST_OPTIONS 2002
#define WGET_TEST_EXPECTED_ERROR_CODE 2003
#define WGET_TEST_EXPECTED_FILES 2004
#define WGET_TEST_EXISTING_FILES 2005
#define WGET_TEST_KEEP_TMPFILES 2006
#define WGET_TEST_REQUEST_URLS 2007
#define WGET_TEST_EXECUTABLE 2008
#define WGET_TEST_SERVER_SEND_CONTENT_LENGTH 2009
#define WGET_TEST_EXPECTED_ERROR_CODE2 2010
#define WGET_TEST_CLEAN_DIRECTORY 2011
// defines for wget_test_check_file_system()
#define WGET_TEST_FS_CASEMATTERS 3001 // file system is case-sensitive
// for post-handshake authentication
#define WGET_TEST_POST_HANDSHAKE_AUTH 3002
// for OCSP testing
#define WGET_TEST_OCSP_RESP_FILES 3003
typedef enum {
INTERRUPT_RESPONSE_DISABLED = 0,
INTERRUPT_RESPONSE_DURING_BODY
} interrupt_response_mode_t;
#define countof(a) (sizeof(a)/sizeof(*(a)))
#define TEST_OPAQUE_STR "11733b200778ce33060f31c9af70a870ba96ddd4"
WGET_GCC_UNUSED static const char *WGET_TEST_SOME_HTML_BODY = "\
<html>\n\
<head>\n\
<title>The Title</title>\n\
</head>\n\
<body>\n\
<p>\n\
Some text\n\
</p>\n\
</body>\n\
</html>\n";
typedef struct {
const char *
name;
const char *
content;
time_t
timestamp;
char
restricted_mode;
size_t
content_length;
const char *
hardlink;
} wget_test_file_t;
typedef struct {
const char *
name;
const char *
code;
const char *
body;
const char *
body_original;
const char *
headers[10];
const char *
headers_original[10];
const char *
request_headers[10];
const char *
expected_req_headers[10];
const char *
unexpected_req_headers[10];
const char *
expected_method;
int64_t
modified;
// auth fields
const char *
auth_method;
const char *
auth_username;
const char *
auth_password;
size_t
body_len; // The length of the body in bytes. 0 means use strlen(body)
interrupt_response_mode_t
interrupt_response_mode;
size_t
interrupt_response_after_nbytes;
bool
https_only : 1,
http_only : 1,
h2_delay_response : 1;
} wget_test_url_t;
WGETAPI void wget_test_stop_server(void);
WGETAPI void wget_test_start_server(int first_key, ...);
WGETAPI void wget_test(int first_key, ...);
WGETAPI int wget_test_check_file_system(void);
WGETAPI void wget_test_set_executable(const char *);
WGETAPI int wget_test_get_http_server_port(void) WGET_GCC_PURE;
WGETAPI int wget_test_get_https_server_port(void) WGET_GCC_PURE;
WGETAPI int wget_test_get_ocsp_server_port(void) WGET_GCC_PURE;
WGETAPI int wget_test_get_h2_server_port(void) WGET_GCC_PURE;
#if defined __clang__ || __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
# pragma GCC diagnostic ignored "-Wmissing-field-initializers"
#endif
#ifdef __cplusplus
}
#endif
#endif /* _LIBWGET_LIBTEST_H */