summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2014-12-29 09:41:37 -0500
committerNick Mathewson <nickm@torproject.org>2014-12-29 10:00:22 -0500
commitfeed26d037608a3a40c1f4fd8450ea59f0091321 (patch)
tree6cea6dc1c1032db5a832e8b4b833eea5a19320d6
parent3538dfc91fa34c1cf4e34a334c76de65883bbc0e (diff)
downloadtor-feed26d037608a3a40c1f4fd8450ea59f0091321.tar.gz
tor-feed26d037608a3a40c1f4fd8450ea59f0091321.zip
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.
-rw-r--r--src/test/test_config.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/test/test_config.c b/src/test/test_config.c
index b9a0672aba..f8161b1c58 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));