ares-test-parse-soa-any.cc (c-ares-1.17.1) | : | ares-test-parse-soa-any.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, ParseSoaAnyReplyOK) { | TEST_F(LibraryTest, ParseSoaAnyReplyOK) { | |||
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_any))\ | .add_question(new DNSQuestion("example.com", T_ANY))\ | |||
.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 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")) | |||
.add_answer(new DNSSoaRR("example.com", 100, | .add_answer(new DNSSoaRR("example.com", 100, | |||
"soa1.example.com", "fred.example.com", | "soa1.example.com", "fred.example.com", | |||
1, 2, 3, 4, 5)); | 1, 2, 3, 4, 5)); | |||
std::vector<byte> data = pkt.data(); | std::vector<byte> data = pkt.data(); | |||
struct ares_soa_reply* soa = nullptr; | struct ares_soa_reply* soa = nullptr; | |||
EXPECT_EQ(ARES_SUCCESS, ares_parse_soa_reply(data.data(), data.size(), &soa)); | EXPECT_EQ(ARES_SUCCESS, ares_parse_soa_reply(data.data(), data.size(), &soa)); | |||
skipping to change at line 38 | skipping to change at line 38 | |||
EXPECT_EQ(2, soa->refresh); | EXPECT_EQ(2, soa->refresh); | |||
EXPECT_EQ(3, soa->retry); | EXPECT_EQ(3, soa->retry); | |||
EXPECT_EQ(4, soa->expire); | EXPECT_EQ(4, soa->expire); | |||
EXPECT_EQ(5, soa->minttl); | EXPECT_EQ(5, soa->minttl); | |||
ares_free_data(soa); | ares_free_data(soa); | |||
} | } | |||
TEST_F(LibraryTest, ParseSoaAnyReplyErrors) { | TEST_F(LibraryTest, ParseSoaAnyReplyErrors) { | |||
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_any)) | .add_question(new DNSQuestion("example.com", T_ANY)) | |||
.add_answer(new DNSSoaRR("example.com", 100, | .add_answer(new DNSSoaRR("example.com", 100, | |||
"soa1.example.com", "fred.example.com", | "soa1.example.com", "fred.example.com", | |||
1, 2, 3, 4, 5)); | 1, 2, 3, 4, 5)); | |||
std::vector<byte> data; | std::vector<byte> data; | |||
struct ares_soa_reply* soa = nullptr; | struct ares_soa_reply* soa = nullptr; | |||
// No question. | // No question. | |||
pkt.questions_.clear(); | pkt.questions_.clear(); | |||
data = pkt.data(); | data = pkt.data(); | |||
EXPECT_EQ(ARES_EBADRESP, ares_parse_soa_reply(data.data(), data.size(), &soa)) ; | EXPECT_EQ(ARES_EBADRESP, ares_parse_soa_reply(data.data(), data.size(), &soa)) ; | |||
pkt.add_question(new DNSQuestion("example.com", ns_t_any)); | pkt.add_question(new DNSQuestion("example.com", T_ANY)); | |||
#ifdef DISABLED | #ifdef DISABLED | |||
// Question != answer | // Question != answer | |||
pkt.questions_.clear(); | pkt.questions_.clear(); | |||
pkt.add_question(new DNSQuestion("Axample.com", ns_t_any)); | pkt.add_question(new DNSQuestion("Axample.com", T_ANY)); | |||
data = pkt.data(); | data = pkt.data(); | |||
EXPECT_EQ(ARES_EBADRESP, ares_parse_soa_reply(data.data(), data.size(), &soa)) ; | EXPECT_EQ(ARES_EBADRESP, ares_parse_soa_reply(data.data(), data.size(), &soa)) ; | |||
pkt.questions_.clear(); | pkt.questions_.clear(); | |||
pkt.add_question(new DNSQuestion("example.com", ns_t_any)); | pkt.add_question(new DNSQuestion("example.com", T_ANY)); | |||
#endif | #endif | |||
// Two questions | // Two questions | |||
pkt.add_question(new DNSQuestion("example.com", ns_t_any)); | pkt.add_question(new DNSQuestion("example.com", T_ANY)); | |||
data = pkt.data(); | data = pkt.data(); | |||
EXPECT_EQ(ARES_EBADRESP, ares_parse_soa_reply(data.data(), data.size(), &soa)) ; | EXPECT_EQ(ARES_EBADRESP, ares_parse_soa_reply(data.data(), data.size(), &soa)) ; | |||
pkt.questions_.clear(); | pkt.questions_.clear(); | |||
pkt.add_question(new DNSQuestion("example.com", ns_t_any)); | pkt.add_question(new DNSQuestion("example.com", T_ANY)); | |||
// 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_EBADRESP, ares_parse_soa_reply(data.data(), data.size(), &soa)) ; | EXPECT_EQ(ARES_EBADRESP, ares_parse_soa_reply(data.data(), data.size(), &soa)) ; | |||
pkt.answers_.clear(); | pkt.answers_.clear(); | |||
pkt.add_answer(new DNSSoaRR("example.com", 100, | pkt.add_answer(new DNSSoaRR("example.com", 100, | |||
"soa1.example.com", "fred.example.com", | "soa1.example.com", "fred.example.com", | |||
1, 2, 3, 4, 5)); | 1, 2, 3, 4, 5)); | |||
skipping to change at line 96 | skipping to change at line 96 | |||
// 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_soa_reply(data.data(), len, &soa)); | EXPECT_EQ(ARES_EBADRESP, ares_parse_soa_reply(data.data(), len, &soa)); | |||
} | } | |||
} | } | |||
TEST_F(LibraryTest, ParseSoaAnyReplyAllocFail) { | TEST_F(LibraryTest, ParseSoaAnyReplyAllocFail) { | |||
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_any)) | .add_question(new DNSQuestion("example.com", T_ANY)) | |||
.add_answer(new DNSSoaRR("example.com", 100, | .add_answer(new DNSSoaRR("example.com", 100, | |||
"soa1.example.com", "fred.example.com", | "soa1.example.com", "fred.example.com", | |||
1, 2, 3, 4, 5)); | 1, 2, 3, 4, 5)); | |||
std::vector<byte> data = pkt.data(); | std::vector<byte> data = pkt.data(); | |||
struct ares_soa_reply* soa = nullptr; | struct ares_soa_reply* soa = 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_soa_reply(data.data(), data.size(), &soa)) << ii; | EXPECT_EQ(ARES_ENOMEM, ares_parse_soa_reply(data.data(), data.size(), &soa)) << ii; | |||
End of changes. 8 change blocks. | ||||
8 lines changed or deleted | 8 lines changed or added |