"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "test/ares-test-mock-ai.cc" between
c-ares-1.17.1.tar.gz and c-ares-1.17.2.tar.gz

About: c-ares is a C library for asynchronous DNS requests (including name resolves).

ares-test-mock-ai.cc  (c-ares-1.17.1):ares-test-mock-ai.cc  (c-ares-1.17.2)
skipping to change at line 64 skipping to change at line 64
addressnum.s6_addr, sizeof(addressnum.s6_addr))) addressnum.s6_addr, sizeof(addressnum.s6_addr)))
return true; // found return true; // found
} }
return false; return false;
} }
// UDP only so mock server doesn't get confused by concatenated requests // UDP only so mock server doesn't get confused by concatenated requests
TEST_P(MockUDPChannelTestAI, GetAddrInfoParallelLookups) { TEST_P(MockUDPChannelTestAI, GetAddrInfoParallelLookups) {
DNSPacket rsp1; DNSPacket rsp1;
rsp1.set_response().set_aa() rsp1.set_response().set_aa()
.add_question(new DNSQuestion("www.google.com", ns_t_a)) .add_question(new DNSQuestion("www.google.com", T_A))
.add_answer(new DNSARR("www.google.com", 100, {2, 3, 4, 5})); .add_answer(new DNSARR("www.google.com", 100, {2, 3, 4, 5}));
ON_CALL(server_, OnRequest("www.google.com", ns_t_a)) ON_CALL(server_, OnRequest("www.google.com", T_A))
.WillByDefault(SetReply(&server_, &rsp1)); .WillByDefault(SetReply(&server_, &rsp1));
DNSPacket rsp2; DNSPacket rsp2;
rsp2.set_response().set_aa() rsp2.set_response().set_aa()
.add_question(new DNSQuestion("www.example.com", ns_t_a)) .add_question(new DNSQuestion("www.example.com", T_A))
.add_answer(new DNSARR("www.example.com", 100, {1, 2, 3, 4})); .add_answer(new DNSARR("www.example.com", 100, {1, 2, 3, 4}));
ON_CALL(server_, OnRequest("www.example.com", ns_t_a)) ON_CALL(server_, OnRequest("www.example.com", T_A))
.WillByDefault(SetReply(&server_, &rsp2)); .WillByDefault(SetReply(&server_, &rsp2));
struct ares_addrinfo_hints hints = {}; struct ares_addrinfo_hints hints = {};
hints.ai_family = AF_INET; hints.ai_family = AF_INET;
hints.ai_flags = ARES_AI_NOSORT; hints.ai_flags = ARES_AI_NOSORT;
AddrInfoResult result1; AddrInfoResult result1;
ares_getaddrinfo(channel_, "www.google.com.", NULL, &hints, AddrInfoCallback, &result1); ares_getaddrinfo(channel_, "www.google.com.", NULL, &hints, AddrInfoCallback, &result1);
AddrInfoResult result2; AddrInfoResult result2;
ares_getaddrinfo(channel_, "www.example.com.", NULL, &hints, AddrInfoCallback, &result2); ares_getaddrinfo(channel_, "www.example.com.", NULL, &hints, AddrInfoCallback, &result2);
AddrInfoResult result3; AddrInfoResult result3;
skipping to change at line 106 skipping to change at line 106
EXPECT_TRUE(result3.done_); EXPECT_TRUE(result3.done_);
EXPECT_EQ(result3.status_, ARES_SUCCESS); EXPECT_EQ(result3.status_, ARES_SUCCESS);
EXPECT_THAT(result3.ai_, IncludesNumAddresses(1)); EXPECT_THAT(result3.ai_, IncludesNumAddresses(1));
EXPECT_THAT(result3.ai_, IncludesV4Address("2.3.4.5")); EXPECT_THAT(result3.ai_, IncludesV4Address("2.3.4.5"));
} }
// UDP to TCP specific test // UDP to TCP specific test
TEST_P(MockUDPChannelTestAI, TruncationRetry) { TEST_P(MockUDPChannelTestAI, TruncationRetry) {
DNSPacket rsptruncated; DNSPacket rsptruncated;
rsptruncated.set_response().set_aa().set_tc() rsptruncated.set_response().set_aa().set_tc()
.add_question(new DNSQuestion("www.google.com", ns_t_a)); .add_question(new DNSQuestion("www.google.com", T_A));
DNSPacket rspok; DNSPacket rspok;
rspok.set_response() rspok.set_response()
.add_question(new DNSQuestion("www.google.com", ns_t_a)) .add_question(new DNSQuestion("www.google.com", T_A))
.add_answer(new DNSARR("www.google.com", 100, {1, 2, 3, 4})); .add_answer(new DNSARR("www.google.com", 100, {1, 2, 3, 4}));
EXPECT_CALL(server_, OnRequest("www.google.com", ns_t_a)) EXPECT_CALL(server_, OnRequest("www.google.com", T_A))
.WillOnce(SetReply(&server_, &rsptruncated)) .WillOnce(SetReply(&server_, &rsptruncated))
.WillOnce(SetReply(&server_, &rspok)); .WillOnce(SetReply(&server_, &rspok));
AddrInfoResult result; AddrInfoResult result;
struct ares_addrinfo_hints hints = {}; struct ares_addrinfo_hints hints = {};
hints.ai_family = AF_INET; hints.ai_family = AF_INET;
hints.ai_flags = ARES_AI_NOSORT; hints.ai_flags = ARES_AI_NOSORT;
ares_getaddrinfo(channel_, "www.google.com.", NULL, &hints, AddrInfoCallback, &result); ares_getaddrinfo(channel_, "www.google.com.", NULL, &hints, AddrInfoCallback, &result);
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
EXPECT_EQ(result.status_, ARES_SUCCESS); EXPECT_EQ(result.status_, ARES_SUCCESS);
EXPECT_THAT(result.ai_, IncludesNumAddresses(1)); EXPECT_THAT(result.ai_, IncludesNumAddresses(1));
EXPECT_THAT(result.ai_, IncludesV4Address("1.2.3.4")); EXPECT_THAT(result.ai_, IncludesV4Address("1.2.3.4"));
} }
// TCP only to prevent retries // TCP only to prevent retries
TEST_P(MockTCPChannelTestAI, MalformedResponse) { TEST_P(MockTCPChannelTestAI, MalformedResponse) {
std::vector<byte> one = {0x01}; std::vector<byte> one = {0x01};
EXPECT_CALL(server_, OnRequest("www.google.com", ns_t_a)) EXPECT_CALL(server_, OnRequest("www.google.com", T_A))
.WillOnce(SetReplyData(&server_, one)); .WillOnce(SetReplyData(&server_, one));
AddrInfoResult result; AddrInfoResult result;
struct ares_addrinfo_hints hints = {}; struct ares_addrinfo_hints hints = {};
hints.ai_family = AF_INET; hints.ai_family = AF_INET;
hints.ai_flags = ARES_AI_NOSORT; hints.ai_flags = ARES_AI_NOSORT;
ares_getaddrinfo(channel_, "www.google.com.", NULL, &hints, AddrInfoCallback, &result); ares_getaddrinfo(channel_, "www.google.com.", NULL, &hints, AddrInfoCallback, &result);
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
EXPECT_EQ(ARES_ETIMEOUT, result.status_); EXPECT_EQ(ARES_ETIMEOUT, result.status_);
} }
TEST_P(MockTCPChannelTestAI, FormErrResponse) { TEST_P(MockTCPChannelTestAI, FormErrResponse) {
DNSPacket rsp; DNSPacket rsp;
rsp.set_response().set_aa() rsp.set_response().set_aa()
.add_question(new DNSQuestion("www.google.com", ns_t_a)); .add_question(new DNSQuestion("www.google.com", T_A));
rsp.set_rcode(ns_r_formerr); rsp.set_rcode(FORMERR);
EXPECT_CALL(server_, OnRequest("www.google.com", ns_t_a)) EXPECT_CALL(server_, OnRequest("www.google.com", T_A))
.WillOnce(SetReply(&server_, &rsp)); .WillOnce(SetReply(&server_, &rsp));
AddrInfoResult result; AddrInfoResult result;
struct ares_addrinfo_hints hints = {}; struct ares_addrinfo_hints hints = {};
hints.ai_family = AF_INET; hints.ai_family = AF_INET;
hints.ai_flags = ARES_AI_NOSORT; hints.ai_flags = ARES_AI_NOSORT;
ares_getaddrinfo(channel_, "www.google.com.", NULL, &hints, AddrInfoCallback, &result); ares_getaddrinfo(channel_, "www.google.com.", NULL, &hints, AddrInfoCallback, &result);
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
EXPECT_EQ(ARES_EFORMERR, result.status_); EXPECT_EQ(ARES_EFORMERR, result.status_);
} }
TEST_P(MockTCPChannelTestAI, ServFailResponse) { TEST_P(MockTCPChannelTestAI, ServFailResponse) {
DNSPacket rsp; DNSPacket rsp;
rsp.set_response().set_aa() rsp.set_response().set_aa()
.add_question(new DNSQuestion("www.google.com", ns_t_a)); .add_question(new DNSQuestion("www.google.com", T_A));
rsp.set_rcode(ns_r_servfail); rsp.set_rcode(SERVFAIL);
EXPECT_CALL(server_, OnRequest("www.google.com", ns_t_a)) EXPECT_CALL(server_, OnRequest("www.google.com", T_A))
.WillOnce(SetReply(&server_, &rsp)); .WillOnce(SetReply(&server_, &rsp));
AddrInfoResult result; AddrInfoResult result;
struct ares_addrinfo_hints hints = {}; struct ares_addrinfo_hints hints = {};
hints.ai_family = AF_INET; hints.ai_family = AF_INET;
hints.ai_flags = ARES_AI_NOSORT; hints.ai_flags = ARES_AI_NOSORT;
ares_getaddrinfo(channel_, "www.google.com.", NULL, &hints, AddrInfoCallback, &result); ares_getaddrinfo(channel_, "www.google.com.", NULL, &hints, AddrInfoCallback, &result);
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
// ARES_FLAG_NOCHECKRESP not set, so SERVFAIL consumed // ARES_FLAG_NOCHECKRESP not set, so SERVFAIL consumed
EXPECT_EQ(ARES_ECONNREFUSED, result.status_); EXPECT_EQ(ARES_ECONNREFUSED, result.status_);
} }
TEST_P(MockTCPChannelTestAI, NotImplResponse) { TEST_P(MockTCPChannelTestAI, NotImplResponse) {
DNSPacket rsp; DNSPacket rsp;
rsp.set_response().set_aa() rsp.set_response().set_aa()
.add_question(new DNSQuestion("www.google.com", ns_t_a)); .add_question(new DNSQuestion("www.google.com", T_A));
rsp.set_rcode(ns_r_notimpl); rsp.set_rcode(NOTIMP);
EXPECT_CALL(server_, OnRequest("www.google.com", ns_t_a)) EXPECT_CALL(server_, OnRequest("www.google.com", T_A))
.WillOnce(SetReply(&server_, &rsp)); .WillOnce(SetReply(&server_, &rsp));
AddrInfoResult result; AddrInfoResult result;
struct ares_addrinfo_hints hints = {}; struct ares_addrinfo_hints hints = {};
hints.ai_family = AF_INET; hints.ai_family = AF_INET;
hints.ai_flags = ARES_AI_NOSORT; hints.ai_flags = ARES_AI_NOSORT;
ares_getaddrinfo(channel_, "www.google.com.", NULL, &hints, AddrInfoCallback, &result); ares_getaddrinfo(channel_, "www.google.com.", NULL, &hints, AddrInfoCallback, &result);
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
// ARES_FLAG_NOCHECKRESP not set, so NOTIMPL consumed // ARES_FLAG_NOCHECKRESP not set, so NOTIMP consumed
EXPECT_EQ(ARES_ECONNREFUSED, result.status_); EXPECT_EQ(ARES_ECONNREFUSED, result.status_);
} }
TEST_P(MockTCPChannelTestAI, RefusedResponse) { TEST_P(MockTCPChannelTestAI, RefusedResponse) {
DNSPacket rsp; DNSPacket rsp;
rsp.set_response().set_aa() rsp.set_response().set_aa()
.add_question(new DNSQuestion("www.google.com", ns_t_a)); .add_question(new DNSQuestion("www.google.com", T_A));
rsp.set_rcode(ns_r_refused); rsp.set_rcode(REFUSED);
EXPECT_CALL(server_, OnRequest("www.google.com", ns_t_a)) EXPECT_CALL(server_, OnRequest("www.google.com", T_A))
.WillOnce(SetReply(&server_, &rsp)); .WillOnce(SetReply(&server_, &rsp));
AddrInfoResult result; AddrInfoResult result;
struct ares_addrinfo_hints hints = {}; struct ares_addrinfo_hints hints = {};
hints.ai_family = AF_INET; hints.ai_family = AF_INET;
hints.ai_flags = ARES_AI_NOSORT; hints.ai_flags = ARES_AI_NOSORT;
ares_getaddrinfo(channel_, "www.google.com.", NULL, &hints, AddrInfoCallback, &result); ares_getaddrinfo(channel_, "www.google.com.", NULL, &hints, AddrInfoCallback, &result);
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
// ARES_FLAG_NOCHECKRESP not set, so REFUSED consumed // ARES_FLAG_NOCHECKRESP not set, so REFUSED consumed
EXPECT_EQ(ARES_ECONNREFUSED, result.status_); EXPECT_EQ(ARES_ECONNREFUSED, result.status_);
} }
TEST_P(MockTCPChannelTestAI, YXDomainResponse) { TEST_P(MockTCPChannelTestAI, YXDomainResponse) {
DNSPacket rsp; DNSPacket rsp;
rsp.set_response().set_aa() rsp.set_response().set_aa()
.add_question(new DNSQuestion("www.google.com", ns_t_a)); .add_question(new DNSQuestion("www.google.com", T_A));
rsp.set_rcode(ns_r_yxdomain); rsp.set_rcode(YXDOMAIN);
EXPECT_CALL(server_, OnRequest("www.google.com", ns_t_a)) EXPECT_CALL(server_, OnRequest("www.google.com", T_A))
.WillOnce(SetReply(&server_, &rsp)); .WillOnce(SetReply(&server_, &rsp));
AddrInfoResult result; AddrInfoResult result;
struct ares_addrinfo_hints hints = {}; struct ares_addrinfo_hints hints = {};
hints.ai_family = AF_INET; hints.ai_family = AF_INET;
hints.ai_flags = ARES_AI_NOSORT; hints.ai_flags = ARES_AI_NOSORT;
ares_getaddrinfo(channel_, "www.google.com.", NULL, &hints, AddrInfoCallback, &result); ares_getaddrinfo(channel_, "www.google.com.", NULL, &hints, AddrInfoCallback, &result);
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
EXPECT_EQ(ARES_ENODATA, result.status_); EXPECT_EQ(ARES_ENODATA, result.status_);
skipping to change at line 264 skipping to change at line 264
TEST_P(MockExtraOptsTestAI, SimpleQuery) { TEST_P(MockExtraOptsTestAI, SimpleQuery) {
ares_set_local_ip4(channel_, 0x7F000001); ares_set_local_ip4(channel_, 0x7F000001);
byte addr6[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, byte addr6[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}; 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
ares_set_local_ip6(channel_, addr6); ares_set_local_ip6(channel_, addr6);
ares_set_local_dev(channel_, "dummy"); ares_set_local_dev(channel_, "dummy");
DNSPacket rsp; DNSPacket rsp;
rsp.set_response().set_aa() rsp.set_response().set_aa()
.add_question(new DNSQuestion("www.google.com", ns_t_a)) .add_question(new DNSQuestion("www.google.com", T_A))
.add_answer(new DNSARR("www.google.com", 100, {2, 3, 4, 5})); .add_answer(new DNSARR("www.google.com", 100, {2, 3, 4, 5}));
ON_CALL(server_, OnRequest("www.google.com", ns_t_a)) ON_CALL(server_, OnRequest("www.google.com", T_A))
.WillByDefault(SetReply(&server_, &rsp)); .WillByDefault(SetReply(&server_, &rsp));
AddrInfoResult result; AddrInfoResult result;
struct ares_addrinfo_hints hints = {}; struct ares_addrinfo_hints hints = {};
hints.ai_family = AF_INET; hints.ai_family = AF_INET;
hints.ai_flags = ARES_AI_NOSORT; hints.ai_flags = ARES_AI_NOSORT;
ares_getaddrinfo(channel_, "www.google.com.", NULL, &hints, AddrInfoCallback, &result); ares_getaddrinfo(channel_, "www.google.com.", NULL, &hints, AddrInfoCallback, &result);
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
EXPECT_EQ(ARES_SUCCESS, result.status_); EXPECT_EQ(ARES_SUCCESS, result.status_);
skipping to change at line 315 skipping to change at line 315
TEST_P(MockExtraOptsNDots5TestAI, SimpleQuery) { TEST_P(MockExtraOptsNDots5TestAI, SimpleQuery) {
ares_set_local_ip4(channel_, 0x7F000001); ares_set_local_ip4(channel_, 0x7F000001);
byte addr6[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, byte addr6[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}; 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
ares_set_local_ip6(channel_, addr6); ares_set_local_ip6(channel_, addr6);
ares_set_local_dev(channel_, "dummy"); ares_set_local_dev(channel_, "dummy");
DNSPacket rsp; DNSPacket rsp;
rsp.set_response().set_aa() rsp.set_response().set_aa()
.add_question(new DNSQuestion("dynamodb.us-east-1.amazonaws.com", ns_t_a)) .add_question(new DNSQuestion("dynamodb.us-east-1.amazonaws.com", T_A))
.add_answer(new DNSARR("dynamodb.us-east-1.amazonaws.com", 100, {123, 45, 67 , 8})); .add_answer(new DNSARR("dynamodb.us-east-1.amazonaws.com", 100, {123, 45, 67 , 8}));
ON_CALL(server_, OnRequest("dynamodb.us-east-1.amazonaws.com", ns_t_a)) ON_CALL(server_, OnRequest("dynamodb.us-east-1.amazonaws.com", T_A))
.WillByDefault(SetReply(&server_, &rsp)); .WillByDefault(SetReply(&server_, &rsp));
AddrInfoResult result; AddrInfoResult result;
struct ares_addrinfo_hints hints = {}; struct ares_addrinfo_hints hints = {};
hints.ai_family = AF_INET; hints.ai_family = AF_INET;
hints.ai_flags = ARES_AI_NOSORT; hints.ai_flags = ARES_AI_NOSORT;
ares_getaddrinfo(channel_, "dynamodb.us-east-1.amazonaws.com.", NULL, &hints, AddrInfoCallback, &result); ares_getaddrinfo(channel_, "dynamodb.us-east-1.amazonaws.com.", NULL, &hints, AddrInfoCallback, &result);
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
EXPECT_EQ(ARES_SUCCESS, result.status_); EXPECT_EQ(ARES_SUCCESS, result.status_);
skipping to change at line 356 skipping to change at line 356
}; };
class MockNoCheckRespChannelTestAI : public MockFlagsChannelOptsTestAI { class MockNoCheckRespChannelTestAI : public MockFlagsChannelOptsTestAI {
public: public:
MockNoCheckRespChannelTestAI() : MockFlagsChannelOptsTestAI(ARES_FLAG_NOCHECKR ESP) {} MockNoCheckRespChannelTestAI() : MockFlagsChannelOptsTestAI(ARES_FLAG_NOCHECKR ESP) {}
}; };
TEST_P(MockNoCheckRespChannelTestAI, ServFailResponse) { TEST_P(MockNoCheckRespChannelTestAI, ServFailResponse) {
DNSPacket rsp; DNSPacket rsp;
rsp.set_response().set_aa() rsp.set_response().set_aa()
.add_question(new DNSQuestion("www.google.com", ns_t_a)); .add_question(new DNSQuestion("www.google.com", T_A));
rsp.set_rcode(ns_r_servfail); rsp.set_rcode(SERVFAIL);
ON_CALL(server_, OnRequest("www.google.com", ns_t_a)) ON_CALL(server_, OnRequest("www.google.com", T_A))
.WillByDefault(SetReply(&server_, &rsp)); .WillByDefault(SetReply(&server_, &rsp));
AddrInfoResult result; AddrInfoResult result;
struct ares_addrinfo_hints hints = {}; struct ares_addrinfo_hints hints = {};
hints.ai_family = AF_INET; hints.ai_family = AF_INET;
hints.ai_flags = ARES_AI_NOSORT; hints.ai_flags = ARES_AI_NOSORT;
ares_getaddrinfo(channel_, "www.google.com.", NULL, &hints, AddrInfoCallback, &result); ares_getaddrinfo(channel_, "www.google.com.", NULL, &hints, AddrInfoCallback, &result);
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
EXPECT_EQ(ARES_ESERVFAIL, result.status_); EXPECT_EQ(ARES_ESERVFAIL, result.status_);
} }
TEST_P(MockNoCheckRespChannelTestAI, NotImplResponse) { TEST_P(MockNoCheckRespChannelTestAI, NotImplResponse) {
DNSPacket rsp; DNSPacket rsp;
rsp.set_response().set_aa() rsp.set_response().set_aa()
.add_question(new DNSQuestion("www.google.com", ns_t_a)); .add_question(new DNSQuestion("www.google.com", T_A));
rsp.set_rcode(ns_r_notimpl); rsp.set_rcode(NOTIMP);
ON_CALL(server_, OnRequest("www.google.com", ns_t_a)) ON_CALL(server_, OnRequest("www.google.com", T_A))
.WillByDefault(SetReply(&server_, &rsp)); .WillByDefault(SetReply(&server_, &rsp));
AddrInfoResult result; AddrInfoResult result;
struct ares_addrinfo_hints hints = {}; struct ares_addrinfo_hints hints = {};
hints.ai_family = AF_INET; hints.ai_family = AF_INET;
hints.ai_flags = ARES_AI_NOSORT; hints.ai_flags = ARES_AI_NOSORT;
ares_getaddrinfo(channel_, "www.google.com.", NULL, &hints, AddrInfoCallback, &result); ares_getaddrinfo(channel_, "www.google.com.", NULL, &hints, AddrInfoCallback, &result);
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
EXPECT_EQ(ARES_ENOTIMP, result.status_); EXPECT_EQ(ARES_ENOTIMP, result.status_);
} }
TEST_P(MockNoCheckRespChannelTestAI, RefusedResponse) { TEST_P(MockNoCheckRespChannelTestAI, RefusedResponse) {
DNSPacket rsp; DNSPacket rsp;
rsp.set_response().set_aa() rsp.set_response().set_aa()
.add_question(new DNSQuestion("www.google.com", ns_t_a)); .add_question(new DNSQuestion("www.google.com", T_A));
rsp.set_rcode(ns_r_refused); rsp.set_rcode(REFUSED);
ON_CALL(server_, OnRequest("www.google.com", ns_t_a)) ON_CALL(server_, OnRequest("www.google.com", T_A))
.WillByDefault(SetReply(&server_, &rsp)); .WillByDefault(SetReply(&server_, &rsp));
AddrInfoResult result; AddrInfoResult result;
struct ares_addrinfo_hints hints = {}; struct ares_addrinfo_hints hints = {};
hints.ai_family = AF_INET; hints.ai_family = AF_INET;
hints.ai_flags = ARES_AI_NOSORT; hints.ai_flags = ARES_AI_NOSORT;
ares_getaddrinfo(channel_, "www.google.com.", NULL, &hints, AddrInfoCallback, &result); ares_getaddrinfo(channel_, "www.google.com.", NULL, &hints, AddrInfoCallback, &result);
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
EXPECT_EQ(ARES_EREFUSED, result.status_); EXPECT_EQ(ARES_EREFUSED, result.status_);
} }
TEST_P(MockChannelTestAI, FamilyV6) { TEST_P(MockChannelTestAI, FamilyV6) {
DNSPacket rsp6; DNSPacket rsp6;
rsp6.set_response().set_aa() rsp6.set_response().set_aa()
.add_question(new DNSQuestion("example.com", ns_t_aaaa)) .add_question(new DNSQuestion("example.com", T_AAAA))
.add_answer(new DNSAaaaRR("example.com", 100, .add_answer(new DNSAaaaRR("example.com", 100,
{0x21, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, {0x21, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03})) ; 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03})) ;
ON_CALL(server_, OnRequest("example.com", ns_t_aaaa)) ON_CALL(server_, OnRequest("example.com", T_AAAA))
.WillByDefault(SetReply(&server_, &rsp6)); .WillByDefault(SetReply(&server_, &rsp6));
AddrInfoResult result; AddrInfoResult result;
struct ares_addrinfo_hints hints = {}; struct ares_addrinfo_hints hints = {};
hints.ai_family = AF_INET6; hints.ai_family = AF_INET6;
hints.ai_flags = ARES_AI_NOSORT; hints.ai_flags = ARES_AI_NOSORT;
ares_getaddrinfo(channel_, "example.com.", NULL, &hints, ares_getaddrinfo(channel_, "example.com.", NULL, &hints,
AddrInfoCallback, &result); AddrInfoCallback, &result);
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
EXPECT_THAT(result.ai_, IncludesNumAddresses(1)); EXPECT_THAT(result.ai_, IncludesNumAddresses(1));
EXPECT_THAT(result.ai_, IncludesV6Address("2121:0000:0000:0000:0000:0000:0000: 0303")); EXPECT_THAT(result.ai_, IncludesV6Address("2121:0000:0000:0000:0000:0000:0000: 0303"));
} }
TEST_P(MockChannelTestAI, FamilyV4) { TEST_P(MockChannelTestAI, FamilyV4) {
DNSPacket rsp4; DNSPacket rsp4;
rsp4.set_response().set_aa() rsp4.set_response().set_aa()
.add_question(new DNSQuestion("example.com", ns_t_a)) .add_question(new DNSQuestion("example.com", T_A))
.add_answer(new DNSARR("example.com", 100, {2, 3, 4, 5})); .add_answer(new DNSARR("example.com", 100, {2, 3, 4, 5}));
ON_CALL(server_, OnRequest("example.com", ns_t_a)) ON_CALL(server_, OnRequest("example.com", T_A))
.WillByDefault(SetReply(&server_, &rsp4)); .WillByDefault(SetReply(&server_, &rsp4));
AddrInfoResult result = {}; AddrInfoResult result = {};
struct ares_addrinfo_hints hints = {}; struct ares_addrinfo_hints hints = {};
hints.ai_family = AF_INET; hints.ai_family = AF_INET;
hints.ai_flags = ARES_AI_NOSORT; hints.ai_flags = ARES_AI_NOSORT;
ares_getaddrinfo(channel_, "example.com.", NULL, &hints, ares_getaddrinfo(channel_, "example.com.", NULL, &hints,
AddrInfoCallback, &result); AddrInfoCallback, &result);
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
EXPECT_THAT(result.ai_, IncludesNumAddresses(1)); EXPECT_THAT(result.ai_, IncludesNumAddresses(1));
EXPECT_THAT(result.ai_, IncludesV4Address("2.3.4.5")); EXPECT_THAT(result.ai_, IncludesV4Address("2.3.4.5"));
} }
TEST_P(MockChannelTestAI, FamilyV4_MultipleAddresses) { TEST_P(MockChannelTestAI, FamilyV4_MultipleAddresses) {
DNSPacket rsp4; DNSPacket rsp4;
rsp4.set_response().set_aa() rsp4.set_response().set_aa()
.add_question(new DNSQuestion("example.com", ns_t_a)) .add_question(new DNSQuestion("example.com", T_A))
.add_answer(new DNSARR("example.com", 100, {2, 3, 4, 5})) .add_answer(new DNSARR("example.com", 100, {2, 3, 4, 5}))
.add_answer(new DNSARR("example.com", 100, {7, 8, 9, 0})); .add_answer(new DNSARR("example.com", 100, {7, 8, 9, 0}));
ON_CALL(server_, OnRequest("example.com", ns_t_a)) ON_CALL(server_, OnRequest("example.com", T_A))
.WillByDefault(SetReply(&server_, &rsp4)); .WillByDefault(SetReply(&server_, &rsp4));
AddrInfoResult result = {}; AddrInfoResult result = {};
struct ares_addrinfo_hints hints = {}; struct ares_addrinfo_hints hints = {};
hints.ai_family = AF_INET; hints.ai_family = AF_INET;
hints.ai_flags = ARES_AI_NOSORT; hints.ai_flags = ARES_AI_NOSORT;
ares_getaddrinfo(channel_, "example.com.", NULL, &hints, ares_getaddrinfo(channel_, "example.com.", NULL, &hints,
AddrInfoCallback, &result); AddrInfoCallback, &result);
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
std::stringstream ss; std::stringstream ss;
ss << result.ai_; ss << result.ai_;
EXPECT_EQ("{addr=[2.3.4.5], addr=[7.8.9.0]}", ss.str()); EXPECT_EQ("{addr=[2.3.4.5], addr=[7.8.9.0]}", ss.str());
} }
TEST_P(MockChannelTestAI, FamilyUnspecified) { TEST_P(MockChannelTestAI, FamilyUnspecified) {
DNSPacket rsp6; DNSPacket rsp6;
rsp6.set_response().set_aa() rsp6.set_response().set_aa()
.add_question(new DNSQuestion("example.com", ns_t_aaaa)) .add_question(new DNSQuestion("example.com", T_AAAA))
.add_answer(new DNSAaaaRR("example.com", 100, .add_answer(new DNSAaaaRR("example.com", 100,
{0x21, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, {0x21, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03})) ; 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03})) ;
ON_CALL(server_, OnRequest("example.com", ns_t_aaaa)) ON_CALL(server_, OnRequest("example.com", T_AAAA))
.WillByDefault(SetReply(&server_, &rsp6)); .WillByDefault(SetReply(&server_, &rsp6));
DNSPacket rsp4; DNSPacket rsp4;
rsp4.set_response().set_aa() rsp4.set_response().set_aa()
.add_question(new DNSQuestion("example.com", ns_t_a)) .add_question(new DNSQuestion("example.com", T_A))
.add_answer(new DNSARR("example.com", 100, {2, 3, 4, 5})); .add_answer(new DNSARR("example.com", 100, {2, 3, 4, 5}));
ON_CALL(server_, OnRequest("example.com", ns_t_a)) ON_CALL(server_, OnRequest("example.com", T_A))
.WillByDefault(SetReply(&server_, &rsp4)); .WillByDefault(SetReply(&server_, &rsp4));
AddrInfoResult result; AddrInfoResult result;
struct ares_addrinfo_hints hints = {}; struct ares_addrinfo_hints hints = {};
hints.ai_family = AF_UNSPEC; hints.ai_family = AF_UNSPEC;
hints.ai_flags = ARES_AI_NOSORT; hints.ai_flags = ARES_AI_NOSORT;
ares_getaddrinfo(channel_, "example.com.", NULL, &hints, ares_getaddrinfo(channel_, "example.com.", NULL, &hints,
AddrInfoCallback, &result); AddrInfoCallback, &result);
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
EXPECT_THAT(result.ai_, IncludesNumAddresses(2)); EXPECT_THAT(result.ai_, IncludesNumAddresses(2));
skipping to change at line 503 skipping to change at line 503
EXPECT_THAT(result.ai_, IncludesV6Address("2121:0000:0000:0000:0000:0000:0000: 0303")); EXPECT_THAT(result.ai_, IncludesV6Address("2121:0000:0000:0000:0000:0000:0000: 0303"));
} }
class MockEDNSChannelTestAI : public MockFlagsChannelOptsTestAI { class MockEDNSChannelTestAI : public MockFlagsChannelOptsTestAI {
public: public:
MockEDNSChannelTestAI() : MockFlagsChannelOptsTestAI(ARES_FLAG_EDNS) {} MockEDNSChannelTestAI() : MockFlagsChannelOptsTestAI(ARES_FLAG_EDNS) {}
}; };
TEST_P(MockEDNSChannelTestAI, RetryWithoutEDNS) { TEST_P(MockEDNSChannelTestAI, RetryWithoutEDNS) {
DNSPacket rspfail; DNSPacket rspfail;
rspfail.set_response().set_aa().set_rcode(ns_r_formerr) rspfail.set_response().set_aa().set_rcode(FORMERR)
.add_question(new DNSQuestion("www.google.com", ns_t_a)); .add_question(new DNSQuestion("www.google.com", T_A));
DNSPacket rspok; DNSPacket rspok;
rspok.set_response() rspok.set_response()
.add_question(new DNSQuestion("www.google.com", ns_t_a)) .add_question(new DNSQuestion("www.google.com", T_A))
.add_answer(new DNSARR("www.google.com", 100, {1, 2, 3, 4})); .add_answer(new DNSARR("www.google.com", 100, {1, 2, 3, 4}));
EXPECT_CALL(server_, OnRequest("www.google.com", ns_t_a)) EXPECT_CALL(server_, OnRequest("www.google.com", T_A))
.WillOnce(SetReply(&server_, &rspfail)) .WillOnce(SetReply(&server_, &rspfail))
.WillOnce(SetReply(&server_, &rspok)); .WillOnce(SetReply(&server_, &rspok));
AddrInfoResult result; AddrInfoResult result;
struct ares_addrinfo_hints hints = {}; struct ares_addrinfo_hints hints = {};
hints.ai_family = AF_INET; hints.ai_family = AF_INET;
hints.ai_flags = ARES_AI_NOSORT; hints.ai_flags = ARES_AI_NOSORT;
ares_getaddrinfo(channel_, "www.google.com.", NULL, &hints, AddrInfoCallback, &result); ares_getaddrinfo(channel_, "www.google.com.", NULL, &hints, AddrInfoCallback, &result);
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
EXPECT_THAT(result.ai_, IncludesNumAddresses(1)); EXPECT_THAT(result.ai_, IncludesNumAddresses(1));
EXPECT_THAT(result.ai_, IncludesV4Address("1.2.3.4")); EXPECT_THAT(result.ai_, IncludesV4Address("1.2.3.4"));
} }
TEST_P(MockChannelTestAI, SearchDomains) { TEST_P(MockChannelTestAI, SearchDomains) {
DNSPacket nofirst; DNSPacket nofirst;
nofirst.set_response().set_aa().set_rcode(ns_r_nxdomain) nofirst.set_response().set_aa().set_rcode(NXDOMAIN)
.add_question(new DNSQuestion("www.first.com", ns_t_a)); .add_question(new DNSQuestion("www.first.com", T_A));
ON_CALL(server_, OnRequest("www.first.com", ns_t_a)) ON_CALL(server_, OnRequest("www.first.com", T_A))
.WillByDefault(SetReply(&server_, &nofirst)); .WillByDefault(SetReply(&server_, &nofirst));
DNSPacket nosecond; DNSPacket nosecond;
nosecond.set_response().set_aa().set_rcode(ns_r_nxdomain) nosecond.set_response().set_aa().set_rcode(NXDOMAIN)
.add_question(new DNSQuestion("www.second.org", ns_t_a)); .add_question(new DNSQuestion("www.second.org", T_A));
ON_CALL(server_, OnRequest("www.second.org", ns_t_a)) ON_CALL(server_, OnRequest("www.second.org", T_A))
.WillByDefault(SetReply(&server_, &nosecond)); .WillByDefault(SetReply(&server_, &nosecond));
DNSPacket yesthird; DNSPacket yesthird;
yesthird.set_response().set_aa() yesthird.set_response().set_aa()
.add_question(new DNSQuestion("www.third.gov", ns_t_a)) .add_question(new DNSQuestion("www.third.gov", T_A))
.add_answer(new DNSARR("www.third.gov", 0x0200, {2, 3, 4, 5})); .add_answer(new DNSARR("www.third.gov", 0x0200, {2, 3, 4, 5}));
ON_CALL(server_, OnRequest("www.third.gov", ns_t_a)) ON_CALL(server_, OnRequest("www.third.gov", T_A))
.WillByDefault(SetReply(&server_, &yesthird)); .WillByDefault(SetReply(&server_, &yesthird));
AddrInfoResult result; AddrInfoResult result;
struct ares_addrinfo_hints hints = {}; struct ares_addrinfo_hints hints = {};
hints.ai_family = AF_INET; hints.ai_family = AF_INET;
hints.ai_flags = ARES_AI_NOSORT; hints.ai_flags = ARES_AI_NOSORT;
ares_getaddrinfo(channel_, "www", NULL, &hints, AddrInfoCallback, &result); ares_getaddrinfo(channel_, "www", NULL, &hints, AddrInfoCallback, &result);
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
EXPECT_THAT(result.ai_, IncludesNumAddresses(1)); EXPECT_THAT(result.ai_, IncludesNumAddresses(1));
EXPECT_THAT(result.ai_, IncludesV4Address("2.3.4.5")); EXPECT_THAT(result.ai_, IncludesV4Address("2.3.4.5"));
} }
TEST_P(MockChannelTestAI, SearchDomainsServFailOnAAAA) { TEST_P(MockChannelTestAI, SearchDomainsServFailOnAAAA) {
DNSPacket nofirst; DNSPacket nofirst;
nofirst.set_response().set_aa().set_rcode(ns_r_nxdomain) nofirst.set_response().set_aa().set_rcode(NXDOMAIN)
.add_question(new DNSQuestion("www.first.com", ns_t_aaaa)); .add_question(new DNSQuestion("www.first.com", T_AAAA));
ON_CALL(server_, OnRequest("www.first.com", ns_t_aaaa)) ON_CALL(server_, OnRequest("www.first.com", T_AAAA))
.WillByDefault(SetReply(&server_, &nofirst)); .WillByDefault(SetReply(&server_, &nofirst));
DNSPacket nofirst4; DNSPacket nofirst4;
nofirst4.set_response().set_aa().set_rcode(ns_r_nxdomain) nofirst4.set_response().set_aa().set_rcode(NXDOMAIN)
.add_question(new DNSQuestion("www.first.com", ns_t_a)); .add_question(new DNSQuestion("www.first.com", T_A));
ON_CALL(server_, OnRequest("www.first.com", ns_t_a)) ON_CALL(server_, OnRequest("www.first.com", T_A))
.WillByDefault(SetReply(&server_, &nofirst4)); .WillByDefault(SetReply(&server_, &nofirst4));
DNSPacket nosecond; DNSPacket nosecond;
nosecond.set_response().set_aa().set_rcode(ns_r_nxdomain) nosecond.set_response().set_aa().set_rcode(NXDOMAIN)
.add_question(new DNSQuestion("www.second.org", ns_t_aaaa)); .add_question(new DNSQuestion("www.second.org", T_AAAA));
ON_CALL(server_, OnRequest("www.second.org", ns_t_aaaa)) ON_CALL(server_, OnRequest("www.second.org", T_AAAA))
.WillByDefault(SetReply(&server_, &nosecond)); .WillByDefault(SetReply(&server_, &nosecond));
DNSPacket yessecond4; DNSPacket yessecond4;
yessecond4.set_response().set_aa() yessecond4.set_response().set_aa()
.add_question(new DNSQuestion("www.second.org", ns_t_a)) .add_question(new DNSQuestion("www.second.org", T_A))
.add_answer(new DNSARR("www.second.org", 0x0200, {2, 3, 4, 5})); .add_answer(new DNSARR("www.second.org", 0x0200, {2, 3, 4, 5}));
ON_CALL(server_, OnRequest("www.second.org", ns_t_a)) ON_CALL(server_, OnRequest("www.second.org", T_A))
.WillByDefault(SetReply(&server_, &yessecond4)); .WillByDefault(SetReply(&server_, &yessecond4));
DNSPacket failthird; DNSPacket failthird;
failthird.set_response().set_aa().set_rcode(ns_r_servfail) failthird.set_response().set_aa().set_rcode(SERVFAIL)
.add_question(new DNSQuestion("www.third.gov", ns_t_aaaa)); .add_question(new DNSQuestion("www.third.gov", T_AAAA));
ON_CALL(server_, OnRequest("www.third.gov", ns_t_aaaa)) ON_CALL(server_, OnRequest("www.third.gov", T_AAAA))
.WillByDefault(SetReply(&server_, &failthird)); .WillByDefault(SetReply(&server_, &failthird));
DNSPacket failthird4; DNSPacket failthird4;
failthird4.set_response().set_aa().set_rcode(ns_r_servfail) failthird4.set_response().set_aa().set_rcode(SERVFAIL)
.add_question(new DNSQuestion("www.third.gov", ns_t_a)); .add_question(new DNSQuestion("www.third.gov", T_A));
ON_CALL(server_, OnRequest("www.third.gov", ns_t_a)) ON_CALL(server_, OnRequest("www.third.gov", T_A))
.WillByDefault(SetReply(&server_, &failthird4)); .WillByDefault(SetReply(&server_, &failthird4));
AddrInfoResult result; AddrInfoResult result;
struct ares_addrinfo_hints hints = {}; struct ares_addrinfo_hints hints = {};
hints.ai_family = AF_UNSPEC; hints.ai_family = AF_UNSPEC;
hints.ai_flags = ARES_AI_NOSORT; hints.ai_flags = ARES_AI_NOSORT;
ares_getaddrinfo(channel_, "www", NULL, &hints, AddrInfoCallback, &result); ares_getaddrinfo(channel_, "www", NULL, &hints, AddrInfoCallback, &result);
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
EXPECT_THAT(result.ai_, IncludesNumAddresses(1)); EXPECT_THAT(result.ai_, IncludesNumAddresses(1));
skipping to change at line 637 skipping to change at line 637
}; };
TEST_P(RotateMultiMockTestAI, ThirdServer) { TEST_P(RotateMultiMockTestAI, ThirdServer) {
struct ares_options opts = {0}; struct ares_options opts = {0};
int optmask = 0; int optmask = 0;
EXPECT_EQ(ARES_SUCCESS, ares_save_options(channel_, &opts, &optmask)); EXPECT_EQ(ARES_SUCCESS, ares_save_options(channel_, &opts, &optmask));
EXPECT_EQ(0, (optmask & ARES_OPT_NOROTATE)); EXPECT_EQ(0, (optmask & ARES_OPT_NOROTATE));
ares_destroy_options(&opts); ares_destroy_options(&opts);
DNSPacket servfailrsp; DNSPacket servfailrsp;
servfailrsp.set_response().set_aa().set_rcode(ns_r_servfail) servfailrsp.set_response().set_aa().set_rcode(SERVFAIL)
.add_question(new DNSQuestion("www.example.com", ns_t_a)); .add_question(new DNSQuestion("www.example.com", T_A));
DNSPacket notimplrsp; DNSPacket notimplrsp;
notimplrsp.set_response().set_aa().set_rcode(ns_r_notimpl) notimplrsp.set_response().set_aa().set_rcode(NOTIMP)
.add_question(new DNSQuestion("www.example.com", ns_t_a)); .add_question(new DNSQuestion("www.example.com", T_A));
DNSPacket okrsp; DNSPacket okrsp;
okrsp.set_response().set_aa() okrsp.set_response().set_aa()
.add_question(new DNSQuestion("www.example.com", ns_t_a)) .add_question(new DNSQuestion("www.example.com", T_A))
.add_answer(new DNSARR("www.example.com", 100, {2,3,4,5})); .add_answer(new DNSARR("www.example.com", 100, {2,3,4,5}));
EXPECT_CALL(*servers_[0], OnRequest("www.example.com", ns_t_a)) EXPECT_CALL(*servers_[0], OnRequest("www.example.com", T_A))
.WillOnce(SetReply(servers_[0].get(), &servfailrsp)); .WillOnce(SetReply(servers_[0].get(), &servfailrsp));
EXPECT_CALL(*servers_[1], OnRequest("www.example.com", ns_t_a)) EXPECT_CALL(*servers_[1], OnRequest("www.example.com", T_A))
.WillOnce(SetReply(servers_[1].get(), &notimplrsp)); .WillOnce(SetReply(servers_[1].get(), &notimplrsp));
EXPECT_CALL(*servers_[2], OnRequest("www.example.com", ns_t_a)) EXPECT_CALL(*servers_[2], OnRequest("www.example.com", T_A))
.WillOnce(SetReply(servers_[2].get(), &okrsp)); .WillOnce(SetReply(servers_[2].get(), &okrsp));
CheckExample(); CheckExample();
// Second time around, starts from server [1]. // Second time around, starts from server [1].
EXPECT_CALL(*servers_[1], OnRequest("www.example.com", ns_t_a)) EXPECT_CALL(*servers_[1], OnRequest("www.example.com", T_A))
.WillOnce(SetReply(servers_[1].get(), &servfailrsp)); .WillOnce(SetReply(servers_[1].get(), &servfailrsp));
EXPECT_CALL(*servers_[2], OnRequest("www.example.com", ns_t_a)) EXPECT_CALL(*servers_[2], OnRequest("www.example.com", T_A))
.WillOnce(SetReply(servers_[2].get(), &notimplrsp)); .WillOnce(SetReply(servers_[2].get(), &notimplrsp));
EXPECT_CALL(*servers_[0], OnRequest("www.example.com", ns_t_a)) EXPECT_CALL(*servers_[0], OnRequest("www.example.com", T_A))
.WillOnce(SetReply(servers_[0].get(), &okrsp)); .WillOnce(SetReply(servers_[0].get(), &okrsp));
CheckExample(); CheckExample();
// Third time around, starts from server [2]. // Third time around, starts from server [2].
EXPECT_CALL(*servers_[2], OnRequest("www.example.com", ns_t_a)) EXPECT_CALL(*servers_[2], OnRequest("www.example.com", T_A))
.WillOnce(SetReply(servers_[2].get(), &servfailrsp)); .WillOnce(SetReply(servers_[2].get(), &servfailrsp));
EXPECT_CALL(*servers_[0], OnRequest("www.example.com", ns_t_a)) EXPECT_CALL(*servers_[0], OnRequest("www.example.com", T_A))
.WillOnce(SetReply(servers_[0].get(), &notimplrsp)); .WillOnce(SetReply(servers_[0].get(), &notimplrsp));
EXPECT_CALL(*servers_[1], OnRequest("www.example.com", ns_t_a)) EXPECT_CALL(*servers_[1], OnRequest("www.example.com", T_A))
.WillOnce(SetReply(servers_[1].get(), &okrsp)); .WillOnce(SetReply(servers_[1].get(), &okrsp));
CheckExample(); CheckExample();
} }
TEST_P(NoRotateMultiMockTestAI, ThirdServer) { TEST_P(NoRotateMultiMockTestAI, ThirdServer) {
struct ares_options opts = {0}; struct ares_options opts = {0};
int optmask = 0; int optmask = 0;
EXPECT_EQ(ARES_SUCCESS, ares_save_options(channel_, &opts, &optmask)); EXPECT_EQ(ARES_SUCCESS, ares_save_options(channel_, &opts, &optmask));
EXPECT_EQ(ARES_OPT_NOROTATE, (optmask & ARES_OPT_NOROTATE)); EXPECT_EQ(ARES_OPT_NOROTATE, (optmask & ARES_OPT_NOROTATE));
ares_destroy_options(&opts); ares_destroy_options(&opts);
DNSPacket servfailrsp; DNSPacket servfailrsp;
servfailrsp.set_response().set_aa().set_rcode(ns_r_servfail) servfailrsp.set_response().set_aa().set_rcode(SERVFAIL)
.add_question(new DNSQuestion("www.example.com", ns_t_a)); .add_question(new DNSQuestion("www.example.com", T_A));
DNSPacket notimplrsp; DNSPacket notimplrsp;
notimplrsp.set_response().set_aa().set_rcode(ns_r_notimpl) notimplrsp.set_response().set_aa().set_rcode(NOTIMP)
.add_question(new DNSQuestion("www.example.com", ns_t_a)); .add_question(new DNSQuestion("www.example.com", T_A));
DNSPacket okrsp; DNSPacket okrsp;
okrsp.set_response().set_aa() okrsp.set_response().set_aa()
.add_question(new DNSQuestion("www.example.com", ns_t_a)) .add_question(new DNSQuestion("www.example.com", T_A))
.add_answer(new DNSARR("www.example.com", 100, {2,3,4,5})); .add_answer(new DNSARR("www.example.com", 100, {2,3,4,5}));
EXPECT_CALL(*servers_[0], OnRequest("www.example.com", ns_t_a)) EXPECT_CALL(*servers_[0], OnRequest("www.example.com", T_A))
.WillOnce(SetReply(servers_[0].get(), &servfailrsp)); .WillOnce(SetReply(servers_[0].get(), &servfailrsp));
EXPECT_CALL(*servers_[1], OnRequest("www.example.com", ns_t_a)) EXPECT_CALL(*servers_[1], OnRequest("www.example.com", T_A))
.WillOnce(SetReply(servers_[1].get(), &notimplrsp)); .WillOnce(SetReply(servers_[1].get(), &notimplrsp));
EXPECT_CALL(*servers_[2], OnRequest("www.example.com", ns_t_a)) EXPECT_CALL(*servers_[2], OnRequest("www.example.com", T_A))
.WillOnce(SetReply(servers_[2].get(), &okrsp)); .WillOnce(SetReply(servers_[2].get(), &okrsp));
CheckExample(); CheckExample();
// Second time around, still starts from server [0]. // Second time around, still starts from server [0].
EXPECT_CALL(*servers_[0], OnRequest("www.example.com", ns_t_a)) EXPECT_CALL(*servers_[0], OnRequest("www.example.com", T_A))
.WillOnce(SetReply(servers_[0].get(), &servfailrsp)); .WillOnce(SetReply(servers_[0].get(), &servfailrsp));
EXPECT_CALL(*servers_[1], OnRequest("www.example.com", ns_t_a)) EXPECT_CALL(*servers_[1], OnRequest("www.example.com", T_A))
.WillOnce(SetReply(servers_[1].get(), &notimplrsp)); .WillOnce(SetReply(servers_[1].get(), &notimplrsp));
EXPECT_CALL(*servers_[2], OnRequest("www.example.com", ns_t_a)) EXPECT_CALL(*servers_[2], OnRequest("www.example.com", T_A))
.WillOnce(SetReply(servers_[2].get(), &okrsp)); .WillOnce(SetReply(servers_[2].get(), &okrsp));
CheckExample(); CheckExample();
// Third time around, still starts from server [0]. // Third time around, still starts from server [0].
EXPECT_CALL(*servers_[0], OnRequest("www.example.com", ns_t_a)) EXPECT_CALL(*servers_[0], OnRequest("www.example.com", T_A))
.WillOnce(SetReply(servers_[0].get(), &servfailrsp)); .WillOnce(SetReply(servers_[0].get(), &servfailrsp));
EXPECT_CALL(*servers_[1], OnRequest("www.example.com", ns_t_a)) EXPECT_CALL(*servers_[1], OnRequest("www.example.com", T_A))
.WillOnce(SetReply(servers_[1].get(), &notimplrsp)); .WillOnce(SetReply(servers_[1].get(), &notimplrsp));
EXPECT_CALL(*servers_[2], OnRequest("www.example.com", ns_t_a)) EXPECT_CALL(*servers_[2], OnRequest("www.example.com", T_A))
.WillOnce(SetReply(servers_[2].get(), &okrsp)); .WillOnce(SetReply(servers_[2].get(), &okrsp));
CheckExample(); CheckExample();
} }
TEST_P(MockChannelTestAI, FamilyV4ServiceName) { TEST_P(MockChannelTestAI, FamilyV4ServiceName) {
DNSPacket rsp4; DNSPacket rsp4;
rsp4.set_response().set_aa() rsp4.set_response().set_aa()
.add_question(new DNSQuestion("example.com", ns_t_a)) .add_question(new DNSQuestion("example.com", T_A))
.add_answer(new DNSARR("example.com", 100, {1, 1, 1, 1})) .add_answer(new DNSARR("example.com", 100, {1, 1, 1, 1}))
.add_answer(new DNSARR("example.com", 100, {2, 2, 2, 2})); .add_answer(new DNSARR("example.com", 100, {2, 2, 2, 2}));
ON_CALL(server_, OnRequest("example.com", ns_t_a)) ON_CALL(server_, OnRequest("example.com", T_A))
.WillByDefault(SetReply(&server_, &rsp4)); .WillByDefault(SetReply(&server_, &rsp4));
AddrInfoResult result = {}; AddrInfoResult result = {};
struct ares_addrinfo_hints hints = {}; struct ares_addrinfo_hints hints = {};
hints.ai_family = AF_INET; hints.ai_family = AF_INET;
hints.ai_flags = ARES_AI_NOSORT; hints.ai_flags = ARES_AI_NOSORT;
ares_getaddrinfo(channel_, "example.com", "http", &hints, AddrInfoCallback, &r esult); ares_getaddrinfo(channel_, "example.com", "http", &hints, AddrInfoCallback, &r esult);
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
std::stringstream ss; std::stringstream ss;
ss << result.ai_; ss << result.ai_;
 End of changes. 71 change blocks. 
106 lines changed or deleted 106 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)