"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "test/ares-test-parse-naptr.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-naptr.cc  (c-ares-1.17.1):ares-test-parse-naptr.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, ParseNaptrReplyOK) { TEST_F(LibraryTest, ParseNaptrReplyOK) {
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_naptr)) .add_question(new DNSQuestion("example.com", T_NAPTR))
.add_answer(new DNSNaptrRR("example.com", 100, .add_answer(new DNSNaptrRR("example.com", 100,
10, 20, "SP", "service", "regexp", "replace")) 10, 20, "SP", "service", "regexp", "replace"))
.add_answer(new DNSNaptrRR("example.com", 0x0010, .add_answer(new DNSNaptrRR("example.com", 0x0010,
11, 21, "SP", "service2", "regexp2", "replace2")) ; 11, 21, "SP", "service2", "regexp2", "replace2")) ;
std::vector<byte> data = pkt.data(); std::vector<byte> data = pkt.data();
struct ares_naptr_reply* naptr = nullptr; struct ares_naptr_reply* naptr = nullptr;
EXPECT_EQ(ARES_SUCCESS, ares_parse_naptr_reply(data.data(), data.size(), &napt r)); EXPECT_EQ(ARES_SUCCESS, ares_parse_naptr_reply(data.data(), data.size(), &napt r));
ASSERT_NE(nullptr, naptr); ASSERT_NE(nullptr, naptr);
EXPECT_EQ("SP", std::string((char*)naptr->flags)); EXPECT_EQ("SP", std::string((char*)naptr->flags));
skipping to change at line 46 skipping to change at line 46
EXPECT_EQ(11, naptr2->order); EXPECT_EQ(11, naptr2->order);
EXPECT_EQ(21, naptr2->preference); EXPECT_EQ(21, naptr2->preference);
EXPECT_EQ(nullptr, naptr2->next); EXPECT_EQ(nullptr, naptr2->next);
ares_free_data(naptr); ares_free_data(naptr);
} }
TEST_F(LibraryTest, ParseNaptrReplyErrors) { TEST_F(LibraryTest, ParseNaptrReplyErrors) {
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_naptr)) .add_question(new DNSQuestion("example.com", T_NAPTR))
.add_answer(new DNSNaptrRR("example.com", 100, .add_answer(new DNSNaptrRR("example.com", 100,
10, 20, "SP", "service", "regexp", "replace")); 10, 20, "SP", "service", "regexp", "replace"));
std::vector<byte> data; std::vector<byte> data;
struct ares_naptr_reply* naptr = nullptr; struct ares_naptr_reply* naptr = nullptr;
// No question. // No question.
pkt.questions_.clear(); pkt.questions_.clear();
data = pkt.data(); data = pkt.data();
EXPECT_EQ(ARES_EBADRESP, ares_parse_naptr_reply(data.data(), data.size(), &nap tr)); EXPECT_EQ(ARES_EBADRESP, ares_parse_naptr_reply(data.data(), data.size(), &nap tr));
pkt.add_question(new DNSQuestion("example.com", ns_t_naptr)); pkt.add_question(new DNSQuestion("example.com", T_NAPTR));
#ifdef DISABLED #ifdef DISABLED
// Question != answer // Question != answer
pkt.questions_.clear(); pkt.questions_.clear();
pkt.add_question(new DNSQuestion("Axample.com", ns_t_naptr)); pkt.add_question(new DNSQuestion("Axample.com", T_NAPTR));
data = pkt.data(); data = pkt.data();
EXPECT_EQ(ARES_ENODATA, ares_parse_naptr_reply(data.data(), data.size(), &napt r)); EXPECT_EQ(ARES_ENODATA, ares_parse_naptr_reply(data.data(), data.size(), &napt r));
pkt.questions_.clear(); pkt.questions_.clear();
pkt.add_question(new DNSQuestion("example.com", ns_t_naptr)); pkt.add_question(new DNSQuestion("example.com", T_NAPTR));
#endif #endif
// Two questions // Two questions
pkt.add_question(new DNSQuestion("example.com", ns_t_naptr)); pkt.add_question(new DNSQuestion("example.com", T_NAPTR));
data = pkt.data(); data = pkt.data();
EXPECT_EQ(ARES_EBADRESP, ares_parse_naptr_reply(data.data(), data.size(), &nap tr)); EXPECT_EQ(ARES_EBADRESP, ares_parse_naptr_reply(data.data(), data.size(), &nap tr));
pkt.questions_.clear(); pkt.questions_.clear();
pkt.add_question(new DNSQuestion("example.com", ns_t_naptr)); pkt.add_question(new DNSQuestion("example.com", T_NAPTR));
// 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_naptr_reply(data.data(), data.size(), &napt r)); EXPECT_EQ(ARES_SUCCESS, ares_parse_naptr_reply(data.data(), data.size(), &napt r));
EXPECT_EQ(nullptr, naptr); EXPECT_EQ(nullptr, naptr);
pkt.answers_.clear(); pkt.answers_.clear();
pkt.add_answer(new DNSNaptrRR("example.com", 100, pkt.add_answer(new DNSNaptrRR("example.com", 100,
10, 20, "SP", "service", "regexp", "replace")); 10, 20, "SP", "service", "regexp", "replace"));
skipping to change at line 132 skipping to change at line 132
0x00, 0x01, // rdata length 0x00, 0x01, // rdata length
0x00, // Too short: expect 2 x int16 and 3 x name (min 1 byte each) 0x00, // Too short: expect 2 x int16 and 3 x name (min 1 byte each)
}; };
struct ares_naptr_reply* naptr = nullptr; struct ares_naptr_reply* naptr = nullptr;
EXPECT_EQ(ARES_EBADRESP, ares_parse_naptr_reply(data.data(), data.size(), &nap tr)); EXPECT_EQ(ARES_EBADRESP, ares_parse_naptr_reply(data.data(), data.size(), &nap tr));
} }
TEST_F(LibraryTest, ParseNaptrReplyAllocFail) { TEST_F(LibraryTest, ParseNaptrReplyAllocFail) {
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_naptr)) .add_question(new DNSQuestion("example.com", T_NAPTR))
.add_answer(new DNSNaptrRR("example.com", 100, .add_answer(new DNSNaptrRR("example.com", 100,
10, 20, "SP", "service", "regexp", "replace")) 10, 20, "SP", "service", "regexp", "replace"))
.add_answer(new DNSNaptrRR("example.com", 0x0010, .add_answer(new DNSNaptrRR("example.com", 0x0010,
11, 21, "SP", "service2", "regexp2", "replace2")) ; 11, 21, "SP", "service2", "regexp2", "replace2")) ;
std::vector<byte> data = pkt.data(); std::vector<byte> data = pkt.data();
struct ares_naptr_reply* naptr = nullptr; struct ares_naptr_reply* naptr = nullptr;
for (int ii = 1; ii <= 13; ii++) { for (int ii = 1; ii <= 13; ii++) {
ClearFails(); ClearFails();
SetAllocFail(ii); SetAllocFail(ii);
 End of changes. 8 change blocks. 
8 lines changed or deleted 8 lines changed or added

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