]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
PROXY Stream pre-rendered PROXY handling test
authorArtem Boldariev <artem@boldariev.com>
Mon, 13 Nov 2023 20:35:50 +0000 (22:35 +0200)
committerArtem Boldariev <artem@boldariev.com>
Wed, 6 Dec 2023 13:15:25 +0000 (15:15 +0200)
This commit extends the PROXY Stream transport unit test suite with a
pre-rendered PROXY header handling test.

tests/isc/netmgr_common.c
tests/isc/netmgr_common.h
tests/isc/proxystream_test.c

index e11d7f83300aaf8c0209e73648f2f219226dc8bc..0f16219321a2e12a354ccd0cdf7bb6cc99528640 100644 (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));
        }
 }
 
index 230e2499d4a4e998678ccffc35a0cae06b8006ad..c010a320ea935b8d5e4a23ef3af4c6fe0e1219e1 100644 (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);
 
index 0d9a1bab2158bba1d723d2c12e8b69d7bb243db5..3fa0b9fd9ff9a026a278aa90fe550854806890b5 100644 (file)
 
 #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,