"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "test/ares-test-parse-srv.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-srv.cc  (c-ares-1.17.1):ares-test-parse-srv.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, ParseSrvReplyOK) { TEST_F(LibraryTest, ParseSrvReplyOK) {
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_srv)) .add_question(new DNSQuestion("example.com", T_SRV))
.add_answer(new DNSSrvRR("example.com", 100, 10, 20, 30, "srv.example.com")) .add_answer(new DNSSrvRR("example.com", 100, 10, 20, 30, "srv.example.com"))
.add_answer(new DNSSrvRR("example.com", 100, 11, 21, 31, "srv2.example.com") ); .add_answer(new DNSSrvRR("example.com", 100, 11, 21, 31, "srv2.example.com") );
std::vector<byte> data = pkt.data(); std::vector<byte> data = pkt.data();
struct ares_srv_reply* srv = nullptr; struct ares_srv_reply* srv = nullptr;
EXPECT_EQ(ARES_SUCCESS, ares_parse_srv_reply(data.data(), data.size(), &srv)); EXPECT_EQ(ARES_SUCCESS, ares_parse_srv_reply(data.data(), data.size(), &srv));
ASSERT_NE(nullptr, srv); ASSERT_NE(nullptr, srv);
EXPECT_EQ("srv.example.com", std::string(srv->host)); EXPECT_EQ("srv.example.com", std::string(srv->host));
EXPECT_EQ(10, srv->priority); EXPECT_EQ(10, srv->priority);
skipping to change at line 41 skipping to change at line 41
EXPECT_EQ(21, srv2->weight); EXPECT_EQ(21, srv2->weight);
EXPECT_EQ(31, srv2->port); EXPECT_EQ(31, srv2->port);
EXPECT_EQ(nullptr, srv2->next); EXPECT_EQ(nullptr, srv2->next);
ares_free_data(srv); ares_free_data(srv);
} }
TEST_F(LibraryTest, ParseSrvReplySingle) { TEST_F(LibraryTest, ParseSrvReplySingle) {
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.abc.def.com", ns_t_srv)) .add_question(new DNSQuestion("example.abc.def.com", T_SRV))
.add_answer(new DNSSrvRR("example.abc.def.com", 180, 0, 10, 8160, "example.a bc.def.com")) .add_answer(new DNSSrvRR("example.abc.def.com", 180, 0, 10, 8160, "example.a bc.def.com"))
.add_auth(new DNSNsRR("abc.def.com", 44, "else1.where.com")) .add_auth(new DNSNsRR("abc.def.com", 44, "else1.where.com"))
.add_auth(new DNSNsRR("abc.def.com", 44, "else2.where.com")) .add_auth(new DNSNsRR("abc.def.com", 44, "else2.where.com"))
.add_auth(new DNSNsRR("abc.def.com", 44, "else3.where.com")) .add_auth(new DNSNsRR("abc.def.com", 44, "else3.where.com"))
.add_auth(new DNSNsRR("abc.def.com", 44, "else4.where.com")) .add_auth(new DNSNsRR("abc.def.com", 44, "else4.where.com"))
.add_auth(new DNSNsRR("abc.def.com", 44, "else5.where.com")) .add_auth(new DNSNsRR("abc.def.com", 44, "else5.where.com"))
.add_additional(new DNSARR("else2.where.com", 42, {172,19,0,1})) .add_additional(new DNSARR("else2.where.com", 42, {172,19,0,1}))
.add_additional(new DNSARR("else5.where.com", 42, {172,19,0,2})); .add_additional(new DNSARR("else5.where.com", 42, {172,19,0,2}));
std::vector<byte> data = pkt.data(); std::vector<byte> data = pkt.data();
skipping to change at line 99 skipping to change at line 99
}; };
struct ares_srv_reply* srv = nullptr; struct ares_srv_reply* srv = nullptr;
EXPECT_EQ(ARES_EBADRESP, ares_parse_srv_reply(data.data(), data.size(), &srv)) ; EXPECT_EQ(ARES_EBADRESP, ares_parse_srv_reply(data.data(), data.size(), &srv)) ;
ASSERT_EQ(nullptr, srv); ASSERT_EQ(nullptr, srv);
} }
TEST_F(LibraryTest, ParseSrvReplyMultiple) { TEST_F(LibraryTest, ParseSrvReplyMultiple) {
DNSPacket pkt; DNSPacket pkt;
pkt.set_qid(0x1234).set_response().set_ra().set_rd() pkt.set_qid(0x1234).set_response().set_ra().set_rd()
.add_question(new DNSQuestion("srv.example.com", ns_t_srv)) .add_question(new DNSQuestion("srv.example.com", T_SRV))
.add_answer(new DNSSrvRR("srv.example.com", 300, 0, 5, 6789, "a1.srv.example .com")) .add_answer(new DNSSrvRR("srv.example.com", 300, 0, 5, 6789, "a1.srv.example .com"))
.add_answer(new DNSSrvRR("srv.example.com", 300, 0, 5, 4567, "a2.srv.example .com")) .add_answer(new DNSSrvRR("srv.example.com", 300, 0, 5, 4567, "a2.srv.example .com"))
.add_answer(new DNSSrvRR("srv.example.com", 300, 0, 5, 5678, "a3.srv.example .com")) .add_answer(new DNSSrvRR("srv.example.com", 300, 0, 5, 5678, "a3.srv.example .com"))
.add_auth(new DNSNsRR("example.com", 300, "ns1.example.com")) .add_auth(new DNSNsRR("example.com", 300, "ns1.example.com"))
.add_auth(new DNSNsRR("example.com", 300, "ns2.example.com")) .add_auth(new DNSNsRR("example.com", 300, "ns2.example.com"))
.add_auth(new DNSNsRR("example.com", 300, "ns3.example.com")) .add_auth(new DNSNsRR("example.com", 300, "ns3.example.com"))
.add_additional(new DNSARR("a1.srv.example.com", 300, {172,19,1,1})) .add_additional(new DNSARR("a1.srv.example.com", 300, {172,19,1,1}))
.add_additional(new DNSARR("a2.srv.example.com", 300, {172,19,1,2})) .add_additional(new DNSARR("a2.srv.example.com", 300, {172,19,1,2}))
.add_additional(new DNSARR("a3.srv.example.com", 300, {172,19,1,3})) .add_additional(new DNSARR("a3.srv.example.com", 300, {172,19,1,3}))
.add_additional(new DNSARR("n1.example.com", 300, {172,19,0,1})) .add_additional(new DNSARR("n1.example.com", 300, {172,19,0,1}))
skipping to change at line 145 skipping to change at line 145
EXPECT_EQ(5, srv->weight); EXPECT_EQ(5, srv->weight);
EXPECT_EQ(5678, srv->port); EXPECT_EQ(5678, srv->port);
EXPECT_EQ(nullptr, srv->next); EXPECT_EQ(nullptr, srv->next);
ares_free_data(srv0); ares_free_data(srv0);
} }
TEST_F(LibraryTest, ParseSrvReplyCname) { TEST_F(LibraryTest, ParseSrvReplyCname) {
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.abc.def.com", ns_t_srv)) .add_question(new DNSQuestion("example.abc.def.com", T_SRV))
.add_answer(new DNSCnameRR("example.abc.def.com", 300, "cname.abc.def.com")) .add_answer(new DNSCnameRR("example.abc.def.com", 300, "cname.abc.def.com"))
.add_answer(new DNSSrvRR("cname.abc.def.com", 300, 0, 10, 1234, "srv.abc.def .com")) .add_answer(new DNSSrvRR("cname.abc.def.com", 300, 0, 10, 1234, "srv.abc.def .com"))
.add_auth(new DNSNsRR("abc.def.com", 44, "else1.where.com")) .add_auth(new DNSNsRR("abc.def.com", 44, "else1.where.com"))
.add_auth(new DNSNsRR("abc.def.com", 44, "else2.where.com")) .add_auth(new DNSNsRR("abc.def.com", 44, "else2.where.com"))
.add_auth(new DNSNsRR("abc.def.com", 44, "else3.where.com")) .add_auth(new DNSNsRR("abc.def.com", 44, "else3.where.com"))
.add_additional(new DNSARR("example.abc.def.com", 300, {172,19,0,1})) .add_additional(new DNSARR("example.abc.def.com", 300, {172,19,0,1}))
.add_additional(new DNSARR("else1.where.com", 42, {172,19,0,1})) .add_additional(new DNSARR("else1.where.com", 42, {172,19,0,1}))
.add_additional(new DNSARR("else2.where.com", 42, {172,19,0,2})) .add_additional(new DNSARR("else2.where.com", 42, {172,19,0,2}))
.add_additional(new DNSARR("else3.where.com", 42, {172,19,0,3})); .add_additional(new DNSARR("else3.where.com", 42, {172,19,0,3}));
std::vector<byte> data = pkt.data(); std::vector<byte> data = pkt.data();
skipping to change at line 173 skipping to change at line 173
EXPECT_EQ(10, srv->weight); EXPECT_EQ(10, srv->weight);
EXPECT_EQ(1234, srv->port); EXPECT_EQ(1234, srv->port);
EXPECT_EQ(nullptr, srv->next); EXPECT_EQ(nullptr, srv->next);
ares_free_data(srv); ares_free_data(srv);
} }
TEST_F(LibraryTest, ParseSrvReplyCnameMultiple) { TEST_F(LibraryTest, ParseSrvReplyCnameMultiple) {
DNSPacket pkt; DNSPacket pkt;
pkt.set_qid(0x1234).set_response().set_ra().set_rd() pkt.set_qid(0x1234).set_response().set_ra().set_rd()
.add_question(new DNSQuestion("query.example.com", ns_t_srv)) .add_question(new DNSQuestion("query.example.com", T_SRV))
.add_answer(new DNSCnameRR("query.example.com", 300, "srv.example.com")) .add_answer(new DNSCnameRR("query.example.com", 300, "srv.example.com"))
.add_answer(new DNSSrvRR("srv.example.com", 300, 0, 5, 6789, "a1.srv.example .com")) .add_answer(new DNSSrvRR("srv.example.com", 300, 0, 5, 6789, "a1.srv.example .com"))
.add_answer(new DNSSrvRR("srv.example.com", 300, 0, 5, 4567, "a2.srv.example .com")) .add_answer(new DNSSrvRR("srv.example.com", 300, 0, 5, 4567, "a2.srv.example .com"))
.add_answer(new DNSSrvRR("srv.example.com", 300, 0, 5, 5678, "a3.srv.example .com")) .add_answer(new DNSSrvRR("srv.example.com", 300, 0, 5, 5678, "a3.srv.example .com"))
.add_auth(new DNSNsRR("example.com", 300, "ns1.example.com")) .add_auth(new DNSNsRR("example.com", 300, "ns1.example.com"))
.add_auth(new DNSNsRR("example.com", 300, "ns2.example.com")) .add_auth(new DNSNsRR("example.com", 300, "ns2.example.com"))
.add_auth(new DNSNsRR("example.com", 300, "ns3.example.com")) .add_auth(new DNSNsRR("example.com", 300, "ns3.example.com"))
.add_additional(new DNSARR("a1.srv.example.com", 300, {172,19,1,1})) .add_additional(new DNSARR("a1.srv.example.com", 300, {172,19,1,1}))
.add_additional(new DNSARR("a2.srv.example.com", 300, {172,19,1,2})) .add_additional(new DNSARR("a2.srv.example.com", 300, {172,19,1,2}))
.add_additional(new DNSARR("a3.srv.example.com", 300, {172,19,1,3})) .add_additional(new DNSARR("a3.srv.example.com", 300, {172,19,1,3}))
skipping to change at line 220 skipping to change at line 220
EXPECT_EQ(5, srv->weight); EXPECT_EQ(5, srv->weight);
EXPECT_EQ(5678, srv->port); EXPECT_EQ(5678, srv->port);
EXPECT_EQ(nullptr, srv->next); EXPECT_EQ(nullptr, srv->next);
ares_free_data(srv0); ares_free_data(srv0);
} }
TEST_F(LibraryTest, ParseSrvReplyErrors) { TEST_F(LibraryTest, ParseSrvReplyErrors) {
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.abc.def.com", ns_t_srv)) .add_question(new DNSQuestion("example.abc.def.com", T_SRV))
.add_answer(new DNSSrvRR("example.abc.def.com", 180, 0, 10, 8160, "example.a bc.def.com")); .add_answer(new DNSSrvRR("example.abc.def.com", 180, 0, 10, 8160, "example.a bc.def.com"));
std::vector<byte> data; std::vector<byte> data;
struct ares_srv_reply* srv = nullptr; struct ares_srv_reply* srv = nullptr;
// No question. // No question.
pkt.questions_.clear(); pkt.questions_.clear();
data = pkt.data(); data = pkt.data();
EXPECT_EQ(ARES_EBADRESP, ares_parse_srv_reply(data.data(), data.size(), &srv)) ; EXPECT_EQ(ARES_EBADRESP, ares_parse_srv_reply(data.data(), data.size(), &srv)) ;
pkt.add_question(new DNSQuestion("example.abc.def.com", ns_t_srv)); pkt.add_question(new DNSQuestion("example.abc.def.com", T_SRV));
#ifdef DISABLED #ifdef DISABLED
// Question != answer // Question != answer
pkt.questions_.clear(); pkt.questions_.clear();
pkt.add_question(new DNSQuestion("Axample.com", ns_t_srv)); pkt.add_question(new DNSQuestion("Axample.com", T_SRV));
data = pkt.data(); data = pkt.data();
EXPECT_EQ(ARES_ENODATA, ares_parse_srv_reply(data.data(), data.size(), &srv)); EXPECT_EQ(ARES_ENODATA, ares_parse_srv_reply(data.data(), data.size(), &srv));
pkt.questions_.clear(); pkt.questions_.clear();
pkt.add_question(new DNSQuestion("example.com", ns_t_srv)); pkt.add_question(new DNSQuestion("example.com", T_SRV));
#endif #endif
// Two questions. // Two questions.
pkt.add_question(new DNSQuestion("example.abc.def.com", ns_t_srv)); pkt.add_question(new DNSQuestion("example.abc.def.com", T_SRV));
data = pkt.data(); data = pkt.data();
EXPECT_EQ(ARES_EBADRESP, ares_parse_srv_reply(data.data(), data.size(), &srv)) ; EXPECT_EQ(ARES_EBADRESP, ares_parse_srv_reply(data.data(), data.size(), &srv)) ;
pkt.questions_.clear(); pkt.questions_.clear();
pkt.add_question(new DNSQuestion("64.48.32.16.in-addr.arpa", ns_t_ptr)); pkt.add_question(new DNSQuestion("64.48.32.16.in-addr.arpa", T_PTR));
// 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_SUCCESS, ares_parse_srv_reply(data.data(), data.size(), &srv)); EXPECT_EQ(ARES_SUCCESS, ares_parse_srv_reply(data.data(), data.size(), &srv));
EXPECT_EQ(nullptr, srv); EXPECT_EQ(nullptr, srv);
pkt.answers_.clear(); pkt.answers_.clear();
pkt.add_answer(new DNSSrvRR("example.abc.def.com", 180, 0, 10, 8160, "example. abc.def.com")); pkt.add_answer(new DNSSrvRR("example.abc.def.com", 180, 0, 10, 8160, "example. abc.def.com"));
skipping to change at line 274 skipping to change at line 274
data = pkt.data(); data = pkt.data();
for (size_t len = 1; len < data.size(); len++) { for (size_t len = 1; len < data.size(); len++) {
int rc = ares_parse_srv_reply(data.data(), len, &srv); int rc = ares_parse_srv_reply(data.data(), len, &srv);
EXPECT_TRUE(rc == ARES_EBADRESP || rc == ARES_EBADNAME); EXPECT_TRUE(rc == ARES_EBADRESP || rc == ARES_EBADNAME);
} }
} }
TEST_F(LibraryTest, ParseSrvReplyAllocFail) { TEST_F(LibraryTest, ParseSrvReplyAllocFail) {
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.abc.def.com", ns_t_srv)) .add_question(new DNSQuestion("example.abc.def.com", T_SRV))
.add_answer(new DNSCnameRR("example.com", 300, "c.example.com")) .add_answer(new DNSCnameRR("example.com", 300, "c.example.com"))
.add_answer(new DNSSrvRR("example.abc.def.com", 180, 0, 10, 8160, "example.a bc.def.com")); .add_answer(new DNSSrvRR("example.abc.def.com", 180, 0, 10, 8160, "example.a bc.def.com"));
std::vector<byte> data = pkt.data(); std::vector<byte> data = pkt.data();
struct ares_srv_reply* srv = nullptr; struct ares_srv_reply* srv = nullptr;
for (int ii = 1; ii <= 5; ii++) { for (int ii = 1; ii <= 5; ii++) {
ClearFails(); ClearFails();
SetAllocFail(ii); SetAllocFail(ii);
EXPECT_EQ(ARES_ENOMEM, ares_parse_srv_reply(data.data(), data.size(), &srv)) << ii; EXPECT_EQ(ARES_ENOMEM, ares_parse_srv_reply(data.data(), data.size(), &srv)) << ii;
} }
 End of changes. 12 change blocks. 
12 lines changed or deleted 12 lines changed or added

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