diff options
author | George Kadianakis <desnacked@riseup.net> | 2020-07-29 12:39:05 +0300 |
---|---|---|
committer | George Kadianakis <desnacked@riseup.net> | 2020-07-30 19:46:39 +0300 |
commit | 2bb9acca73f37a1d63485afa6bf1e52e37b333b9 (patch) | |
tree | 00d17e904c38fad5701bbfb9cc6af588a8b4ab99 /src/test/test_config.c | |
parent | fc5fe094b1a330c30c951492d2401a8de1acfa97 (diff) | |
download | tor-2bb9acca73f37a1d63485afa6bf1e52e37b333b9.tar.gz tor-2bb9acca73f37a1d63485afa6bf1e52e37b333b9.zip |
Write unittest for #40065.
Make the unit test pass by including an explicit IPv6 port and an
implicit IPv4 port. See comments for more details.
Diffstat (limited to 'src/test/test_config.c')
-rw-r--r-- | src/test/test_config.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/test/test_config.c b/src/test/test_config.c index 9eadfeed33..c116a1bbe9 100644 --- a/src/test/test_config.c +++ b/src/test/test_config.c @@ -6497,6 +6497,39 @@ test_config_getinfo_config_names(void *arg) tor_free(answer); } +static void +test_config_duplicate_orports(void *arg) +{ + (void)arg; + + config_line_t *config_port = NULL; + smartlist_t *ports = smartlist_new(); + + // Pretend that the user has specified an implicit 0.0.0.0:9050, an implicit + // [::]:9050, and an explicit on [::1]:9050. + config_line_append(&config_port, "ORPort", "9050"); // two implicit entries. + config_line_append(&config_port, "ORPort", "[::1]:9050"); + + // Parse IPv4, then IPv6. + port_parse_config(ports, config_port, "OR", CONN_TYPE_OR_LISTENER, "0.0.0.0", + 0, CL_PORT_SERVER_OPTIONS); + port_parse_config(ports, config_port, "OR", CONN_TYPE_OR_LISTENER, "[::]", + 0, CL_PORT_SERVER_OPTIONS); + + // There should be three ports at this point. + tt_int_op(smartlist_len(ports), OP_EQ, 3); + + remove_duplicate_orports(ports); + + // The explicit IPv6 port should have replaced the implicit IPv6 port. + tt_int_op(smartlist_len(ports), OP_EQ, 2); + + done: + SMARTLIST_FOREACH(ports,port_cfg_t *,pf,port_cfg_free(pf)); + smartlist_free(ports); + config_free_lines(config_port); +} + #ifndef COCCI #define CONFIG_TEST(name, flags) \ { #name, test_config_ ## name, flags, NULL, NULL } @@ -6562,5 +6595,6 @@ struct testcase_t config_tests[] = { CONFIG_TEST(extended_fmt, 0), CONFIG_TEST(kvline_parse, 0), CONFIG_TEST(getinfo_config_names, 0), + CONFIG_TEST(duplicate_orports, 0), END_OF_TESTCASES }; |