|
|
@ -38,7 +38,7 @@ TEST_F(LibraryTest, ParseTxtReplyOK) { |
|
|
|
std::string expected2a = "txt2a"; |
|
|
|
std::string expected2a = "txt2a"; |
|
|
|
std::string expected2b("ABC\0ABC", 7); |
|
|
|
std::string expected2b("ABC\0ABC", 7); |
|
|
|
pkt.set_qid(0x1234).set_response().set_aa() |
|
|
|
pkt.set_qid(0x1234).set_response().set_aa() |
|
|
|
.add_question(new DNSQuestion("example.com", T_TXT)) |
|
|
|
.add_question(new DNSQuestion("example.com", T_MX)) |
|
|
|
.add_answer(new DNSTxtRR("example.com", 100, {expected1})) |
|
|
|
.add_answer(new DNSTxtRR("example.com", 100, {expected1})) |
|
|
|
.add_answer(new DNSTxtRR("example.com", 100, {expected2a, expected2b})); |
|
|
|
.add_answer(new DNSTxtRR("example.com", 100, {expected2a, expected2b})); |
|
|
|
std::vector<byte> data = pkt.data(); |
|
|
|
std::vector<byte> data = pkt.data(); |
|
|
@ -68,7 +68,7 @@ TEST_F(LibraryTest, ParseTxtExtReplyOK) { |
|
|
|
std::string expected2a = "txt2a"; |
|
|
|
std::string expected2a = "txt2a"; |
|
|
|
std::string expected2b("ABC\0ABC", 7); |
|
|
|
std::string expected2b("ABC\0ABC", 7); |
|
|
|
pkt.set_qid(0x1234).set_response().set_aa() |
|
|
|
pkt.set_qid(0x1234).set_response().set_aa() |
|
|
|
.add_question(new DNSQuestion("example.com", T_TXT)) |
|
|
|
.add_question(new DNSQuestion("example.com", T_MX)) |
|
|
|
.add_answer(new DNSTxtRR("example.com", 100, {expected1})) |
|
|
|
.add_answer(new DNSTxtRR("example.com", 100, {expected1})) |
|
|
|
.add_answer(new DNSTxtRR("example.com", 100, {expected2a, expected2b})); |
|
|
|
.add_answer(new DNSTxtRR("example.com", 100, {expected2a, expected2b})); |
|
|
|
std::vector<byte> data = pkt.data(); |
|
|
|
std::vector<byte> data = pkt.data(); |
|
|
@ -95,39 +95,6 @@ TEST_F(LibraryTest, ParseTxtExtReplyOK) { |
|
|
|
ares_free_data(txt); |
|
|
|
ares_free_data(txt); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(LibraryTest, ParseTxtEmpty) { |
|
|
|
|
|
|
|
DNSPacket pkt; |
|
|
|
|
|
|
|
std::string expected1 = ""; |
|
|
|
|
|
|
|
pkt.set_qid(0x1234).set_response().set_aa() |
|
|
|
|
|
|
|
.add_question(new DNSQuestion("example.com", T_TXT)) |
|
|
|
|
|
|
|
.add_answer(new DNSTxtRR("example.com", 100, {expected1})); |
|
|
|
|
|
|
|
std::vector<byte> data = pkt.data(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ares_dns_record_t *dnsrec = NULL; |
|
|
|
|
|
|
|
ares_dns_rr_t *rr = NULL; |
|
|
|
|
|
|
|
EXPECT_EQ(ARES_SUCCESS, ares_dns_parse(data.data(), data.size(), 0, &dnsrec)); |
|
|
|
|
|
|
|
EXPECT_EQ(1, ares_dns_record_rr_cnt(dnsrec, ARES_SECTION_ANSWER)); |
|
|
|
|
|
|
|
rr = ares_dns_record_rr_get(dnsrec, ARES_SECTION_ANSWER, 0); |
|
|
|
|
|
|
|
ASSERT_NE(nullptr, rr); |
|
|
|
|
|
|
|
EXPECT_EQ(ARES_REC_TYPE_TXT, ares_dns_rr_get_type(rr)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
size_t txtdata_len; |
|
|
|
|
|
|
|
const unsigned char *txtdata; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Using array methodology */ |
|
|
|
|
|
|
|
EXPECT_EQ(1, ares_dns_rr_get_abin_cnt(rr, ARES_RR_TXT_DATA)); |
|
|
|
|
|
|
|
txtdata = ares_dns_rr_get_abin(rr, ARES_RR_TXT_DATA, 0, &txtdata_len); |
|
|
|
|
|
|
|
EXPECT_EQ(txtdata_len, 0); |
|
|
|
|
|
|
|
EXPECT_NE(nullptr, txtdata); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Using combined methodology */ |
|
|
|
|
|
|
|
txtdata = ares_dns_rr_get_bin(rr, ARES_RR_TXT_DATA, &txtdata_len); |
|
|
|
|
|
|
|
EXPECT_EQ(txtdata_len, 0); |
|
|
|
|
|
|
|
EXPECT_NE(nullptr, txtdata); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ares_dns_record_destroy(dnsrec); dnsrec = NULL; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(LibraryTest, ParseTxtMalformedReply1) { |
|
|
|
TEST_F(LibraryTest, ParseTxtMalformedReply1) { |
|
|
|
std::vector<byte> data = { |
|
|
|
std::vector<byte> data = { |
|
|
|
0x12, 0x34, // qid
|
|
|
|
0x12, 0x34, // qid
|
|
|
@ -246,7 +213,7 @@ TEST_F(LibraryTest, ParseTxtReplyErrors) { |
|
|
|
std::string expected2a = "txt2a"; |
|
|
|
std::string expected2a = "txt2a"; |
|
|
|
std::string expected2b = "txt2b"; |
|
|
|
std::string expected2b = "txt2b"; |
|
|
|
pkt.set_qid(0x1234).set_response().set_aa() |
|
|
|
pkt.set_qid(0x1234).set_response().set_aa() |
|
|
|
.add_question(new DNSQuestion("example.com", T_TXT)) |
|
|
|
.add_question(new DNSQuestion("example.com", T_MX)) |
|
|
|
.add_answer(new DNSTxtRR("example.com", 100, {expected1})) |
|
|
|
.add_answer(new DNSTxtRR("example.com", 100, {expected1})) |
|
|
|
.add_answer(new DNSTxtRR("example.com", 100, {expected1})) |
|
|
|
.add_answer(new DNSTxtRR("example.com", 100, {expected1})) |
|
|
|
.add_answer(new DNSTxtRR("example.com", 100, {expected2a, expected2b})); |
|
|
|
.add_answer(new DNSTxtRR("example.com", 100, {expected2a, expected2b})); |
|
|
@ -260,7 +227,7 @@ TEST_F(LibraryTest, ParseTxtReplyErrors) { |
|
|
|
txt = nullptr; |
|
|
|
txt = nullptr; |
|
|
|
EXPECT_EQ(ARES_EBADRESP, ares_parse_txt_reply(data.data(), (int)data.size(), &txt)); |
|
|
|
EXPECT_EQ(ARES_EBADRESP, ares_parse_txt_reply(data.data(), (int)data.size(), &txt)); |
|
|
|
EXPECT_EQ(nullptr, txt); |
|
|
|
EXPECT_EQ(nullptr, txt); |
|
|
|
pkt.add_question(new DNSQuestion("example.com", T_TXT)); |
|
|
|
pkt.add_question(new DNSQuestion("example.com", T_MX)); |
|
|
|
|
|
|
|
|
|
|
|
#ifdef DISABLED |
|
|
|
#ifdef DISABLED |
|
|
|
// Question != answer
|
|
|
|
// Question != answer
|
|
|
@ -273,13 +240,13 @@ TEST_F(LibraryTest, ParseTxtReplyErrors) { |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
// Two questions.
|
|
|
|
// Two questions.
|
|
|
|
pkt.add_question(new DNSQuestion("example.com", T_TXT)); |
|
|
|
pkt.add_question(new DNSQuestion("example.com", T_MX)); |
|
|
|
data = pkt.data(); |
|
|
|
data = pkt.data(); |
|
|
|
txt = nullptr; |
|
|
|
txt = nullptr; |
|
|
|
EXPECT_EQ(ARES_EBADRESP, ares_parse_txt_reply(data.data(), (int)data.size(), &txt)); |
|
|
|
EXPECT_EQ(ARES_EBADRESP, ares_parse_txt_reply(data.data(), (int)data.size(), &txt)); |
|
|
|
EXPECT_EQ(nullptr, txt); |
|
|
|
EXPECT_EQ(nullptr, txt); |
|
|
|
pkt.questions_.clear(); |
|
|
|
pkt.questions_.clear(); |
|
|
|
pkt.add_question(new DNSQuestion("example.com", T_TXT)); |
|
|
|
pkt.add_question(new DNSQuestion("example.com", T_MX)); |
|
|
|
|
|
|
|
|
|
|
|
// No answer.
|
|
|
|
// No answer.
|
|
|
|
pkt.answers_.clear(); |
|
|
|
pkt.answers_.clear(); |
|
|
@ -307,7 +274,7 @@ TEST_F(LibraryTest, ParseTxtReplyAllocFail) { |
|
|
|
std::string expected2a = "txt2a"; |
|
|
|
std::string expected2a = "txt2a"; |
|
|
|
std::string expected2b = "txt2b"; |
|
|
|
std::string expected2b = "txt2b"; |
|
|
|
pkt.set_qid(0x1234).set_response().set_aa() |
|
|
|
pkt.set_qid(0x1234).set_response().set_aa() |
|
|
|
.add_question(new DNSQuestion("example.com", T_TXT)) |
|
|
|
.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 DNSTxtRR("c.example.com", 100, {expected1})) |
|
|
|
.add_answer(new DNSTxtRR("c.example.com", 100, {expected1})) |
|
|
|
.add_answer(new DNSTxtRR("c.example.com", 100, {expected1})) |
|
|
|
.add_answer(new DNSTxtRR("c.example.com", 100, {expected1})) |
|
|
|