aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_addr.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2018-07-10 13:18:55 -0400
committerNick Mathewson <nickm@torproject.org>2018-07-10 13:23:37 -0400
commit2f657a1416f2f81dd1be900269c4ae9bdb29f52d (patch)
treedd54069b078d165de04a85295bba79a1590fb422 /src/test/test_addr.c
parentc2ddb7b231c640a292d261af265dd423cee09179 (diff)
downloadtor-2f657a1416f2f81dd1be900269c4ae9bdb29f52d.tar.gz
tor-2f657a1416f2f81dd1be900269c4ae9bdb29f52d.zip
Remove all users of addr_port_lookup outside of address.c
This function has a nasty API, since whether or not it invokes the resolver depends on whether one of its arguments is NULL. That's a good way for accidents to happen. This patch incidentally makes tor-resolve support socks hosts on IPv6.
Diffstat (limited to 'src/test/test_addr.c')
-rw-r--r--src/test/test_addr.c61
1 files changed, 2 insertions, 59 deletions
diff --git a/src/test/test_addr.c b/src/test/test_addr.c
index 9ab921c5b6..c85779e52e 100644
--- a/src/test/test_addr.c
+++ b/src/test/test_addr.c
@@ -15,66 +15,10 @@
#include <sys/un.h>
#endif
-/** Mocking replacement: only handles localhost. */
-static int
-mock_tor_addr_lookup(const char *name, uint16_t family, tor_addr_t *addr_out)
-{
- if (!strcmp(name, "localhost")) {
- if (family == AF_INET || family == AF_UNSPEC) {
- tor_addr_from_ipv4h(addr_out, 0x7f000001);
- return 0;
- } else if (family == AF_INET6) {
- char bytes[16] = { 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 1 };
- tor_addr_from_ipv6_bytes(addr_out, bytes);
- return 0;
- }
- }
- return -1;
-}
-
static void
test_addr_basic(void *arg)
{
- uint32_t u32;
- uint16_t u16;
- char *cp;
-
- /* Test addr_port_lookup */
- (void)arg;
- cp = NULL; u32 = 3; u16 = 3;
- tt_assert(!addr_port_lookup(LOG_WARN, "1.2.3.4", &cp, &u32, &u16));
- tt_str_op(cp,OP_EQ, "1.2.3.4");
- tt_int_op(u32,OP_EQ, 0x01020304u);
- tt_int_op(u16,OP_EQ, 0);
- tor_free(cp);
- tt_assert(!addr_port_lookup(LOG_WARN, "4.3.2.1:99", &cp, &u32, &u16));
- tt_str_op(cp,OP_EQ, "4.3.2.1");
- tt_int_op(u32,OP_EQ, 0x04030201u);
- tt_int_op(u16,OP_EQ, 99);
- tor_free(cp);
-
- MOCK(tor_addr_lookup, mock_tor_addr_lookup);
-
- tt_assert(!addr_port_lookup(LOG_WARN, "nonexistent.address:4040",
- &cp, NULL, &u16));
- tt_str_op(cp,OP_EQ, "nonexistent.address");
- tt_int_op(u16,OP_EQ, 4040);
- tor_free(cp);
- tt_assert(!addr_port_lookup(LOG_WARN, "localhost:9999", &cp, &u32, &u16));
- tt_str_op(cp,OP_EQ, "localhost");
- tt_int_op(u16,OP_EQ, 9999);
- tt_int_op(u32,OP_EQ, 0x7f000001u);
- tor_free(cp);
- u32 = 3;
- tt_assert(!addr_port_lookup(LOG_WARN, "localhost", NULL, &u32, &u16));
- tt_ptr_op(cp,OP_EQ, NULL);
- tt_int_op(u32,OP_EQ, 0x7f000001u);
- tt_int_op(u16,OP_EQ, 0);
- tor_free(cp);
-
- tt_assert(addr_port_lookup(LOG_WARN, "localhost:3", &cp, &u32, NULL));
- tor_free(cp);
+ (void) arg;
tt_int_op(0,OP_EQ, addr_mask_get_bits(0x0u));
tt_int_op(32,OP_EQ, addr_mask_get_bits(0xFFFFFFFFu));
@@ -102,8 +46,7 @@ test_addr_basic(void *arg)
}
done:
- UNMOCK(tor_addr_lookup);
- tor_free(cp);
+ ;
}
#define test_op_ip6_(a,op,b,e1,e2) \