aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_router.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2020-03-19 09:44:27 -0400
committerteor <teor@torproject.org>2020-03-21 03:43:58 +1000
commit1251265a0f49c7446f3e00854eda8091e84d9e96 (patch)
treebb345868003185d56b8858469f07658eb935629b /src/test/test_router.c
parent1ba79d4567c95f75daf171878faaa07b78d89130 (diff)
downloadtor-1251265a0f49c7446f3e00854eda8091e84d9e96.tar.gz
tor-1251265a0f49c7446f3e00854eda8091e84d9e96.zip
Extend test to handle router_get_advertised_ipv6_or_ap
Diffstat (limited to 'src/test/test_router.c')
-rw-r--r--src/test/test_router.c33
1 files changed, 27 insertions, 6 deletions
diff --git a/src/test/test_router.c b/src/test/test_router.c
index 5699d5472b..8c772c6817 100644
--- a/src/test/test_router.c
+++ b/src/test/test_router.c
@@ -253,28 +253,49 @@ test_router_get_advertised_or_port(void *arg)
char *msg=NULL;
or_options_t *opts = options_new();
listener_connection_t *listener = NULL;
+ tor_addr_port_t ipv6;
+
+ // Test one failing case of router_get_advertised_ipv6_or_ap().
+ router_get_advertised_ipv6_or_ap(opts, &ipv6);
+ tt_str_op(fmt_addrport(&ipv6.addr, ipv6.port), OP_EQ, "[::]:0");
+
+ // And one failing case of router_get_advertised_or_port().
+ tt_int_op(0, OP_EQ, router_get_advertised_or_port_by_af(opts, AF_INET));
+ tt_int_op(0, OP_EQ, router_get_advertised_or_port(opts));
// Set up a couple of configured ports.
- config_line_append(&opts->ORPort_lines, "ORPort", "[1234::5678]:9999");
- config_line_append(&opts->ORPort_lines, "ORPort", "5.6.7.8:auto");
+ config_line_append(&opts->ORPort_lines, "ORPort", "[1234::5678]:auto");
+ config_line_append(&opts->ORPort_lines, "ORPort", "5.6.7.8:9999");
r = parse_ports(opts, 0, &msg, &n, &w);
tt_assert(r == 0);
// There are no listeners, so the "auto" case will turn up no results.
- tt_int_op(0, OP_EQ, router_get_advertised_or_port_by_af(opts, AF_INET));
+ tt_int_op(0, OP_EQ, router_get_advertised_or_port_by_af(opts, AF_INET6));
+ router_get_advertised_ipv6_or_ap(opts, &ipv6);
+ tt_str_op(fmt_addrport(&ipv6.addr, ipv6.port), OP_EQ, "[::]:0");
// This will return the matching value from the configured port.
- tt_int_op(9999, OP_EQ, router_get_advertised_or_port_by_af(opts, AF_INET6));
+ tt_int_op(9999, OP_EQ, router_get_advertised_or_port_by_af(opts, AF_INET));
+ tt_int_op(9999, OP_EQ, router_get_advertised_or_port(opts));
// Now set up a dummy listener.
MOCK(get_connection_array, mock_get_connection_array);
fake_connection_array = smartlist_new();
- listener = listener_connection_new(CONN_TYPE_OR_LISTENER, AF_INET);
+ listener = listener_connection_new(CONN_TYPE_OR_LISTENER, AF_INET6);
TO_CONN(listener)->port = 54321;
smartlist_add(fake_connection_array, TO_CONN(listener));
// We should get a port this time.
- tt_int_op(54321, OP_EQ, router_get_advertised_or_port_by_af(opts, AF_INET));
+ tt_int_op(54321, OP_EQ, router_get_advertised_or_port_by_af(opts, AF_INET6));
+
+ // Test one succeeding case of router_get_advertised_ipv6_or_ap().
+ router_get_advertised_ipv6_or_ap(opts, &ipv6);
+ tt_str_op(fmt_addrport(&ipv6.addr, ipv6.port), OP_EQ,
+ "[1234::5678]:54321");
+
+ // This will return the matching value from the configured port.
+ tt_int_op(9999, OP_EQ, router_get_advertised_or_port_by_af(opts, AF_INET));
+ tt_int_op(9999, OP_EQ, router_get_advertised_or_port(opts));
done:
or_options_free(opts);