ares-test-misc.cc (c-ares-1.17.1) | : | ares-test-misc.cc (c-ares-1.17.2) | ||
---|---|---|---|---|
skipping to change at line 169 | skipping to change at line 169 | |||
struct in_addr addr; | struct in_addr addr; | |||
addr.s_addr = htonl(0x01020304); | addr.s_addr = htonl(0x01020304); | |||
char buffer[256]; | char buffer[256]; | |||
EXPECT_EQ(buffer, ares_inet_ntop(AF_INET, &addr, buffer, sizeof(buffer))); | EXPECT_EQ(buffer, ares_inet_ntop(AF_INET, &addr, buffer, sizeof(buffer))); | |||
EXPECT_EQ("1.2.3.4", std::string(buffer)); | EXPECT_EQ("1.2.3.4", std::string(buffer)); | |||
} | } | |||
TEST_F(LibraryTest, Mkquery) { | TEST_F(LibraryTest, Mkquery) { | |||
byte* p; | byte* p; | |||
int len; | int len; | |||
ares_mkquery("example.com", ns_c_in, ns_t_a, 0x1234, 0, &p, &len); | ares_mkquery("example.com", C_IN, T_A, 0x1234, 0, &p, &len); | |||
std::vector<byte> data(p, p + len); | std::vector<byte> data(p, p + len); | |||
ares_free_string(p); | ares_free_string(p); | |||
std::string actual = PacketToString(data); | std::string actual = PacketToString(data); | |||
DNSPacket pkt; | DNSPacket pkt; | |||
pkt.set_qid(0x1234).add_question(new DNSQuestion("example.com", ns_t_a)); | pkt.set_qid(0x1234).add_question(new DNSQuestion("example.com", T_A)); | |||
std::string expected = PacketToString(pkt.data()); | std::string expected = PacketToString(pkt.data()); | |||
EXPECT_EQ(expected, actual); | EXPECT_EQ(expected, actual); | |||
} | } | |||
TEST_F(LibraryTest, CreateQuery) { | TEST_F(LibraryTest, CreateQuery) { | |||
byte* p; | byte* p; | |||
int len; | int len; | |||
EXPECT_EQ(ARES_SUCCESS, | EXPECT_EQ(ARES_SUCCESS, | |||
ares_create_query("exam\\@le.com", ns_c_in, ns_t_a, 0x1234, 0, | ares_create_query("exam\\@le.com", C_IN, T_A, 0x1234, 0, | |||
&p, &len, 0)); | &p, &len, 0)); | |||
std::vector<byte> data(p, p + len); | std::vector<byte> data(p, p + len); | |||
ares_free_string(p); | ares_free_string(p); | |||
std::string actual = PacketToString(data); | std::string actual = PacketToString(data); | |||
DNSPacket pkt; | DNSPacket pkt; | |||
pkt.set_qid(0x1234).add_question(new DNSQuestion("exam@le.com", ns_t_a)); | pkt.set_qid(0x1234).add_question(new DNSQuestion("exam@le.com", T_A)); | |||
std::string expected = PacketToString(pkt.data()); | std::string expected = PacketToString(pkt.data()); | |||
EXPECT_EQ(expected, actual); | EXPECT_EQ(expected, actual); | |||
} | } | |||
TEST_F(LibraryTest, CreateQueryTrailingEscapedDot) { | TEST_F(LibraryTest, CreateQueryTrailingEscapedDot) { | |||
byte* p; | byte* p; | |||
int len; | int len; | |||
EXPECT_EQ(ARES_SUCCESS, | EXPECT_EQ(ARES_SUCCESS, | |||
ares_create_query("example.com\\.", ns_c_in, ns_t_a, 0x1234, 0, | ares_create_query("example.com\\.", C_IN, T_A, 0x1234, 0, | |||
&p, &len, 0)); | &p, &len, 0)); | |||
std::vector<byte> data(p, p + len); | std::vector<byte> data(p, p + len); | |||
ares_free_string(p); | ares_free_string(p); | |||
std::string actual = PacketToString(data); | std::string actual = PacketToString(data); | |||
EXPECT_EQ("REQ QRY Q:{'example.com\\.' IN A}", actual); | EXPECT_EQ("REQ QRY Q:{'example.com\\.' IN A}", actual); | |||
} | } | |||
TEST_F(LibraryTest, CreateQueryNameTooLong) { | TEST_F(LibraryTest, CreateQueryNameTooLong) { | |||
byte* p; | byte* p; | |||
int len; | int len; | |||
EXPECT_EQ(ARES_EBADNAME, | EXPECT_EQ(ARES_EBADNAME, | |||
ares_create_query( | ares_create_query( | |||
"a1234567890123456789.b1234567890123456789.c1234567890123456789.d1 234567890123456789." | "a1234567890123456789.b1234567890123456789.c1234567890123456789.d1 234567890123456789." | |||
"a1234567890123456789.b1234567890123456789.c1234567890123456789.d1 234567890123456789." | "a1234567890123456789.b1234567890123456789.c1234567890123456789.d1 234567890123456789." | |||
"a1234567890123456789.b1234567890123456789.c1234567890123456789.d1 234567890123456789." | "a1234567890123456789.b1234567890123456789.c1234567890123456789.d1 234567890123456789." | |||
"x1234567890123456789.y1234567890123456789.", | "x1234567890123456789.y1234567890123456789.", | |||
ns_c_in, ns_t_a, 0x1234, 0, &p, &len, 0)); | C_IN, T_A, 0x1234, 0, &p, &len, 0)); | |||
} | } | |||
TEST_F(LibraryTest, CreateQueryFailures) { | TEST_F(LibraryTest, CreateQueryFailures) { | |||
byte* p; | byte* p; | |||
int len; | int len; | |||
// RC1035 has a 255 byte limit on names. | // RC1035 has a 255 byte limit on names. | |||
std::string longname; | std::string longname; | |||
for (int ii = 0; ii < 17; ii++) { | for (int ii = 0; ii < 17; ii++) { | |||
longname += "fedcba9876543210"; | longname += "fedcba9876543210"; | |||
} | } | |||
p = nullptr; | p = nullptr; | |||
EXPECT_EQ(ARES_EBADNAME, | EXPECT_EQ(ARES_EBADNAME, | |||
ares_create_query(longname.c_str(), ns_c_in, ns_t_a, 0x1234, 0, | ares_create_query(longname.c_str(), C_IN, T_A, 0x1234, 0, | |||
&p, &len, 0)); | &p, &len, 0)); | |||
if (p) ares_free_string(p); | if (p) ares_free_string(p); | |||
SetAllocFail(1); | SetAllocFail(1); | |||
p = nullptr; | p = nullptr; | |||
EXPECT_EQ(ARES_ENOMEM, | EXPECT_EQ(ARES_ENOMEM, | |||
ares_create_query("example.com", ns_c_in, ns_t_a, 0x1234, 0, | ares_create_query("example.com", C_IN, T_A, 0x1234, 0, | |||
&p, &len, 0)); | &p, &len, 0)); | |||
if (p) ares_free_string(p); | if (p) ares_free_string(p); | |||
// 63-char limit on a single label | // 63-char limit on a single label | |||
std::string longlabel = "a.a123456789b123456789c123456789d123456789e123456789f 123456789g123456789.org"; | std::string longlabel = "a.a123456789b123456789c123456789d123456789e123456789f 123456789g123456789.org"; | |||
p = nullptr; | p = nullptr; | |||
EXPECT_EQ(ARES_EBADNAME, | EXPECT_EQ(ARES_EBADNAME, | |||
ares_create_query(longlabel.c_str(), ns_c_in, ns_t_a, 0x1234, 0, | ares_create_query(longlabel.c_str(), C_IN, T_A, 0x1234, 0, | |||
&p, &len, 0)); | &p, &len, 0)); | |||
if (p) ares_free_string(p); | if (p) ares_free_string(p); | |||
// Empty non-terminal label | // Empty non-terminal label | |||
p = nullptr; | p = nullptr; | |||
EXPECT_EQ(ARES_EBADNAME, | EXPECT_EQ(ARES_EBADNAME, | |||
ares_create_query("example..com", ns_c_in, ns_t_a, 0x1234, 0, | ares_create_query("example..com", C_IN, T_A, 0x1234, 0, | |||
&p, &len, 0)); | &p, &len, 0)); | |||
if (p) ares_free_string(p); | if (p) ares_free_string(p); | |||
} | } | |||
TEST_F(LibraryTest, CreateQueryOnionDomain) { | TEST_F(LibraryTest, CreateQueryOnionDomain) { | |||
byte* p; | byte* p; | |||
int len; | int len; | |||
EXPECT_EQ(ARES_ENOTFOUND, | EXPECT_EQ(ARES_ENOTFOUND, | |||
ares_create_query("dontleak.onion", ns_c_in, ns_t_a, 0x1234, 0, | ares_create_query("dontleak.onion", C_IN, T_A, 0x1234, 0, | |||
&p, &len, 0)); | &p, &len, 0)); | |||
} | } | |||
TEST_F(DefaultChannelTest, HostByNameOnionDomain) { | TEST_F(DefaultChannelTest, HostByNameOnionDomain) { | |||
HostResult result; | HostResult result; | |||
ares_gethostbyname(channel_, "dontleak.onion", AF_INET, HostCallback, &result) ; | ares_gethostbyname(channel_, "dontleak.onion", AF_INET, HostCallback, &result) ; | |||
EXPECT_TRUE(result.done_); | EXPECT_TRUE(result.done_); | |||
EXPECT_EQ(ARES_ENOTFOUND, result.status_); | EXPECT_EQ(ARES_ENOTFOUND, result.status_); | |||
} | } | |||
skipping to change at line 294 | skipping to change at line 294 | |||
ares_getaddrinfo(channel_, "dontleak.onion", NULL, &hints, AddrInfoCallback, & result); | ares_getaddrinfo(channel_, "dontleak.onion", NULL, &hints, AddrInfoCallback, & result); | |||
EXPECT_TRUE(result.done_); | EXPECT_TRUE(result.done_); | |||
EXPECT_EQ(ARES_ENOTFOUND, result.status_); | EXPECT_EQ(ARES_ENOTFOUND, result.status_); | |||
} | } | |||
// Interesting question: should tacking on a search domain let the query | // Interesting question: should tacking on a search domain let the query | |||
// through? It seems safer to reject it because "supersecret.onion.search" | // through? It seems safer to reject it because "supersecret.onion.search" | |||
// still leaks information about the query to malicious resolvers. | // still leaks information about the query to malicious resolvers. | |||
TEST_F(DefaultChannelTest, SearchOnionDomain) { | TEST_F(DefaultChannelTest, SearchOnionDomain) { | |||
SearchResult result; | SearchResult result; | |||
ares_search(channel_, "dontleak.onion", ns_c_in, ns_t_a, | ares_search(channel_, "dontleak.onion", C_IN, T_A, | |||
SearchCallback, &result); | SearchCallback, &result); | |||
EXPECT_TRUE(result.done_); | EXPECT_TRUE(result.done_); | |||
EXPECT_EQ(ARES_ENOTFOUND, result.status_); | EXPECT_EQ(ARES_ENOTFOUND, result.status_); | |||
} | } | |||
TEST_F(DefaultChannelTest, SendFailure) { | TEST_F(DefaultChannelTest, SendFailure) { | |||
unsigned char buf[2]; | unsigned char buf[2]; | |||
SearchResult result; | SearchResult result; | |||
ares_send(channel_, buf, sizeof(buf), SearchCallback, &result); | ares_send(channel_, buf, sizeof(buf), SearchCallback, &result); | |||
EXPECT_TRUE(result.done_); | EXPECT_TRUE(result.done_); | |||
skipping to change at line 457 | skipping to change at line 457 | |||
3, 'd', 'e', 'f', 0xC0, 0x02}; | 3, 'd', 'e', 'f', 0xC0, 0x02}; | |||
EXPECT_EQ(ARES_EBADNAME, | EXPECT_EQ(ARES_EBADNAME, | |||
ares_expand_name(data9.data() + 2, data9.data(), data9.size(), | ares_expand_name(data9.data() + 2, data9.data(), data9.size(), | |||
&name, &enclen)); | &name, &enclen)); | |||
} | } | |||
TEST_F(LibraryTest, CreateEDNSQuery) { | TEST_F(LibraryTest, CreateEDNSQuery) { | |||
byte* p; | byte* p; | |||
int len; | int len; | |||
EXPECT_EQ(ARES_SUCCESS, | EXPECT_EQ(ARES_SUCCESS, | |||
ares_create_query("example.com", ns_c_in, ns_t_a, 0x1234, 0, | ares_create_query("example.com", C_IN, T_A, 0x1234, 0, | |||
&p, &len, 1280)); | &p, &len, 1280)); | |||
std::vector<byte> data(p, p + len); | std::vector<byte> data(p, p + len); | |||
ares_free_string(p); | ares_free_string(p); | |||
std::string actual = PacketToString(data); | std::string actual = PacketToString(data); | |||
DNSPacket pkt; | DNSPacket pkt; | |||
pkt.set_qid(0x1234).add_question(new DNSQuestion("example.com", ns_t_a)) | pkt.set_qid(0x1234).add_question(new DNSQuestion("example.com", T_A)) | |||
.add_additional(new DNSOptRR(0, 1280)); | .add_additional(new DNSOptRR(0, 1280)); | |||
std::string expected = PacketToString(pkt.data()); | std::string expected = PacketToString(pkt.data()); | |||
EXPECT_EQ(expected, actual); | EXPECT_EQ(expected, actual); | |||
} | } | |||
TEST_F(LibraryTest, CreateRootQuery) { | TEST_F(LibraryTest, CreateRootQuery) { | |||
byte* p; | byte* p; | |||
int len; | int len; | |||
ares_create_query(".", ns_c_in, ns_t_a, 0x1234, 0, &p, &len, 0); | ares_create_query(".", C_IN, T_A, 0x1234, 0, &p, &len, 0); | |||
std::vector<byte> data(p, p + len); | std::vector<byte> data(p, p + len); | |||
ares_free_string(p); | ares_free_string(p); | |||
std::string actual = PacketToString(data); | std::string actual = PacketToString(data); | |||
DNSPacket pkt; | DNSPacket pkt; | |||
pkt.set_qid(0x1234).add_question(new DNSQuestion("", ns_t_a)); | pkt.set_qid(0x1234).add_question(new DNSQuestion("", T_A)); | |||
std::string expected = PacketToString(pkt.data()); | std::string expected = PacketToString(pkt.data()); | |||
EXPECT_EQ(expected, actual); | EXPECT_EQ(expected, actual); | |||
} | } | |||
TEST_F(LibraryTest, Version) { | TEST_F(LibraryTest, Version) { | |||
// Assume linked to same version | // Assume linked to same version | |||
EXPECT_EQ(std::string(ARES_VERSION_STR), | EXPECT_EQ(std::string(ARES_VERSION_STR), | |||
std::string(ares_version(nullptr))); | std::string(ares_version(nullptr))); | |||
int version; | int version; | |||
ares_version(&version); | ares_version(&version); | |||
End of changes. 16 change blocks. | ||||
16 lines changed or deleted | 16 lines changed or added |