summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorNeel Chauhan <neel@neelc.org>2019-08-13 20:36:05 -0400
committerNick Mathewson <nickm@torproject.org>2019-08-26 20:02:11 -0400
commitc8e69e63f9d39776bd926f1a07628c03c7582280 (patch)
tree5dcad886ced7cc7948f46c8882ac71e44e5d4394 /src/test
parentcc5af6dbd5d27cc80fba9df65eea1fff5833a08d (diff)
downloadtor-c8e69e63f9d39776bd926f1a07628c03c7582280.tar.gz
tor-c8e69e63f9d39776bd926f1a07628c03c7582280.zip
Add test for dirserv_router_has_valid_address()
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test_address.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/test/test_address.c b/src/test/test_address.c
index bf9ca047dc..eb0500be8f 100644
--- a/src/test/test_address.c
+++ b/src/test/test_address.c
@@ -24,6 +24,7 @@
#endif /* defined(HAVE_IFCONF_TO_SMARTLIST) */
#include "core/or/or.h"
+#include "feature/dirauth/process_descs.h"
#include "feature/nodelist/routerinfo_st.h"
#include "feature/nodelist/node_st.h"
#include "feature/nodelist/nodelist.h"
@@ -1244,6 +1245,38 @@ test_address_tor_node_in_same_network_family(void *ignored)
helper_free_mock_node(node_b);
}
+#define CHECK_RI_ADDR(addr_str, rv) STMT_BEGIN \
+ routerinfo_t *ri = tor_malloc_zero(sizeof(routerinfo_t)); \
+ tor_addr_t addr; \
+ tor_addr_parse(&addr, addr_str); \
+ ri->addr = tor_addr_to_ipv4h(&addr); \
+ tor_addr_make_null(&ri->ipv6_addr, AF_INET6); \
+ tt_int_op(dirserv_router_has_valid_address(ri), OP_EQ, rv); \
+ tor_free(ri); \
+ STMT_END
+
+/* XXX: Here, we use a non-internal IPv4 as dirserv_router_has_valid_address()
+ * will check internal/null IPv4 first. */
+#define CHECK_RI_ADDR6(addr_str, rv) STMT_BEGIN \
+ routerinfo_t *ri = tor_malloc_zero(sizeof(routerinfo_t)); \
+ ri->addr = 16777217; /* 1.0.0.1 */ \
+ tor_addr_parse(&ri->ipv6_addr, addr_str); \
+ tt_int_op(dirserv_router_has_valid_address(ri), OP_EQ, rv); \
+ tor_free(ri); \
+ STMT_END
+
+static void
+test_address_dirserv_router_addr_private(void *ignored)
+{
+ (void)ignored;
+ CHECK_RI_ADDR("1.0.0.1", 0);
+ CHECK_RI_ADDR("10.0.0.1", -1);
+ CHECK_RI_ADDR6("2600::1", 0);
+ CHECK_RI_ADDR6("fe80::1", -1);
+ done:
+ ;
+}
+
#define ADDRESS_TEST(name, flags) \
{ #name, test_address_ ## name, flags, NULL, NULL }
@@ -1277,5 +1310,6 @@ struct testcase_t address_tests[] = {
ADDRESS_TEST(tor_addr_eq_ipv4h, 0),
ADDRESS_TEST(tor_addr_in_same_network_family, 0),
ADDRESS_TEST(tor_node_in_same_network_family, 0),
+ ADDRESS_TEST(dirserv_router_addr_private, 0),
END_OF_TESTCASES
};