|
|
|
@ -38,6 +38,40 @@ TEST_F(LibraryTest, ParseTxtReplyOK) { |
|
|
|
|
ares_free_data(txt); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(LibraryTest, ParseTxtExtReplyOK) { |
|
|
|
|
DNSPacket pkt; |
|
|
|
|
std::string expected1 = "txt1.example.com"; |
|
|
|
|
std::string expected2a = "txt2a"; |
|
|
|
|
std::string expected2b("ABC\0ABC", 7); |
|
|
|
|
pkt.set_qid(0x1234).set_response().set_aa() |
|
|
|
|
.add_question(new DNSQuestion("example.com", ns_t_mx)) |
|
|
|
|
.add_answer(new DNSTxtRR("example.com", 100, {expected1})) |
|
|
|
|
.add_answer(new DNSTxtRR("example.com", 100, {expected2a, expected2b})); |
|
|
|
|
std::vector<byte> data = pkt.data(); |
|
|
|
|
|
|
|
|
|
struct ares_txt_ext* txt = nullptr; |
|
|
|
|
EXPECT_EQ(ARES_SUCCESS, ares_parse_txt_reply_ext(data.data(), data.size(), &txt)); |
|
|
|
|
ASSERT_NE(nullptr, txt); |
|
|
|
|
EXPECT_EQ(std::vector<byte>(expected1.data(), expected1.data() + expected1.size()), |
|
|
|
|
std::vector<byte>(txt->txt, txt->txt + txt->length)); |
|
|
|
|
EXPECT_EQ(1, txt->record_start); |
|
|
|
|
|
|
|
|
|
struct ares_txt_ext* txt2 = txt->next; |
|
|
|
|
ASSERT_NE(nullptr, txt2); |
|
|
|
|
EXPECT_EQ(std::vector<byte>(expected2a.data(), expected2a.data() + expected2a.size()), |
|
|
|
|
std::vector<byte>(txt2->txt, txt2->txt + txt2->length)); |
|
|
|
|
EXPECT_EQ(1, txt2->record_start); |
|
|
|
|
|
|
|
|
|
struct ares_txt_ext* txt3 = txt2->next; |
|
|
|
|
ASSERT_NE(nullptr, txt3); |
|
|
|
|
EXPECT_EQ(std::vector<byte>(expected2b.data(), expected2b.data() + expected2b.size()), |
|
|
|
|
std::vector<byte>(txt3->txt, txt3->txt + txt3->length)); |
|
|
|
|
EXPECT_EQ(nullptr, txt3->next); |
|
|
|
|
EXPECT_EQ(0, txt3->record_start); |
|
|
|
|
|
|
|
|
|
ares_free_data(txt); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(LibraryTest, ParseTxtMalformedReply1) { |
|
|
|
|
std::vector<byte> data = { |
|
|
|
|
0x12, 0x34, // qid
|
|
|
|
|