diff --git a/src/test/check_getdns.c b/src/test/check_getdns.c index 753fdce5..2f18e086 100644 --- a/src/test/check_getdns.c +++ b/src/test/check_getdns.c @@ -14,6 +14,7 @@ #include "check_getdns_context_destroy.h" #include "check_getdns_cancel_callback.h" #include "check_getdns_address.h" +#include "check_getdns_address_sync.h" #include "check_getdns_list_get_length.h" #include "check_getdns_list_get_data_type.h" #include "check_getdns_list_get_dict.h" @@ -34,7 +35,6 @@ #include "check_getdns_convert_ulabel_to_alabel.h" #include "check_getdns_convert_alabel_to_ulabel.h" #include "check_getdns_pretty_print_dict.h" -#include "check_getdns_display_ip_address.h" int @@ -45,6 +45,7 @@ main (void) Suite *getdns_general_suite(void); Suite *getdns_general_sync_suite(void); + Suite *getdns_address_suite(void); Suite *getdns_address_sync_suite(void); Suite *getdns_context_create_suite(void); Suite *getdns_context_destroy_suite(void); @@ -70,10 +71,10 @@ main (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); sr = srunner_create(getdns_general_suite()); srunner_add_suite(sr, getdns_general_sync_suite()); + srunner_add_suite(sr, getdns_address_suite()); srunner_add_suite(sr, getdns_address_sync_suite()); srunner_add_suite(sr, getdns_context_create_suite()); srunner_add_suite(sr, getdns_context_destroy_suite()); @@ -98,7 +99,6 @@ main (void) srunner_add_suite(sr, getdns_convert_ulabel_to_alabel_suite()); srunner_add_suite(sr, getdns_convert_alabel_to_ulabel_suite()); srunner_add_suite(sr, getdns_pretty_print_dict_suite()); - srunner_add_suite(sr, getdns_display_ip_address_suite()); srunner_set_log(sr, "check_getdns.log"); srunner_run_all(sr, CK_NORMAL); diff --git a/src/test/check_getdns_address.h b/src/test/check_getdns_address.h index 55044c33..1c1b20ba 100644 --- a/src/test/check_getdns_address.h +++ b/src/test/check_getdns_address.h @@ -4,21 +4,22 @@ /* *************************************************** * * - * T E S T S F O R G E T D N S _ A D D R E S S * + * T E S T S F O R G E T D N S _ A D D R E S S * * * *************************************************** */ - + START_TEST (getdns_address_1) { /* * context = NULL * expect: GETDNS_RETURN_BAD_CONTEXT */ - struct getdns_context *context = NULL; - struct getdns_dict *response = NULL; + struct getdns_context *context = NULL; + getdns_transaction_t transaction_id = 0; - ASSERT_RC(getdns_address(context, "google.com", NULL, &response), + ASSERT_RC(getdns_address(context, "google.com", NULL, + NULL, &transaction_id, callbackfn), GETDNS_RETURN_BAD_CONTEXT, "Return code from getdns_address()"); } END_TEST @@ -29,37 +30,44 @@ * name = NULL * expect: GETDNS_RETURN_INVALID_PARAMETER */ - struct getdns_context *context = NULL; - struct getdns_dict *response = NULL; + 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_address(context, NULL, NULL, &response), + ASSERT_RC(getdns_address(context, NULL, NULL, + NULL, &transaction_id, callbackfn), GETDNS_RETURN_INVALID_PARAMETER, "Return code from getdns_address()"); + RUN_EVENT_LOOP; CONTEXT_DESTROY; } END_TEST - - START_TEST (getdns_address_3) + + START_TEST (getdns_address_3) { /* * name = invalid domain (too many octets) * expect: GETDNS_RETURN_BAD_DOMAIN_NAME */ - struct getdns_context *context = NULL; - struct getdns_dict *response = NULL; + 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_address(context, name, NULL, &response), + ASSERT_RC(getdns_address(context, name, NULL, + NULL, &transaction_id, callbackfn), GETDNS_RETURN_BAD_DOMAIN_NAME, "Return code from getdns_address()"); + RUN_EVENT_LOOP; CONTEXT_DESTROY; } END_TEST - START_TEST (getdns_address_4) { @@ -67,15 +75,19 @@ * name = invalid domain (label too long) * expect: GETDNS_RETURN_BAD_DOMAIN_NAME */ - struct getdns_context *context = NULL; - struct getdns_dict *response = NULL; + 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_address(context, name, NULL, &response), + ASSERT_RC(getdns_address(context, name, NULL, + NULL, &transaction_id, callbackfn), GETDNS_RETURN_BAD_DOMAIN_NAME, "Return code from getdns_address()"); + RUN_EVENT_LOOP; CONTEXT_DESTROY; } END_TEST @@ -83,209 +95,124 @@ START_TEST (getdns_address_5) { /* - * response = NULL + * callbackfn = NULL * expect: GETDNS_RETURN_INVALID_PARAMETER */ - struct getdns_context *context = NULL; - + 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_address(context, "google.com", NULL, NULL), + ASSERT_RC(getdns_address(context, "google.com", NULL, + NULL, &transaction_id, NULL), GETDNS_RETURN_INVALID_PARAMETER, "Return code from getdns_address()"); + RUN_EVENT_LOOP; CONTEXT_DESTROY; } END_TEST + START_TEST (getdns_address_6) { /* * name = "google.com" - * expect: NOERROR response: - * status = GETDNS_RETURN_GOOD + * status = GETDNS_RESPSTATUS_GOOD * rcode = 0 - todo: create zonefile with exact count - * ancount = tbd (number of records in ANSWER section) */ - struct getdns_context *context = NULL; - struct getdns_dict *response = NULL; - - CONTEXT_CREATE(TRUE); + void verify_getdns_address_6(struct extracted_response *ex_response); + struct getdns_context *context = NULL; \ + struct event_base *event_base = NULL; \ + getdns_transaction_t transaction_id = 0; - ASSERT_RC(getdns_address(context, "google.com", NULL, &response), + CONTEXT_CREATE(TRUE); + EVENT_BASE_CREATE; + + ASSERT_RC(getdns_address(context, "google.com", NULL, + verify_getdns_address_6, &transaction_id, callbackfn), GETDNS_RETURN_GOOD, "Return code from getdns_address()"); - EXTRACT_RESPONSE; - - assert_noerror(&ex_response); - + RUN_EVENT_LOOP; CONTEXT_DESTROY; } END_TEST - + + void verify_getdns_address_6(struct extracted_response *ex_response) + { + assert_noerror(ex_response); + //assert_soa_in_authority(ex_response); + assert_address_in_answer(ex_response, TRUE, TRUE); + } + + START_TEST (getdns_address_7) { /* - * name = "localhost" - * expect: NOERROR response: - * expect: GETDNS_RETURN_GOOD + * name = "localhost" name should be resolved from host file + * expect: NOERROR/NODATA response: + * status = GETDNS_RESPSTATUS_GOOD * rcode = 0 - todo: investigate that proper search order is set for resolution (is local being checked) - todo: create zonefile with exact count - * ancount = tbd (number of records in ANSWER section) + * ancount = 1 (number of records in ANSWER section) */ - struct getdns_context *context = NULL; - struct getdns_dict *response = NULL; + void verify_getdns_address_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_address(context, "localhost", NULL, &response), + ASSERT_RC(getdns_address(context, "localhost", NULL, + verify_getdns_address_7, &transaction_id, callbackfn), GETDNS_RETURN_GOOD, "Return code from getdns_address()"); - EXTRACT_RESPONSE; - - assert_noerror(&ex_response); + RUN_EVENT_LOOP; CONTEXT_DESTROY; } END_TEST + + void verify_getdns_address_7(struct extracted_response *ex_response) + { + assert_noerror(ex_response); + assert_address_in_answer(ex_response, TRUE, TRUE); + //assert_nodata(ex_response); + } START_TEST (getdns_address_8) { /* - * name = "google.joe" - * status = GETDNS_RETURN_GOOD for NXDOMAIN - * expect: NXDOMAIN response with SOA record - * rcode = 0 - todo: investigate that proper search order is set for resolution (is local being checked) - todo: create host file with exact count - * ancount >= 1 (number of records in ANSWER section) - * and one SOA record ("type": 6) in "answer" list - */ - struct getdns_context *context = NULL; - struct getdns_dict *response = NULL; - - CONTEXT_CREATE(TRUE); - - ASSERT_RC(getdns_address(context, "google.joe", NULL, &response), - GETDNS_RETURN_GOOD, "Return code from getdns_address()"); - - EXTRACT_RESPONSE; - - assert_nxdomain(&ex_response); - assert_nodata(&ex_response); - assert_soa_in_authority(&ex_response); - - CONTEXT_DESTROY; - } - END_TEST - - START_TEST (getdns_address_9) - { - /* - * name = "hampster.com" need to replace this with domain from unbound zone - * expect: NOERROR/NODATA response: + * name = "hostnamedoesntexist" (name should not be resolved) + * expect: NOERROR response * status = GETDNS_RESPSTATUS_GOOD * rcode = 0 - * ancount = 0 (number of records in ANSWER section) */ - struct getdns_context *context = NULL; - struct getdns_dict *response = NULL; + void verify_getdns_address_8(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); - ASSERT_RC(getdns_address(context, "hampster.com", NULL, &response), + EVENT_BASE_CREATE; + + ASSERT_RC(getdns_address(context, "hostnamedoesntexist", NULL, + verify_getdns_address_8, &transaction_id, callbackfn), GETDNS_RETURN_GOOD, "Return code from getdns_address()"); - EXTRACT_RESPONSE; - - assert_noerror(&ex_response); - + RUN_EVENT_LOOP; CONTEXT_DESTROY; } END_TEST - - START_TEST (getdns_address_10) + + void verify_getdns_address_8(struct extracted_response *ex_response) { - /* - * name = "google.com" need to swap this out for max domain name length with max lable length` - * expect: NOERROR response with A records - * status = GETDNS_RESPSTATUS_GOOD - * rcode = 0 - * ancount >= 11 (number of records in ANSWER section) - */ - struct getdns_context *context = NULL; - struct getdns_dict *response = NULL; - - CONTEXT_CREATE(TRUE); - - ASSERT_RC(getdns_address(context, "google.com", NULL, &response), - GETDNS_RETURN_GOOD, "Return code from getdns_address()"); - - EXTRACT_RESPONSE; - - assert_noerror(&ex_response); - assert_address_in_answer(&ex_response, TRUE, FALSE); - - CONTEXT_DESTROY; + assert_noerror(ex_response); + assert_soa_in_authority(ex_response); } - END_TEST - START_TEST (getdns_address_11) - { - /* - * name = "75.101.146.66" need to change this to local unbound data - * status = GETDNS_RETURN_GOOD for NXDOMAIN - * expect: NXDOMAIN response with SOA record for NUMERICAL data - * rcode = 0 - * ancount >= 1 (number of records in ANSWER section) - * and one SOA record ("type": 6) in "answer" list - */ - struct getdns_context *context = NULL; - struct getdns_dict *response = NULL; - - CONTEXT_CREATE(TRUE); - - ASSERT_RC(getdns_address(context, "75.101.146.66", NULL, &response), - GETDNS_RETURN_GOOD, "Return code from getdns_address()"); - - EXTRACT_RESPONSE; - - assert_nxdomain(&ex_response); - assert_nodata(&ex_response); - assert_soa_in_authority(&ex_response); - - CONTEXT_DESTROY; - } - END_TEST - - START_TEST (getdns_address_12) - { - /* - * name = "2607:f8b0:4006:802::1007" need to change this to local unbound data - * status = GETDNS_RETURN_GOOD for NXDOMAIN - * expect: NXDOMAIN response with SOA record for NUMERICAL data - * rcode = 0 - * ancount >= 1 (number of records in ANSWER section) - * and one SOA record ("type": 6) in "answer" list - */ - struct getdns_context *context = NULL; - struct getdns_dict *response = NULL; - - CONTEXT_CREATE(TRUE); - - ASSERT_RC(getdns_address(context, "2607:f8b0:4006:802::1007", NULL, &response), - GETDNS_RETURN_GOOD, "Return code from getdns_address()"); - - EXTRACT_RESPONSE; - - assert_nxdomain(&ex_response); - assert_nodata(&ex_response); - assert_soa_in_authority(&ex_response); - - CONTEXT_DESTROY; - } - END_TEST Suite * getdns_address_suite (void) @@ -299,20 +226,16 @@ tcase_add_test(tc_neg, getdns_address_3); tcase_add_test(tc_neg, getdns_address_4); tcase_add_test(tc_neg, getdns_address_5); - tcase_add_test(tc_neg, getdns_address_6); suite_add_tcase(s, tc_neg); + /* Positive test cases */ - TCase *tc_pos = tcase_create("Positive"); + tcase_add_test(tc_pos, getdns_address_6); tcase_add_test(tc_pos, getdns_address_7); tcase_add_test(tc_pos, getdns_address_8); - tcase_add_test(tc_pos, getdns_address_9); - tcase_add_test(tc_pos, getdns_address_10); - tcase_add_test(tc_pos, getdns_address_11); - tcase_add_test(tc_pos, getdns_address_12); suite_add_tcase(s, tc_pos); return s; } - + #endif diff --git a/src/test/check_getdns_address_sync.h b/src/test/check_getdns_address_sync.h new file mode 100644 index 00000000..f850b2b3 --- /dev/null +++ b/src/test/check_getdns_address_sync.h @@ -0,0 +1,166 @@ +#ifndef _check_getdns_address_sync_h_ +#define _check_getdns_address_sync_h_ + + /* + ************************************************************** + * * + * T E S T S F O R G E T D N S _ A D D R E S S _ S Y N C * + * * + ************************************************************** + */ + + START_TEST (getdns_address_sync_1) + { + /* + * context = NULL + * expect: GETDNS_RETURN_BAD_CONTEXT + */ + struct getdns_context *context = NULL; + struct getdns_dict *response = NULL; + + ASSERT_RC(getdns_address_sync(context, "google.com", NULL, &response), + GETDNS_RETURN_BAD_CONTEXT, "Return code from getdns_address_sync()"); + } + END_TEST + + START_TEST (getdns_address_sync_2) + { + /* + * name = NULL + * expect: GETDNS_RETURN_INVALID_PARAMETER + */ + struct getdns_context *context = NULL; + struct getdns_dict *response = NULL; + + CONTEXT_CREATE(TRUE); + + ASSERT_RC(getdns_address_sync(context, NULL, NULL, &response), + GETDNS_RETURN_INVALID_PARAMETER, "Return code from getdns_address_sync()"); + + CONTEXT_DESTROY; + } + END_TEST + + START_TEST (getdns_address_sync_3) + { + /* + * name = NULL + * 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_address_sync(context, name, NULL, &response), + GETDNS_RETURN_BAD_DOMAIN_NAME, "Return code from getdns_address_sync()"); + + CONTEXT_DESTROY; + } + END_TEST + + + + START_TEST (getdns_address_sync_4) + { + /* + * name = "google.com" + * status = GETDNS_RETURN_GOOD + * rcode = 0 + */ + struct getdns_context *context = NULL; + struct getdns_dict *response = NULL; + + CONTEXT_CREATE(TRUE); + + ASSERT_RC(getdns_address_sync(context, "google.com", NULL, &response), + GETDNS_RETURN_GOOD, "Return code from getdns_address_sync()"); + + EXTRACT_RESPONSE; + + CONTEXT_DESTROY; + } + END_TEST + + + + START_TEST (getdns_address_sync_5) + { + /* + * name = "localhost" + * expect: NOERROR response: + * expect: GETDNS_RETURN_GOOD + * rcode = 0 + todo: investigate that proper search order is set for resolution (is local being checked) + todo: create zonefile with exact count + * ancount = tbd (number of records in ANSWER section) + */ + struct getdns_context *context = NULL; + struct getdns_dict *response = NULL; + + CONTEXT_CREATE(TRUE); + + ASSERT_RC(getdns_address_sync(context, "localhost", NULL, &response), + GETDNS_RETURN_GOOD, "Return code from getdns_address_sync()"); + + EXTRACT_RESPONSE; + + assert_noerror( &ex_response); + assert_address_in_answer(&ex_response, TRUE, TRUE); + + + CONTEXT_DESTROY; + } + END_TEST + + + START_TEST (getdns_address_sync_6) + { + /* + * name = "hampster.com" need to replace this with domain from unbound zone + * expect: NOERROR/NODATA response: + * status = GETDNS_RESPSTATUS_GOOD + * rcode = 0 + * ancount = 0 (number of records in ANSWER section) + */ + struct getdns_context *context = NULL; + struct getdns_dict *response = NULL; + + CONTEXT_CREATE(TRUE); + + ASSERT_RC(getdns_address_sync(context, "hampster.com", NULL, &response), + GETDNS_RETURN_GOOD, "Return code from getdns_address_sync()"); + + EXTRACT_RESPONSE; + + assert_noerror(&ex_response); + //assert_soa_in_authority(&ex_response); + + CONTEXT_DESTROY; + } + END_TEST + + Suite * + getdns_address_sync_suite (void) + { + Suite *s = suite_create ("getdns_address_sync()"); + + /* Negative test caseis */ + TCase *tc_neg = tcase_create("Negative"); + tcase_add_test(tc_neg, getdns_address_sync_1); + tcase_add_test(tc_neg, getdns_address_sync_2); + tcase_add_test(tc_neg, getdns_address_sync_3); + suite_add_tcase(s, tc_neg); + /* Positive test cases */ + + TCase *tc_pos = tcase_create("Positive"); + tcase_add_test(tc_pos, getdns_address_sync_4); + tcase_add_test(tc_pos, getdns_address_sync_5); + tcase_add_test(tc_pos, getdns_address_sync_6); + suite_add_tcase(s, tc_pos); + + return s; + } + +#endif