mirror of
https://github.com/libevent/libevent.git
synced 2025-01-31 09:12:55 +08:00
Tests for 94fba5b and f72e8f6
This commit is contained in:
parent
8589f6c45b
commit
d58c15ee84
@ -495,6 +495,8 @@ static struct regress_dns_server_table search_table[] = {
|
||||
{ "host2.a.example.com", "err", "3", 0 },
|
||||
{ "host2.b.example.com", "A", "200.100.0.100", 0 },
|
||||
{ "host2.c.example.com", "err", "3", 0 },
|
||||
{ "hostn.a.example.com", "errsoa", "0", 0 },
|
||||
{ "hostn.b.example.com", "errsoa", "3", 0 },
|
||||
|
||||
{ "host", "err", "3", 0 },
|
||||
{ "host2", "err", "3", 0 },
|
||||
@ -511,7 +513,7 @@ dns_search_test(void *arg)
|
||||
ev_uint16_t portnum = 0;
|
||||
char buf[64];
|
||||
|
||||
struct generic_dns_callback_result r1, r2, r3, r4, r5;
|
||||
struct generic_dns_callback_result r[7];
|
||||
|
||||
tt_assert(regress_dnsserver(base, &portnum, search_table));
|
||||
evutil_snprintf(buf, sizeof(buf), "127.0.0.1:%d", (int)portnum);
|
||||
@ -523,26 +525,32 @@ dns_search_test(void *arg)
|
||||
evdns_base_search_add(dns, "b.example.com");
|
||||
evdns_base_search_add(dns, "c.example.com");
|
||||
|
||||
n_replies_left = 5;
|
||||
n_replies_left = sizeof(r)/sizeof(r[0]);
|
||||
exit_base = base;
|
||||
|
||||
evdns_base_resolve_ipv4(dns, "host", 0, generic_dns_callback, &r1);
|
||||
evdns_base_resolve_ipv4(dns, "host2", 0, generic_dns_callback, &r2);
|
||||
evdns_base_resolve_ipv4(dns, "host", DNS_NO_SEARCH, generic_dns_callback, &r3);
|
||||
evdns_base_resolve_ipv4(dns, "host2", DNS_NO_SEARCH, generic_dns_callback, &r4);
|
||||
evdns_base_resolve_ipv4(dns, "host3", 0, generic_dns_callback, &r5);
|
||||
evdns_base_resolve_ipv4(dns, "host", 0, generic_dns_callback, &r[0]);
|
||||
evdns_base_resolve_ipv4(dns, "host2", 0, generic_dns_callback, &r[1]);
|
||||
evdns_base_resolve_ipv4(dns, "host", DNS_NO_SEARCH, generic_dns_callback, &r[2]);
|
||||
evdns_base_resolve_ipv4(dns, "host2", DNS_NO_SEARCH, generic_dns_callback, &r[3]);
|
||||
evdns_base_resolve_ipv4(dns, "host3", 0, generic_dns_callback, &r[4]);
|
||||
evdns_base_resolve_ipv4(dns, "hostn.a.example.com", DNS_NO_SEARCH, generic_dns_callback, &r[5]);
|
||||
evdns_base_resolve_ipv4(dns, "hostn.b.example.com", DNS_NO_SEARCH, generic_dns_callback, &r[6]);
|
||||
|
||||
event_base_dispatch(base);
|
||||
|
||||
tt_int_op(r1.type, ==, DNS_IPv4_A);
|
||||
tt_int_op(r1.count, ==, 1);
|
||||
tt_int_op(((ev_uint32_t*)r1.addrs)[0], ==, htonl(0x0b16212c));
|
||||
tt_int_op(r2.type, ==, DNS_IPv4_A);
|
||||
tt_int_op(r2.count, ==, 1);
|
||||
tt_int_op(((ev_uint32_t*)r2.addrs)[0], ==, htonl(0xc8640064));
|
||||
tt_int_op(r3.result, ==, DNS_ERR_NOTEXIST);
|
||||
tt_int_op(r4.result, ==, DNS_ERR_NOTEXIST);
|
||||
tt_int_op(r5.result, ==, DNS_ERR_NOTEXIST);
|
||||
tt_int_op(r[0].type, ==, DNS_IPv4_A);
|
||||
tt_int_op(r[0].count, ==, 1);
|
||||
tt_int_op(((ev_uint32_t*)r[0].addrs)[0], ==, htonl(0x0b16212c));
|
||||
tt_int_op(r[1].type, ==, DNS_IPv4_A);
|
||||
tt_int_op(r[1].count, ==, 1);
|
||||
tt_int_op(((ev_uint32_t*)r[1].addrs)[0], ==, htonl(0xc8640064));
|
||||
tt_int_op(r[2].result, ==, DNS_ERR_NOTEXIST);
|
||||
tt_int_op(r[3].result, ==, DNS_ERR_NOTEXIST);
|
||||
tt_int_op(r[4].result, ==, DNS_ERR_NOTEXIST);
|
||||
tt_int_op(r[5].result, ==, DNS_ERR_NODATA);
|
||||
tt_int_op(r[5].ttl, ==, 42);
|
||||
tt_int_op(r[6].result, ==, DNS_ERR_NOTEXIST);
|
||||
tt_int_op(r[6].ttl, ==, 42);
|
||||
|
||||
end:
|
||||
if (dns)
|
||||
|
@ -159,6 +159,23 @@ regress_dns_server_cb(struct evdns_server_request *req, void *data)
|
||||
int err = atoi(tab->ans);
|
||||
tt_assert(! evdns_server_request_respond(req, err));
|
||||
return;
|
||||
} else if (!strcmp(tab->anstype, "errsoa")) {
|
||||
int err = atoi(tab->ans);
|
||||
char soa_record[] =
|
||||
"\x04" "dns1" "\x05" "icann" "\x03" "org" "\0"
|
||||
"\x0a" "hostmaster" "\x05" "icann" "\x03" "org" "\0"
|
||||
"\x77\xde\x5e\xba" /* serial */
|
||||
"\x00\x00\x1c\x20" /* refreshtime = 2h */
|
||||
"\x00\x00\x0e\x10" /* retry = 1h */
|
||||
"\x00\x12\x75\x00" /* expiration = 14d */
|
||||
"\x00\x00\x0e\x10" /* min.ttl = 1h */
|
||||
;
|
||||
evdns_server_request_add_reply(
|
||||
req, EVDNS_AUTHORITY_SECTION,
|
||||
"example.com", EVDNS_TYPE_SOA, EVDNS_CLASS_INET,
|
||||
42, sizeof(soa_record) - 1, 0, soa_record);
|
||||
tt_assert(! evdns_server_request_respond(req, err));
|
||||
return;
|
||||
} else if (!strcmp(tab->anstype, "A")) {
|
||||
struct in_addr in;
|
||||
evutil_inet_pton(AF_INET, tab->ans, &in);
|
||||
|
Loading…
x
Reference in New Issue
Block a user