Sixth test case for dns_resolve_impl.

This commit is contained in:
rl1987 2015-10-20 20:40:21 +03:00
parent cc1bed9974
commit f53dcf6a35
3 changed files with 74 additions and 8 deletions

View File

@ -111,9 +111,6 @@ static int launch_resolve(cached_resolve_t *resolve);
static void add_wildcarded_test_address(const char *address);
static int configure_nameservers(int force);
static int answer_is_wildcarded(const char *ip);
static int set_exitconn_info_from_resolve(edge_connection_t *exitconn,
const cached_resolve_t *resolve,
char **hostname_out);
static int evdns_err_is_transient(int err);
static void inform_pending_connections(cached_resolve_t *resolve);
static void make_pending_resolve_cached(cached_resolve_t *cached);
@ -859,10 +856,10 @@ dns_resolve_impl,(edge_connection_t *exitconn, int is_resolve,
* Return -2 on a transient error, -1 on a permenent error, and 1 on
* a successful lookup.
*/
static int
set_exitconn_info_from_resolve(edge_connection_t *exitconn,
const cached_resolve_t *resolve,
char **hostname_out)
MOCK_IMPL(STATIC int,
set_exitconn_info_from_resolve,(edge_connection_t *exitconn,
const cached_resolve_t *resolve,
char **hostname_out))
{
int ipv4_ok, ipv6_ok, answer_with_ipv4, r;
uint32_t begincell_flags;

View File

@ -46,6 +46,11 @@ const char *hostname));
cached_resolve_t *dns_get_cache_entry(cached_resolve_t *query);
void dns_insert_cache_entry(cached_resolve_t *new_entry);
MOCK_DECL(STATIC int,
set_exitconn_info_from_resolve,(edge_connection_t *exitconn,
const cached_resolve_t *resolve,
char **hostname_out));
#endif
#endif

View File

@ -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;
}