2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 22:45:39 +00:00

PROXY Stream pre-rendered PROXY handling test

This commit extends the PROXY Stream transport unit test suite with a
pre-rendered PROXY header handling test.
This commit is contained in:
Artem Boldariev
2023-11-13 22:35:50 +02:00
parent 5ed3a76f9d
commit c9da121ece
3 changed files with 87 additions and 0 deletions

View File

@@ -600,6 +600,11 @@ tls_connect(isc_nm_t *nm) {
stream_use_PROXY, NULL);
}
void
set_proxyheader_info(isc_nm_proxyheader_info_t *pi) {
proxy_info = pi;
}
isc_nm_proxyheader_info_t *
get_proxyheader_info(void) {
if (proxy_info != NULL) {
@@ -915,6 +920,36 @@ stream_timeout_recovery_setup(void **state ISC_ATTR_UNUSED) {
return (r);
}
typedef struct proxy_addrs {
isc_sockaddr_t src_addr;
isc_sockaddr_t dst_addr;
} proxy_addrs_t;
static void
proxy2_handler_save_addrs_cb(const isc_result_t result,
const isc_proxy2_command_t cmd, const int socktype,
const isc_sockaddr_t *restrict src_addr,
const isc_sockaddr_t *restrict dst_addr,
const isc_region_t *restrict tlv_data,
const isc_region_t *restrict extra, void *cbarg) {
proxy_addrs_t *addrs = (proxy_addrs_t *)cbarg;
UNUSED(cmd);
UNUSED(socktype);
UNUSED(tlv_data);
UNUSED(extra);
REQUIRE(result == ISC_R_SUCCESS);
if (src_addr != NULL) {
addrs->src_addr = *src_addr;
}
if (dst_addr != NULL) {
addrs->dst_addr = *dst_addr;
}
}
void
proxy_verify_endpoints(isc_nmhandle_t *handle) {
isc_sockaddr_t local, peer;
@@ -931,6 +966,20 @@ proxy_verify_endpoints(isc_nmhandle_t *handle) {
} else if (proxy_info == NULL) {
assert_true(isc_sockaddr_equal(&peer, &proxy_src));
assert_true(isc_sockaddr_equal(&local, &proxy_dst));
} else if (proxy_info != NULL && !proxy_info->complete) {
assert_true(isc_sockaddr_equal(
&peer, &proxy_info->proxy_info.src_addr));
assert_true(isc_sockaddr_equal(
&local, &proxy_info->proxy_info.dst_addr));
} else if (proxy_info != NULL && proxy_info->complete) {
proxy_addrs_t addrs = { 0 };
RUNTIME_CHECK(isc_proxy2_header_handle_directly(
&proxy_info->complete_header,
proxy2_handler_save_addrs_cb,
&addrs) == ISC_R_SUCCESS);
assert_true(isc_sockaddr_equal(&peer, &addrs.src_addr));
assert_true(isc_sockaddr_equal(&local, &addrs.dst_addr));
}
}

View File

@@ -292,6 +292,9 @@ stream_listen(isc_nm_accept_cb_t accept_cb, void *accept_cbarg, int backlog,
void
stream_connect(isc_nm_cb_t cb, void *cbarg, unsigned int timeout);
void
set_proxyheader_info(isc_nm_proxyheader_info_t *pi);
isc_nm_proxyheader_info_t *
get_proxyheader_info(void);

View File

@@ -46,6 +46,13 @@
#include <tests/isc.h>
static isc_nm_proxyheader_info_t custom_info;
char complete_proxy_data[] = { 0x0d, 0x0a, 0x0d, 0x0a, 0x00, 0x0d, 0x0a,
0x51, 0x55, 0x49, 0x54, 0x0a, 0x21, 0x11,
0x00, 0x0c, 0x01, 0x02, 0x03, 0x04, 0x04,
0x03, 0x02, 0x01, 0x14, 0xe9, 0x14, 0xe9 };
/* TCP */
ISC_LOOP_TEST_IMPL(proxystream_noop) {
stream_noop(arg);
@@ -77,6 +84,24 @@ ISC_LOOP_TEST_IMPL(proxystream_recv_one) {
return;
}
static void
proxystream_recv_one_prerendered(void **arg ISC_ATTR_UNUSED) {
isc_region_t header = { 0 };
header.base = (unsigned char *)complete_proxy_data;
header.length = sizeof(complete_proxy_data);
isc_nm_proxyheader_info_init_complete(&custom_info, &header);
set_proxyheader_info(&custom_info);
stream_recv_one(arg);
}
ISC_LOOP_TEST_IMPL(proxystream_recv_one_prerendered) {
proxystream_recv_one_prerendered(arg);
return;
}
ISC_LOOP_TEST_IMPL(proxystream_recv_two) {
stream_recv_two(arg);
return;
@@ -151,6 +176,11 @@ ISC_LOOP_TEST_IMPL(proxystreamtls_recv_one) {
return;
}
ISC_LOOP_TEST_IMPL(proxystreamtls_recv_one_prerendered) {
proxystream_recv_one_prerendered(arg);
return;
}
ISC_LOOP_TEST_IMPL(proxystreamtls_recv_two) {
stream_recv_two(arg);
return;
@@ -209,6 +239,8 @@ ISC_TEST_ENTRY_CUSTOM(proxystream_timeout_recovery,
proxystream_timeout_recovery_teardown)
ISC_TEST_ENTRY_CUSTOM(proxystream_recv_one, proxystream_recv_one_setup,
proxystream_recv_one_teardown)
ISC_TEST_ENTRY_CUSTOM(proxystream_recv_one_prerendered,
proxystream_recv_one_setup, proxystream_recv_one_teardown)
ISC_TEST_ENTRY_CUSTOM(proxystream_recv_two, proxystream_recv_two_setup,
proxystream_recv_two_teardown)
ISC_TEST_ENTRY_CUSTOM(proxystream_recv_send, proxystream_recv_send_setup,
@@ -247,6 +279,9 @@ ISC_TEST_ENTRY_CUSTOM(proxystreamtls_timeout_recovery,
proxystreamtls_timeout_recovery_teardown)
ISC_TEST_ENTRY_CUSTOM(proxystreamtls_recv_one, proxystreamtls_recv_one_setup,
proxystreamtls_recv_one_teardown)
ISC_TEST_ENTRY_CUSTOM(proxystreamtls_recv_one_prerendered,
proxystreamtls_recv_one_setup,
proxystreamtls_recv_one_teardown)
ISC_TEST_ENTRY_CUSTOM(proxystreamtls_recv_two, proxystreamtls_recv_two_setup,
proxystreamtls_recv_two_teardown)
ISC_TEST_ENTRY_CUSTOM(proxystreamtls_recv_send, proxystreamtls_recv_send_setup,