From 88bdbdc972bcf319b3df5a665011da21aaea0613 Mon Sep 17 00:00:00 2001 From: saradickinson Date: Wed, 22 Oct 2014 17:09:33 +0000 Subject: [PATCH] Crude changes to stub test scripts to allow testing of all transport and recusive mode combinations --- src/test/tests_stub_async.c | 33 ++- src/test/tests_stub_async.good | 361 ++++++++++++++++++++++----------- src/test/tests_stub_sync.c | 38 +++- src/test/tests_stub_sync.good | 305 ++++++++++++++++++++-------- 4 files changed, 531 insertions(+), 206 deletions(-) mode change 100644 => 100755 src/test/tests_stub_async.c diff --git a/src/test/tests_stub_async.c b/src/test/tests_stub_async.c old mode 100644 new mode 100755 index bb3a8a3d..a6e6fce2 --- a/src/test/tests_stub_async.c +++ b/src/test/tests_stub_async.c @@ -41,6 +41,12 @@ #include "getdns/getdns_extra.h" #include +#define TRANSPORT_UDP "udp" +#define TRANSPORT_TCP "tcp" +#define TRANSPORT_PIPELINE "pipeline" +#define RESOLUTION_STUB "stub" +#define RESOLUTION_REC "rec" + /* Set up the callback function, which will also do the processing of the results */ void this_callbackfn(struct getdns_context *this_context, @@ -55,11 +61,11 @@ this_callbackfn(struct getdns_context *this_context, } else if (this_callback_type == GETDNS_CALLBACK_CANCEL) fprintf(stderr, - "The callback with ID %llu was cancelled. Exiting.", + "The callback with ID %llu was cancelled. Exiting.\n", (unsigned long long)this_transaction_id); else fprintf(stderr, - "The callback got a callback_type of %d. Exiting.", + "The callback got a callback_type of %d. Exiting.\n", this_callback_type); getdns_dict_destroy(this_response); } @@ -67,6 +73,10 @@ this_callbackfn(struct getdns_context *this_context, int main(int argc, char** argv) { + + const char *transport = argc > 2 ? argv[2] : "udp"; + const char *resolution = argc > 3 ? argv[3] : "stub"; + /* Create the DNS context for this call */ struct getdns_context *this_context = NULL; getdns_return_t context_create_return = @@ -76,7 +86,22 @@ main(int argc, char** argv) context_create_return); return (GETDNS_RETURN_GENERIC_ERROR); } - getdns_context_set_resolution_type(this_context, GETDNS_RESOLUTION_STUB); + + if (strncmp(resolution, RESOLUTION_STUB, 4) == 0) + getdns_context_set_resolution_type(this_context, GETDNS_RESOLUTION_STUB); + else if (strncmp(resolution, RESOLUTION_REC, 4) != 0) { + fprintf(stderr, "Invalid resolution %s, must be one of stub or rec\n", transport); + exit(EXIT_FAILURE); + } + + if (strncmp(transport, TRANSPORT_TCP, 3) == 0) + getdns_context_set_dns_transport(this_context, GETDNS_TRANSPORT_TCP_ONLY); + else if (strncmp(transport, TRANSPORT_PIPELINE, 8) == 0) + getdns_context_set_dns_transport(this_context, GETDNS_TRANSPORT_TCP_ONLY_KEEP_CONNECTIONS_OPEN); + else if (strncmp(transport, TRANSPORT_UDP, 3) != 0) { + fprintf(stderr, "Invalid transport %s, must be one of udp, tcp or pipeline\n", transport); + exit(EXIT_FAILURE); + } getdns_context_set_timeout(this_context, 5000); /* Create an event base and put it in the context using the unknown function name */ @@ -87,7 +112,7 @@ main(int argc, char** argv) /* Make the call */ getdns_return_t dns_request_return = - getdns_general(this_context, this_name, GETDNS_RRTYPE_A, + getdns_address(this_context, this_name, NULL, this_userarg, &this_transaction_id, this_callbackfn); if (dns_request_return == GETDNS_RETURN_BAD_DOMAIN_NAME) { fprintf(stderr, "A bad domain name was used: %s. Exiting.", diff --git a/src/test/tests_stub_async.good b/src/test/tests_stub_async.good index 9e953d57..ecf41f9f 100644 --- a/src/test/tests_stub_async.good +++ b/src/test/tests_stub_async.good @@ -1,187 +1,322 @@ { - "answer_type": 800, - "canonical_name": , + "answer_type": GETDNS_NAMETYPE_DNS, + "canonical_name": , "just_address_answers": [ { - "address_data": , + "address_data": , "address_type": }, { - "address_data": , - "address_type": - }, - { - "address_data": , - "address_type": - }, - { - "address_data": , - "address_type": - }, - { - "address_data": , - "address_type": - }, - { - "address_data": , - "address_type": - }, - { - "address_data": , + "address_data": , "address_type": } ], "replies_full": [ - , - + , + ], "replies_tree": [ { - "additional": [], + "additional": + [ + { + "class": GETDNS_RRCLASS_IN, + "name": , + "rdata": + { + "ipv6_address": , + "rdata_raw": + }, + "ttl": 376, + "type": GETDNS_RRTYPE_AAAA + }, + { + "class": GETDNS_RRCLASS_IN, + "name": , + "rdata": + { + "algorithm": 7, + "key_tag": 50394, + "labels": 2, + "original_ttl": 450, + "rdata_raw": , + "signature": , + "signature_expiration": 1415758282, + "signature_inception": 1413897732, + "signers_name": , + "type_covered": GETDNS_RRTYPE_AAAA + }, + "ttl": 376, + "type": GETDNS_RRTYPE_RRSIG + } + ], "answer": [ { - "class": 1, - "name": , + "class": GETDNS_RRCLASS_IN, + "name": , "rdata": { - "ipv4_address": , - "rdata_raw": + "ipv4_address": , + "rdata_raw": }, - "ttl": 227, + "ttl": 376, "type": GETDNS_RRTYPE_A }, { - "class": 1, - "name": , + "class": GETDNS_RRCLASS_IN, + "name": , "rdata": { - "ipv4_address": , - "rdata_raw": + "algorithm": 7, + "key_tag": 50394, + "labels": 2, + "original_ttl": 450, + "rdata_raw": , + "signature": , + "signature_expiration": 1415671554, + "signature_inception": 1413868932, + "signers_name": , + "type_covered": GETDNS_RRTYPE_A }, - "ttl": 227, - "type": GETDNS_RRTYPE_A - }, - { - "class": 1, - "name": , - "rdata": - { - "ipv4_address": , - "rdata_raw": - }, - "ttl": 227, - "type": GETDNS_RRTYPE_A - }, - { - "class": 1, - "name": , - "rdata": - { - "ipv4_address": , - "rdata_raw": - }, - "ttl": 227, - "type": GETDNS_RRTYPE_A - }, - { - "class": 1, - "name": , - "rdata": - { - "ipv4_address": , - "rdata_raw": - }, - "ttl": 227, - "type": GETDNS_RRTYPE_A - }, - { - "class": 1, - "name": , - "rdata": - { - "ipv4_address": , - "rdata_raw": - }, - "ttl": 227, - "type": GETDNS_RRTYPE_A + "ttl": 376, + "type": GETDNS_RRTYPE_RRSIG } ], - "answer_type": 800, - "authority": [], - "canonical_name": , + "answer_type": GETDNS_NAMETYPE_DNS, + "authority": + [ + { + "class": GETDNS_RRCLASS_IN, + "name": , + "rdata": + { + "nsdname": , + "rdata_raw": + }, + "ttl": 376, + "type": GETDNS_RRTYPE_NS + }, + { + "class": GETDNS_RRCLASS_IN, + "name": , + "rdata": + { + "nsdname": , + "rdata_raw": + }, + "ttl": 376, + "type": GETDNS_RRTYPE_NS + }, + { + "class": GETDNS_RRCLASS_IN, + "name": , + "rdata": + { + "nsdname": , + "rdata_raw": + }, + "ttl": 376, + "type": GETDNS_RRTYPE_NS + }, + { + "class": GETDNS_RRCLASS_IN, + "name": , + "rdata": + { + "algorithm": 7, + "key_tag": 50394, + "labels": 2, + "original_ttl": 450, + "rdata_raw": , + "signature": , + "signature_expiration": 1415604992, + "signature_inception": 1413811332, + "signers_name": , + "type_covered": GETDNS_RRTYPE_NS + }, + "ttl": 376, + "type": GETDNS_RRTYPE_RRSIG + } + ], + "canonical_name": , "header": { "aa": 0, "ad": 0, - "ancount": 6, - "arcount": 0, + "ancount": 2, + "arcount": 2, "cd": 0, - "id": 0, - "nscount": 0, - "opcode": 0, + "id": 28767, + "nscount": 4, + "opcode": GETDNS_OPCODE_QUERY, "qdcount": 1, "qr": 1, "ra": 1, - "rcode": 0, + "rcode": GETDNS_RCODE_NOERROR, "rd": 1, "tc": 0, "z": 0 }, "question": { - "qclass": 1, - "qname": , - "qtype": 1 + "qclass": GETDNS_RRCLASS_IN, + "qname": , + "qtype": GETDNS_RRTYPE_A } }, { - "additional": [], + "additional": + [ + { + "class": GETDNS_RRCLASS_IN, + "name": , + "rdata": + { + "ipv4_address": , + "rdata_raw": + }, + "ttl": 376, + "type": GETDNS_RRTYPE_A + }, + { + "class": GETDNS_RRCLASS_IN, + "name": , + "rdata": + { + "algorithm": 7, + "key_tag": 50394, + "labels": 2, + "original_ttl": 450, + "rdata_raw": , + "signature": , + "signature_expiration": 1415671554, + "signature_inception": 1413868932, + "signers_name": , + "type_covered": GETDNS_RRTYPE_A + }, + "ttl": 376, + "type": GETDNS_RRTYPE_RRSIG + } + ], "answer": [ { - "class": 1, - "name": , + "class": GETDNS_RRCLASS_IN, + "name": , "rdata": { - "ipv6_address": , - "rdata_raw": + "ipv6_address": , + "rdata_raw": }, - "ttl": 136, + "ttl": 376, "type": GETDNS_RRTYPE_AAAA + }, + { + "class": GETDNS_RRCLASS_IN, + "name": , + "rdata": + { + "algorithm": 7, + "key_tag": 50394, + "labels": 2, + "original_ttl": 450, + "rdata_raw": , + "signature": , + "signature_expiration": 1415758282, + "signature_inception": 1413897732, + "signers_name": , + "type_covered": GETDNS_RRTYPE_AAAA + }, + "ttl": 376, + "type": GETDNS_RRTYPE_RRSIG } ], - "answer_type": 800, - "authority": [], - "canonical_name": , + "answer_type": GETDNS_NAMETYPE_DNS, + "authority": + [ + { + "class": GETDNS_RRCLASS_IN, + "name": , + "rdata": + { + "nsdname": , + "rdata_raw": + }, + "ttl": 376, + "type": GETDNS_RRTYPE_NS + }, + { + "class": GETDNS_RRCLASS_IN, + "name": , + "rdata": + { + "nsdname": , + "rdata_raw": + }, + "ttl": 376, + "type": GETDNS_RRTYPE_NS + }, + { + "class": GETDNS_RRCLASS_IN, + "name": , + "rdata": + { + "nsdname": , + "rdata_raw": + }, + "ttl": 376, + "type": GETDNS_RRTYPE_NS + }, + { + "class": GETDNS_RRCLASS_IN, + "name": , + "rdata": + { + "algorithm": 7, + "key_tag": 50394, + "labels": 2, + "original_ttl": 450, + "rdata_raw": , + "signature": , + "signature_expiration": 1415604992, + "signature_inception": 1413811332, + "signers_name": , + "type_covered": GETDNS_RRTYPE_NS + }, + "ttl": 376, + "type": GETDNS_RRTYPE_RRSIG + } + ], + "canonical_name": , "header": { "aa": 0, "ad": 0, - "ancount": 1, - "arcount": 0, + "ancount": 2, + "arcount": 2, "cd": 0, - "id": 0, - "nscount": 0, - "opcode": 0, + "id": 24501, + "nscount": 4, + "opcode": GETDNS_OPCODE_QUERY, "qdcount": 1, "qr": 1, "ra": 1, - "rcode": 0, + "rcode": GETDNS_RCODE_NOERROR, "rd": 1, "tc": 0, "z": 0 }, "question": { - "qclass": 1, - "qname": , - "qtype": 28 + "qclass": GETDNS_RRCLASS_IN, + "qname": , + "qtype": GETDNS_RRTYPE_AAAA } } ], - "status": 900 + "status": GETDNS_RESPSTATUS_GOOD } diff --git a/src/test/tests_stub_sync.c b/src/test/tests_stub_sync.c index b8366c55..4b04d5fb 100755 --- a/src/test/tests_stub_sync.c +++ b/src/test/tests_stub_sync.c @@ -38,6 +38,12 @@ #include "testmessages.h" #include "getdns/getdns.h" +#define TRANSPORT_UDP "udp" +#define TRANSPORT_TCP "tcp" +#define TRANSPORT_PIPELINE "pipeline" +#define RESOLUTION_STUB "stub" +#define RESOLUTION_REC "rec" + static void print_response(struct getdns_dict * response) { @@ -49,8 +55,12 @@ print_response(struct getdns_dict * response) } int -main() +main(int argc, char** argv) { + + const char *transport = argc > 1 ? argv[1] : "udp"; + const char *resolution = argc > 2 ? argv[2] : "stub"; + /* Create the DNS context for this call */ struct getdns_context *this_context = NULL; getdns_return_t context_create_return = @@ -60,7 +70,22 @@ main() context_create_return); return (GETDNS_RETURN_GENERIC_ERROR); } - getdns_context_set_resolution_type(this_context, GETDNS_RESOLUTION_STUB); + + if (strncmp(resolution, RESOLUTION_STUB, 4) == 0) + getdns_context_set_resolution_type(this_context, GETDNS_RESOLUTION_STUB); + else if (strncmp(resolution, RESOLUTION_REC, 4) != 0) { + fprintf(stderr, "Invalid resolution %s, must be one of stub or rec\n", transport); + exit(EXIT_FAILURE); + } + + if (strncmp(transport, TRANSPORT_TCP, 3) == 0) + getdns_context_set_dns_transport(this_context, GETDNS_TRANSPORT_TCP_ONLY); + else if (strncmp(transport, TRANSPORT_PIPELINE, 8) == 0) + getdns_context_set_dns_transport(this_context, GETDNS_TRANSPORT_TCP_ONLY_KEEP_CONNECTIONS_OPEN); + else if (strncmp(transport, TRANSPORT_UDP, 3) != 0) { + fprintf(stderr, "Invalid transport %s, must be one of udp, tcp or pipeline\n", transport); + exit(EXIT_FAILURE); + } struct getdns_dict *response = NULL; getdns_return_t ret = @@ -74,17 +99,14 @@ main() getdns_dict_destroy(response); ret = - getdns_service_sync(this_context, "www.google.com", NULL, &response); + getdns_service_sync(this_context, "_xmpp-client._tcp.jabber.com.", NULL, &response); if (ret != GETDNS_RETURN_GOOD || response == NULL) { fprintf(stderr, "Service sync returned error.\n"); exit(EXIT_FAILURE); } print_response(response); getdns_dict_destroy(response); - - /* Now switch to TCP and make sure everything works */ - getdns_context_set_dns_transport(this_context, GETDNS_TRANSPORT_TCP_ONLY); - + ret = getdns_general_sync(this_context, "www.google.com", GETDNS_RRTYPE_A, NULL, &response); if (ret != GETDNS_RETURN_GOOD || response == NULL) { @@ -93,7 +115,7 @@ main() } print_response(response); getdns_dict_destroy(response); - + /* Clean up */ getdns_context_destroy(this_context); /* Assuming we get here, leave gracefully */ diff --git a/src/test/tests_stub_sync.good b/src/test/tests_stub_sync.good index 1f7f69b0..637e8a44 100644 --- a/src/test/tests_stub_sync.good +++ b/src/test/tests_stub_sync.good @@ -1,41 +1,37 @@ The packet { - "answer_type": 800, + "answer_type": GETDNS_NAMETYPE_DNS, "canonical_name": , "just_address_answers": [ { - "address_data": , + "address_data": , "address_type": }, { - "address_data": , + "address_data": , "address_type": }, { - "address_data": , + "address_data": , "address_type": }, { - "address_data": , + "address_data": , "address_type": }, { - "address_data": , + "address_data": , "address_type": }, { - "address_data": , - "address_type": - }, - { - "address_data": , + "address_data": , "address_type": } ], "replies_full": [ - , - + , + ], "replies_tree": [ @@ -44,98 +40,87 @@ The packet { "answer": [ { - "class": 1, + "class": GETDNS_RRCLASS_IN, "name": , "rdata": { - "ipv4_address": , - "rdata_raw": + "ipv4_address": , + "rdata_raw": }, "ttl": 300, "type": GETDNS_RRTYPE_A }, { - "class": 1, + "class": GETDNS_RRCLASS_IN, "name": , "rdata": { - "ipv4_address": , - "rdata_raw": + "ipv4_address": , + "rdata_raw": }, "ttl": 300, "type": GETDNS_RRTYPE_A }, { - "class": 1, + "class": GETDNS_RRCLASS_IN, "name": , "rdata": { - "ipv4_address": , - "rdata_raw": + "ipv4_address": , + "rdata_raw": }, "ttl": 300, "type": GETDNS_RRTYPE_A }, { - "class": 1, + "class": GETDNS_RRCLASS_IN, "name": , "rdata": { - "ipv4_address": , - "rdata_raw": + "ipv4_address": , + "rdata_raw": }, "ttl": 300, "type": GETDNS_RRTYPE_A }, { - "class": 1, + "class": GETDNS_RRCLASS_IN, "name": , "rdata": { - "ipv4_address": , - "rdata_raw": - }, - "ttl": 300, - "type": GETDNS_RRTYPE_A - }, - { - "class": 1, - "name": , - "rdata": - { - "ipv4_address": , - "rdata_raw": + "ipv4_address": , + "rdata_raw": }, "ttl": 300, "type": GETDNS_RRTYPE_A } ], - "answer_type": 800, + "answer_type": GETDNS_NAMETYPE_DNS, "authority": [], "canonical_name": , "header": { "aa": 0, "ad": 0, - "ancount": 6, + "ancount": 5, "arcount": 0, "cd": 0, - "id": 0, + "id": 45440, "nscount": 0, - "opcode": 0, + "opcode": GETDNS_OPCODE_QUERY, "qdcount": 1, "qr": 1, "ra": 1, - "rcode": 0, + "rcode": GETDNS_RCODE_NOERROR, "rd": 1, "tc": 0, "z": 0 }, "question": { - "qclass": 1, + "qclass": GETDNS_RRCLASS_IN, "qname": , - "qtype": 1 + "qtype": GETDNS_RRTYPE_A } }, { @@ -143,18 +128,18 @@ The packet { "answer": [ { - "class": 1, + "class": GETDNS_RRCLASS_IN, "name": , "rdata": { - "ipv6_address": , - "rdata_raw": + "ipv6_address": , + "rdata_raw": }, "ttl": 300, "type": GETDNS_RRTYPE_AAAA } ], - "answer_type": 800, + "answer_type": GETDNS_NAMETYPE_DNS, "authority": [], "canonical_name": , "header": @@ -164,86 +149,244 @@ The packet { "ancount": 1, "arcount": 0, "cd": 0, - "id": 0, + "id": 60320, "nscount": 0, - "opcode": 0, + "opcode": GETDNS_OPCODE_QUERY, "qdcount": 1, "qr": 1, "ra": 1, - "rcode": 0, + "rcode": GETDNS_RCODE_NOERROR, "rd": 1, "tc": 0, "z": 0 }, "question": { - "qclass": 1, + "qclass": GETDNS_RRCLASS_IN, "qname": , - "qtype": 28 + "qtype": GETDNS_RRTYPE_AAAA } } ], - "status": 900 + "status": GETDNS_RESPSTATUS_GOOD } The packet { - "answer_type": 800, - "canonical_name": , + "answer_type": GETDNS_NAMETYPE_DNS, + "canonical_name": , "just_address_answers": [], "replies_full": [ - + + ], + "replies_tree": + [ + { + "additional": + [ + { + "class": GETDNS_RRCLASS_IN, + "name": , + "rdata": + { + "ipv4_address": , + "rdata_raw": + }, + "ttl": 85567, + "type": GETDNS_RRTYPE_A + } + ], + "answer": + [ + { + "class": GETDNS_RRCLASS_IN, + "name": , + "rdata": + { + "port": 5222, + "priority": 10, + "rdata_raw": , + "target": , + "weight": 0 + }, + "ttl": 6367, + "type": GETDNS_RRTYPE_SRV + } + ], + "answer_type": GETDNS_NAMETYPE_DNS, + "authority": + [ + { + "class": GETDNS_RRCLASS_IN, + "name": , + "rdata": + { + "nsdname": , + "rdata_raw": + }, + "ttl": 85567, + "type": GETDNS_RRTYPE_NS + }, + { + "class": GETDNS_RRCLASS_IN, + "name": , + "rdata": + { + "nsdname": , + "rdata_raw": + }, + "ttl": 85567, + "type": GETDNS_RRTYPE_NS + } + ], + "canonical_name": , + "header": + { + "aa": 0, + "ad": 0, + "ancount": 1, + "arcount": 1, + "cd": 0, + "id": 44399, + "nscount": 2, + "opcode": GETDNS_OPCODE_QUERY, + "qdcount": 1, + "qr": 1, + "ra": 1, + "rcode": GETDNS_RCODE_NOERROR, + "rd": 1, + "tc": 0, + "z": 0 + }, + "question": + { + "qclass": GETDNS_RRCLASS_IN, + "qname": , + "qtype": GETDNS_RRTYPE_SRV + } + } + ], + "status": GETDNS_RESPSTATUS_GOOD +} +The packet { + "answer_type": GETDNS_NAMETYPE_DNS, + "canonical_name": , + "just_address_answers": + [ + { + "address_data": , + "address_type": + }, + { + "address_data": , + "address_type": + }, + { + "address_data": , + "address_type": + }, + { + "address_data": , + "address_type": + }, + { + "address_data": , + "address_type": + } + ], + "replies_full": + [ + ], "replies_tree": [ { "additional": [], - "answer": [], - "answer_type": 800, - "authority": + "answer": [ { - "class": 1, - "name": , + "class": GETDNS_RRCLASS_IN, + "name": , "rdata": { - "expire": 300, - "mname": , - "rdata_raw": , - "refresh": 1800, - "retry": 1209600, - "rname": , - "serial": 1546121 + "ipv4_address": , + "rdata_raw": }, - "ttl": 60, - "type": GETDNS_RRTYPE_SOA + "ttl": 300, + "type": GETDNS_RRTYPE_A + }, + { + "class": GETDNS_RRCLASS_IN, + "name": , + "rdata": + { + "ipv4_address": , + "rdata_raw": + }, + "ttl": 300, + "type": GETDNS_RRTYPE_A + }, + { + "class": GETDNS_RRCLASS_IN, + "name": , + "rdata": + { + "ipv4_address": , + "rdata_raw": + }, + "ttl": 300, + "type": GETDNS_RRTYPE_A + }, + { + "class": GETDNS_RRCLASS_IN, + "name": , + "rdata": + { + "ipv4_address": , + "rdata_raw": + }, + "ttl": 300, + "type": GETDNS_RRTYPE_A + }, + { + "class": GETDNS_RRCLASS_IN, + "name": , + "rdata": + { + "ipv4_address": , + "rdata_raw": + }, + "ttl": 300, + "type": GETDNS_RRTYPE_A } ], + "answer_type": GETDNS_NAMETYPE_DNS, + "authority": [], "canonical_name": , "header": { "aa": 0, "ad": 0, - "ancount": 0, + "ancount": 5, "arcount": 0, "cd": 0, - "id": 0, - "nscount": 1, - "opcode": 0, + "id": 28460, + "nscount": 0, + "opcode": GETDNS_OPCODE_QUERY, "qdcount": 1, "qr": 1, "ra": 1, - "rcode": 0, + "rcode": GETDNS_RCODE_NOERROR, "rd": 1, "tc": 0, "z": 0 }, "question": { - "qclass": 1, + "qclass": GETDNS_RRCLASS_IN, "qname": , - "qtype": 33 + "qtype": GETDNS_RRTYPE_A } } ], - "status": 900 + "status": GETDNS_RESPSTATUS_GOOD }