add get functions to check the values

This commit is contained in:
Hoda Rohani 2017-05-08 12:49:59 +02:00
parent 2ac13e0807
commit 6ec0f2e021
9 changed files with 1692 additions and 19 deletions

View File

@ -301,6 +301,8 @@
* expect: GETDNS_CONTEXT_CODE_EDNS_EXTENDED_RCODE
*/
struct getdns_context *context = NULL;
uint8_t extended_rcode;
CONTEXT_CREATE(TRUE);
ASSERT_RC(getdns_context_set_context_update_callback(context, update_callbackfn),
@ -310,6 +312,9 @@
ASSERT_RC(getdns_context_set_edns_extended_rcode(context, 1),
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_edns_extended_rcode()");
ASSERT_RC(getdns_context_get_edns_extended_rcode(context, &extended_rcode),
GETDNS_RETURN_GOOD, "Return code from getdns_context_get_edns_extended_rcode()");
ck_assert_msg(extended_rcode == 1, "extended_rcode should be 1, got %d", (int)extended_rcode);
CONTEXT_DESTROY;
@ -325,6 +330,8 @@
* expect: GETDNS_CONTEXT_CODE_EDNS_VERSION
*/
struct getdns_context *context = NULL;
uint8_t version;
CONTEXT_CREATE(TRUE);
ASSERT_RC(getdns_context_set_context_update_callback(context, update_callbackfn),
@ -334,6 +341,9 @@
ASSERT_RC(getdns_context_set_edns_version(context, 1),
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_edns_version()");
ASSERT_RC(getdns_context_get_edns_version(context, &version),
GETDNS_RETURN_GOOD, "Return code from getdns_context_get_edns_version()");
ck_assert_msg(version == 1, "version should be 1, got %d", (int)version);
CONTEXT_DESTROY;
@ -373,6 +383,8 @@
* expect: GETDNS_CONTEXT_CODE_EDNS_CLIENT_SUBNET_PRIVATE
*/
struct getdns_context *context = NULL;
uint8_t client_subnet_private;
CONTEXT_CREATE(TRUE);
ASSERT_RC(getdns_context_set_context_update_callback(context, update_callbackfn),
@ -382,6 +394,9 @@
ASSERT_RC(getdns_context_set_edns_client_subnet_private(context, 1),
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_edns_client_subnet_private()");
ASSERT_RC(getdns_context_get_edns_client_subnet_private(context, &client_subnet_private),
GETDNS_RETURN_GOOD, "Return code from getdns_context_get_edns_client_subnet_private()");
ck_assert_msg(client_subnet_private == 1, "client_subnet_private should be 1, got %d", (int)client_subnet_private);
CONTEXT_DESTROY;
@ -397,6 +412,8 @@
* expect: GETDNS_CONTEXT_CODE_TLS_QUERY_PADDING_BLOCKSIZE
*/
struct getdns_context *context = NULL;
uint16_t pad;
CONTEXT_CREATE(TRUE);
ASSERT_RC(getdns_context_set_context_update_callback(context, update_callbackfn),
@ -406,6 +423,9 @@
ASSERT_RC(getdns_context_set_tls_query_padding_blocksize(context, 1400),
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_tls_query_padding_blocksize()");
ASSERT_RC(getdns_context_get_tls_query_padding_blocksize(context, &pad),
GETDNS_RETURN_GOOD, "Return code from getdns_context_get_tls_query_padding_blocksize()");
ck_assert_msg(pad == 1400, "padding_blocksize should be 1400 but got %d", (int) pad);
CONTEXT_DESTROY;
@ -438,11 +458,12 @@
START_TEST (getdns_context_set_context_update_callback_23)
{
/*
* value is NULL
* expect: GETDNS_RETURN_INVALID_PARAMETER
* expect: GETDNS_RETURN_GOOD
*/
struct getdns_context *context = NULL;
uint8_t round_robin;
CONTEXT_CREATE(TRUE);
ASSERT_RC(getdns_context_set_context_update_callback(context, update_callbackfn),
@ -451,7 +472,10 @@
expected_changed_item = GETDNS_CONTEXT_CODE_ROUND_ROBIN_UPSTREAMS;
ASSERT_RC(getdns_context_set_round_robin_upstreams(context, 1),
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_timeout()");
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_round_robin_upstream()");
ASSERT_RC(getdns_context_get_round_robin_upstreams(context, &round_robin),
GETDNS_RETURN_GOOD, "Return code from getdns_context_get_round_robin_upstream()");
ck_assert_msg( round_robin == 1, "round_robin should be 1, got %d", (int)round_robin);
CONTEXT_DESTROY;

View File

@ -39,7 +39,7 @@
{
/*
* context is NULL
* expect: GETDNS_RETURN_BAD_CONTEXT
* expect: GETDNS_RETURN_INVALID_PARAMETER
*/
struct getdns_context *context = NULL;
@ -47,7 +47,12 @@
ASSERT_RC(getdns_context_set_dns_transport(context, value),
GETDNS_RETURN_INVALID_PARAMETER, "Return code from getdns_context_set_dns_transport()");
ASSERT_RC(getdns_context_set_edns_maximum_udp_payload_size(context, 512),
GETDNS_RETURN_INVALID_PARAMETER, "Return code from getdns_context_set_edns_maximum_udp_payload_size()");
ASSERT_RC(getdns_context_unset_edns_maximum_udp_payload_size(context),
GETDNS_RETURN_INVALID_PARAMETER, "Return code from getdns_context_unset_edns_maximum_udp_payload_size()");
}
END_TEST
@ -55,6 +60,7 @@
{
/*
* value is an undefined transport value
* do_bit is not correct
* expect: GETDNS_RETURN_CONTEXT_UPDATE_FAIL
*/
@ -66,6 +72,9 @@
ASSERT_RC(getdns_context_set_dns_transport(context, 233),
GETDNS_RETURN_CONTEXT_UPDATE_FAIL, "Return code from getdns_context_set_dns_transport()");
ASSERT_RC(getdns_context_set_edns_do_bit(context, 5),
GETDNS_RETURN_CONTEXT_UPDATE_FAIL, "Return code from getdns_context_set_edns_do_bit()");
CONTEXT_DESTROY;
}
@ -132,6 +141,9 @@
uint32_t tc;
uint32_t transport;
uint32_t type;
uint16_t payload_size;
uint8_t do_bit;
getdns_transport_t trans;
/* Note that stricly this test just establishes that the requested transport
and the reported transport are consistent, it does not guarentee which
@ -147,10 +159,22 @@
/* Request a response that should be truncated over UDP */
ASSERT_RC(getdns_context_set_dns_transport(context, GETDNS_TRANSPORT_UDP_ONLY),
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_dns_transport()");
ASSERT_RC(getdns_context_get_dns_transport(context, &trans),
GETDNS_RETURN_GOOD, "Return code from getdns_context_get_dns_transport()");
ck_assert_msg(trans == 541, "dns_transport should be 541(GETDNS_TRANSPORT_UDP_ONLY) but got %d", (int)trans);
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_get_edns_maximum_udp_payload_size(context, &payload_size),
GETDNS_RETURN_GOOD, "Return code from getdns_context_get_edns_maximum_udp_payload_size()");
ck_assert_msg(payload_size == 512, "payload_size should be 512, got %d", (int)payload_size);
ASSERT_RC(getdns_context_set_edns_do_bit(context, 1),
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_edns_do_bit()");
ASSERT_RC(getdns_context_get_edns_do_bit(context, &do_bit),
GETDNS_RETURN_GOOD, "Return code from getdns_context_get_edns_do_bit()");
ck_assert_msg(do_bit == 1, "do_bit should be 1, got %d", (int)do_bit);
ASSERT_RC(getdns_general_sync(context, "large.getdnsapi.net", GETDNS_RRTYPE_TXT, extensions, &response),
GETDNS_RETURN_GOOD, "Return code from getdns_general_sync()");
@ -192,6 +216,9 @@
GETDNS_RETURN_GOOD, "Failed to extract \"tc\"");
ASSERT_RC(tc, 0, "Packet trucated - not as expected");
ASSERT_RC(getdns_context_unset_edns_maximum_udp_payload_size(context),
GETDNS_RETURN_GOOD, "Return code from getdns_context_unset_edns_maximum_udp_payload_size()");
CONTEXT_DESTROY;
}

View File

@ -282,6 +282,7 @@ START_TEST (getdns_context_set_timeout_3)
t_data.num_callbacks = 0;
t_data.num_timeouts = 0;
t_data.port = 43210;
uint64_t timeout;
pthread_create(&thread, NULL, run_server, (void *)&t_data);
@ -324,6 +325,10 @@ START_TEST (getdns_context_set_timeout_3)
RUN_EVENT_LOOP;
ASSERT_RC(getdns_context_get_timeout(context, &timeout),
GETDNS_RETURN_GOOD, "Return code from getdns_context_get_timeout()");
ck_assert_msg(timeout == 500, "timeout should be 500, got %d", (int)timeout);
CONTEXT_DESTROY;
t_data.running = 0;

View File

@ -88,6 +88,68 @@ static const char pretty_expected[] = "{\n"
" ]\n"
"}";
static const char pretty_expected2[] = "{\n"
" \"bindata\":\"bindata\",\n"
" \"dict\":\n"
" {\n"
" \"bindata\":\"bindata\",\n"
" \"dict\":\n"
" {\n"
" \"bindata\":\"bindata\",\n"
" \"dict\":\n"
" {\n"
" \"int\": 4\n"
" },\n"
" \"int\": 3,\n"
" \"list\":\n"
" [\n"
" 5\n"
" ]\n"
" },\n"
" \"int\": 2,\n"
" \"list\":\n"
" [\n"
" 6,\n"
" \"bindata\",\n"
" {\n"
" \"bindata\":\"bindata\"\n"
" },\n"
" [\n"
" \"bindata\"\n"
" ]\n"
" ]\n"
" },\n"
" \"int\": 1,\n"
" \"list\":\n"
" [\n"
" 7,\n"
" \"bindata\",\n"
" {\n"
" \"bindata\":\"bindata\",\n"
" \"dict\":\n"
" {\n"
" \"int\": 9\n"
" },\n"
" \"int\": 8,\n"
" \"list\":\n"
" [\n"
" 10\n"
" ]\n"
" },\n"
" [\n"
" 11,\n"
" \"bindata\",\n"
" {\n"
" \"bindata\":\"bindata\"\n"
" },\n"
" [\n"
" \"bindata\"\n"
" ]\n"
" ]\n"
" ]\n"
"}";
/*
**************************************************************************
* *
@ -267,6 +329,11 @@ static const char pretty_expected[] = "{\n"
ck_assert_msg(strcmp(pretty_expected, pretty) == 0,
"Expected:\n%s\ngot:\n%s\n", pretty_expected, pretty);
pretty = getdns_print_json_dict(dict1, 1);
ck_assert_msg(pretty != NULL, "NULL returned by getdns_print_json_dict()");
ck_assert_msg(strcmp(pretty_expected2, pretty) == 0,
"Expected:\n%s\ngot:\n%s\n", pretty_expected2, pretty);
/*
* Destroy all of the sub-dicts and sub-lists
*/

View File

@ -27,6 +27,14 @@ void print_list(getdns_list *rr_list)
free(str);
}
void print_json_list(getdns_list *rr_list, int pretty)
{
char *str = getdns_print_json_list(rr_list, pretty);
printf("%s\n", str);
free(str);
}
void print_wire(uint8_t *wire, size_t wire_len)
{
size_t pos, i;
@ -254,6 +262,7 @@ int main(int argc, char const * const argv[])
fclose(in);
print_list(rr_list);
print_json_list(rr_list, 1);
/* Fill the wire_buf with wireformat RR's in rr_list

View File

@ -918,9 +918,23 @@
"rdata":
{
"certificate_association_data": <bindata of 0x274c6f96c9885c8050e8a05ad1c3162c...>,
"certificate_usage": 3,
"certificate_usage": 0,
"matching_type": 1,
"rdata_raw": <bindata of 0x030101274c6f96c9885c8050e8a05ad1...>,
"rdata_raw": <bindata of 0x000001274c6f96c9885c8050e8a05ad1...>,
"selector": 0
},
"ttl": 30,
"type": GETDNS_RRTYPE_TLSA
},
{
"class": GETDNS_RRCLASS_IN,
"name": <bindata for _443._tcp.ww.net-dns.org.>,
"rdata":
{
"certificate_association_data": <bindata of 0x92003ba34942dc74152e2f2c408d29ec...>,
"certificate_usage": 1,
"matching_type": 2,
"rdata_raw": <bindata of 0x01010292003ba34942dc74152e2f2c40...>,
"selector": 1
},
"ttl": 30,
@ -1008,7 +1022,7 @@
}
]
;; ->>HEADER<<- opcode: QUERY, rcode: NOERROR, id: 0
;; flags: ; QUERY: 0, ANSWER: 77, AUTHORITY: 0, ADDITIONAL: 0
;; flags: ; QUERY: 0, ANSWER: 78, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;; ANSWER SECTION:
@ -1082,7 +1096,8 @@ spf.net-dns.org. 30 IN SPF "v=spf1 +mx a:colo.nlnetlabs.nl/28 -all"
srv.net-dns.org. 30 IN SRV 0 5 80 www.net-dns.org.
sshfp.net-dns.org. 30 IN SSHFP 1 1 450C7D19D5DA9A3A5B7C19992D1FBDE15D8DAD44
talink.net-dns.org. 30 IN TALINK h0.net-dns.org. h2.net-dns.org.
_443._tcp.net-dns.org. 30 IN TLSA 3 1 1 274C6F96C9885C8050E8A05AD1C3162C1D51752C35B6196474E3F05AD31CD923
_443._tcp.net-dns.org. 30 IN TLSA 0 0 1 274C6F96C9885C8050E8A05AD1C3162C1D51752C35B6196474E3F05AD31CD923
_443._tcp.ww.net-dns.org. 30 IN TLSA 1 1 2 92003BA34942DC74152E2F2C408D29ECA5A520E7F2E06BB944F4DCA346BAF63C1B177615D466F6C4B71C216A50292BD58C9EBDD2F74E38FE51FFD48C43326CBC
_443._tcp.www.net-dns.org. 30 IN TLSA 3 1 1 274C6F96C9885C8050E8A05AD1C3162C1D51752C35B6196474E3F05AD31CD923
dynup.net-dns.org. 30 IN TXT "fooFoo2" "Bla ; Foo"
default._domainkey.net-dns.org. 30 IN TXT "v=DKIM1; r=postmaster; g=*; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDVG/lfF5GtPlMOcSGnfbp5u+EWM+OOg/f6QmbDXOW/zKQkRIRIZ+BtfSYchP8MeFPfMvUZtdRPzCWg1G7OdD7qaTUqc6kV84on6/8kPVMgdDLyLl2DeU/Lts9hfVHVDSpWuChwDAFXnbnW8jpp54zuof9OIbWSWIxZqLL8flgOsQIDAQAB"
@ -1093,5 +1108,5 @@ x25.net-dns.org. 30 IN X25 "1234567"
;; AUTHORITY SECTION:
;; ADDITIONAL SECTION:
;; MSG SIZE rcvd: 6561
;; MSG SIZE rcvd: 6664

View File

@ -94,7 +94,8 @@ sshfp SSHFP 1 1 450c7d19d5da9a3a5b7c19992d1fbde15d8dad44
;ta TA
talink TALINK h0 h2
;tkey TKEY
_443._tcp TLSA 3 1 1 274c6f96c9885c8050e8a05ad1c3162c1d51752c35b6196474e3f05ad31cd923
_443._tcp TLSA 0 0 1 274c6f96c9885c8050e8a05ad1c3162c1d51752c35b6196474e3f05ad31cd923
_443._tcp.ww TLSA 1 1 2 92003ba34942dc74152e2f2c408d29eca5a520e7f2e06bb944f4dca346baf63c1b177615d466f6c4b71c216a50292bd58c9ebdd2f74e38fe51ffd48c43326cbc
_443._tcp.www TLSA 3 1 1 274c6f96c9885c8050e8a05ad1c3162c1d51752c35b6196474e3f05ad31cd923
;tsig TSIG
dynup TXT "fooFoo2" "Bla \; Foo"

View File

@ -5,10 +5,4 @@
[ -f .tpkg.var.test ] && source .tpkg.var.test
cd "${BUILDDIR}/build-event-loops"
if make test
then
if grep ERROR "${BUILDDIR}/build-event-loops/src/test/*.log"
then
exit 1
fi
fi
make test