diff options
author | Suphanat Chunhapanya <haxx.pop@gmail.com> | 2019-08-22 10:25:04 +0800 |
---|---|---|
committer | Suphanat Chunhapanya <haxx.pop@gmail.com> | 2019-10-17 15:33:16 +0800 |
commit | 9dd04396ba66602e89df52fd8bc1cbad1201083b (patch) | |
tree | f051c5a082229740f99078bcd744275ceb327548 /src | |
parent | 5a6a6ed33c400c93387f388e3b8fb109d7047f2f (diff) | |
download | tor-9dd04396ba66602e89df52fd8bc1cbad1201083b.tar.gz tor-9dd04396ba66602e89df52fd8bc1cbad1201083b.zip |
test: Add TCPProxy option for haproxy protocol
Diffstat (limited to 'src')
-rw-r--r-- | src/test/test_config.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/test/test_config.c b/src/test/test_config.c index cbb84e4dcf..a9094c79b8 100644 --- a/src/test/test_config.c +++ b/src/test/test_config.c @@ -672,6 +672,52 @@ transport_is_needed_mock(const char *transport_name) return transport_is_needed_mock_return; } +static void +test_config_parse_tcp_proxy_line(void *arg) +{ + (void)arg; + + int ret; + char *msg = NULL; + or_options_t *options = get_options_mutable(); + + /* Bad TCPProxy line - too short. */ + ret = parse_tcp_proxy_line("haproxy", options, &msg); + /* Return error. */ + tt_int_op(ret, OP_EQ, -1); + /* Correct error message. */ + tt_str_op(msg, OP_EQ, "TCPProxy has no address/port. Please fix."); + /* Free error message. */ + tor_free(msg); + + /* Bad TCPProxy line - unsupported protocol. */ + ret = parse_tcp_proxy_line("unsupported 95.216.163.36:443", options, &msg); + tt_int_op(ret, OP_EQ, -1); + tt_str_op(msg, OP_EQ, "TCPProxy protocol is not supported. Currently the " + "only supported protocol is 'haproxy'. Please fix."); + tor_free(msg); + + /* Bad TCPProxy line - unparsable address/port. */ + ret = parse_tcp_proxy_line("haproxy 95.216.163.36/443", options, &msg); + tt_int_op(ret, OP_EQ, -1); + tt_str_op(msg, OP_EQ, "TCPProxy address/port failed to parse or resolve. " + "Please fix."); + tor_free(msg); + + /* Good TCPProxy line - ipv4. */ + ret = parse_tcp_proxy_line("haproxy 95.216.163.36:443", options, &msg); + tt_int_op(ret, OP_EQ, 0); + tt_ptr_op(msg, OP_EQ, NULL); + tt_int_op(options->TCPProxyProtocol, OP_EQ, TCP_PROXY_PROTOCOL_HAPROXY); + /* Correct the address. */ + tt_assert(tor_addr_eq_ipv4h(&options->TCPProxyAddr, 0x5fd8a324)); + tt_int_op(options->TCPProxyPort, OP_EQ, 443); + tor_free(msg); + + done: + ; +} + /** * Test parsing for the ClientTransportPlugin and ServerTransportPlugin config * options. @@ -6097,6 +6143,7 @@ struct testcase_t config_tests[] = { CONFIG_TEST(parse_bridge_line, 0), CONFIG_TEST(parse_transport_options_line, 0), CONFIG_TEST(parse_transport_plugin_line, TT_FORK), + CONFIG_TEST(parse_tcp_proxy_line, TT_FORK), CONFIG_TEST(check_or_create_data_subdir, TT_FORK), CONFIG_TEST(write_to_data_subdir, TT_FORK), CONFIG_TEST(fix_my_family, 0), |