"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "test/ares-test-parse-a.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-a.cc  (c-ares-1.17.1):ares-test-parse-a.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, ParseAReplyOK) { TEST_F(LibraryTest, ParseAReplyOK) {
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_a)) .add_question(new DNSQuestion("example.com", T_A))
.add_answer(new DNSARR("example.com", 0x01020304, {2,3,4,5})) .add_answer(new DNSARR("example.com", 0x01020304, {2,3,4,5}))
.add_answer(new DNSAaaaRR("example.com", 0x01020304, {0,0,0,0,0,0,0,0,0,0,0, 0,2,3,4,5})); .add_answer(new DNSAaaaRR("example.com", 0x01020304, {0,0,0,0,0,0,0,0,0,0,0, 0,2,3,4,5}));
std::vector<byte> data = { std::vector<byte> data = {
0x12, 0x34, // qid 0x12, 0x34, // qid
0x84, // response + query + AA + not-TC + not-RD 0x84, // response + query + AA + not-TC + not-RD
0x00, // not-RA + not-Z + not-AD + not-CD + rc=NoError 0x00, // not-RA + not-Z + not-AD + not-CD + rc=NoError
0x00, 0x01, // num questions 0x00, 0x01, // num questions
0x00, 0x02, // num answer RRs 0x00, 0x02, // num answer RRs
0x00, 0x00, // num authority RRs 0x00, 0x00, // num authority RRs
0x00, 0x00, // num additional RRs 0x00, 0x00, // num additional RRs
skipping to change at line 122 skipping to change at line 122
&host, info, &count)); &host, info, &count));
// Truncate mid-answer. // Truncate mid-answer.
EXPECT_EQ(ARES_EBADRESP, ares_parse_a_reply(data.data(), 42, EXPECT_EQ(ARES_EBADRESP, ares_parse_a_reply(data.data(), 42,
&host, info, &count)); &host, info, &count));
} }
TEST_F(LibraryTest, ParseAReplyNoData) { TEST_F(LibraryTest, ParseAReplyNoData) {
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_a)); .add_question(new DNSQuestion("example.com", T_A));
std::vector<byte> data = pkt.data(); std::vector<byte> data = pkt.data();
struct hostent *host = nullptr; struct hostent *host = nullptr;
struct ares_addrttl info[2]; struct ares_addrttl info[2];
int count = 2; int count = 2;
EXPECT_EQ(ARES_ENODATA, ares_parse_a_reply(data.data(), data.size(), EXPECT_EQ(ARES_ENODATA, ares_parse_a_reply(data.data(), data.size(),
&host, info, &count)); &host, info, &count));
EXPECT_EQ(0, count); EXPECT_EQ(0, count);
EXPECT_EQ(nullptr, host); EXPECT_EQ(nullptr, host);
// Again but with a CNAME. // Again but with a CNAME.
skipping to change at line 149 skipping to change at line 149
EXPECT_NE(nullptr, host); EXPECT_NE(nullptr, host);
std::stringstream ss; std::stringstream ss;
ss << HostEnt(host); ss << HostEnt(host);
EXPECT_EQ("{'c.example.com' aliases=[example.com] addrs=[]}", ss.str()); EXPECT_EQ("{'c.example.com' aliases=[example.com] addrs=[]}", ss.str());
ares_free_hostent(host); ares_free_hostent(host);
} }
TEST_F(LibraryTest, ParseAReplyVariantA) { TEST_F(LibraryTest, ParseAReplyVariantA) {
DNSPacket pkt; DNSPacket pkt;
pkt.set_qid(6366).set_rd().set_ra() pkt.set_qid(6366).set_rd().set_ra()
.add_question(new DNSQuestion("mit.edu", ns_t_a)) .add_question(new DNSQuestion("mit.edu", T_A))
.add_answer(new DNSARR("mit.edu", 52, {18,7,22,69})) .add_answer(new DNSARR("mit.edu", 52, {18,7,22,69}))
.add_auth(new DNSNsRR("mit.edu", 292, "W20NS.mit.edu")) .add_auth(new DNSNsRR("mit.edu", 292, "W20NS.mit.edu"))
.add_auth(new DNSNsRR("mit.edu", 292, "BITSY.mit.edu")) .add_auth(new DNSNsRR("mit.edu", 292, "BITSY.mit.edu"))
.add_auth(new DNSNsRR("mit.edu", 292, "STRAWB.mit.edu")) .add_auth(new DNSNsRR("mit.edu", 292, "STRAWB.mit.edu"))
.add_additional(new DNSARR("STRAWB.mit.edu", 292, {18,71,0,151})); .add_additional(new DNSARR("STRAWB.mit.edu", 292, {18,71,0,151}));
struct hostent *host = nullptr; struct hostent *host = nullptr;
struct ares_addrttl info[2]; struct ares_addrttl info[2];
int count = 2; int count = 2;
std::vector<byte> data = pkt.data(); std::vector<byte> data = pkt.data();
EXPECT_EQ(ARES_SUCCESS, ares_parse_a_reply(data.data(), data.size(), EXPECT_EQ(ARES_SUCCESS, ares_parse_a_reply(data.data(), data.size(),
&host, info, &count)); &host, info, &count));
EXPECT_EQ(1, count); EXPECT_EQ(1, count);
EXPECT_EQ("18.7.22.69", AddressToString(&(info[0].ipaddr), 4)); EXPECT_EQ("18.7.22.69", AddressToString(&(info[0].ipaddr), 4));
EXPECT_EQ(52, info[0].ttl); EXPECT_EQ(52, info[0].ttl);
ares_free_hostent(host); ares_free_hostent(host);
} }
TEST_F(LibraryTest, ParseAReplyJustCname) { TEST_F(LibraryTest, ParseAReplyJustCname) {
DNSPacket pkt; DNSPacket pkt;
pkt.set_qid(6366).set_rd().set_ra() pkt.set_qid(6366).set_rd().set_ra()
.add_question(new DNSQuestion("mit.edu", ns_t_a)) .add_question(new DNSQuestion("mit.edu", T_A))
.add_answer(new DNSCnameRR("mit.edu", 52, "other.mit.edu")); .add_answer(new DNSCnameRR("mit.edu", 52, "other.mit.edu"));
struct hostent *host = nullptr; struct hostent *host = nullptr;
struct ares_addrttl info[2]; struct ares_addrttl info[2];
int count = 2; int count = 2;
std::vector<byte> data = pkt.data(); std::vector<byte> data = pkt.data();
EXPECT_EQ(ARES_SUCCESS, ares_parse_a_reply(data.data(), data.size(), EXPECT_EQ(ARES_SUCCESS, ares_parse_a_reply(data.data(), data.size(),
&host, info, &count)); &host, info, &count));
EXPECT_EQ(0, count); EXPECT_EQ(0, count);
ASSERT_NE(nullptr, host); ASSERT_NE(nullptr, host);
std::stringstream ss; std::stringstream ss;
ss << HostEnt(host); ss << HostEnt(host);
EXPECT_EQ("{'other.mit.edu' aliases=[mit.edu] addrs=[]}", ss.str()); EXPECT_EQ("{'other.mit.edu' aliases=[mit.edu] addrs=[]}", ss.str());
ares_free_hostent(host); ares_free_hostent(host);
} }
TEST_F(LibraryTest, ParseAReplyVariantCname) { TEST_F(LibraryTest, ParseAReplyVariantCname) {
DNSPacket pkt; DNSPacket pkt;
pkt.set_qid(6366).set_rd().set_ra() pkt.set_qid(6366).set_rd().set_ra()
.add_question(new DNSQuestion("query.example.com", ns_t_a)) .add_question(new DNSQuestion("query.example.com", T_A))
.add_answer(new DNSCnameRR("query.example.com", 200, "redirect.query.example .com")) .add_answer(new DNSCnameRR("query.example.com", 200, "redirect.query.example .com"))
.add_answer(new DNSARR("redirect.query.example.com", 300, {129,97,123,22})) .add_answer(new DNSARR("redirect.query.example.com", 300, {129,97,123,22}))
.add_auth(new DNSNsRR("example.com", 218, "aa.ns1.example.com")) .add_auth(new DNSNsRR("example.com", 218, "aa.ns1.example.com"))
.add_auth(new DNSNsRR("example.com", 218, "ns2.example.com")) .add_auth(new DNSNsRR("example.com", 218, "ns2.example.com"))
.add_auth(new DNSNsRR("example.com", 218, "ns3.example.com")) .add_auth(new DNSNsRR("example.com", 218, "ns3.example.com"))
.add_auth(new DNSNsRR("example.com", 218, "ns4.example.com")) .add_auth(new DNSNsRR("example.com", 218, "ns4.example.com"))
.add_additional(new DNSARR("aa.ns1.example.com", 218, {129,97,1,1})) .add_additional(new DNSARR("aa.ns1.example.com", 218, {129,97,1,1}))
.add_additional(new DNSARR("ns2.example.com", 218, {129,97,1,2})) .add_additional(new DNSARR("ns2.example.com", 218, {129,97,1,2}))
.add_additional(new DNSARR("ns3.example.com", 218, {129,97,1,3})) .add_additional(new DNSARR("ns3.example.com", 218, {129,97,1,3}))
.add_additional(new DNSARR("ns4.example.com", 218, {129,97,1,4})); .add_additional(new DNSARR("ns4.example.com", 218, {129,97,1,4}));
skipping to change at line 221 skipping to change at line 221
// Repeat parsing without places to put the results. // Repeat parsing without places to put the results.
count = 0; count = 0;
EXPECT_EQ(ARES_SUCCESS, ares_parse_a_reply(data.data(), data.size(), EXPECT_EQ(ARES_SUCCESS, ares_parse_a_reply(data.data(), data.size(),
nullptr, info, &count)); nullptr, info, &count));
} }
TEST_F(LibraryTest, ParseAReplyVariantCnameChain) { TEST_F(LibraryTest, ParseAReplyVariantCnameChain) {
DNSPacket pkt; DNSPacket pkt;
pkt.set_qid(6366).set_rd().set_ra() pkt.set_qid(6366).set_rd().set_ra()
.add_question(new DNSQuestion("c1.localhost", ns_t_a)) .add_question(new DNSQuestion("c1.localhost", T_A))
.add_answer(new DNSCnameRR("c1.localhost", 604800, "c2.localhost")) .add_answer(new DNSCnameRR("c1.localhost", 604800, "c2.localhost"))
.add_answer(new DNSCnameRR("c2.localhost", 604800, "c3.localhost")) .add_answer(new DNSCnameRR("c2.localhost", 604800, "c3.localhost"))
.add_answer(new DNSCnameRR("c3.localhost", 604800, "c4.localhost")) .add_answer(new DNSCnameRR("c3.localhost", 604800, "c4.localhost"))
.add_answer(new DNSARR("c4.localhost", 604800, {8,8,8,8})) .add_answer(new DNSARR("c4.localhost", 604800, {8,8,8,8}))
.add_auth(new DNSNsRR("localhost", 604800, "localhost")) .add_auth(new DNSNsRR("localhost", 604800, "localhost"))
.add_additional(new DNSARR("localhost", 604800, {127,0,0,1})) .add_additional(new DNSARR("localhost", 604800, {127,0,0,1}))
.add_additional(new DNSAaaaRR("localhost", 604800, .add_additional(new DNSAaaaRR("localhost", 604800,
{0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, {0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01})) ; 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01})) ;
struct hostent *host = nullptr; struct hostent *host = nullptr;
skipping to change at line 246 skipping to change at line 246
&host, info, &count)); &host, info, &count));
EXPECT_EQ(1, count); EXPECT_EQ(1, count);
EXPECT_EQ("8.8.8.8", AddressToString(&(info[0].ipaddr), 4)); EXPECT_EQ("8.8.8.8", AddressToString(&(info[0].ipaddr), 4));
EXPECT_EQ(604800, info[0].ttl); EXPECT_EQ(604800, info[0].ttl);
ares_free_hostent(host); ares_free_hostent(host);
} }
TEST_F(LibraryTest, DISABLED_ParseAReplyVariantCnameLast) { TEST_F(LibraryTest, DISABLED_ParseAReplyVariantCnameLast) {
DNSPacket pkt; DNSPacket pkt;
pkt.set_qid(6366).set_rd().set_ra() pkt.set_qid(6366).set_rd().set_ra()
.add_question(new DNSQuestion("query.example.com", ns_t_a)) .add_question(new DNSQuestion("query.example.com", T_A))
.add_answer(new DNSARR("redirect.query.example.com", 300, {129,97,123,221})) .add_answer(new DNSARR("redirect.query.example.com", 300, {129,97,123,221}))
.add_answer(new DNSARR("redirect.query.example.com", 300, {129,97,123,222})) .add_answer(new DNSARR("redirect.query.example.com", 300, {129,97,123,222}))
.add_answer(new DNSARR("redirect.query.example.com", 300, {129,97,123,223})) .add_answer(new DNSARR("redirect.query.example.com", 300, {129,97,123,223}))
.add_answer(new DNSARR("redirect.query.example.com", 300, {129,97,123,224})) .add_answer(new DNSARR("redirect.query.example.com", 300, {129,97,123,224}))
.add_answer(new DNSCnameRR("query.example.com", 60, "redirect.query.example. com")) .add_answer(new DNSCnameRR("query.example.com", 60, "redirect.query.example. com"))
.add_additional(new DNSTxtRR("query.example.com", 60, {"text record"})); .add_additional(new DNSTxtRR("query.example.com", 60, {"text record"}));
struct hostent *host = nullptr; struct hostent *host = nullptr;
struct ares_addrttl info[8]; struct ares_addrttl info[8];
int count = 8; int count = 8;
std::vector<byte> data = pkt.data(); std::vector<byte> data = pkt.data();
skipping to change at line 274 skipping to change at line 274
EXPECT_EQ(300, info[0].ttl); EXPECT_EQ(300, info[0].ttl);
EXPECT_EQ(300, info[1].ttl); EXPECT_EQ(300, info[1].ttl);
EXPECT_EQ(300, info[2].ttl); EXPECT_EQ(300, info[2].ttl);
EXPECT_EQ(300, info[3].ttl); EXPECT_EQ(300, info[3].ttl);
ares_free_hostent(host); ares_free_hostent(host);
} }
TEST_F(LibraryTest, ParseAReplyErrors) { TEST_F(LibraryTest, ParseAReplyErrors) {
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_a)) .add_question(new DNSQuestion("example.com", T_A))
.add_answer(new DNSARR("example.com", 100, {0x02, 0x03, 0x04, 0x05})); .add_answer(new DNSARR("example.com", 100, {0x02, 0x03, 0x04, 0x05}));
std::vector<byte> data; std::vector<byte> data;
struct hostent *host = nullptr; struct hostent *host = nullptr;
struct ares_addrttl info[2]; struct ares_addrttl info[2];
int count = 2; int count = 2;
// No question. // No question.
pkt.questions_.clear(); pkt.questions_.clear();
data = pkt.data(); data = pkt.data();
EXPECT_EQ(ARES_EBADRESP, ares_parse_a_reply(data.data(), data.size(), EXPECT_EQ(ARES_EBADRESP, ares_parse_a_reply(data.data(), data.size(),
&host, info, &count)); &host, info, &count));
EXPECT_EQ(nullptr, host); EXPECT_EQ(nullptr, host);
pkt.add_question(new DNSQuestion("example.com", ns_t_a)); pkt.add_question(new DNSQuestion("example.com", T_A));
// Question != answer // Question != answer
pkt.questions_.clear(); pkt.questions_.clear();
pkt.add_question(new DNSQuestion("Axample.com", ns_t_a)); pkt.add_question(new DNSQuestion("Axample.com", T_A));
data = pkt.data(); data = pkt.data();
EXPECT_EQ(ARES_ENODATA, ares_parse_a_reply(data.data(), data.size(), EXPECT_EQ(ARES_ENODATA, ares_parse_a_reply(data.data(), data.size(),
&host, info, &count)); &host, info, &count));
EXPECT_EQ(nullptr, host); EXPECT_EQ(nullptr, host);
pkt.questions_.clear(); pkt.questions_.clear();
pkt.add_question(new DNSQuestion("example.com", ns_t_a)); pkt.add_question(new DNSQuestion("example.com", T_A));
#ifdef DISABLED #ifdef DISABLED
// Not a response. // Not a response.
pkt.set_response(false); pkt.set_response(false);
data = pkt.data(); data = pkt.data();
EXPECT_EQ(ARES_EBADRESP, ares_parse_a_reply(data.data(), data.size(), EXPECT_EQ(ARES_EBADRESP, ares_parse_a_reply(data.data(), data.size(),
&host, info, &count)); &host, info, &count));
EXPECT_EQ(nullptr, host); EXPECT_EQ(nullptr, host);
pkt.set_response(true); pkt.set_response(true);
// Bad return code. // Bad return code.
pkt.set_rcode(ns_r_formerr); pkt.set_rcode(FORMERR);
data = pkt.data(); data = pkt.data();
EXPECT_EQ(ARES_ENODATA, ares_parse_a_reply(data.data(), data.size(), EXPECT_EQ(ARES_ENODATA, ares_parse_a_reply(data.data(), data.size(),
&host, info, &count)); &host, info, &count));
EXPECT_EQ(nullptr, host); EXPECT_EQ(nullptr, host);
pkt.set_rcode(ns_r_noerror); pkt.set_rcode(NOERROR);
#endif #endif
// Two questions // Two questions
pkt.add_question(new DNSQuestion("example.com", ns_t_a)); pkt.add_question(new DNSQuestion("example.com", T_A));
data = pkt.data(); data = pkt.data();
EXPECT_EQ(ARES_EBADRESP, ares_parse_a_reply(data.data(), data.size(), EXPECT_EQ(ARES_EBADRESP, ares_parse_a_reply(data.data(), data.size(),
&host, info, &count)); &host, info, &count));
EXPECT_EQ(nullptr, host); EXPECT_EQ(nullptr, host);
pkt.questions_.clear(); pkt.questions_.clear();
pkt.add_question(new DNSQuestion("example.com", ns_t_a)); pkt.add_question(new DNSQuestion("example.com", T_A));
// 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_a_reply(data.data(), data.size(), EXPECT_EQ(ARES_ENODATA, ares_parse_a_reply(data.data(), data.size(),
&host, info, &count)); &host, info, &count));
EXPECT_EQ(nullptr, host); EXPECT_EQ(nullptr, host);
pkt.answers_.clear(); pkt.answers_.clear();
pkt.add_answer(new DNSARR("example.com", 100, {0x02, 0x03, 0x04, 0x05})); pkt.add_answer(new DNSARR("example.com", 100, {0x02, 0x03, 0x04, 0x05}));
skipping to change at line 359 skipping to change at line 359
&host, info, &count)); &host, info, &count));
EXPECT_EQ(nullptr, host); EXPECT_EQ(nullptr, host);
EXPECT_EQ(ARES_EBADRESP, ares_parse_a_reply(data.data(), len, EXPECT_EQ(ARES_EBADRESP, ares_parse_a_reply(data.data(), len,
nullptr, info, &count)); nullptr, info, &count));
} }
} }
TEST_F(LibraryTest, ParseAReplyAllocFail) { TEST_F(LibraryTest, ParseAReplyAllocFail) {
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_a)) .add_question(new DNSQuestion("example.com", T_A))
.add_answer(new DNSCnameRR("example.com", 300, "c.example.com")) .add_answer(new DNSCnameRR("example.com", 300, "c.example.com"))
.add_answer(new DNSARR("c.example.com", 500, {0x02, 0x03, 0x04, 0x05})); .add_answer(new DNSARR("c.example.com", 500, {0x02, 0x03, 0x04, 0x05}));
std::vector<byte> data = pkt.data(); std::vector<byte> data = pkt.data();
struct hostent *host = nullptr; struct hostent *host = nullptr;
struct ares_addrttl info[2]; struct ares_addrttl info[2];
int count = 2; int count = 2;
for (int ii = 1; ii <= 8; ii++) { for (int ii = 1; ii <= 8; ii++) {
ClearFails(); ClearFails();
 End of changes. 16 change blocks. 
16 lines changed or deleted 16 lines changed or added

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