[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] Make the resolvemyaddr unit tests pass when local dns is hijacked
commit feed26d037608a3a40c1f4fd8450ea59f0091321
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Mon Dec 29 09:41:37 2014 -0500
Make the resolvemyaddr unit tests pass when local dns is hijacked
If you are in a coffee shop that returns a helpful redirect page for
"onionrouter", or on an ISP that does the same, the test as written
would fail.
---
src/test/test_config.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/src/test/test_config.c b/src/test/test_config.c
index b9a0672..f8161b1 100644
--- a/src/test/test_config.c
+++ b/src/test/test_config.c
@@ -636,7 +636,7 @@ tor_lookup_hostname_failure(const char *name, uint32_t *addr)
static int n_gethostname_replacement = 0;
/** This mock function is meant to replace tor_gethostname(). It
- * responds with string "onionrouter" as hostname. This function
+ * responds with string "onionrouter!" as hostname. This function
* increments <b>n_gethostname_replacement</b> by one every time
* it is called.
*/
@@ -646,7 +646,7 @@ tor_gethostname_replacement(char *name, size_t namelen)
n_gethostname_replacement++;
if (name && namelen) {
- strlcpy(name,"onionrouter",namelen);
+ strlcpy(name,"onionrouter!",namelen);
}
return 0;
@@ -870,7 +870,7 @@ test_config_resolve_my_address(void *arg)
tt_want(n_gethostname_replacement == prev_n_gethostname_replacement + 1);
tt_want(n_hostname_01010101 == prev_n_hostname_01010101 + 1);
tt_want_str_op(method_used,==,"GETHOSTNAME");
- tt_want_str_op(hostname_out,==,"onionrouter");
+ tt_want_str_op(hostname_out,==,"onionrouter!");
tt_assert(htonl(resolved_addr) == 0x01010101);
UNMOCK(tor_gethostname);
@@ -949,6 +949,7 @@ test_config_resolve_my_address(void *arg)
*/
MOCK(tor_gethostname,tor_gethostname_replacement);
+ MOCK(tor_lookup_hostname,tor_lookup_hostname_failure);
MOCK(get_interface_address,get_interface_address_08080808);
prev_n_gethostname_replacement = n_gethostname_replacement;
@@ -958,8 +959,10 @@ test_config_resolve_my_address(void *arg)
&method_used,&hostname_out);
tt_want(retval == 0);
- tt_want(n_gethostname_replacement == prev_n_gethostname_replacement + 1);
- tt_want(n_get_interface_address == prev_n_get_interface_address + 1);
+ tt_want_int_op(n_gethostname_replacement, ==,
+ prev_n_gethostname_replacement + 1);
+ tt_want_int_op(n_get_interface_address, ==,
+ prev_n_get_interface_address + 1);
tt_want_str_op(method_used,==,"INTERFACE");
tt_want(hostname_out == NULL);
tt_assert(resolved_addr == ntohl(0x08080808));
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits