diff options
author | rl1987 <rl1987@sdf.lonestar.org> | 2018-10-20 20:15:06 +0300 |
---|---|---|
committer | rl1987 <rl1987@sdf.lonestar.org> | 2018-10-20 20:34:08 +0300 |
commit | d827902cb1107593473552974be5fcbb1fbb4abe (patch) | |
tree | 42ee1b9c484a52330d965dee11baec88a3a27ab3 /src/test/test_dns.c | |
parent | 1a1b088f8cab73ca258c35e83d21df900f8e2e32 (diff) | |
download | tor-d827902cb1107593473552974be5fcbb1fbb4abe.tar.gz tor-d827902cb1107593473552974be5fcbb1fbb4abe.zip |
Unit test for DNS fallback in configure_nameservers
Diffstat (limited to 'src/test/test_dns.c')
-rw-r--r-- | src/test/test_dns.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/test/test_dns.c b/src/test/test_dns.c index 8369f844f6..ea59a49b5b 100644 --- a/src/test/test_dns.c +++ b/src/test/test_dns.c @@ -13,9 +13,69 @@ #include "core/or/edge_connection_st.h" #include "core/or/or_circuit_st.h" +#include "app/config/or_options_st.h" +#include "app/config/config.h" + +#include <event2/event.h> +#include <event2/dns.h> #define NS_MODULE dns +#define NS_SUBMODULE configure_nameservers_fallback + +static or_options_t options = { + .ORPort_set = 1, +}; + +static const or_options_t * +mock_get_options(void) +{ + return &options; +} + +static void +NS(test_main)(void *arg) +{ + (void)arg; + tor_addr_t *nameserver_addr = NULL; + + MOCK(get_options, mock_get_options); + + options.ServerDNSResolvConfFile = (char *)"no_such_file!!!"; + + dns_init(); // calls configure_nameservers() + + tt_int_op(number_of_configured_nameservers(), OP_EQ, 1); + + nameserver_addr = configured_nameserver_address(0); + + tt_assert(tor_addr_family(nameserver_addr) == AF_INET); + tt_assert(tor_addr_eq_ipv4h(nameserver_addr, 0x7f000001)); + +#ifndef _WIN32 + tor_free(nameserver_addr); + + options.ServerDNSResolvConfFile = (char *)"/dev/null"; + + dns_init(); + + tt_int_op(number_of_configured_nameservers(), OP_EQ, 1); + + nameserver_addr = configured_nameserver_address(0); + + tt_assert(tor_addr_family(nameserver_addr) == AF_INET); + tt_assert(tor_addr_eq_ipv4h(nameserver_addr, 0x7f000001)); +#endif + + UNMOCK(get_options); + + done: + tor_free(nameserver_addr); + return; +} + +#undef NS_SUBMODULE + #define NS_SUBMODULE clip_ttl static void @@ -736,6 +796,7 @@ NS(test_main)(void *arg) #undef NS_SUBMODULE struct testcase_t dns_tests[] = { + TEST_CASE(configure_nameservers_fallback), TEST_CASE(clip_ttl), TEST_CASE(resolve), TEST_CASE_ASPECT(resolve_impl, addr_is_ip_no_need_to_resolve), |