diff options
author | rl1987 <rl1987@sdf.lonestar.org> | 2015-10-20 20:40:21 +0300 |
---|---|---|
committer | rl1987 <rl1987@sdf.lonestar.org> | 2015-10-24 14:30:52 +0300 |
commit | f53dcf6a357e83a0b018d6f66bfb8a30734bd9a9 (patch) | |
tree | 2f4e470f0a413f78d5567da54d9c230710de0001 /src/test/test_dns.c | |
parent | cc1bed9974f90e7021468f9f85b0a66b21ee9151 (diff) | |
download | tor-f53dcf6a357e83a0b018d6f66bfb8a30734bd9a9.tar.gz tor-f53dcf6a357e83a0b018d6f66bfb8a30734bd9a9.zip |
Sixth test case for dns_resolve_impl.
Diffstat (limited to 'src/test/test_dns.c')
-rw-r--r-- | src/test/test_dns.c | 66 |
1 files changed, 65 insertions, 1 deletions
diff --git a/src/test/test_dns.c b/src/test/test_dns.c index 3fbb6f25d9..0ed3c9db44 100644 --- a/src/test/test_dns.c +++ b/src/test/test_dns.c @@ -576,12 +576,76 @@ NS(test_main)(void *arg) #define NS_SUBMODULE ASPECT(resolve_impl, cache_hit_cached) +/* Given that a finished DNS resolve is available in our cache, we want + * dns_resolve_impl() return it to called via resolve_out and pass the + * handling to set_exitconn_info_from_resolve function. + */ +static int +NS(router_my_exit_policy_is_reject_star)(void) +{ + return 0; +} + +static edge_connection_t *last_exitconn = NULL; +static cached_resolve_t *last_resolve = NULL; + +static int +NS(set_exitconn_info_from_resolve)(edge_connection_t *exitconn, + const cached_resolve_t *resolve, + char **hostname_out) +{ + last_exitconn = exitconn; + last_resolve = (cached_resolve_t *)resolve; + + return 0; +} + static void NS(test_main)(void *arg) { - tt_skip(); + int retval; + int made_pending = 0; + + edge_connection_t *exitconn = create_valid_exitconn(); + or_circuit_t *on_circ = tor_malloc_zero(sizeof(or_circuit_t)); + + cached_resolve_t *resolve_out = NULL; + + cached_resolve_t *cache_entry = tor_malloc_zero(sizeof(cached_resolve_t)); + cache_entry->magic = CACHED_RESOLVE_MAGIC; + cache_entry->state = CACHE_STATE_CACHED; + cache_entry->minheap_idx = -1; + cache_entry->expire = time(NULL) + 60 * 60; + + TO_CONN(exitconn)->address = tor_strdup("torproject.org"); + + strlcpy(cache_entry->address, TO_CONN(exitconn)->address, + sizeof(cache_entry->address)); + + NS_MOCK(router_my_exit_policy_is_reject_star); + NS_MOCK(set_exitconn_info_from_resolve); + + dns_init(); + + dns_insert_cache_entry(cache_entry); + + retval = dns_resolve_impl(exitconn, 1, on_circ, NULL, &made_pending, + &resolve_out); + + tt_int_op(retval,==,0); + tt_int_op(made_pending,==,0); + tt_assert(resolve_out == cache_entry); + + tt_assert(last_exitconn == exitconn); + tt_assert(last_resolve == cache_entry); done: + NS_UNMOCK(router_my_exit_policy_is_reject_star); + NS_UNMOCK(set_exitconn_info_from_resolve); + tor_free(on_circ); + tor_free(TO_CONN(exitconn)->address); + tor_free(cache_entry->pending_connections); + tor_free(cache_entry); return; } |