|
7 | 7 | #include <fluent-bit/flb_pipe.h> |
8 | 8 | #include <fluent-bit/flb_socket.h> |
9 | 9 | #include <fluent-bit/tls/flb_tls.h> |
| 10 | +#include <fluent-bit/flb_config.h> |
10 | 11 |
|
11 | 12 | #include "flb_tests_internal.h" |
12 | 13 |
|
@@ -94,11 +95,86 @@ void test_prepare_destroy_conn_marks_tls_session_stale(void) |
94 | 95 | #endif |
95 | 96 | } |
96 | 97 |
|
| 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 | + |
97 | 171 | #endif |
98 | 172 |
|
99 | 173 | TEST_LIST = { |
100 | 174 | #ifdef FLB_HAVE_TLS |
101 | 175 | {"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}, |
102 | 178 | #endif |
103 | 179 | {0} |
104 | 180 | }; |
0 commit comments