"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "test/ares-test-mock.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.cc  (c-ares-1.17.1):ares-test-mock.cc  (c-ares-1.17.2)
skipping to change at line 41 skipping to change at line 41
0x06, 'g', 'o', 'o', 'g', 'l', 'e', 0x06, 'g', 'o', 'o', 'g', 'l', 'e',
0x03, 'c', 'o', 'm', 0x03, 'c', 'o', 'm',
0x00, 0x00,
0x00, 0x01, // type A 0x00, 0x01, // type A
0x00, 0x01, // class IN 0x00, 0x01, // class IN
0x00, 0x00, 0x01, 0x00, // TTL 0x00, 0x00, 0x01, 0x00, // TTL
0x00, 0x04, // rdata length 0x00, 0x04, // rdata length
0x01, 0x02, 0x03, 0x04 0x01, 0x02, 0x03, 0x04
}; };
ON_CALL(server_, OnRequest("www.google.com", ns_t_a)) ON_CALL(server_, OnRequest("www.google.com", T_A))
.WillByDefault(SetReplyData(&server_, reply)); .WillByDefault(SetReplyData(&server_, reply));
HostResult result; HostResult result;
ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result ); ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result );
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
std::stringstream ss; std::stringstream ss;
ss << result.host_; ss << result.host_;
EXPECT_EQ("{'www.google.com' aliases=[] addrs=[1.2.3.4]}", ss.str()); EXPECT_EQ("{'www.google.com' aliases=[] addrs=[1.2.3.4]}", ss.str());
} }
// 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(MockUDPChannelTest, GetHostByNameParallelLookups) { TEST_P(MockUDPChannelTest, GetHostByNameParallelLookups) {
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));
HostResult result1; HostResult result1;
ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result 1); ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result 1);
HostResult result2; HostResult result2;
ares_gethostbyname(channel_, "www.example.com.", AF_INET, HostCallback, &resul t2); ares_gethostbyname(channel_, "www.example.com.", AF_INET, HostCallback, &resul t2);
HostResult result3; HostResult result3;
ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result 3); ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result 3);
Process(); Process();
EXPECT_TRUE(result1.done_); EXPECT_TRUE(result1.done_);
skipping to change at line 93 skipping to change at line 93
EXPECT_EQ("{'www.example.com' aliases=[] addrs=[1.2.3.4]}", ss2.str()); EXPECT_EQ("{'www.example.com' aliases=[] addrs=[1.2.3.4]}", ss2.str());
std::stringstream ss3; std::stringstream ss3;
ss3 << result3.host_; ss3 << result3.host_;
EXPECT_EQ("{'www.google.com' aliases=[] addrs=[2.3.4.5]}", ss3.str()); EXPECT_EQ("{'www.google.com' aliases=[] addrs=[2.3.4.5]}", ss3.str());
} }
// UDP to TCP specific test // UDP to TCP specific test
TEST_P(MockUDPChannelTest, TruncationRetry) { TEST_P(MockUDPChannelTest, 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));
HostResult result; HostResult result;
ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result ); ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result );
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
std::stringstream ss; std::stringstream ss;
ss << result.host_; ss << result.host_;
EXPECT_EQ("{'www.google.com' aliases=[] addrs=[1.2.3.4]}", ss.str()); EXPECT_EQ("{'www.google.com' aliases=[] addrs=[1.2.3.4]}", ss.str());
} }
skipping to change at line 121 skipping to change at line 121
static int SocketConnectCallback(ares_socket_t fd, int type, void *data) { static int SocketConnectCallback(ares_socket_t fd, int type, void *data) {
int rc = *(int*)data; int rc = *(int*)data;
if (verbose) std::cerr << "SocketConnectCallback(" << fd << ") invoked" << std ::endl; if (verbose) std::cerr << "SocketConnectCallback(" << fd << ") invoked" << std ::endl;
sock_cb_count++; sock_cb_count++;
return rc; return rc;
} }
TEST_P(MockChannelTest, SockCallback) { TEST_P(MockChannelTest, SockCallback) {
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}));
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));
// Get notified of new sockets // Get notified of new sockets
int rc = ARES_SUCCESS; int rc = ARES_SUCCESS;
ares_set_socket_callback(channel_, SocketConnectCallback, &rc); ares_set_socket_callback(channel_, SocketConnectCallback, &rc);
HostResult result; HostResult result;
sock_cb_count = 0; sock_cb_count = 0;
ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result ); ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result );
Process(); Process();
skipping to change at line 166 skipping to change at line 166
static int SocketConfigureCallback(ares_socket_t fd, int type, void *data) { static int SocketConfigureCallback(ares_socket_t fd, int type, void *data) {
int rc = *(int*)data; int rc = *(int*)data;
if (verbose) std::cerr << "SocketConfigureCallback(" << fd << ") invoked" << s td::endl; if (verbose) std::cerr << "SocketConfigureCallback(" << fd << ") invoked" << s td::endl;
sock_config_cb_count++; sock_config_cb_count++;
return rc; return rc;
} }
TEST_P(MockChannelTest, SockConfigureCallback) { TEST_P(MockChannelTest, SockConfigureCallback) {
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}));
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));
// Get notified of new sockets // Get notified of new sockets
int rc = ARES_SUCCESS; int rc = ARES_SUCCESS;
ares_set_socket_configure_callback(channel_, SocketConfigureCallback, &rc); ares_set_socket_configure_callback(channel_, SocketConfigureCallback, &rc);
HostResult result; HostResult result;
sock_config_cb_count = 0; sock_config_cb_count = 0;
ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result ); ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result );
Process(); Process();
skipping to change at line 203 skipping to change at line 203
ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result ); ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result );
Process(); Process();
EXPECT_LT(1, sock_config_cb_count); EXPECT_LT(1, sock_config_cb_count);
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
EXPECT_EQ(ARES_ECONNREFUSED, result.status_); EXPECT_EQ(ARES_ECONNREFUSED, result.status_);
} }
// TCP only to prevent retries // TCP only to prevent retries
TEST_P(MockTCPChannelTest, MalformedResponse) { TEST_P(MockTCPChannelTest, 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));
HostResult result; HostResult result;
ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result ); ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &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(MockTCPChannelTest, FormErrResponse) { TEST_P(MockTCPChannelTest, 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));
HostResult result; HostResult result;
ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result ); ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &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(MockTCPChannelTest, ServFailResponse) { TEST_P(MockTCPChannelTest, 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));
HostResult result; HostResult result;
ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result ); ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &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(MockTCPChannelTest, NotImplResponse) { TEST_P(MockTCPChannelTest, 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));
HostResult result; HostResult result;
ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result ); ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &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(MockTCPChannelTest, RefusedResponse) { TEST_P(MockTCPChannelTest, 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));
HostResult result; HostResult result;
ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result ); ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &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(MockTCPChannelTest, YXDomainResponse) { TEST_P(MockTCPChannelTest, 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));
HostResult result; HostResult result;
ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result ); ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result );
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
EXPECT_EQ(ARES_ENODATA, result.status_); EXPECT_EQ(ARES_ENODATA, result.status_);
} }
class MockExtraOptsTest class MockExtraOptsTest
: public MockChannelOptsTest, : public MockChannelOptsTest,
skipping to change at line 314 skipping to change at line 314
TEST_P(MockExtraOptsTest, SimpleQuery) { TEST_P(MockExtraOptsTest, 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));
HostResult result; HostResult result;
ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result ); ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result );
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
std::stringstream ss; std::stringstream ss;
ss << result.host_; ss << result.host_;
EXPECT_EQ("{'www.google.com' aliases=[] addrs=[2.3.4.5]}", ss.str()); EXPECT_EQ("{'www.google.com' aliases=[] addrs=[2.3.4.5]}", ss.str());
} }
skipping to change at line 352 skipping to change at line 352
}; };
class MockNoCheckRespChannelTest : public MockFlagsChannelOptsTest { class MockNoCheckRespChannelTest : public MockFlagsChannelOptsTest {
public: public:
MockNoCheckRespChannelTest() : MockFlagsChannelOptsTest(ARES_FLAG_NOCHECKRESP) {} MockNoCheckRespChannelTest() : MockFlagsChannelOptsTest(ARES_FLAG_NOCHECKRESP) {}
}; };
TEST_P(MockNoCheckRespChannelTest, ServFailResponse) { TEST_P(MockNoCheckRespChannelTest, 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));
HostResult result; HostResult result;
ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result ); ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &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(MockNoCheckRespChannelTest, NotImplResponse) { TEST_P(MockNoCheckRespChannelTest, 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));
HostResult result; HostResult result;
ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result ); ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &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(MockNoCheckRespChannelTest, RefusedResponse) { TEST_P(MockNoCheckRespChannelTest, 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));
HostResult result; HostResult result;
ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result ); ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result );
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
EXPECT_EQ(ARES_EREFUSED, result.status_); EXPECT_EQ(ARES_EREFUSED, result.status_);
} }
class MockEDNSChannelTest : public MockFlagsChannelOptsTest { class MockEDNSChannelTest : public MockFlagsChannelOptsTest {
public: public:
MockEDNSChannelTest() : MockFlagsChannelOptsTest(ARES_FLAG_EDNS) {} MockEDNSChannelTest() : MockFlagsChannelOptsTest(ARES_FLAG_EDNS) {}
}; };
TEST_P(MockEDNSChannelTest, RetryWithoutEDNS) { TEST_P(MockEDNSChannelTest, 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));
HostResult result; HostResult result;
ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result ); ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result );
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
std::stringstream ss; std::stringstream ss;
ss << result.host_; ss << result.host_;
EXPECT_EQ("{'www.google.com' aliases=[] addrs=[1.2.3.4]}", ss.str()); EXPECT_EQ("{'www.google.com' aliases=[] addrs=[1.2.3.4]}", ss.str());
} }
TEST_P(MockChannelTest, SearchDomains) { TEST_P(MockChannelTest, 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));
HostResult result; HostResult result;
ares_gethostbyname(channel_, "www", AF_INET, HostCallback, &result); ares_gethostbyname(channel_, "www", AF_INET, HostCallback, &result);
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
std::stringstream ss; std::stringstream ss;
ss << result.host_; ss << result.host_;
EXPECT_EQ("{'www.third.gov' aliases=[] addrs=[2.3.4.5]}", ss.str()); EXPECT_EQ("{'www.third.gov' aliases=[] addrs=[2.3.4.5]}", ss.str());
} }
// Relies on retries so is UDP-only // Relies on retries so is UDP-only
TEST_P(MockUDPChannelTest, SearchDomainsWithResentReply) { TEST_P(MockUDPChannelTest, SearchDomainsWithResentReply) {
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));
EXPECT_CALL(server_, OnRequest("www.first.com", ns_t_a)) EXPECT_CALL(server_, OnRequest("www.first.com", T_A))
.WillOnce(SetReply(&server_, &nofirst)); .WillOnce(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));
EXPECT_CALL(server_, OnRequest("www.second.org", ns_t_a)) EXPECT_CALL(server_, OnRequest("www.second.org", T_A))
.WillOnce(SetReply(&server_, &nosecond)); .WillOnce(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}));
// Before sending the real answer, resend an earlier reply // Before sending the real answer, resend an earlier reply
EXPECT_CALL(server_, OnRequest("www.third.gov", ns_t_a)) EXPECT_CALL(server_, OnRequest("www.third.gov", T_A))
.WillOnce(DoAll(SetReply(&server_, &nofirst), .WillOnce(DoAll(SetReply(&server_, &nofirst),
SetReplyQID(&server_, 123))) SetReplyQID(&server_, 123)))
.WillOnce(DoAll(SetReply(&server_, &yesthird), .WillOnce(DoAll(SetReply(&server_, &yesthird),
SetReplyQID(&server_, -1))); SetReplyQID(&server_, -1)));
HostResult result; HostResult result;
ares_gethostbyname(channel_, "www", AF_INET, HostCallback, &result); ares_gethostbyname(channel_, "www", AF_INET, HostCallback, &result);
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
std::stringstream ss; std::stringstream ss;
ss << result.host_; ss << result.host_;
EXPECT_EQ("{'www.third.gov' aliases=[] addrs=[2.3.4.5]}", ss.str()); EXPECT_EQ("{'www.third.gov' aliases=[] addrs=[2.3.4.5]}", ss.str());
} }
TEST_P(MockChannelTest, SearchDomainsBare) { TEST_P(MockChannelTest, SearchDomainsBare) {
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 nothird; DNSPacket nothird;
nothird.set_response().set_aa().set_rcode(ns_r_nxdomain) nothird.set_response().set_aa().set_rcode(NXDOMAIN)
.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_, &nothird)); .WillByDefault(SetReply(&server_, &nothird));
DNSPacket yesbare; DNSPacket yesbare;
yesbare.set_response().set_aa() yesbare.set_response().set_aa()
.add_question(new DNSQuestion("www", ns_t_a)) .add_question(new DNSQuestion("www", T_A))
.add_answer(new DNSARR("www", 0x0200, {2, 3, 4, 5})); .add_answer(new DNSARR("www", 0x0200, {2, 3, 4, 5}));
ON_CALL(server_, OnRequest("www", ns_t_a)) ON_CALL(server_, OnRequest("www", T_A))
.WillByDefault(SetReply(&server_, &yesbare)); .WillByDefault(SetReply(&server_, &yesbare));
HostResult result; HostResult result;
ares_gethostbyname(channel_, "www", AF_INET, HostCallback, &result); ares_gethostbyname(channel_, "www", AF_INET, HostCallback, &result);
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
std::stringstream ss; std::stringstream ss;
ss << result.host_; ss << result.host_;
EXPECT_EQ("{'www' aliases=[] addrs=[2.3.4.5]}", ss.str()); EXPECT_EQ("{'www' aliases=[] addrs=[2.3.4.5]}", ss.str());
} }
TEST_P(MockChannelTest, SearchNoDataThenSuccess) { TEST_P(MockChannelTest, SearchNoDataThenSuccess) {
// First two search domains recognize the name but have no A records. // First two search domains recognize the name but have no A records.
DNSPacket nofirst; DNSPacket nofirst;
nofirst.set_response().set_aa() nofirst.set_response().set_aa()
.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() nosecond.set_response().set_aa()
.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));
HostResult result; HostResult result;
ares_gethostbyname(channel_, "www", AF_INET, HostCallback, &result); ares_gethostbyname(channel_, "www", AF_INET, HostCallback, &result);
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
std::stringstream ss; std::stringstream ss;
ss << result.host_; ss << result.host_;
EXPECT_EQ("{'www.third.gov' aliases=[] addrs=[2.3.4.5]}", ss.str()); EXPECT_EQ("{'www.third.gov' aliases=[] addrs=[2.3.4.5]}", ss.str());
} }
TEST_P(MockChannelTest, SearchNoDataThenNoDataBare) { TEST_P(MockChannelTest, SearchNoDataThenNoDataBare) {
// First two search domains recognize the name but have no A records. // First two search domains recognize the name but have no A records.
DNSPacket nofirst; DNSPacket nofirst;
nofirst.set_response().set_aa() nofirst.set_response().set_aa()
.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() nosecond.set_response().set_aa()
.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 nothird; DNSPacket nothird;
nothird.set_response().set_aa() nothird.set_response().set_aa()
.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_, &nothird)); .WillByDefault(SetReply(&server_, &nothird));
DNSPacket nobare; DNSPacket nobare;
nobare.set_response().set_aa() nobare.set_response().set_aa()
.add_question(new DNSQuestion("www", ns_t_a)); .add_question(new DNSQuestion("www", T_A));
ON_CALL(server_, OnRequest("www", ns_t_a)) ON_CALL(server_, OnRequest("www", T_A))
.WillByDefault(SetReply(&server_, &nobare)); .WillByDefault(SetReply(&server_, &nobare));
HostResult result; HostResult result;
ares_gethostbyname(channel_, "www", AF_INET, HostCallback, &result); ares_gethostbyname(channel_, "www", AF_INET, HostCallback, &result);
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
EXPECT_EQ(ARES_ENODATA, result.status_); EXPECT_EQ(ARES_ENODATA, result.status_);
} }
TEST_P(MockChannelTest, SearchNoDataThenFail) { TEST_P(MockChannelTest, SearchNoDataThenFail) {
// First two search domains recognize the name but have no A records. // First two search domains recognize the name but have no A records.
DNSPacket nofirst; DNSPacket nofirst;
nofirst.set_response().set_aa() nofirst.set_response().set_aa()
.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() nosecond.set_response().set_aa()
.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 nothird; DNSPacket nothird;
nothird.set_response().set_aa() nothird.set_response().set_aa()
.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_, &nothird)); .WillByDefault(SetReply(&server_, &nothird));
DNSPacket nobare; DNSPacket nobare;
nobare.set_response().set_aa().set_rcode(ns_r_nxdomain) nobare.set_response().set_aa().set_rcode(NXDOMAIN)
.add_question(new DNSQuestion("www", ns_t_a)); .add_question(new DNSQuestion("www", T_A));
ON_CALL(server_, OnRequest("www", ns_t_a)) ON_CALL(server_, OnRequest("www", T_A))
.WillByDefault(SetReply(&server_, &nobare)); .WillByDefault(SetReply(&server_, &nobare));
HostResult result; HostResult result;
ares_gethostbyname(channel_, "www", AF_INET, HostCallback, &result); ares_gethostbyname(channel_, "www", AF_INET, HostCallback, &result);
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
EXPECT_EQ(ARES_ENODATA, result.status_); EXPECT_EQ(ARES_ENODATA, result.status_);
} }
TEST_P(MockChannelTest, SearchAllocFailure) { TEST_P(MockChannelTest, SearchAllocFailure) {
SearchResult result; SearchResult result;
SetAllocFail(1); SetAllocFail(1);
ares_search(channel_, "fully.qualified.", ns_c_in, ns_t_a, SearchCallback, &re sult); ares_search(channel_, "fully.qualified.", C_IN, T_A, SearchCallback, &result);
/* Already done */ /* Already done */
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
EXPECT_EQ(ARES_ENOMEM, result.status_); EXPECT_EQ(ARES_ENOMEM, result.status_);
} }
TEST_P(MockChannelTest, SearchHighNdots) { TEST_P(MockChannelTest, SearchHighNdots) {
DNSPacket nobare; DNSPacket nobare;
nobare.set_response().set_aa().set_rcode(ns_r_nxdomain) nobare.set_response().set_aa().set_rcode(NXDOMAIN)
.add_question(new DNSQuestion("a.b.c.w.w.w", ns_t_a)); .add_question(new DNSQuestion("a.b.c.w.w.w", T_A));
ON_CALL(server_, OnRequest("a.b.c.w.w.w", ns_t_a)) ON_CALL(server_, OnRequest("a.b.c.w.w.w", T_A))
.WillByDefault(SetReply(&server_, &nobare)); .WillByDefault(SetReply(&server_, &nobare));
DNSPacket yesfirst; DNSPacket yesfirst;
yesfirst.set_response().set_aa() yesfirst.set_response().set_aa()
.add_question(new DNSQuestion("a.b.c.w.w.w.first.com", ns_t_a)) .add_question(new DNSQuestion("a.b.c.w.w.w.first.com", T_A))
.add_answer(new DNSARR("a.b.c.w.w.w.first.com", 0x0200, {2, 3, 4, 5})); .add_answer(new DNSARR("a.b.c.w.w.w.first.com", 0x0200, {2, 3, 4, 5}));
ON_CALL(server_, OnRequest("a.b.c.w.w.w.first.com", ns_t_a)) ON_CALL(server_, OnRequest("a.b.c.w.w.w.first.com", T_A))
.WillByDefault(SetReply(&server_, &yesfirst)); .WillByDefault(SetReply(&server_, &yesfirst));
SearchResult result; SearchResult result;
ares_search(channel_, "a.b.c.w.w.w", ns_c_in, ns_t_a, SearchCallback, &result) ; ares_search(channel_, "a.b.c.w.w.w", C_IN, T_A, SearchCallback, &result);
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
EXPECT_EQ(ARES_SUCCESS, result.status_); EXPECT_EQ(ARES_SUCCESS, result.status_);
std::stringstream ss; std::stringstream ss;
ss << PacketToString(result.data_); ss << PacketToString(result.data_);
EXPECT_EQ("RSP QRY AA NOERROR Q:{'a.b.c.w.w.w.first.com' IN A} " EXPECT_EQ("RSP QRY AA NOERROR Q:{'a.b.c.w.w.w.first.com' IN A} "
"A:{'a.b.c.w.w.w.first.com' IN A TTL=512 2.3.4.5}", "A:{'a.b.c.w.w.w.first.com' IN A TTL=512 2.3.4.5}",
ss.str()); ss.str());
} }
TEST_P(MockChannelTest, UnspecifiedFamilyV6) { TEST_P(MockChannelTest, UnspecifiedFamilyV6) {
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));
HostResult result; HostResult result;
ares_gethostbyname(channel_, "example.com.", AF_UNSPEC, HostCallback, &result) ; ares_gethostbyname(channel_, "example.com.", AF_UNSPEC, HostCallback, &result) ;
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
std::stringstream ss; std::stringstream ss;
ss << result.host_; ss << result.host_;
// Default to IPv6 when both are available. // Default to IPv6 when both are available.
EXPECT_EQ("{'example.com' aliases=[] addrs=[2121:0000:0000:0000:0000:0000:0000 :0303]}", ss.str()); EXPECT_EQ("{'example.com' aliases=[] addrs=[2121:0000:0000:0000:0000:0000:0000 :0303]}", ss.str());
} }
TEST_P(MockChannelTest, UnspecifiedFamilyV4) { TEST_P(MockChannelTest, UnspecifiedFamilyV4) {
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));
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));
HostResult result; HostResult result;
ares_gethostbyname(channel_, "example.com.", AF_UNSPEC, HostCallback, &result) ; ares_gethostbyname(channel_, "example.com.", AF_UNSPEC, HostCallback, &result) ;
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
std::stringstream ss; std::stringstream ss;
ss << result.host_; ss << result.host_;
EXPECT_EQ("{'example.com' aliases=[] addrs=[2.3.4.5]}", ss.str()); EXPECT_EQ("{'example.com' aliases=[] addrs=[2.3.4.5]}", ss.str());
} }
TEST_P(MockChannelTest, UnspecifiedFamilyNoData) { TEST_P(MockChannelTest, UnspecifiedFamilyNoData) {
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 DNSCnameRR("example.com", 100, "elsewhere.com")); .add_answer(new DNSCnameRR("example.com", 100, "elsewhere.com"));
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));
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));
HostResult result; HostResult result;
ares_gethostbyname(channel_, "example.com.", AF_UNSPEC, HostCallback, &result) ; ares_gethostbyname(channel_, "example.com.", AF_UNSPEC, HostCallback, &result) ;
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
std::stringstream ss; std::stringstream ss;
ss << result.host_; ss << result.host_;
EXPECT_EQ("{'' aliases=[] addrs=[]}", ss.str()); EXPECT_EQ("{'' aliases=[] addrs=[]}", ss.str());
} }
TEST_P(MockChannelTest, UnspecifiedFamilyCname6A4) { TEST_P(MockChannelTest, UnspecifiedFamilyCname6A4) {
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 DNSCnameRR("example.com", 100, "elsewhere.com")); .add_answer(new DNSCnameRR("example.com", 100, "elsewhere.com"));
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, {1, 2, 3, 4})); .add_answer(new DNSARR("example.com", 100, {1, 2, 3, 4}));
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));
HostResult result; HostResult result;
ares_gethostbyname(channel_, "example.com.", AF_UNSPEC, HostCallback, &result) ; ares_gethostbyname(channel_, "example.com.", AF_UNSPEC, HostCallback, &result) ;
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
std::stringstream ss; std::stringstream ss;
ss << result.host_; ss << result.host_;
EXPECT_EQ("{'example.com' aliases=[] addrs=[1.2.3.4]}", ss.str()); EXPECT_EQ("{'example.com' aliases=[] addrs=[1.2.3.4]}", ss.str());
} }
skipping to change at line 737 skipping to change at line 737
HostResult result; HostResult result;
SetAllocSizeFail(strlen("1.2.3.4") + 1); SetAllocSizeFail(strlen("1.2.3.4") + 1);
ares_gethostbyname(channel_, "1.2.3.4", AF_INET, HostCallback, &result); ares_gethostbyname(channel_, "1.2.3.4", AF_INET, HostCallback, &result);
EXPECT_TRUE(result.done_); // Immediate return EXPECT_TRUE(result.done_); // Immediate return
EXPECT_EQ(ARES_ENOMEM, result.status_); EXPECT_EQ(ARES_ENOMEM, result.status_);
} }
TEST_P(MockChannelTest, SortListV4) { TEST_P(MockChannelTest, SortListV4) {
DNSPacket rsp; DNSPacket rsp;
rsp.set_response().set_aa() rsp.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, {22, 23, 24, 25})) .add_answer(new DNSARR("example.com", 100, {22, 23, 24, 25}))
.add_answer(new DNSARR("example.com", 100, {12, 13, 14, 15})) .add_answer(new DNSARR("example.com", 100, {12, 13, 14, 15}))
.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_, &rsp)); .WillByDefault(SetReply(&server_, &rsp));
{ {
EXPECT_EQ(ARES_SUCCESS, ares_set_sortlist(channel_, "12.13.0.0/255.255.0.0 1 234::5678")); EXPECT_EQ(ARES_SUCCESS, ares_set_sortlist(channel_, "12.13.0.0/255.255.0.0 1 234::5678"));
HostResult result; HostResult result;
ares_gethostbyname(channel_, "example.com.", AF_INET, HostCallback, &result) ; ares_gethostbyname(channel_, "example.com.", AF_INET, HostCallback, &result) ;
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
std::stringstream ss; std::stringstream ss;
ss << result.host_; ss << result.host_;
skipping to change at line 775 skipping to change at line 775
memset(&options, 0, sizeof(options)); memset(&options, 0, sizeof(options));
int optmask = 0; int optmask = 0;
EXPECT_EQ(ARES_SUCCESS, ares_save_options(channel_, &options, &optmask)); EXPECT_EQ(ARES_SUCCESS, ares_save_options(channel_, &options, &optmask));
EXPECT_TRUE((optmask & ARES_OPT_SORTLIST) == ARES_OPT_SORTLIST); EXPECT_TRUE((optmask & ARES_OPT_SORTLIST) == ARES_OPT_SORTLIST);
ares_destroy_options(&options); ares_destroy_options(&options);
} }
TEST_P(MockChannelTest, SortListV6) { TEST_P(MockChannelTest, SortListV6) {
DNSPacket rsp; DNSPacket rsp;
rsp.set_response().set_aa() rsp.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,
{0x11, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, {0x11, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02})) 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02}))
.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_, &rsp)); .WillByDefault(SetReply(&server_, &rsp));
{ {
ares_set_sortlist(channel_, "1111::/16 2.3.0.0/255.255.0.0"); ares_set_sortlist(channel_, "1111::/16 2.3.0.0/255.255.0.0");
HostResult result; HostResult result;
ares_gethostbyname(channel_, "example.com.", AF_INET6, HostCallback, &result ); ares_gethostbyname(channel_, "example.com.", AF_INET6, HostCallback, &result );
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
std::stringstream ss; std::stringstream ss;
ss << result.host_; ss << result.host_;
skipping to change at line 812 skipping to change at line 812
std::stringstream ss; std::stringstream ss;
ss << result.host_; ss << result.host_;
EXPECT_EQ("{'example.com' aliases=[] addrs=[2121:0000:0000:0000:0000:0000:00 00:0303, " EXPECT_EQ("{'example.com' aliases=[] addrs=[2121:0000:0000:0000:0000:0000:00 00:0303, "
"1111:0000:0000:0000:0000:0000:0000:0202]}", ss.str()); "1111:0000:0000:0000:0000:0000:0000:0202]}", ss.str());
} }
} }
// Relies on retries so is UDP-only // Relies on retries so is UDP-only
TEST_P(MockUDPChannelTest, SearchDomainsAllocFail) { TEST_P(MockUDPChannelTest, SearchDomainsAllocFail) {
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));
// Fail a variety of different memory allocations, and confirm // Fail a variety of different memory allocations, and confirm
// that the operation either fails with ENOMEM or succeeds // that the operation either fails with ENOMEM or succeeds
// with the expected result. // with the expected result.
const int kCount = 34; const int kCount = 34;
HostResult results[kCount]; HostResult results[kCount];
for (int ii = 1; ii <= kCount; ii++) { for (int ii = 1; ii <= kCount; ii++) {
HostResult* result = &(results[ii - 1]); HostResult* result = &(results[ii - 1]);
ClearFails(); ClearFails();
skipping to change at line 859 skipping to change at line 859
// are still valid (in case any pending work refers to them). // are still valid (in case any pending work refers to them).
ares_destroy(channel_); ares_destroy(channel_);
channel_ = nullptr; channel_ = nullptr;
} }
// Relies on retries so is UDP-only // Relies on retries so is UDP-only
TEST_P(MockUDPChannelTest, Resend) { TEST_P(MockUDPChannelTest, Resend) {
std::vector<byte> nothing; std::vector<byte> nothing;
DNSPacket reply; DNSPacket reply;
reply.set_response().set_aa() reply.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", 0x0100, {0x01, 0x02, 0x03, 0x04})); .add_answer(new DNSARR("www.google.com", 0x0100, {0x01, 0x02, 0x03, 0x04}));
EXPECT_CALL(server_, OnRequest("www.google.com", ns_t_a)) EXPECT_CALL(server_, OnRequest("www.google.com", T_A))
.WillOnce(SetReplyData(&server_, nothing)) .WillOnce(SetReplyData(&server_, nothing))
.WillOnce(SetReplyData(&server_, nothing)) .WillOnce(SetReplyData(&server_, nothing))
.WillOnce(SetReply(&server_, &reply)); .WillOnce(SetReply(&server_, &reply));
HostResult result; HostResult result;
ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result ); ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result );
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
EXPECT_EQ(2, result.timeouts_); EXPECT_EQ(2, result.timeouts_);
std::stringstream ss; std::stringstream ss;
skipping to change at line 903 skipping to change at line 903
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
EXPECT_EQ(ARES_ECANCELLED, result.status_); EXPECT_EQ(ARES_ECANCELLED, result.status_);
EXPECT_EQ(0, result.timeouts_); EXPECT_EQ(0, result.timeouts_);
} }
// Relies on retries so is UDP-only // Relies on retries so is UDP-only
TEST_P(MockUDPChannelTest, CancelLater) { TEST_P(MockUDPChannelTest, CancelLater) {
std::vector<byte> nothing; std::vector<byte> nothing;
// On second request, cancel the channel. // On second request, cancel the channel.
EXPECT_CALL(server_, OnRequest("www.google.com", ns_t_a)) EXPECT_CALL(server_, OnRequest("www.google.com", T_A))
.WillOnce(SetReplyData(&server_, nothing)) .WillOnce(SetReplyData(&server_, nothing))
.WillOnce(CancelChannel(&server_, channel_)); .WillOnce(CancelChannel(&server_, channel_));
HostResult result; HostResult result;
ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result ); ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result );
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
EXPECT_EQ(ARES_ECANCELLED, result.status_); EXPECT_EQ(ARES_ECANCELLED, result.status_);
EXPECT_EQ(0, result.timeouts_); EXPECT_EQ(0, result.timeouts_);
} }
skipping to change at line 942 skipping to change at line 942
channel_ = nullptr; channel_ = nullptr;
EXPECT_TRUE(result.done_); // Synchronous EXPECT_TRUE(result.done_); // Synchronous
EXPECT_EQ(ARES_EDESTRUCTION, result.status_); EXPECT_EQ(ARES_EDESTRUCTION, result.status_);
EXPECT_EQ(0, result.timeouts_); EXPECT_EQ(0, result.timeouts_);
} }
TEST_P(MockChannelTest, GetHostByNameCNAMENoData) { TEST_P(MockChannelTest, GetHostByNameCNAMENoData) {
DNSPacket response; DNSPacket response;
response.set_response().set_aa() response.set_response().set_aa()
.add_question(new DNSQuestion("cname.first.com", ns_t_a)) .add_question(new DNSQuestion("cname.first.com", T_A))
.add_answer(new DNSCnameRR("cname.first.com", 100, "a.first.com")); .add_answer(new DNSCnameRR("cname.first.com", 100, "a.first.com"));
ON_CALL(server_, OnRequest("cname.first.com", ns_t_a)) ON_CALL(server_, OnRequest("cname.first.com", T_A))
.WillByDefault(SetReply(&server_, &response)); .WillByDefault(SetReply(&server_, &response));
HostResult result; HostResult result;
ares_gethostbyname(channel_, "cname.first.com", AF_INET, HostCallback, &result ); ares_gethostbyname(channel_, "cname.first.com", AF_INET, HostCallback, &result );
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
EXPECT_EQ(ARES_ENODATA, result.status_); EXPECT_EQ(ARES_ENODATA, result.status_);
} }
TEST_P(MockChannelTest, GetHostByAddrDestroy) { TEST_P(MockChannelTest, GetHostByAddrDestroy) {
skipping to change at line 971 skipping to change at line 971
EXPECT_TRUE(result.done_); // Synchronous EXPECT_TRUE(result.done_); // Synchronous
EXPECT_EQ(ARES_EDESTRUCTION, result.status_); EXPECT_EQ(ARES_EDESTRUCTION, result.status_);
EXPECT_EQ(0, result.timeouts_); EXPECT_EQ(0, result.timeouts_);
} }
#ifndef WIN32 #ifndef WIN32
TEST_P(MockChannelTest, HostAlias) { TEST_P(MockChannelTest, HostAlias) {
DNSPacket reply; DNSPacket reply;
reply.set_response().set_aa() reply.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", 0x0100, {0x01, 0x02, 0x03, 0x04})); .add_answer(new DNSARR("www.google.com", 0x0100, {0x01, 0x02, 0x03, 0x04}));
ON_CALL(server_, OnRequest("www.google.com", ns_t_a)) ON_CALL(server_, OnRequest("www.google.com", T_A))
.WillByDefault(SetReply(&server_, &reply)); .WillByDefault(SetReply(&server_, &reply));
TempFile aliases("\n\n# www commentedout\nwww www.google.com\n"); TempFile aliases("\n\n# www commentedout\nwww www.google.com\n");
EnvValue with_env("HOSTALIASES", aliases.filename()); EnvValue with_env("HOSTALIASES", aliases.filename());
HostResult result; HostResult result;
ares_gethostbyname(channel_, "www", AF_INET, HostCallback, &result); ares_gethostbyname(channel_, "www", AF_INET, HostCallback, &result);
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
std::stringstream ss; std::stringstream ss;
ss << result.host_; ss << result.host_;
EXPECT_EQ("{'www.google.com' aliases=[] addrs=[1.2.3.4]}", ss.str()); EXPECT_EQ("{'www.google.com' aliases=[] addrs=[1.2.3.4]}", ss.str());
} }
TEST_P(MockChannelTest, HostAliasMissing) { TEST_P(MockChannelTest, HostAliasMissing) {
DNSPacket yesfirst; DNSPacket yesfirst;
yesfirst.set_response().set_aa() yesfirst.set_response().set_aa()
.add_question(new DNSQuestion("www.first.com", ns_t_a)) .add_question(new DNSQuestion("www.first.com", T_A))
.add_answer(new DNSARR("www.first.com", 0x0200, {2, 3, 4, 5})); .add_answer(new DNSARR("www.first.com", 0x0200, {2, 3, 4, 5}));
ON_CALL(server_, OnRequest("www.first.com", ns_t_a)) ON_CALL(server_, OnRequest("www.first.com", T_A))
.WillByDefault(SetReply(&server_, &yesfirst)); .WillByDefault(SetReply(&server_, &yesfirst));
TempFile aliases("\n\n# www commentedout\nww www.google.com\n"); TempFile aliases("\n\n# www commentedout\nww www.google.com\n");
EnvValue with_env("HOSTALIASES", aliases.filename()); EnvValue with_env("HOSTALIASES", aliases.filename());
HostResult result; HostResult result;
ares_gethostbyname(channel_, "www", AF_INET, HostCallback, &result); ares_gethostbyname(channel_, "www", AF_INET, HostCallback, &result);
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
std::stringstream ss; std::stringstream ss;
ss << result.host_; ss << result.host_;
EXPECT_EQ("{'www.first.com' aliases=[] addrs=[2.3.4.5]}", ss.str()); EXPECT_EQ("{'www.first.com' aliases=[] addrs=[2.3.4.5]}", ss.str());
} }
TEST_P(MockChannelTest, HostAliasMissingFile) { TEST_P(MockChannelTest, HostAliasMissingFile) {
DNSPacket yesfirst; DNSPacket yesfirst;
yesfirst.set_response().set_aa() yesfirst.set_response().set_aa()
.add_question(new DNSQuestion("www.first.com", ns_t_a)) .add_question(new DNSQuestion("www.first.com", T_A))
.add_answer(new DNSARR("www.first.com", 0x0200, {2, 3, 4, 5})); .add_answer(new DNSARR("www.first.com", 0x0200, {2, 3, 4, 5}));
ON_CALL(server_, OnRequest("www.first.com", ns_t_a)) ON_CALL(server_, OnRequest("www.first.com", T_A))
.WillByDefault(SetReply(&server_, &yesfirst)); .WillByDefault(SetReply(&server_, &yesfirst));
EnvValue with_env("HOSTALIASES", "bogus.mcfile"); EnvValue with_env("HOSTALIASES", "bogus.mcfile");
HostResult result; HostResult result;
ares_gethostbyname(channel_, "www", AF_INET, HostCallback, &result); ares_gethostbyname(channel_, "www", AF_INET, HostCallback, &result);
Process(); Process();
EXPECT_TRUE(result.done_); EXPECT_TRUE(result.done_);
std::stringstream ss; std::stringstream ss;
ss << result.host_; ss << result.host_;
EXPECT_EQ("{'www.first.com' aliases=[] addrs=[2.3.4.5]}", ss.str()); EXPECT_EQ("{'www.first.com' aliases=[] addrs=[2.3.4.5]}", ss.str());
skipping to change at line 1073 skipping to change at line 1073
}; };
TEST_P(RotateMultiMockTest, ThirdServer) { TEST_P(RotateMultiMockTest, 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(NoRotateMultiMockTest, ThirdServer) { TEST_P(NoRotateMultiMockTest, 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();
} }
INSTANTIATE_TEST_CASE_P(AddressFamilies, MockChannelTest, ::testing::ValuesIn(ar es::test::families_modes)); INSTANTIATE_TEST_CASE_P(AddressFamilies, MockChannelTest, ::testing::ValuesIn(ar es::test::families_modes));
INSTANTIATE_TEST_CASE_P(AddressFamilies, MockUDPChannelTest, ::testing::ValuesIn (ares::test::families)); INSTANTIATE_TEST_CASE_P(AddressFamilies, MockUDPChannelTest, ::testing::ValuesIn (ares::test::families));
INSTANTIATE_TEST_CASE_P(AddressFamilies, MockTCPChannelTest, ::testing::ValuesIn (ares::test::families)); INSTANTIATE_TEST_CASE_P(AddressFamilies, MockTCPChannelTest, ::testing::ValuesIn (ares::test::families));
 End of changes. 112 change blocks. 
166 lines changed or deleted 166 lines changed or added

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