mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-06 19:41:15 +01:00
Use {mock,unmock}_hostname_resolver() in relevant tests
These tests all invoke the hostname resolver in one way or another, and therefore potentially block if our DNS server is missing, absent, or extremely slow. Closes ticket 31841.
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include "test/log_test_helpers.h"
|
||||
#include "lib/net/resolve.h"
|
||||
#include "test/rng_test_helpers.h"
|
||||
#include "test/resolve_test_helpers.h"
|
||||
|
||||
#ifdef HAVE_SYS_UN_H
|
||||
#include <sys/un.h>
|
||||
@@ -1160,6 +1161,7 @@ test_addr_parse_canonical(void *arg)
|
||||
static void
|
||||
test_addr_parse(void *arg)
|
||||
{
|
||||
|
||||
int r;
|
||||
tor_addr_t addr;
|
||||
uint16_t port;
|
||||
@@ -1169,6 +1171,8 @@ test_addr_parse(void *arg)
|
||||
|
||||
(void)arg;
|
||||
|
||||
mock_hostname_resolver();
|
||||
|
||||
/* IPv6-mapped IPv4 addresses. Tor doesn't really use these. */
|
||||
TEST_ADDR_V6_PARSE("11:22:33:44:55:66:1.2.3.4", 0,
|
||||
"11:22:33:44:55:66:102:304");
|
||||
@@ -1273,7 +1277,7 @@ test_addr_parse(void *arg)
|
||||
"11:22::88",99);
|
||||
|
||||
done:
|
||||
;
|
||||
unmock_hostname_resolver();
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
#include "app/config/statefile.h"
|
||||
|
||||
#include "test/test_helpers.h"
|
||||
#include "test/resolve_test_helpers.h"
|
||||
|
||||
#include "feature/dirclient/dir_server_st.h"
|
||||
#include "core/or/port_cfg_st.h"
|
||||
@@ -4068,6 +4069,8 @@ test_config_parse_port_config__ports__ports_given(void *data)
|
||||
|
||||
slout = smartlist_new();
|
||||
|
||||
mock_hostname_resolver();
|
||||
|
||||
// Test error when encounters an invalid Port specification
|
||||
config_port_invalid = mock_config_line("DNSPort", "");
|
||||
ret = parse_port_config(NULL, config_port_invalid, "DNS", 0, NULL,
|
||||
@@ -4764,6 +4767,7 @@ test_config_parse_port_config__ports__ports_given(void *data)
|
||||
#endif /* defined(_WIN32) */
|
||||
|
||||
done:
|
||||
unmock_hostname_resolver();
|
||||
if (slout)
|
||||
SMARTLIST_FOREACH(slout,port_cfg_t *,pf,port_cfg_free(pf));
|
||||
smartlist_free(slout);
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "test/test.h"
|
||||
#include "test/test_helpers.h"
|
||||
#include "test/log_test_helpers.h"
|
||||
#include "test/resolve_test_helpers.h"
|
||||
|
||||
#include "app/config/config.h"
|
||||
#include "feature/hs/hs_common.h"
|
||||
@@ -272,6 +273,7 @@ test_valid_service_v2(void *arg)
|
||||
int ret;
|
||||
|
||||
(void) arg;
|
||||
mock_hostname_resolver();
|
||||
|
||||
/* Valid complex configuration. Basic client authorization. */
|
||||
{
|
||||
@@ -314,7 +316,7 @@ test_valid_service_v2(void *arg)
|
||||
}
|
||||
|
||||
done:
|
||||
;
|
||||
unmock_hostname_resolver();
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -392,6 +394,7 @@ test_valid_service_v3(void *arg)
|
||||
int ret;
|
||||
|
||||
(void) arg;
|
||||
mock_hostname_resolver();
|
||||
|
||||
/* Valid complex configuration. */
|
||||
{
|
||||
@@ -448,7 +451,7 @@ test_valid_service_v3(void *arg)
|
||||
}
|
||||
|
||||
done:
|
||||
;
|
||||
unmock_hostname_resolver();
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -623,4 +626,3 @@ struct testcase_t hs_config_tests[] = {
|
||||
|
||||
END_OF_TESTCASES
|
||||
};
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "feature/nodelist/routerset.h"
|
||||
#include "core/mainloop/mainloop.h"
|
||||
#include "test/log_test_helpers.h"
|
||||
#include "test/resolve_test_helpers.h"
|
||||
|
||||
#include "lib/sandbox/sandbox.h"
|
||||
#include "lib/memarea/memarea.h"
|
||||
@@ -241,6 +242,7 @@ test_options_validate(void *arg)
|
||||
(void)arg;
|
||||
setup_log_callback();
|
||||
sandbox_disable_getaddrinfo_cache();
|
||||
mock_hostname_resolver();
|
||||
|
||||
WANT_ERR("ExtORPort 500000", "Invalid ExtORPort", PH_VALIDATE);
|
||||
|
||||
@@ -282,6 +284,7 @@ test_options_validate(void *arg)
|
||||
|
||||
close_temp_logs();
|
||||
clear_log_messages();
|
||||
unmock_hostname_resolver();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user