[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Write unittest for #40065.



commit 2bb9acca73f37a1d63485afa6bf1e52e37b333b9
Author: George Kadianakis <desnacked@xxxxxxxxxx>
Date:   Wed Jul 29 12:39:05 2020 +0300

    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.
---
 src/feature/relay/relay_config.c |  2 +-
 src/feature/relay/relay_config.h |  1 +
 src/test/test_config.c           | 34 ++++++++++++++++++++++++++++++++++
 3 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/src/feature/relay/relay_config.c b/src/feature/relay/relay_config.c
index fc934b7879..711fbd14e5 100644
--- a/src/feature/relay/relay_config.c
+++ b/src/feature/relay/relay_config.c
@@ -183,7 +183,7 @@ describe_relay_port(const port_cfg_t *port)
  *
  * The following is O(n^2) but it is done at bootstrap or config reload and
  * the list is not very long usually. */
-static void
+STATIC void
 remove_duplicate_orports(smartlist_t *ports)
 {
   /* First we'll decide what to remove, then we'll remove it. */
diff --git a/src/feature/relay/relay_config.h b/src/feature/relay/relay_config.h
index c70c322d88..671399ac0a 100644
--- a/src/feature/relay/relay_config.h
+++ b/src/feature/relay/relay_config.h
@@ -84,6 +84,7 @@ int options_act_relay_dir(const struct or_options_t *old_options);
 
 #ifdef RELAY_CONFIG_PRIVATE
 
+STATIC void remove_duplicate_orports(struct smartlist_t *ports);
 STATIC int check_bridge_distribution_setting(const char *bd);
 STATIC int have_enough_mem_for_dircache(const struct or_options_t *options,
                                         size_t total_mem, char **msg);
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
 };



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits