Skip to content

Commit b89e9a7

Browse files
tests: internal: add HTTPS proxy upstream create coverage
Add two tests to upstream_tls.c: - upstream_create_https_proxy_sets_tls_context: verifies that flb_upstream_create creates a non-NULL proxy_tls_context with verify_hostname enabled when an https:// proxy is configured. - upstream_create_http_proxy_no_tls_context: verifies that proxy_tls_context remains NULL when a plain http:// proxy is used, ensuring no regression on the existing code path. Signed-off-by: Antônio Franco <13881523+antoniomrfranco@users.noreply.github.com>
1 parent 8ee410b commit b89e9a7

1 file changed

Lines changed: 76 additions & 0 deletions

File tree

tests/internal/upstream_tls.c

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <fluent-bit/flb_pipe.h>
88
#include <fluent-bit/flb_socket.h>
99
#include <fluent-bit/tls/flb_tls.h>
10+
#include <fluent-bit/flb_config.h>
1011

1112
#include "flb_tests_internal.h"
1213

@@ -94,11 +95,86 @@ void test_prepare_destroy_conn_marks_tls_session_stale(void)
9495
#endif
9596
}
9697

98+
/*
99+
* Verify that flb_upstream_create creates a proxy_tls_context with
100+
* verify_hostname enabled when an https:// proxy is configured.
101+
*/
102+
void test_upstream_create_https_proxy_sets_tls_context(void)
103+
{
104+
struct flb_config *config;
105+
struct flb_upstream *u;
106+
107+
config = flb_config_init();
108+
TEST_CHECK(config != NULL);
109+
if (config == NULL) {
110+
return;
111+
}
112+
113+
config->http_proxy = "https://proxy.example.com:8080";
114+
115+
u = flb_upstream_create(config, "dest.example.com", 443,
116+
FLB_IO_TLS, NULL);
117+
TEST_CHECK(u != NULL);
118+
if (u == NULL) {
119+
config->http_proxy = NULL;
120+
flb_config_exit(config);
121+
return;
122+
}
123+
124+
TEST_CHECK(u->proxy_tls_context != NULL);
125+
TEST_MSG("proxy_tls_context should be non-NULL for https:// proxy");
126+
127+
if (u->proxy_tls_context != NULL) {
128+
TEST_CHECK(u->proxy_tls_context->verify_hostname == FLB_TRUE);
129+
TEST_MSG("proxy_tls_context should have verify_hostname enabled");
130+
}
131+
132+
config->http_proxy = NULL;
133+
flb_upstream_destroy(u);
134+
flb_config_exit(config);
135+
}
136+
137+
/*
138+
* Verify that flb_upstream_create does NOT create a proxy_tls_context
139+
* when a plain http:// proxy is configured.
140+
*/
141+
void test_upstream_create_http_proxy_no_tls_context(void)
142+
{
143+
struct flb_config *config;
144+
struct flb_upstream *u;
145+
146+
config = flb_config_init();
147+
TEST_CHECK(config != NULL);
148+
if (config == NULL) {
149+
return;
150+
}
151+
152+
config->http_proxy = "http://proxy.example.com:3128";
153+
154+
u = flb_upstream_create(config, "dest.example.com", 80,
155+
FLB_IO_TCP, NULL);
156+
TEST_CHECK(u != NULL);
157+
if (u == NULL) {
158+
config->http_proxy = NULL;
159+
flb_config_exit(config);
160+
return;
161+
}
162+
163+
TEST_CHECK(u->proxy_tls_context == NULL);
164+
TEST_MSG("proxy_tls_context should be NULL for plain http:// proxy");
165+
166+
config->http_proxy = NULL;
167+
flb_upstream_destroy(u);
168+
flb_config_exit(config);
169+
}
170+
97171
#endif
98172

99173
TEST_LIST = {
100174
#ifdef FLB_HAVE_TLS
101175
{"prepare_destroy_conn_marks_tls_session_stale", test_prepare_destroy_conn_marks_tls_session_stale},
176+
{"upstream_create_https_proxy_sets_tls_context", test_upstream_create_https_proxy_sets_tls_context},
177+
{"upstream_create_http_proxy_no_tls_context", test_upstream_create_http_proxy_no_tls_context},
102178
#endif
103179
{0}
104180
};

0 commit comments

Comments
 (0)