Loading changes/bug6298 0 → 100644 +4 −0 Original line number Diff line number Diff line o Minor bugfixes (unit tests): - The unit tests now pass on systems where localhost is misconfigured to some IPv4 address other than 127.0.0.1. Fixes bug 6298; bugfix on 0.0.9pre2. src/test/test_addr.c +23 −1 Original line number Diff line number Diff line Loading @@ -9,6 +9,24 @@ #include "test.h" #include "addressmap.h" /** 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) { Loading @@ -29,6 +47,9 @@ test_addr_basic(void *arg) 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"); Loading @@ -36,8 +57,8 @@ test_addr_basic(void *arg) 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(u32,OP_EQ, 0x7f000001u); 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)); Loading Loading @@ -75,6 +96,7 @@ test_addr_basic(void *arg) } done: UNMOCK(tor_addr_lookup); tor_free(cp); } Loading Loading
changes/bug6298 0 → 100644 +4 −0 Original line number Diff line number Diff line o Minor bugfixes (unit tests): - The unit tests now pass on systems where localhost is misconfigured to some IPv4 address other than 127.0.0.1. Fixes bug 6298; bugfix on 0.0.9pre2.
src/test/test_addr.c +23 −1 Original line number Diff line number Diff line Loading @@ -9,6 +9,24 @@ #include "test.h" #include "addressmap.h" /** 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) { Loading @@ -29,6 +47,9 @@ test_addr_basic(void *arg) 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"); Loading @@ -36,8 +57,8 @@ test_addr_basic(void *arg) 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(u32,OP_EQ, 0x7f000001u); 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)); Loading Loading @@ -75,6 +96,7 @@ test_addr_basic(void *arg) } done: UNMOCK(tor_addr_lookup); tor_free(cp); } Loading