"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "test/ares-test-parse-ns.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-parse-ns.cc  (c-ares-1.17.1):ares-test-parse-ns.cc  (c-ares-1.17.2)
skipping to change at line 13 skipping to change at line 13
#include <sstream> #include <sstream>
#include <vector> #include <vector>
namespace ares { namespace ares {
namespace test { namespace test {
TEST_F(LibraryTest, ParseNsReplyOK) { TEST_F(LibraryTest, ParseNsReplyOK) {
DNSPacket pkt; DNSPacket pkt;
pkt.set_qid(0x1234).set_response().set_aa() pkt.set_qid(0x1234).set_response().set_aa()
.add_question(new DNSQuestion("example.com", ns_t_ns)) .add_question(new DNSQuestion("example.com", T_NS))
.add_answer(new DNSNsRR("example.com", 100, "ns.example.com")); .add_answer(new DNSNsRR("example.com", 100, "ns.example.com"));
std::vector<byte> data = pkt.data(); std::vector<byte> data = pkt.data();
struct hostent *host = nullptr; struct hostent *host = nullptr;
EXPECT_EQ(ARES_SUCCESS, ares_parse_ns_reply(data.data(), data.size(), &host)); EXPECT_EQ(ARES_SUCCESS, ares_parse_ns_reply(data.data(), data.size(), &host));
ASSERT_NE(nullptr, host); ASSERT_NE(nullptr, host);
std::stringstream ss; std::stringstream ss;
ss << HostEnt(host); ss << HostEnt(host);
EXPECT_EQ("{'example.com' aliases=[ns.example.com] addrs=[]}", ss.str()); EXPECT_EQ("{'example.com' aliases=[ns.example.com] addrs=[]}", ss.str());
ares_free_hostent(host); ares_free_hostent(host);
} }
TEST_F(LibraryTest, ParseNsReplyMultiple) { TEST_F(LibraryTest, ParseNsReplyMultiple) {
DNSPacket pkt; DNSPacket pkt;
pkt.set_qid(10501).set_response().set_rd().set_ra() pkt.set_qid(10501).set_response().set_rd().set_ra()
.add_question(new DNSQuestion("google.com", ns_t_ns)) .add_question(new DNSQuestion("google.com", T_NS))
.add_answer(new DNSNsRR("google.com", 59, "ns1.google.com")) .add_answer(new DNSNsRR("google.com", 59, "ns1.google.com"))
.add_answer(new DNSNsRR("google.com", 59, "ns2.google.com")) .add_answer(new DNSNsRR("google.com", 59, "ns2.google.com"))
.add_answer(new DNSNsRR("google.com", 59, "ns3.google.com")) .add_answer(new DNSNsRR("google.com", 59, "ns3.google.com"))
.add_answer(new DNSNsRR("google.com", 59, "ns4.google.com")) .add_answer(new DNSNsRR("google.com", 59, "ns4.google.com"))
.add_additional(new DNSARR("ns4.google.com", 247, {216,239,38,10})) .add_additional(new DNSARR("ns4.google.com", 247, {216,239,38,10}))
.add_additional(new DNSARR("ns2.google.com", 247, {216,239,34,10})) .add_additional(new DNSARR("ns2.google.com", 247, {216,239,34,10}))
.add_additional(new DNSARR("ns1.google.com", 247, {216,239,32,10})) .add_additional(new DNSARR("ns1.google.com", 247, {216,239,32,10}))
.add_additional(new DNSARR("ns3.google.com", 247, {216,239,36,10})); .add_additional(new DNSARR("ns3.google.com", 247, {216,239,36,10}));
std::vector<byte> data = pkt.data(); std::vector<byte> data = pkt.data();
skipping to change at line 52 skipping to change at line 52
ASSERT_NE(nullptr, host); ASSERT_NE(nullptr, host);
std::stringstream ss; std::stringstream ss;
ss << HostEnt(host); ss << HostEnt(host);
EXPECT_EQ("{'google.com' aliases=[ns1.google.com, ns2.google.com, ns3.google.c om, ns4.google.com] addrs=[]}", ss.str()); EXPECT_EQ("{'google.com' aliases=[ns1.google.com, ns2.google.com, ns3.google.c om, ns4.google.com] addrs=[]}", ss.str());
ares_free_hostent(host); ares_free_hostent(host);
} }
TEST_F(LibraryTest, ParseNsReplyErrors) { TEST_F(LibraryTest, ParseNsReplyErrors) {
DNSPacket pkt; DNSPacket pkt;
pkt.set_qid(0x1234).set_response().set_aa() pkt.set_qid(0x1234).set_response().set_aa()
.add_question(new DNSQuestion("example.com", ns_t_ns)) .add_question(new DNSQuestion("example.com", T_NS))
.add_answer(new DNSNsRR("example.com", 100, "ns.example.com")); .add_answer(new DNSNsRR("example.com", 100, "ns.example.com"));
std::vector<byte> data; std::vector<byte> data;
struct hostent *host = nullptr; struct hostent *host = nullptr;
// No question. // No question.
pkt.questions_.clear(); pkt.questions_.clear();
data = pkt.data(); data = pkt.data();
EXPECT_EQ(ARES_EBADRESP, ares_parse_ns_reply(data.data(), data.size(), &host)) ; EXPECT_EQ(ARES_EBADRESP, ares_parse_ns_reply(data.data(), data.size(), &host)) ;
pkt.add_question(new DNSQuestion("example.com", ns_t_ns)); pkt.add_question(new DNSQuestion("example.com", T_NS));
#ifdef DISABLED #ifdef DISABLED
// Question != answer // Question != answer
pkt.questions_.clear(); pkt.questions_.clear();
pkt.add_question(new DNSQuestion("Axample.com", ns_t_ns)); pkt.add_question(new DNSQuestion("Axample.com", T_NS));
data = pkt.data(); data = pkt.data();
EXPECT_EQ(ARES_ENODATA, ares_parse_ns_reply(data.data(), data.size(), &host)); EXPECT_EQ(ARES_ENODATA, ares_parse_ns_reply(data.data(), data.size(), &host));
pkt.questions_.clear(); pkt.questions_.clear();
pkt.add_question(new DNSQuestion("example.com", ns_t_ns)); pkt.add_question(new DNSQuestion("example.com", T_NS));
#endif #endif
// Two questions. // Two questions.
pkt.add_question(new DNSQuestion("example.com", ns_t_ns)); pkt.add_question(new DNSQuestion("example.com", T_NS));
data = pkt.data(); data = pkt.data();
EXPECT_EQ(ARES_EBADRESP, ares_parse_ns_reply(data.data(), data.size(), &host)) ; EXPECT_EQ(ARES_EBADRESP, ares_parse_ns_reply(data.data(), data.size(), &host)) ;
pkt.questions_.clear(); pkt.questions_.clear();
pkt.add_question(new DNSQuestion("example.com", ns_t_ns)); pkt.add_question(new DNSQuestion("example.com", T_NS));
// Wrong sort of answer. // Wrong sort of answer.
pkt.answers_.clear(); pkt.answers_.clear();
pkt.add_answer(new DNSMxRR("example.com", 100, 100, "mx1.example.com")); pkt.add_answer(new DNSMxRR("example.com", 100, 100, "mx1.example.com"));
data = pkt.data(); data = pkt.data();
EXPECT_EQ(ARES_ENODATA, ares_parse_ns_reply(data.data(), data.size(), &host)); EXPECT_EQ(ARES_ENODATA, ares_parse_ns_reply(data.data(), data.size(), &host));
pkt.answers_.clear(); pkt.answers_.clear();
pkt.add_answer(new DNSNsRR("example.com", 100, "ns.example.com")); pkt.add_answer(new DNSNsRR("example.com", 100, "ns.example.com"));
// No answer. // No answer.
skipping to change at line 104 skipping to change at line 104
// Truncated packets. // Truncated packets.
data = pkt.data(); data = pkt.data();
for (size_t len = 1; len < data.size(); len++) { for (size_t len = 1; len < data.size(); len++) {
EXPECT_EQ(ARES_EBADRESP, ares_parse_ns_reply(data.data(), len, &host)); EXPECT_EQ(ARES_EBADRESP, ares_parse_ns_reply(data.data(), len, &host));
} }
} }
TEST_F(LibraryTest, ParseNsReplyAllocFail) { TEST_F(LibraryTest, ParseNsReplyAllocFail) {
DNSPacket pkt; DNSPacket pkt;
pkt.set_qid(0x1234).set_response().set_aa() pkt.set_qid(0x1234).set_response().set_aa()
.add_question(new DNSQuestion("example.com", ns_t_ns)) .add_question(new DNSQuestion("example.com", T_NS))
.add_answer(new DNSCnameRR("example.com", 300, "c.example.com")) .add_answer(new DNSCnameRR("example.com", 300, "c.example.com"))
.add_answer(new DNSNsRR("c.example.com", 100, "ns.example.com")); .add_answer(new DNSNsRR("c.example.com", 100, "ns.example.com"));
std::vector<byte> data = pkt.data(); std::vector<byte> data = pkt.data();
struct hostent *host = nullptr; struct hostent *host = nullptr;
for (int ii = 1; ii <= 8; ii++) { for (int ii = 1; ii <= 8; ii++) {
ClearFails(); ClearFails();
SetAllocFail(ii); SetAllocFail(ii);
EXPECT_EQ(ARES_ENOMEM, ares_parse_ns_reply(data.data(), data.size(), &host)) << ii; EXPECT_EQ(ARES_ENOMEM, ares_parse_ns_reply(data.data(), data.size(), &host)) << ii;
} }
 End of changes. 9 change blocks. 
9 lines changed or deleted 9 lines changed or added

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