Skip to content

Commit 5ce5a2a

Browse files
tests: internal: add HTTPS proxy support coverage
Extend proxy_url_checks in utils.c with HTTPS proxy cases (explicit port, default port 443, credentials) and rejection cases for unsupported schemes (ftp://, socks5://). Add two tests to upstream_tls.c: one verifies that flb_upstream_create with an https:// proxy sets a non-NULL proxy_tls_context with verify_hostname enabled; another verifies that a plain http:// proxy leaves proxy_tls_context NULL. Signed-off-by: Antônio Franco <13881523+antoniomrfranco@users.noreply.github.com>
1 parent 23e2f2b commit 5ce5a2a

2 files changed

Lines changed: 88 additions & 2 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

@@ -161,12 +162,87 @@ void test_tls_session_destroy_no_double_free(void)
161162
#endif
162163
}
163164

165+
/*
166+
* Verify that flb_upstream_create creates a proxy_tls_context with
167+
* verify_hostname enabled when an https:// proxy is configured.
168+
*/
169+
void test_upstream_create_https_proxy_sets_tls_context(void)
170+
{
171+
struct flb_config *config;
172+
struct flb_upstream *u;
173+
174+
config = flb_config_init();
175+
TEST_CHECK(config != NULL);
176+
if (config == NULL) {
177+
return;
178+
}
179+
180+
config->http_proxy = "https://proxy.example.com:8080";
181+
182+
u = flb_upstream_create(config, "dest.example.com", 443,
183+
FLB_IO_TLS, NULL);
184+
TEST_CHECK(u != NULL);
185+
if (u == NULL) {
186+
config->http_proxy = NULL;
187+
flb_config_exit(config);
188+
return;
189+
}
190+
191+
TEST_CHECK(u->proxy_tls_context != NULL);
192+
TEST_MSG("proxy_tls_context should be non-NULL for https:// proxy");
193+
194+
if (u->proxy_tls_context != NULL) {
195+
TEST_CHECK(u->proxy_tls_context->verify_hostname == FLB_TRUE);
196+
TEST_MSG("proxy_tls_context should have verify_hostname enabled");
197+
}
198+
199+
config->http_proxy = NULL;
200+
flb_upstream_destroy(u);
201+
flb_config_exit(config);
202+
}
203+
204+
/*
205+
* Verify that flb_upstream_create does NOT create a proxy_tls_context
206+
* when a plain http:// proxy is configured.
207+
*/
208+
void test_upstream_create_http_proxy_no_tls_context(void)
209+
{
210+
struct flb_config *config;
211+
struct flb_upstream *u;
212+
213+
config = flb_config_init();
214+
TEST_CHECK(config != NULL);
215+
if (config == NULL) {
216+
return;
217+
}
218+
219+
config->http_proxy = "http://proxy.example.com:3128";
220+
221+
u = flb_upstream_create(config, "dest.example.com", 80,
222+
FLB_IO_TCP, NULL);
223+
TEST_CHECK(u != NULL);
224+
if (u == NULL) {
225+
config->http_proxy = NULL;
226+
flb_config_exit(config);
227+
return;
228+
}
229+
230+
TEST_CHECK(u->proxy_tls_context == NULL);
231+
TEST_MSG("proxy_tls_context should be NULL for plain http:// proxy");
232+
233+
config->http_proxy = NULL;
234+
flb_upstream_destroy(u);
235+
flb_config_exit(config);
236+
}
237+
164238
#endif
165239

166240
TEST_LIST = {
167241
#ifdef FLB_HAVE_TLS
168242
{"prepare_destroy_conn_marks_tls_session_stale", test_prepare_destroy_conn_marks_tls_session_stale},
169243
{"tls_session_destroy_no_double_free", test_tls_session_destroy_no_double_free},
244+
{"upstream_create_https_proxy_sets_tls_context", test_upstream_create_https_proxy_sets_tls_context},
245+
{"upstream_create_http_proxy_no_tls_context", test_upstream_create_http_proxy_no_tls_context},
170246
#endif
171247
{0}
172248
};

tests/internal/utils.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -658,8 +658,18 @@ struct proxy_url_check proxy_url_checks[] = {
658658
/* issue #5530. Password contains @ */
659659
{0, "http://example_user:example_pass_w_@_char@proxy.com:8080",
660660
"http", "proxy.com", "8080", "example_user", "example_pass_w_@_char"},
661-
{-1, "https://proxy.com:8080",
662-
NULL, NULL, NULL, NULL, NULL}
661+
/* HTTPS proxy with explicit port */
662+
{0, "https://proxy.com:8080",
663+
"https", "proxy.com", "8080", NULL, NULL},
664+
/* HTTPS proxy, default port 443 */
665+
{0, "https://proxy.com",
666+
"https", "proxy.com", "443", NULL, NULL},
667+
/* HTTPS proxy with credentials */
668+
{0, "https://user:pass@proxy.com:443",
669+
"https", "proxy.com", "443", "user", "pass"},
670+
/* Unsupported schemes must be rejected */
671+
{-1, "ftp://proxy.com:21", NULL, NULL, NULL, NULL, NULL},
672+
{-1, "socks5://proxy.com", NULL, NULL, NULL, NULL, NULL},
663673

664674
};
665675

0 commit comments

Comments
 (0)