Merge pull request #190 from saradickinson/bugfix/transport_test

Split the recursive transport test 6 into 3 and add a shorter timeout…
This commit is contained in:
wtoorop 2016-06-28 11:54:58 +02:00 committed by GitHub
commit 66b7bb2ca1
1 changed files with 81 additions and 30 deletions

View File

@ -131,7 +131,7 @@
struct getdns_dict *extensions = getdns_dict_create(); struct getdns_dict *extensions = getdns_dict_create();
uint32_t tc; uint32_t tc;
uint32_t transport; uint32_t transport;
uint32_t mode; uint32_t type;
/* Note that stricly this test just establishes that the requested transport /* Note that stricly this test just establishes that the requested transport
and the reported transport are consistent, it does not guarentee which and the reported transport are consistent, it does not guarentee which
@ -158,9 +158,9 @@
ASSERT_RC(getdns_dict_get_int(response, "/call_reporting/0/transport", &transport), ASSERT_RC(getdns_dict_get_int(response, "/call_reporting/0/transport", &transport),
GETDNS_RETURN_GOOD, "Failed to extract \"transport\""); GETDNS_RETURN_GOOD, "Failed to extract \"transport\"");
ASSERT_RC(transport, GETDNS_TRANSPORT_UDP, "Query did not go over UDP"); ASSERT_RC(transport, GETDNS_TRANSPORT_UDP, "Query did not go over UDP");
ASSERT_RC(getdns_dict_get_int(response, "/call_reporting/0/resolution_type", &mode), ASSERT_RC(getdns_dict_get_int(response, "/call_reporting/0/resolution_type", &type),
GETDNS_RETURN_GOOD, "Failed to extract \"resolution_type\""); GETDNS_RETURN_GOOD, "Failed to extract \"resolution_type\"");
ASSERT_RC(mode, GETDNS_RESOLUTION_STUB, "Query did not use stub mode"); ASSERT_RC(type, GETDNS_RESOLUTION_STUB, "Query did not use stub mode");
ASSERT_RC(getdns_dict_get_int(response, "/replies_tree/0/header/tc", &tc), ASSERT_RC(getdns_dict_get_int(response, "/replies_tree/0/header/tc", &tc),
GETDNS_RETURN_GOOD, "Failed to extract \"tc\""); GETDNS_RETURN_GOOD, "Failed to extract \"tc\"");
ASSERT_RC(tc, 1, "Packet not trucated as expected"); ASSERT_RC(tc, 1, "Packet not trucated as expected");
@ -203,17 +203,11 @@
* Request answer larger then 512 bytes but set UDP payload to that * Request answer larger then 512 bytes but set UDP payload to that
* Call getdns_context_set_dns_transport() with value = GETDNS_TRANSPORT_UDP_ONLY * Call getdns_context_set_dns_transport() with value = GETDNS_TRANSPORT_UDP_ONLY
* expect: No response returned * expect: No response returned
* Call getdns_context_set_dns_transport() with value = GETDNS_TRANSPORT_TCP_ONLY
* expect: Response returned
* Call getdns_context_set_dns_transport() with value = GETDNS_TRANSPORT_UDP_FIRST_AND_FALL_BACK_TO_TCP
* expect: Response returned
*/ */
struct getdns_context *context = NULL; struct getdns_context *context = NULL;
struct getdns_dict *response = NULL; struct getdns_dict *response = NULL;
struct getdns_dict *extensions = getdns_dict_create(); struct getdns_dict *extensions = getdns_dict_create();
uint32_t status; uint32_t status;
uint32_t mode;
uint32_t tc;
/* Recursive mode does not report the transport used and does not answer /* Recursive mode does not report the transport used and does not answer
if the response is trucated. Also, transport can't be changed on a ub ctx.*/ if the response is trucated. Also, transport can't be changed on a ub ctx.*/
@ -230,7 +224,8 @@
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_dns_transport()"); GETDNS_RETURN_GOOD, "Return code from getdns_context_set_dns_transport()");
ASSERT_RC(getdns_context_set_edns_maximum_udp_payload_size(context, 512), ASSERT_RC(getdns_context_set_edns_maximum_udp_payload_size(context, 512),
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_edns_maximum_udp_payload_size()"); GETDNS_RETURN_GOOD, "Return code from getdns_context_set_edns_maximum_udp_payload_size()");
ASSERT_RC(getdns_context_set_timeout(context, 2000),
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_edns_maximum_udp_payload_size()");
ASSERT_RC(getdns_general_sync(context, "getdnsapi.net", 48, extensions, &response), ASSERT_RC(getdns_general_sync(context, "getdnsapi.net", 48, extensions, &response),
GETDNS_RETURN_GOOD, "Return code from getdns_general_sync()"); GETDNS_RETURN_GOOD, "Return code from getdns_general_sync()");
@ -239,9 +234,32 @@
/* TODO: INVESTIGATE THIS AS IT SHOULDN'T BE A TIMEOUT...*/ /* TODO: INVESTIGATE THIS AS IT SHOULDN'T BE A TIMEOUT...*/
ASSERT_RC(status, GETDNS_RESPSTATUS_ALL_TIMEOUT, "Status not as expected"); ASSERT_RC(status, GETDNS_RESPSTATUS_ALL_TIMEOUT, "Status not as expected");
}
CONTEXT_DESTROY; CONTEXT_DESTROY;
}
END_TEST
START_TEST (getdns_context_set_dns_transport_recursing_7)
{
/*
* Call getdns_context_set_dns_transport() with value = GETDNS_TRANSPORT_TCP_ONLY
* expect: Response returned
*/
struct getdns_context *context = NULL;
struct getdns_dict *response = NULL;
struct getdns_dict *extensions = getdns_dict_create();
uint32_t status;
uint32_t type;
uint32_t tc;
CONTEXT_CREATE(TRUE); CONTEXT_CREATE(TRUE);
/* Need to explicit check as we may be compiled stub-only*/
getdns_resolution_t resolution_type;
ASSERT_RC(getdns_context_get_resolution_type(context, &resolution_type),
GETDNS_RETURN_GOOD, "Return code from getdns_context_get_resolution_type()");
if (resolution_type == GETDNS_RESOLUTION_RECURSING) {
/* Re-do over TCP */ /* Re-do over TCP */
ASSERT_RC(getdns_dict_set_int(extensions,"return_call_reporting", GETDNS_EXTENSION_TRUE), ASSERT_RC(getdns_dict_set_int(extensions,"return_call_reporting", GETDNS_EXTENSION_TRUE),
@ -253,15 +271,40 @@
ASSERT_RC(getdns_general_sync(context, "getdnsapi.net", 48, extensions, &response), ASSERT_RC(getdns_general_sync(context, "getdnsapi.net", 48, extensions, &response),
GETDNS_RETURN_GOOD, "Return code from getdns_general_sync()"); GETDNS_RETURN_GOOD, "Return code from getdns_general_sync()");
ASSERT_RC(getdns_dict_get_int(response, "/call_reporting/0/resolution_type", &mode), ASSERT_RC(getdns_dict_get_int(response, "status", &status),
GETDNS_RETURN_GOOD, "Failed to extract \"status\"");
ASSERT_RC(status, GETDNS_RESPSTATUS_GOOD, "Status not as expected");
ASSERT_RC(getdns_dict_get_int(response, "/call_reporting/0/resolution_type", &type),
GETDNS_RETURN_GOOD, "Failed to extract \"resolution_type\""); GETDNS_RETURN_GOOD, "Failed to extract \"resolution_type\"");
ASSERT_RC(mode, GETDNS_RESOLUTION_RECURSING, "Query did not use Recursive mode"); ASSERT_RC(type, GETDNS_RESOLUTION_RECURSING, "Query did not use Recursive mode");
ASSERT_RC(getdns_dict_get_int(response, "/replies_tree/0/header/tc", &tc), ASSERT_RC(getdns_dict_get_int(response, "/replies_tree/0/header/tc", &tc),
GETDNS_RETURN_GOOD, "Failed to extract \"tc\""); GETDNS_RETURN_GOOD, "Failed to extract \"tc\"");
ASSERT_RC(tc, 0, "Packet trucated - not as expected"); ASSERT_RC(tc, 0, "Packet trucated - not as expected");
}
CONTEXT_DESTROY; CONTEXT_DESTROY;
}
END_TEST
START_TEST (getdns_context_set_dns_transport_recursing_8)
{
/*
* Call getdns_context_set_dns_transport() with value = GETDNS_TRANSPORT_UDP_FIRST_AND_FALL_BACK_TO_TCP
* expect: Response returned
*/
struct getdns_context *context = NULL;
struct getdns_dict *response = NULL;
struct getdns_dict *extensions = getdns_dict_create();
uint32_t status;
uint32_t tc;
CONTEXT_CREATE(TRUE); CONTEXT_CREATE(TRUE);
/* Need to explicit check as we may be compiled stub-only*/
getdns_resolution_t resolution_type;
ASSERT_RC(getdns_context_get_resolution_type(context, &resolution_type),
GETDNS_RETURN_GOOD, "Return code from getdns_context_get_resolution_type()");
if (resolution_type == GETDNS_RESOLUTION_RECURSING) {
/* Now let it fall back to TCP */ /* Now let it fall back to TCP */
ASSERT_RC(getdns_context_set_dns_transport(context, GETDNS_TRANSPORT_UDP_FIRST_AND_FALL_BACK_TO_TCP), ASSERT_RC(getdns_context_set_dns_transport(context, GETDNS_TRANSPORT_UDP_FIRST_AND_FALL_BACK_TO_TCP),
@ -271,6 +314,10 @@
ASSERT_RC(getdns_general_sync(context, "getdnsapi.net", 48, extensions, &response), ASSERT_RC(getdns_general_sync(context, "getdnsapi.net", 48, extensions, &response),
GETDNS_RETURN_GOOD, "Return code from getdns_general_sync()"); GETDNS_RETURN_GOOD, "Return code from getdns_general_sync()");
ASSERT_RC(getdns_dict_get_int(response, "status", &status),
GETDNS_RETURN_GOOD, "Failed to extract \"status\"");
ASSERT_RC(status, GETDNS_RESPSTATUS_GOOD, "Status not as expected");
ASSERT_RC(getdns_dict_get_int(response, "/replies_tree/0/header/tc", &tc), ASSERT_RC(getdns_dict_get_int(response, "/replies_tree/0/header/tc", &tc),
GETDNS_RETURN_GOOD, "Failed to extract \"tc\""); GETDNS_RETURN_GOOD, "Failed to extract \"tc\"");
ASSERT_RC(tc, 0, "Packet trucated - not as expected"); ASSERT_RC(tc, 0, "Packet trucated - not as expected");
@ -282,6 +329,8 @@
END_TEST END_TEST
Suite * Suite *
getdns_context_set_dns_transport_suite (void) getdns_context_set_dns_transport_suite (void)
{ {
@ -301,6 +350,8 @@
/* TODO: Test which specific lists are supported */ /* TODO: Test which specific lists are supported */
tcase_add_test(tc_pos, getdns_context_set_dns_transport_stub_5); tcase_add_test(tc_pos, getdns_context_set_dns_transport_stub_5);
tcase_add_test(tc_pos, getdns_context_set_dns_transport_recursing_6); tcase_add_test(tc_pos, getdns_context_set_dns_transport_recursing_6);
tcase_add_test(tc_pos, getdns_context_set_dns_transport_recursing_7);
tcase_add_test(tc_pos, getdns_context_set_dns_transport_recursing_8);
/* TODO: TLS... */ /* TODO: TLS... */
suite_add_tcase(s, tc_pos); suite_add_tcase(s, tc_pos);