"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "test/ares-test-parse-mx.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-mx.cc  (c-ares-1.17.1):ares-test-parse-mx.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, ParseMxReplyOK) { TEST_F(LibraryTest, ParseMxReplyOK) {
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_mx)) .add_question(new DNSQuestion("example.com", T_MX))
.add_answer(new DNSMxRR("example.com", 100, 100, "mx1.example.com")) .add_answer(new DNSMxRR("example.com", 100, 100, "mx1.example.com"))
.add_answer(new DNSMxRR("example.com", 100, 200, "mx2.example.com")); .add_answer(new DNSMxRR("example.com", 100, 200, "mx2.example.com"));
std::vector<byte> data = pkt.data(); std::vector<byte> data = pkt.data();
struct ares_mx_reply* mx = nullptr; struct ares_mx_reply* mx = nullptr;
EXPECT_EQ(ARES_SUCCESS, ares_parse_mx_reply(data.data(), data.size(), &mx)); EXPECT_EQ(ARES_SUCCESS, ares_parse_mx_reply(data.data(), data.size(), &mx));
ASSERT_NE(nullptr, mx); ASSERT_NE(nullptr, mx);
EXPECT_EQ("mx1.example.com", std::string(mx->host)); EXPECT_EQ("mx1.example.com", std::string(mx->host));
EXPECT_EQ(100, mx->priority); EXPECT_EQ(100, mx->priority);
skipping to change at line 67 skipping to change at line 67
}; };
struct ares_mx_reply* mx = nullptr; struct ares_mx_reply* mx = nullptr;
EXPECT_EQ(ARES_EBADRESP, ares_parse_mx_reply(data.data(), data.size(), &mx)); EXPECT_EQ(ARES_EBADRESP, ares_parse_mx_reply(data.data(), data.size(), &mx));
ASSERT_EQ(nullptr, mx); ASSERT_EQ(nullptr, mx);
} }
TEST_F(LibraryTest, ParseMxReplyErrors) { TEST_F(LibraryTest, ParseMxReplyErrors) {
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_mx)) .add_question(new DNSQuestion("example.com", T_MX))
.add_answer(new DNSMxRR("example.com", 100, 100, "mx1.example.com")); .add_answer(new DNSMxRR("example.com", 100, 100, "mx1.example.com"));
std::vector<byte> data; std::vector<byte> data;
struct ares_mx_reply* mx = nullptr; struct ares_mx_reply* mx = nullptr;
// No question. // No question.
pkt.questions_.clear(); pkt.questions_.clear();
data = pkt.data(); data = pkt.data();
EXPECT_EQ(ARES_EBADRESP, ares_parse_mx_reply(data.data(), data.size(), &mx)); EXPECT_EQ(ARES_EBADRESP, ares_parse_mx_reply(data.data(), data.size(), &mx));
EXPECT_EQ(nullptr, mx); EXPECT_EQ(nullptr, mx);
pkt.add_question(new DNSQuestion("example.com", ns_t_mx)); pkt.add_question(new DNSQuestion("example.com", T_MX));
#ifdef DISABLED #ifdef DISABLED
// Question != answer // Question != answer
pkt.questions_.clear(); pkt.questions_.clear();
pkt.add_question(new DNSQuestion("Axample.com", ns_t_mx)); pkt.add_question(new DNSQuestion("Axample.com", T_MX));
data = pkt.data(); data = pkt.data();
EXPECT_EQ(ARES_EBADRESP, ares_parse_mx_reply(data.data(), data.size(), &mx)); EXPECT_EQ(ARES_EBADRESP, ares_parse_mx_reply(data.data(), data.size(), &mx));
pkt.questions_.clear(); pkt.questions_.clear();
pkt.add_question(new DNSQuestion("example.com", ns_t_mx)); pkt.add_question(new DNSQuestion("example.com", T_MX));
#endif #endif
// Two questions. // Two questions.
pkt.add_question(new DNSQuestion("example.com", ns_t_mx)); pkt.add_question(new DNSQuestion("example.com", T_MX));
data = pkt.data(); data = pkt.data();
EXPECT_EQ(ARES_EBADRESP, ares_parse_mx_reply(data.data(), data.size(), &mx)); EXPECT_EQ(ARES_EBADRESP, ares_parse_mx_reply(data.data(), data.size(), &mx));
EXPECT_EQ(nullptr, mx); EXPECT_EQ(nullptr, mx);
pkt.questions_.clear(); pkt.questions_.clear();
pkt.add_question(new DNSQuestion("example.com", ns_t_mx)); pkt.add_question(new DNSQuestion("example.com", T_MX));
// Wrong sort of answer. // Wrong sort of answer.
// TODO(drysdale): check if this should be ARES_ENODATA? // TODO(drysdale): check if this should be ARES_ENODATA?
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"));
data = pkt.data(); data = pkt.data();
EXPECT_EQ(ARES_SUCCESS, ares_parse_mx_reply(data.data(), data.size(), &mx)); EXPECT_EQ(ARES_SUCCESS, ares_parse_mx_reply(data.data(), data.size(), &mx));
EXPECT_EQ(nullptr, mx); EXPECT_EQ(nullptr, mx);
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"));
skipping to change at line 126 skipping to change at line 126
for (size_t len = 1; len < data.size(); len++) { for (size_t len = 1; len < data.size(); len++) {
int rc = ares_parse_mx_reply(data.data(), len, &mx); int rc = ares_parse_mx_reply(data.data(), len, &mx);
EXPECT_EQ(nullptr, mx); EXPECT_EQ(nullptr, mx);
EXPECT_TRUE(rc == ARES_EBADRESP || rc == ARES_EBADNAME); EXPECT_TRUE(rc == ARES_EBADRESP || rc == ARES_EBADNAME);
} }
} }
TEST_F(LibraryTest, ParseMxReplyAllocFail) { TEST_F(LibraryTest, ParseMxReplyAllocFail) {
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_mx)) .add_question(new DNSQuestion("example.com", T_MX))
.add_answer(new DNSCnameRR("example.com", 300, "c.example.com")) .add_answer(new DNSCnameRR("example.com", 300, "c.example.com"))
.add_answer(new DNSMxRR("c.example.com", 100, 100, "mx1.example.com")); .add_answer(new DNSMxRR("c.example.com", 100, 100, "mx1.example.com"));
std::vector<byte> data = pkt.data(); std::vector<byte> data = pkt.data();
struct ares_mx_reply* mx = nullptr; struct ares_mx_reply* mx = 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_mx_reply(data.data(), data.size(), &mx)) < < ii; EXPECT_EQ(ARES_ENOMEM, ares_parse_mx_reply(data.data(), data.size(), &mx)) < < 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)