mirror of https://github.com/getdnsapi/getdns.git
Merge branch 'develop' of github.com:verisign/getdns into develop
This commit is contained in:
commit
0bbc6fd8b3
|
@ -39,6 +39,9 @@
|
|||
#include "check_getdns_display_ip_address.h"
|
||||
#include "check_getdns_context_set_context_update_callback.h"
|
||||
#include "check_getdns_context_set_timeout.h"
|
||||
#include "check_getdns_context_set_upstream_recursive_servers.h"
|
||||
#include "check_getdns_service.h"
|
||||
#include "check_getdns_service_sync.h"
|
||||
|
||||
|
||||
int
|
||||
|
@ -47,6 +50,42 @@ main (int argc, char** argv)
|
|||
int number_failed;
|
||||
SRunner *sr ;
|
||||
|
||||
Suite *getdns_general_suite(void);
|
||||
Suite *getdns_general_sync_suite(void);
|
||||
Suite *getdns_address_suite(void);
|
||||
Suite *getdns_address_sync_suite(void);
|
||||
Suite *getdns_hostname_suite(void);
|
||||
Suite *getdns_hostname_sync_suite(void);
|
||||
Suite *getdns_context_create_suite(void);
|
||||
Suite *getdns_context_destroy_suite(void);
|
||||
Suite *getdns_cancel_callback_suite(void);
|
||||
Suite *getdns_list_get_length_suite(void);
|
||||
Suite *getdns_list_get_dict_suite(void);
|
||||
Suite *getdns_list_get_list_suite(void);
|
||||
Suite *getdns_list_get_int_suite(void);
|
||||
Suite *getdns_list_get_data_type_suite(void);
|
||||
Suite *getdns_list_get_bindata_suite(void);
|
||||
Suite *getdns_dict_get_names_suite(void);
|
||||
Suite *getdns_dict_get_data_type_suite(void);
|
||||
Suite *getdns_dict_get_dict_suite(void);
|
||||
Suite *getdns_dict_get_list_suite(void);
|
||||
Suite *getdns_dict_get_dict_suite(void);
|
||||
Suite *getdns_dict_get_bindata_suite(void);
|
||||
Suite *getdns_dict_get_int_suite(void);
|
||||
Suite *getdns_dict_destroy_suite(void);
|
||||
Suite *getdns_dict_set_dict_suite(void);
|
||||
Suite *getdns_dict_set_list_suite(void);
|
||||
Suite *getdns_dict_set_bindata_suite(void);
|
||||
Suite *getdns_dict_set_int_suite(void);
|
||||
Suite *getdns_convert_ulabel_to_alabel_suite(void);
|
||||
Suite *getdns_convert_alabel_to_ulabel_suite(void);
|
||||
Suite *getdns_pretty_print_dict_suite(void);
|
||||
Suite *getdns_display_ip_address_suite(void);
|
||||
Suite *getdns_context_set_context_update_callback_suite(void);
|
||||
Suite *getdns_context_set_upstream_recursive_servers_suite(void);
|
||||
Suite *getdns_service_suite(void);
|
||||
Suite *getdns_service_sync_suite(void);
|
||||
|
||||
sr = srunner_create(getdns_general_suite());
|
||||
srunner_add_suite(sr, getdns_general_sync_suite());
|
||||
srunner_add_suite(sr, getdns_address_suite());
|
||||
|
@ -79,6 +118,9 @@ main (int argc, char** argv)
|
|||
srunner_add_suite(sr,getdns_display_ip_address_suite());
|
||||
srunner_add_suite(sr,getdns_context_set_context_update_callback_suite());
|
||||
srunner_add_suite(sr,getdns_context_set_timeout_suite());
|
||||
srunner_add_suite(sr,getdns_context_set_upstream_recursive_servers_suite());
|
||||
srunner_add_suite(sr,getdns_service_suite());
|
||||
srunner_add_suite(sr,getdns_service_sync_suite());
|
||||
|
||||
srunner_set_log(sr, "check_getdns.log");
|
||||
srunner_run_all(sr, CK_NORMAL);
|
||||
|
|
|
@ -287,10 +287,8 @@ void callbackfn(struct getdns_context *context,
|
|||
|
||||
}
|
||||
|
||||
//refactor later
|
||||
/*
|
||||
* callbackfn is the callback function given to all
|
||||
* asynchronous query tests. It is expected to only
|
||||
* update_callbackfn is expected to only
|
||||
* be called for positive tests and will verify the
|
||||
* response that is returned.
|
||||
*/
|
||||
|
|
|
@ -32,10 +32,22 @@
|
|||
*/
|
||||
|
||||
struct getdns_context *context = NULL;
|
||||
CONTEXT_CREATE(TRUE);
|
||||
|
||||
ASSERT_RC(getdns_context_set_context_update_callback(context, update_callbackfn),
|
||||
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_context_update_callback()");
|
||||
|
||||
expected_changed_item = GETDNS_CONTEXT_CODE_TIMEOUT;
|
||||
|
||||
|
||||
ASSERT_RC(getdns_context_set_timeout(context, 3),
|
||||
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_timeout()");
|
||||
|
||||
ASSERT_RC(getdns_context_set_context_update_callback(context, NULL),
|
||||
GETDNS_RETURN_INVALID_PARAMETER, "Return code from getdns_context_set_context_update_callback()");
|
||||
|
||||
CONTEXT_DESTROY;
|
||||
|
||||
}
|
||||
END_TEST
|
||||
|
||||
|
|
|
@ -0,0 +1,156 @@
|
|||
#ifndef _check_getdns_context_set_dns_transport_h_
|
||||
#define _check_getdns_context_set_dns_transport_h_
|
||||
|
||||
/*
|
||||
**************************************************************************
|
||||
* *
|
||||
* T E S T S F O R G E T D N S _ C O N T E X T _ S E T _ C O N T E X T _ U P D A T E _ C A L L B A C K *
|
||||
* *
|
||||
**************************************************************************
|
||||
*/
|
||||
|
||||
START_TEST (getdns_context_set_dns_transport_1)
|
||||
{
|
||||
/*
|
||||
* context is NULL
|
||||
* expect: GETDNS_RETURN_BAD_CONTEXT
|
||||
*/
|
||||
|
||||
struct getdns_context *context = NULL;
|
||||
uint16_t value = 302;
|
||||
|
||||
ASSERT_RC(getdns_context_set_dns_transport(context, value),
|
||||
GETDNS_RETURN_BAD_CONTEXT, "Return code from getdns_context_set_dns_transport()");
|
||||
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (getdns_context_set_dns_transport_2)
|
||||
{
|
||||
/*
|
||||
* value is an undefined transport value
|
||||
* expect: GETDNS_RETURN_CONTEXT_UPDATE_FAIL
|
||||
*/
|
||||
|
||||
struct getdns_context *context = NULL;
|
||||
//uint16_t value = 233;
|
||||
CONTEXT_CREATE(TRUE);
|
||||
|
||||
|
||||
ASSERT_RC(getdns_context_set_dns_transport(context, 233),
|
||||
GETDNS_RETURN_CONTEXT_UPDATE_FAIL, "Return code from getdns_context_set_dns_transport()");
|
||||
|
||||
CONTEXT_DESTROY;
|
||||
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (getdns_context_set_dns_transport_3)
|
||||
{
|
||||
/*
|
||||
* Call getdns_context_set_dns_transport() with value = GETDNS_CONTEXT_UDP_ONLY
|
||||
* Define a callback routine for context changes and call getdns_context_set_context_update_callback() so that it gets called when there are context changes
|
||||
* getdns_context_set_resolution_type() to GETDNS_CONTEXT_STUB
|
||||
* expect: GETDNS_CONTEXT_CODE_RESOLUTION_TYPE
|
||||
*/
|
||||
struct getdns_context *context = NULL;
|
||||
struct getdns_dict *response = NULL;
|
||||
uint32_t ancount;
|
||||
uint32_t arcount;
|
||||
uint32_t nscount;
|
||||
uint32_t tcp_ancount;
|
||||
uint32_t tcp_arcount;
|
||||
uint32_t tcp_nscount;
|
||||
int udp_sum;
|
||||
int tcp_sum;
|
||||
|
||||
CONTEXT_CREATE(TRUE);
|
||||
|
||||
|
||||
ASSERT_RC(getdns_context_set_dns_transport(context, GETDNS_CONTEXT_UDP_ONLY),
|
||||
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_dns_transport()");
|
||||
|
||||
|
||||
ASSERT_RC(getdns_general_sync(context, "google.com", 255, NULL, &response),
|
||||
GETDNS_RETURN_GOOD, "Return code from getdns_general_sync()");
|
||||
|
||||
EXTRACT_RESPONSE;
|
||||
|
||||
|
||||
ASSERT_RC(getdns_dict_get_int(ex_response.header, "ancount", &ancount),
|
||||
GETDNS_RETURN_GOOD, "Failed to extract \"nscount\"");
|
||||
|
||||
ASSERT_RC(getdns_dict_get_int(ex_response.header, "arcount", &arcount),
|
||||
GETDNS_RETURN_GOOD, "Failed to extract \"nscount\"");
|
||||
|
||||
ASSERT_RC(getdns_dict_get_int(ex_response.header, "nscount", &nscount),
|
||||
GETDNS_RETURN_GOOD, "Failed to extract \"nscount\"");
|
||||
|
||||
printf("the resp is %s\n", getdns_pretty_print_dict(response));
|
||||
printf("the ancount is %d\n", ancount);
|
||||
printf("the arcount is %d\n", arcount);
|
||||
printf("the nscount is %d\n", nscount);
|
||||
udp_sum = ancount + arcount + nscount;
|
||||
printf("the udp_sum is %d\n", udp_sum);
|
||||
|
||||
//tcp count
|
||||
ASSERT_RC(getdns_context_set_dns_transport(context, GETDNS_CONTEXT_TCP_ONLY),
|
||||
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_dns_transport()");
|
||||
|
||||
|
||||
ASSERT_RC(getdns_general_sync(context, "google.com", 255, NULL, &response),
|
||||
GETDNS_RETURN_GOOD, "Return code from getdns_general_sync()");
|
||||
|
||||
struct extracted_response ex_response1;
|
||||
extract_response(response, &ex_response1);
|
||||
|
||||
ASSERT_RC(getdns_dict_get_int(ex_response1.header, "ancount", &tcp_ancount),
|
||||
GETDNS_RETURN_GOOD, "Failed to extract \"nscount\"");
|
||||
|
||||
ASSERT_RC(getdns_dict_get_int(ex_response1.header, "arcount", &tcp_arcount),
|
||||
GETDNS_RETURN_GOOD, "Failed to extract \"nscount\"");
|
||||
|
||||
ASSERT_RC(getdns_dict_get_int(ex_response1.header, "nscount", &tcp_nscount),
|
||||
GETDNS_RETURN_GOOD, "Failed to extract \"nscount\"");
|
||||
|
||||
printf("the resp is %s\n", getdns_pretty_print_dict(response));
|
||||
|
||||
printf("the tcp_ancount is %d\n", tcp_ancount);
|
||||
printf("the tcp_arcount is %d\n", tcp_arcount);
|
||||
printf("the tcp_nscount is %d\n", tcp_nscount);
|
||||
tcp_sum = tcp_ancount + tcp_arcount + tcp_nscount;
|
||||
printf("the tcp_sum is %d\n", udp_sum);
|
||||
|
||||
CONTEXT_DESTROY;
|
||||
|
||||
|
||||
|
||||
}
|
||||
END_TEST
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Suite *
|
||||
getdns_context_set_dns_transport_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("getdns_context_set_dns_transport()");
|
||||
|
||||
/* Negative test caseis */
|
||||
TCase *tc_neg = tcase_create("Negative");
|
||||
tcase_add_test(tc_neg, getdns_context_set_dns_transport_1);
|
||||
tcase_add_test(tc_neg, getdns_context_set_dns_transport_2);
|
||||
suite_add_tcase(s, tc_neg);
|
||||
|
||||
/* Positive test cases */
|
||||
TCase *tc_pos = tcase_create("Positive");
|
||||
tcase_add_test(tc_pos, getdns_context_set_dns_transport_3);
|
||||
|
||||
suite_add_tcase(s, tc_pos);
|
||||
|
||||
return s;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,446 @@
|
|||
#ifndef _check_getdns_context_set_upstream_recursive_servers_h_
|
||||
#define _check_getdns_context_set_upstream_recursive_servers_h_
|
||||
|
||||
/*
|
||||
******************************************************************************************
|
||||
* *
|
||||
* T E S T S F O R G E T D N S _ C O N T E X T _ S E T _ S T U B _ R E S O L U T I O N *
|
||||
* *
|
||||
******************************************************************************************
|
||||
*/
|
||||
|
||||
START_TEST (getdns_context_set_upstream_recursive_servers_1)
|
||||
{
|
||||
/*
|
||||
* context is NULL
|
||||
* expect: GETDNS_RETURN_INVALID_PARAMETER
|
||||
*/
|
||||
|
||||
struct getdns_context *context = NULL;
|
||||
struct getdns_list *upstream_list = NULL;
|
||||
|
||||
LIST_CREATE(upstream_list);
|
||||
|
||||
ASSERT_RC(getdns_context_set_upstream_recursive_servers(context, upstream_list),
|
||||
GETDNS_RETURN_INVALID_PARAMETER, "Return code from getdns_context_set_upstream_recursive_servers()");
|
||||
|
||||
LIST_DESTROY(upstream_list);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (getdns_context_set_upstream_recursive_servers_2)
|
||||
{
|
||||
/*
|
||||
* upstream_list is NULL
|
||||
* expect: GETDNS_RETURN_INVALID_PARAMETER
|
||||
*/
|
||||
|
||||
struct getdns_context *context = NULL;
|
||||
CONTEXT_CREATE(TRUE);
|
||||
|
||||
ASSERT_RC(getdns_context_set_upstream_recursive_servers(context, NULL),
|
||||
GETDNS_RETURN_CONTEXT_UPDATE_FAIL, "Return code from getdns_context_set_upstream_recursive_servers()");
|
||||
|
||||
|
||||
CONTEXT_DESTROY;
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (getdns_context_set_upstream_recursive_servers_3)
|
||||
{
|
||||
/*
|
||||
* create upstream_list
|
||||
* create context
|
||||
* a dict in upstream_list does not contain getdns_bindata
|
||||
*/
|
||||
|
||||
struct getdns_context *context = NULL;
|
||||
struct getdns_list *upstream_list = NULL;
|
||||
struct getdns_dict *dict = NULL;
|
||||
size_t index = 0;
|
||||
|
||||
CONTEXT_CREATE(TRUE);
|
||||
LIST_CREATE(upstream_list);
|
||||
DICT_CREATE(dict);
|
||||
|
||||
ASSERT_RC(getdns_list_set_dict(upstream_list, index, dict), GETDNS_RETURN_GOOD,
|
||||
"Return code from getdns_list_set_dict()");
|
||||
|
||||
|
||||
ASSERT_RC(getdns_context_set_upstream_recursive_servers(context, upstream_list),
|
||||
GETDNS_RETURN_CONTEXT_UPDATE_FAIL, "Return code from getdns_context_set_upstream_recursive_servers()");
|
||||
|
||||
CONTEXT_DESTROY;
|
||||
LIST_DESTROY(upstream_list);
|
||||
DICT_DESTROY(dict);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (getdns_context_set_upstream_recursive_servers_4)
|
||||
{
|
||||
/*
|
||||
* create upstream_list
|
||||
* create context
|
||||
* a dict in upstream_list does not contain two names
|
||||
*/
|
||||
|
||||
struct getdns_context *context = NULL;
|
||||
struct getdns_list *upstream_list = NULL;
|
||||
struct getdns_dict *dict = NULL;
|
||||
struct getdns_bindata address_type = { 5, (void *) "IPv4" };
|
||||
size_t index = 0;
|
||||
|
||||
CONTEXT_CREATE(TRUE);
|
||||
LIST_CREATE(upstream_list);
|
||||
DICT_CREATE(dict);
|
||||
|
||||
ASSERT_RC(getdns_list_set_dict(upstream_list, index, dict), GETDNS_RETURN_GOOD,
|
||||
"Return code from getdns_list_set_dict()");
|
||||
|
||||
ASSERT_RC(getdns_dict_set_bindata(dict, "address_type", &address_type),
|
||||
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_bindata()");
|
||||
|
||||
|
||||
ASSERT_RC(getdns_context_set_upstream_recursive_servers(context, upstream_list),
|
||||
GETDNS_RETURN_CONTEXT_UPDATE_FAIL, "Return code from getdns_context_set_upstream_recursive_servers()");
|
||||
|
||||
CONTEXT_DESTROY;
|
||||
LIST_DESTROY(upstream_list);
|
||||
DICT_DESTROY(dict);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (getdns_context_set_upstream_recursive_servers_5)
|
||||
{
|
||||
/*
|
||||
* create upstream_list
|
||||
* create context
|
||||
* a dict in upstream_list contains names other than address_type ,
|
||||
address_data, and port
|
||||
*/
|
||||
|
||||
struct getdns_context *context = NULL;
|
||||
struct getdns_list *upstream_list = NULL;
|
||||
struct getdns_dict *dict = NULL;
|
||||
struct getdns_bindata address_data = { 4, (void *)"\x08\x08\x08\x08" };
|
||||
size_t index = 0;
|
||||
|
||||
CONTEXT_CREATE(TRUE);
|
||||
LIST_CREATE(upstream_list);
|
||||
DICT_CREATE(dict);
|
||||
|
||||
ASSERT_RC(getdns_list_set_dict(upstream_list, index, dict), GETDNS_RETURN_GOOD,
|
||||
"Return code from getdns_list_set_dict()");
|
||||
|
||||
ASSERT_RC(getdns_dict_set_int(dict, "not_address_type", 100),
|
||||
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_int()");
|
||||
|
||||
ASSERT_RC(getdns_dict_set_bindata(dict, "not_address_data", &address_data),
|
||||
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_bindata()");
|
||||
|
||||
ASSERT_RC(getdns_context_set_upstream_recursive_servers(context, upstream_list),
|
||||
GETDNS_RETURN_CONTEXT_UPDATE_FAIL, "Return code from getdns_context_set_upstream_recursive_servers()");
|
||||
|
||||
CONTEXT_DESTROY;
|
||||
LIST_DESTROY(upstream_list);
|
||||
DICT_DESTROY(dict);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (getdns_context_set_upstream_recursive_servers_6)
|
||||
{
|
||||
/*
|
||||
* create upstream_list
|
||||
* create context
|
||||
* a dict in upstream_list contains invalid address_ type (not “IPv4” or “IPv6”)
|
||||
*/
|
||||
|
||||
struct getdns_context *context = NULL;
|
||||
struct getdns_list *upstream_list = NULL;
|
||||
struct getdns_dict *dict = NULL;
|
||||
struct getdns_bindata address_type = { 5, (void *)"IPv5" };
|
||||
struct getdns_bindata address_data = { 4, (void *)"\x08\x08\x08\x08" };
|
||||
size_t index = 0;
|
||||
|
||||
CONTEXT_CREATE(TRUE);
|
||||
LIST_CREATE(upstream_list);
|
||||
DICT_CREATE(dict);
|
||||
|
||||
ASSERT_RC(getdns_list_set_dict(upstream_list, index, dict), GETDNS_RETURN_GOOD,
|
||||
"Return code from getdns_list_set_dict()");
|
||||
|
||||
ASSERT_RC(getdns_dict_set_bindata(dict, "address_type", &address_type),
|
||||
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_bindata()");
|
||||
ASSERT_RC(getdns_dict_set_bindata(dict, "address_data", &address_data),
|
||||
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_bindata()");
|
||||
|
||||
ASSERT_RC(getdns_context_set_upstream_recursive_servers(context, upstream_list),
|
||||
GETDNS_RETURN_CONTEXT_UPDATE_FAIL, "Return code from getdns_context_set_upstream_recursive_servers()");
|
||||
|
||||
CONTEXT_DESTROY;
|
||||
LIST_DESTROY(upstream_list);
|
||||
DICT_DESTROY(dict);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (getdns_context_set_upstream_recursive_servers_7)
|
||||
{
|
||||
/*
|
||||
* create upstream_list
|
||||
* create context
|
||||
* a dict in upstream_list contains named address_type and
|
||||
address_data but the data type isn’t bindata
|
||||
*/
|
||||
|
||||
struct getdns_context *context = NULL;
|
||||
struct getdns_list *upstream_list = NULL;
|
||||
struct getdns_dict *dict = NULL;
|
||||
size_t index = 0;
|
||||
|
||||
CONTEXT_CREATE(TRUE);
|
||||
LIST_CREATE(upstream_list);
|
||||
DICT_CREATE(dict);
|
||||
|
||||
ASSERT_RC(getdns_list_set_dict(upstream_list, index, dict), GETDNS_RETURN_GOOD,
|
||||
"Return code from getdns_list_set_dict()");
|
||||
|
||||
ASSERT_RC(getdns_dict_set_int(dict, "address_type", 100),
|
||||
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_int()");
|
||||
|
||||
ASSERT_RC(getdns_dict_set_int(dict, "address_data", 200),
|
||||
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_int()");
|
||||
|
||||
ASSERT_RC(getdns_context_set_upstream_recursive_servers(context, upstream_list),
|
||||
GETDNS_RETURN_CONTEXT_UPDATE_FAIL, "Return code from getdns_context_set_upstream_recursive_servers()");
|
||||
|
||||
CONTEXT_DESTROY;
|
||||
LIST_DESTROY(upstream_list);
|
||||
DICT_DESTROY(dict);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (getdns_context_set_upstream_recursive_servers_8)
|
||||
{
|
||||
/*
|
||||
* create upstream_list
|
||||
* create context
|
||||
* a dict in upstream_list contains invalid address_data
|
||||
*/
|
||||
|
||||
struct getdns_context *context = NULL;
|
||||
struct getdns_list *upstream_list = NULL;
|
||||
struct getdns_dict *dict = NULL;
|
||||
struct getdns_bindata address_type = { 5, (void *)"IPv5" };
|
||||
struct getdns_bindata address_data = { 4, (void *)"\x08\x08\x08\x08" };
|
||||
size_t index = 0;
|
||||
|
||||
CONTEXT_CREATE(TRUE);
|
||||
LIST_CREATE(upstream_list);
|
||||
DICT_CREATE(dict);
|
||||
|
||||
ASSERT_RC(getdns_list_set_dict(upstream_list, index, dict), GETDNS_RETURN_GOOD,
|
||||
"Return code from getdns_list_set_dict()");
|
||||
|
||||
ASSERT_RC(getdns_dict_set_bindata(dict, "address_type", &address_type),
|
||||
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_bindata()");
|
||||
ASSERT_RC(getdns_dict_set_bindata(dict, "address_data", &address_data),
|
||||
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_bindata()");
|
||||
|
||||
ASSERT_RC(getdns_context_set_upstream_recursive_servers(context, upstream_list),
|
||||
GETDNS_RETURN_CONTEXT_UPDATE_FAIL, "Return code from getdns_context_set_upstream_recursive_servers()");
|
||||
|
||||
CONTEXT_DESTROY;
|
||||
LIST_DESTROY(upstream_list);
|
||||
DICT_DESTROY(dict);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (getdns_context_set_upstream_recursive_servers_9)
|
||||
{
|
||||
/*
|
||||
* create context
|
||||
* Call getdns_list_create() to create a list
|
||||
* Call getdns_dict_create() to create a list
|
||||
* Create bindata containing “IPv4”
|
||||
*/
|
||||
|
||||
struct getdns_context *context = NULL;
|
||||
struct getdns_list *upstream_list = NULL;
|
||||
struct getdns_dict *dict = NULL;
|
||||
struct getdns_dict *response = NULL;
|
||||
struct getdns_bindata address_type = { 5, (void *)"IPv4" };
|
||||
struct getdns_bindata address_data = { 4, (void *)"\x0A\xAA\x0C\x38" };
|
||||
size_t index = 0;
|
||||
|
||||
CONTEXT_CREATE(TRUE);
|
||||
LIST_CREATE(upstream_list);
|
||||
DICT_CREATE(dict);
|
||||
|
||||
ASSERT_RC(getdns_dict_set_bindata(dict, "address_type", &address_type),
|
||||
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_bindata()");
|
||||
|
||||
ASSERT_RC(getdns_dict_set_bindata(dict, "address_data", &address_data),
|
||||
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_bindata()");
|
||||
|
||||
ASSERT_RC(getdns_list_set_dict(upstream_list, index, dict), GETDNS_RETURN_GOOD,
|
||||
"Return code from getdns_list_set_dict()");
|
||||
|
||||
|
||||
ASSERT_RC(getdns_context_set_upstream_recursive_servers(context, upstream_list),
|
||||
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_upstream_recursive_servers()");
|
||||
|
||||
ASSERT_RC(getdns_general_sync(context, "google.com", GETDNS_RRTYPE_A, NULL, &response),
|
||||
GETDNS_RETURN_GOOD, "Return code from getdns_general_sync()");
|
||||
|
||||
|
||||
EXTRACT_RESPONSE;
|
||||
|
||||
assert_noerror(&ex_response);
|
||||
assert_address_in_answer(&ex_response, TRUE, FALSE);
|
||||
|
||||
CONTEXT_DESTROY;
|
||||
LIST_DESTROY(upstream_list);
|
||||
DICT_DESTROY(dict);
|
||||
DICT_DESTROY(response);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (getdns_context_set_upstream_recursive_servers_10)
|
||||
{
|
||||
/*
|
||||
* create context
|
||||
* Call getdns_list_create() to create a list
|
||||
* Call getdns_dict_create() to create a list
|
||||
* Create bindata containing “IPv6”
|
||||
*/
|
||||
|
||||
struct getdns_context *context = NULL;
|
||||
struct getdns_list *upstream_list = NULL;
|
||||
struct getdns_dict *dict = NULL;
|
||||
struct getdns_dict *response = NULL;
|
||||
struct getdns_bindata address_type = { 5, (void *)"IPv6" };
|
||||
struct getdns_bindata address_data = { 16, (void *)"\x20\x01\x48\x60\x48\x60\x00\x00\x00\x00\x00\x00\x00\x00\x88\x44" };
|
||||
size_t index = 0;
|
||||
|
||||
CONTEXT_CREATE(TRUE);
|
||||
LIST_CREATE(upstream_list);
|
||||
DICT_CREATE(dict);
|
||||
|
||||
ASSERT_RC(getdns_dict_set_bindata(dict, "address_type", &address_type),
|
||||
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_bindata()");
|
||||
|
||||
ASSERT_RC(getdns_dict_set_bindata(dict, "address_data", &address_data),
|
||||
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_bindata()");
|
||||
|
||||
ASSERT_RC(getdns_list_set_dict(upstream_list, index, dict), GETDNS_RETURN_GOOD,
|
||||
"Return code from getdns_list_set_dict()");
|
||||
|
||||
|
||||
ASSERT_RC(getdns_context_set_upstream_recursive_servers(context, upstream_list),
|
||||
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_upstream_recursive_servers()");
|
||||
|
||||
ASSERT_RC(getdns_general_sync(context, "google.com", GETDNS_RRTYPE_A, NULL, &response),
|
||||
GETDNS_RETURN_GOOD, "Return code from getdns_general_sync()");
|
||||
|
||||
EXTRACT_RESPONSE;
|
||||
|
||||
assert_noerror(&ex_response);
|
||||
assert_address_in_answer(&ex_response, TRUE, FALSE);
|
||||
|
||||
CONTEXT_DESTROY;
|
||||
LIST_DESTROY(upstream_list);
|
||||
DICT_DESTROY(dict);
|
||||
DICT_DESTROY(response);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (getdns_context_set_upstream_recursive_servers_11)
|
||||
{
|
||||
/*
|
||||
* create context
|
||||
* Call getdns_list_create() to create a list
|
||||
* Call getdns_dict_create() to create a list
|
||||
* Create bindata containing “IPv4”
|
||||
*/
|
||||
|
||||
struct getdns_context *context = NULL;
|
||||
struct getdns_list *upstream_list = NULL;
|
||||
struct getdns_dict *dict = NULL;
|
||||
struct getdns_dict *response = NULL;
|
||||
struct getdns_bindata address_type = { 5, (void *)"IPv4" };
|
||||
struct getdns_bindata address_data = { 4, (void *)"\x0A\xAA\x0C\x38" };
|
||||
struct getdns_bindata port = { 3, (void *)"53" };
|
||||
size_t index = 0;
|
||||
|
||||
CONTEXT_CREATE(TRUE);
|
||||
LIST_CREATE(upstream_list);
|
||||
DICT_CREATE(dict);
|
||||
|
||||
ASSERT_RC(getdns_dict_set_bindata(dict, "address_type", &address_type),
|
||||
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_bindata()");
|
||||
|
||||
ASSERT_RC(getdns_dict_set_bindata(dict, "address_data", &address_data),
|
||||
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_bindata()");
|
||||
|
||||
ASSERT_RC(getdns_dict_set_bindata(dict, "53", &port),
|
||||
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_bindata()");
|
||||
|
||||
ASSERT_RC(getdns_list_set_dict(upstream_list, index, dict), GETDNS_RETURN_GOOD,
|
||||
"Return code from getdns_list_set_dict()");
|
||||
|
||||
|
||||
ASSERT_RC(getdns_context_set_upstream_recursive_servers(context, upstream_list),
|
||||
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_upstream_recursive_servers()");
|
||||
|
||||
ASSERT_RC(getdns_general_sync(context, "google.com", GETDNS_RRTYPE_A, NULL, &response),
|
||||
GETDNS_RETURN_GOOD, "Return code from getdns_general_sync()");
|
||||
|
||||
|
||||
EXTRACT_RESPONSE;
|
||||
printf("the resp is %s\n", getdns_pretty_print_dict(response));
|
||||
|
||||
|
||||
assert_noerror(&ex_response);
|
||||
assert_address_in_answer(&ex_response, TRUE, FALSE);
|
||||
|
||||
CONTEXT_DESTROY;
|
||||
LIST_DESTROY(upstream_list);
|
||||
DICT_DESTROY(dict);
|
||||
DICT_DESTROY(response);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
|
||||
|
||||
|
||||
Suite *
|
||||
getdns_context_set_upstream_recursive_servers_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("getdns_context_set_upstream_recursive_servers()");
|
||||
|
||||
/* Negative test caseis */
|
||||
TCase *tc_neg = tcase_create("Negative");
|
||||
tcase_add_test(tc_neg, getdns_context_set_upstream_recursive_servers_1);
|
||||
tcase_add_test(tc_neg, getdns_context_set_upstream_recursive_servers_2);
|
||||
tcase_add_test(tc_neg, getdns_context_set_upstream_recursive_servers_3);
|
||||
tcase_add_test(tc_neg, getdns_context_set_upstream_recursive_servers_4);
|
||||
tcase_add_test(tc_neg, getdns_context_set_upstream_recursive_servers_5);
|
||||
tcase_add_test(tc_neg, getdns_context_set_upstream_recursive_servers_6);
|
||||
tcase_add_test(tc_neg, getdns_context_set_upstream_recursive_servers_7);
|
||||
tcase_add_test(tc_neg, getdns_context_set_upstream_recursive_servers_8);
|
||||
|
||||
suite_add_tcase(s, tc_neg);
|
||||
|
||||
/* Positive test cases */
|
||||
TCase *tc_pos = tcase_create("Positive");
|
||||
tcase_add_test(tc_pos, getdns_context_set_upstream_recursive_servers_9);
|
||||
tcase_add_test(tc_pos, getdns_context_set_upstream_recursive_servers_10);
|
||||
tcase_add_test(tc_pos, getdns_context_set_upstream_recursive_servers_11);
|
||||
|
||||
suite_add_tcase(s, tc_pos);
|
||||
|
||||
return s;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,178 @@
|
|||
#ifndef _check_getdns_service_h_
|
||||
#define _check_getdns_service_h_
|
||||
|
||||
/*
|
||||
***************************************************
|
||||
* *
|
||||
* T E S T S F O R G E T D N S _ S E R V I C E *
|
||||
* *
|
||||
***************************************************
|
||||
*/
|
||||
|
||||
START_TEST (getdns_service_1)
|
||||
{
|
||||
/*
|
||||
* context = NULL
|
||||
* expect: GETDNS_RETURN_INVALID_PARAMETER
|
||||
*/
|
||||
struct getdns_context *context = NULL;
|
||||
getdns_transaction_t transaction_id = 0;
|
||||
|
||||
ASSERT_RC(getdns_service(context, "google.com", NULL,
|
||||
NULL, &transaction_id, callbackfn),
|
||||
GETDNS_RETURN_INVALID_PARAMETER, "Return code from getdns_service()");
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (getdns_service_2)
|
||||
{
|
||||
/*
|
||||
* name = NULL
|
||||
* expect: GETDNS_RETURN_INVALID_PARAMETER
|
||||
*/
|
||||
struct getdns_context *context = NULL;
|
||||
struct event_base *event_base = NULL;
|
||||
getdns_transaction_t transaction_id = 0;
|
||||
|
||||
CONTEXT_CREATE(TRUE);
|
||||
EVENT_BASE_CREATE;
|
||||
|
||||
ASSERT_RC(getdns_service(context, NULL, NULL,
|
||||
NULL, &transaction_id, callbackfn),
|
||||
GETDNS_RETURN_INVALID_PARAMETER, "Return code from getdns_service()");
|
||||
|
||||
RUN_EVENT_LOOP;
|
||||
CONTEXT_DESTROY;
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (getdns_service_3)
|
||||
{
|
||||
/*
|
||||
* name = invalid domain (too many octets)
|
||||
* expect: GETDNS_RETURN_BAD_DOMAIN_NAME
|
||||
*/
|
||||
struct getdns_context *context = NULL;
|
||||
struct event_base *event_base = NULL;
|
||||
getdns_transaction_t transaction_id = 0;
|
||||
const char *name = "oh.my.gosh.and.for.petes.sake.are.you.fricking.crazy.man.because.this.spectacular.and.elaborately.thought.out.domain.name.of.very.significant.length.is.just.too.darn.long.because.you.know.the rfc.states.that.two.hundred.fifty.five.characters.is.the.max.com";
|
||||
|
||||
CONTEXT_CREATE(TRUE);
|
||||
EVENT_BASE_CREATE;
|
||||
|
||||
ASSERT_RC(getdns_service(context, name, NULL,
|
||||
NULL, &transaction_id, callbackfn),
|
||||
GETDNS_RETURN_BAD_DOMAIN_NAME, "Return code from getdns_service()");
|
||||
RUN_EVENT_LOOP;
|
||||
CONTEXT_DESTROY;
|
||||
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (getdns_service_4)
|
||||
{
|
||||
/*
|
||||
* name is invalid (domain name label length > 63)
|
||||
* expect: GETDNS_RETURN_BAD_DOMAIN_NAME
|
||||
*/
|
||||
struct getdns_context *context = NULL;
|
||||
struct event_base *event_base = NULL;
|
||||
getdns_transaction_t transaction_id = 0;
|
||||
const char *name = "this.domain.hasalabelwhichexceedsthemaximumdnslabelsizeofsixtythreecharacters.com";
|
||||
|
||||
CONTEXT_CREATE(TRUE);
|
||||
EVENT_BASE_CREATE;
|
||||
|
||||
ASSERT_RC(getdns_service(context, name, NULL,
|
||||
NULL, &transaction_id, callbackfn),
|
||||
GETDNS_RETURN_BAD_DOMAIN_NAME, "Return code from getdns_service()");
|
||||
RUN_EVENT_LOOP;
|
||||
CONTEXT_DESTROY;
|
||||
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (getdns_service_5)
|
||||
{
|
||||
/*
|
||||
* callbackfn = NULL
|
||||
* expect: GETDNS_RETURN_INVALID_PARAMETER
|
||||
*/
|
||||
struct getdns_context *context = NULL;
|
||||
struct event_base *event_base = NULL;
|
||||
getdns_transaction_t transaction_id = 0;
|
||||
|
||||
CONTEXT_CREATE(TRUE);
|
||||
EVENT_BASE_CREATE;
|
||||
|
||||
ASSERT_RC(getdns_service(context, "google.com", NULL,
|
||||
NULL, &transaction_id, NULL),
|
||||
GETDNS_RETURN_INVALID_PARAMETER, "Return code from getdns_service()");
|
||||
RUN_EVENT_LOOP;
|
||||
CONTEXT_DESTROY;
|
||||
|
||||
}
|
||||
END_TEST
|
||||
|
||||
//name is <non-existent domain name> (NXDOMAIN)
|
||||
//no extensions
|
||||
//expected: NXDOMAIN response (with SOA record)
|
||||
|
||||
START_TEST (getdns_service_7)
|
||||
{
|
||||
/*
|
||||
* name is <non-existent domain name> (NXDOMAIN)
|
||||
* expect: NXDOMAIN response (with SOA record)
|
||||
*/
|
||||
void verify_getdns_service_7(struct extracted_response *ex_response);
|
||||
struct getdns_context *context = NULL; \
|
||||
struct event_base *event_base = NULL; \
|
||||
getdns_transaction_t transaction_id = 0;
|
||||
|
||||
CONTEXT_CREATE(TRUE);
|
||||
|
||||
EVENT_BASE_CREATE;
|
||||
|
||||
ASSERT_RC(getdns_service(context, "nitinsinghit.com", NULL,
|
||||
verify_getdns_address_8, &transaction_id, callbackfn),
|
||||
GETDNS_RETURN_GOOD, "Return code from getdns_service()");
|
||||
|
||||
RUN_EVENT_LOOP;
|
||||
CONTEXT_DESTROY;
|
||||
}
|
||||
END_TEST
|
||||
|
||||
void verify_getdns_service_7(struct extracted_response *ex_response)
|
||||
{
|
||||
assert_nxdomain(ex_response);
|
||||
assert_nodata(ex_response);
|
||||
assert_soa_in_authority(ex_response);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Suite *
|
||||
getdns_service_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("getdns_service()");
|
||||
|
||||
/* Negative test caseis */
|
||||
TCase *tc_neg = tcase_create("Negative");
|
||||
tcase_add_test(tc_neg, getdns_service_1);
|
||||
tcase_add_test(tc_neg, getdns_service_2);
|
||||
tcase_add_test(tc_neg, getdns_service_3);
|
||||
tcase_add_test(tc_neg, getdns_service_4);
|
||||
tcase_add_test(tc_neg, getdns_service_5);
|
||||
|
||||
suite_add_tcase(s, tc_neg);
|
||||
|
||||
/* Positive test cases */
|
||||
TCase *tc_pos = tcase_create("Positive");
|
||||
tcase_add_test(tc_pos, getdns_service_7);
|
||||
suite_add_tcase(s, tc_pos);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,142 @@
|
|||
#ifndef _check_getdns_service_sync_h_
|
||||
#define _check_getdns_service_sync_h_
|
||||
|
||||
/*
|
||||
*************************************************************
|
||||
* *
|
||||
* T E S T S F O R G E T D N S _ S E R V I C E _ S Y N C *
|
||||
* *
|
||||
*************************************************************
|
||||
*/
|
||||
|
||||
START_TEST (getdns_service_sync_1)
|
||||
{
|
||||
/*
|
||||
* context = NULL
|
||||
* expect: GETDNS_RETURN_BAD_CONTEXT
|
||||
*/
|
||||
struct getdns_context *context = NULL;
|
||||
struct getdns_dict *response = NULL;
|
||||
|
||||
ASSERT_RC(getdns_service_sync(context, "google.com", NULL, &response),
|
||||
GETDNS_RETURN_BAD_CONTEXT, "Return code from getdns_service_sync()");
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (getdns_service_sync_2)
|
||||
{
|
||||
/*
|
||||
* name = NULL
|
||||
* expect: GETDNS_RETURN_BAD_CONTEXT
|
||||
*/
|
||||
struct getdns_context *context = NULL;
|
||||
struct getdns_dict *response = NULL;
|
||||
|
||||
CONTEXT_CREATE(TRUE);
|
||||
|
||||
ASSERT_RC(getdns_service_sync(context, NULL, NULL, &response),
|
||||
GETDNS_RETURN_INVALID_PARAMETER, "Return code from getdns_service_sync()");
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (getdns_service_sync_3)
|
||||
{
|
||||
/*
|
||||
* name is invalid (domain name length > 255)
|
||||
* expect: GETDNS_RETURN_BAD_DOMAIN_NAME
|
||||
*/
|
||||
struct getdns_context *context = NULL;
|
||||
struct getdns_dict *response = NULL;
|
||||
const char *name = "oh.my.gosh.and.for.petes.sake.are.you.fricking.crazy.man.because.this.spectacular.and.elaborately.thought.out.domain.name.of.very.significant.length.is.just.too.darn.long.because.you.know.the rfc.states.that.two.hundred.fifty.five.characters.is.the.max.com";
|
||||
|
||||
CONTEXT_CREATE(TRUE);
|
||||
|
||||
ASSERT_RC(getdns_service_sync(context, name, NULL, &response),
|
||||
GETDNS_RETURN_BAD_DOMAIN_NAME, "Return code from getdns_service_sync()");
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (getdns_service_sync_4)
|
||||
{
|
||||
/*
|
||||
* name is invalid (domain name label length > 63)
|
||||
* expect: GETDNS_RETURN_BAD_DOMAIN_NAME
|
||||
*/
|
||||
struct getdns_context *context = NULL;
|
||||
struct getdns_dict *response = NULL;
|
||||
const char *name = "this.domain.hasalabelwhichexceedsthemaximumdnslabelsizeofsixtythreecharacters.com";
|
||||
|
||||
CONTEXT_CREATE(TRUE);
|
||||
|
||||
ASSERT_RC(getdns_service_sync(context, name, NULL, &response),
|
||||
GETDNS_RETURN_BAD_DOMAIN_NAME, "Return code from getdns_service_sync()");
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (getdns_service_sync_5)
|
||||
{
|
||||
/*
|
||||
* response is NULL
|
||||
* expect: GETDNS_RETURN_INVALID_PARAMETER
|
||||
*/
|
||||
struct getdns_context *context = NULL;
|
||||
|
||||
CONTEXT_CREATE(TRUE);
|
||||
|
||||
ASSERT_RC(getdns_service_sync(context, "google.com", NULL, NULL),
|
||||
GETDNS_RETURN_INVALID_PARAMETER, "Return code from getdns_service_sync()");
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (getdns_service_sync_7)
|
||||
{
|
||||
/*
|
||||
* rname is <non-existent domain name> (NXDOMAIN)
|
||||
* no extensions
|
||||
* expected: NXDOMAIN response (with SOA record)
|
||||
|
||||
*/
|
||||
struct getdns_context *context = NULL;
|
||||
struct getdns_dict *response = NULL;
|
||||
const char *name = "labelsizeofsixtythreecharacterscom";
|
||||
|
||||
CONTEXT_CREATE(TRUE);
|
||||
|
||||
ASSERT_RC(getdns_service_sync(context, name, NULL, &response),
|
||||
GETDNS_RETURN_GOOD, "Return code from getdns_service_sync()");
|
||||
|
||||
EXTRACT_RESPONSE;
|
||||
|
||||
assert_nxdomain(&ex_response);
|
||||
assert_nodata(&ex_response);
|
||||
assert_soa_in_authority(&ex_response);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
|
||||
|
||||
|
||||
Suite *
|
||||
getdns_service_sync_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("getdns_service_sync()");
|
||||
|
||||
/* Negative test caseis */
|
||||
TCase *tc_neg = tcase_create("Negative");
|
||||
tcase_add_test(tc_neg, getdns_service_sync_1);
|
||||
tcase_add_test(tc_neg, getdns_service_sync_2);
|
||||
tcase_add_test(tc_neg, getdns_service_sync_3);
|
||||
tcase_add_test(tc_neg, getdns_service_sync_4);
|
||||
tcase_add_test(tc_neg, getdns_service_sync_5);
|
||||
|
||||
suite_add_tcase(s, tc_neg);
|
||||
|
||||
/* Positive test cases */
|
||||
TCase *tc_pos = tcase_create("Positive");
|
||||
tcase_add_test(tc_pos, getdns_service_sync_7);
|
||||
suite_add_tcase(s, tc_pos);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue