Loading Android.bp +2 −0 Original line number Diff line number Diff line Loading @@ -199,6 +199,7 @@ cc_test { "dns_tls_test.cpp", "libnetd_resolv_test.cpp", "res_cache_test.cpp", "tests/resolv_test_utils.cpp", ], shared_libs: [ "libbase", Loading @@ -207,6 +208,7 @@ cc_test { "libssl", ], static_libs: [ "dnsresolver_aidl_interface-V2-cpp", "libgmock", "libnetd_resolv", "libnetd_test_dnsresponder", Loading libnetd_resolv_test.cpp +1 −45 Original line number Diff line number Diff line Loading @@ -28,16 +28,10 @@ #include "gethnamaddr.h" #include "resolv_cache.h" #include "stats.pb.h" #include "tests/resolv_test_utils.h" #define NAME(variable) #variable // TODO: make this dynamic and stop depending on implementation details. constexpr unsigned int TEST_NETID = 30; // Specifying 0 in ai_socktype or ai_protocol of struct addrinfo indicates that any type or // protocol can be returned by getaddrinfo(). constexpr unsigned int ANY = 0; namespace android { namespace net { Loading @@ -58,38 +52,6 @@ class TestBase : public ::testing::Test { resolv_delete_cache_for_net(TEST_NETID); } static std::string ToString(const hostent* he) { if (he == nullptr) return "<null>"; char buffer[INET6_ADDRSTRLEN]; if (!inet_ntop(he->h_addrtype, he->h_addr_list[0], buffer, sizeof(buffer))) { return "<invalid>"; } return buffer; } static std::string ToString(const addrinfo* ai) { if (!ai) return "<null>"; for (const auto* aip = ai; aip != nullptr; aip = aip->ai_next) { char host[NI_MAXHOST]; int rv = getnameinfo(aip->ai_addr, aip->ai_addrlen, host, sizeof(host), nullptr, 0, NI_NUMERICHOST); if (rv != 0) return gai_strerror(rv); return host; } return "<invalid>"; } size_t GetNumQueries(const test::DNSResponder& dns, const char* name) const { auto queries = dns.queries(); size_t found = 0; for (const auto& p : queries) { if (p.first == name) { ++found; } } return found; } int setResolvers() { const std::vector<std::string> servers = {test::kDefaultListenAddr}; const std::vector<std::string> domains = {"example.com"}; Loading @@ -111,12 +73,6 @@ class TestBase : public ::testing::Test { .dns_mark = MARK_UNSET, .uid = NET_CONTEXT_INVALID_UID, }; // Illegal hostnames static constexpr char kBadCharAfterPeriodHost[] = "hello.example.^com."; static constexpr char kBadCharBeforePeriodHost[] = "hello.example^.com."; static constexpr char kBadCharAtTheEndHost[] = "hello.example.com^."; static constexpr char kBadCharInTheMiddleOfLabelHost[] = "hello.ex^ample.com."; }; class ResolvGetAddrInfoTest : public TestBase {}; Loading resolver_test.cpp +1 −7 Original line number Diff line number Diff line Loading @@ -168,12 +168,6 @@ class ResolverTest : public ::testing::Test { DnsResponderClient mDnsClient; static constexpr char kLocalHost[] = "localhost"; static constexpr char kLocalHostAddr[] = "127.0.0.1"; static constexpr char kIp6LocalHost[] = "ip6-localhost"; static constexpr char kIp6LocalHostAddr[] = "::1"; static constexpr char kHelloExampleCom[] = "hello.example.com."; // Use a shared static DNS listener for all tests to avoid registering lots of listeners // which may be released late until process terminated. Currently, registered DNS listener // is removed by binder death notification which is fired when the process hosting an Loading Loading @@ -555,7 +549,7 @@ TEST_F(ResolverTest, GetAddrInfo_InvalidSocketType) { // TODO: Test other invalid socket types. const addrinfo hints = { .ai_family = AF_UNSPEC, .ai_protocol = 0, // any protocol .ai_protocol = ANY, .ai_socktype = SOCK_PACKET, }; addrinfo* result = nullptr; Loading tests/resolv_test_utils.h +16 −0 Original line number Diff line number Diff line Loading @@ -34,6 +34,22 @@ // TODO: make this dynamic and stop depending on implementation details. constexpr int TEST_NETID = 30; // Specifying 0 in ai_socktype or ai_protocol of struct addrinfo indicates that any type or // protocol can be returned by getaddrinfo(). constexpr unsigned int ANY = 0; static constexpr char kLocalHost[] = "localhost"; static constexpr char kLocalHostAddr[] = "127.0.0.1"; static constexpr char kIp6LocalHost[] = "ip6-localhost"; static constexpr char kIp6LocalHostAddr[] = "::1"; static constexpr char kHelloExampleCom[] = "hello.example.com."; // Illegal hostnames static constexpr char kBadCharAfterPeriodHost[] = "hello.example.^com."; static constexpr char kBadCharBeforePeriodHost[] = "hello.example^.com."; static constexpr char kBadCharAtTheEndHost[] = "hello.example.com^."; static constexpr char kBadCharInTheMiddleOfLabelHost[] = "hello.ex^ample.com."; size_t GetNumQueries(const test::DNSResponder& dns, const char* name); size_t GetNumQueriesForType(const test::DNSResponder& dns, ns_type type, const char* name); std::string ToString(const hostent* he); Loading Loading
Android.bp +2 −0 Original line number Diff line number Diff line Loading @@ -199,6 +199,7 @@ cc_test { "dns_tls_test.cpp", "libnetd_resolv_test.cpp", "res_cache_test.cpp", "tests/resolv_test_utils.cpp", ], shared_libs: [ "libbase", Loading @@ -207,6 +208,7 @@ cc_test { "libssl", ], static_libs: [ "dnsresolver_aidl_interface-V2-cpp", "libgmock", "libnetd_resolv", "libnetd_test_dnsresponder", Loading
libnetd_resolv_test.cpp +1 −45 Original line number Diff line number Diff line Loading @@ -28,16 +28,10 @@ #include "gethnamaddr.h" #include "resolv_cache.h" #include "stats.pb.h" #include "tests/resolv_test_utils.h" #define NAME(variable) #variable // TODO: make this dynamic and stop depending on implementation details. constexpr unsigned int TEST_NETID = 30; // Specifying 0 in ai_socktype or ai_protocol of struct addrinfo indicates that any type or // protocol can be returned by getaddrinfo(). constexpr unsigned int ANY = 0; namespace android { namespace net { Loading @@ -58,38 +52,6 @@ class TestBase : public ::testing::Test { resolv_delete_cache_for_net(TEST_NETID); } static std::string ToString(const hostent* he) { if (he == nullptr) return "<null>"; char buffer[INET6_ADDRSTRLEN]; if (!inet_ntop(he->h_addrtype, he->h_addr_list[0], buffer, sizeof(buffer))) { return "<invalid>"; } return buffer; } static std::string ToString(const addrinfo* ai) { if (!ai) return "<null>"; for (const auto* aip = ai; aip != nullptr; aip = aip->ai_next) { char host[NI_MAXHOST]; int rv = getnameinfo(aip->ai_addr, aip->ai_addrlen, host, sizeof(host), nullptr, 0, NI_NUMERICHOST); if (rv != 0) return gai_strerror(rv); return host; } return "<invalid>"; } size_t GetNumQueries(const test::DNSResponder& dns, const char* name) const { auto queries = dns.queries(); size_t found = 0; for (const auto& p : queries) { if (p.first == name) { ++found; } } return found; } int setResolvers() { const std::vector<std::string> servers = {test::kDefaultListenAddr}; const std::vector<std::string> domains = {"example.com"}; Loading @@ -111,12 +73,6 @@ class TestBase : public ::testing::Test { .dns_mark = MARK_UNSET, .uid = NET_CONTEXT_INVALID_UID, }; // Illegal hostnames static constexpr char kBadCharAfterPeriodHost[] = "hello.example.^com."; static constexpr char kBadCharBeforePeriodHost[] = "hello.example^.com."; static constexpr char kBadCharAtTheEndHost[] = "hello.example.com^."; static constexpr char kBadCharInTheMiddleOfLabelHost[] = "hello.ex^ample.com."; }; class ResolvGetAddrInfoTest : public TestBase {}; Loading
resolver_test.cpp +1 −7 Original line number Diff line number Diff line Loading @@ -168,12 +168,6 @@ class ResolverTest : public ::testing::Test { DnsResponderClient mDnsClient; static constexpr char kLocalHost[] = "localhost"; static constexpr char kLocalHostAddr[] = "127.0.0.1"; static constexpr char kIp6LocalHost[] = "ip6-localhost"; static constexpr char kIp6LocalHostAddr[] = "::1"; static constexpr char kHelloExampleCom[] = "hello.example.com."; // Use a shared static DNS listener for all tests to avoid registering lots of listeners // which may be released late until process terminated. Currently, registered DNS listener // is removed by binder death notification which is fired when the process hosting an Loading Loading @@ -555,7 +549,7 @@ TEST_F(ResolverTest, GetAddrInfo_InvalidSocketType) { // TODO: Test other invalid socket types. const addrinfo hints = { .ai_family = AF_UNSPEC, .ai_protocol = 0, // any protocol .ai_protocol = ANY, .ai_socktype = SOCK_PACKET, }; addrinfo* result = nullptr; Loading
tests/resolv_test_utils.h +16 −0 Original line number Diff line number Diff line Loading @@ -34,6 +34,22 @@ // TODO: make this dynamic and stop depending on implementation details. constexpr int TEST_NETID = 30; // Specifying 0 in ai_socktype or ai_protocol of struct addrinfo indicates that any type or // protocol can be returned by getaddrinfo(). constexpr unsigned int ANY = 0; static constexpr char kLocalHost[] = "localhost"; static constexpr char kLocalHostAddr[] = "127.0.0.1"; static constexpr char kIp6LocalHost[] = "ip6-localhost"; static constexpr char kIp6LocalHostAddr[] = "::1"; static constexpr char kHelloExampleCom[] = "hello.example.com."; // Illegal hostnames static constexpr char kBadCharAfterPeriodHost[] = "hello.example.^com."; static constexpr char kBadCharBeforePeriodHost[] = "hello.example^.com."; static constexpr char kBadCharAtTheEndHost[] = "hello.example.com^."; static constexpr char kBadCharInTheMiddleOfLabelHost[] = "hello.ex^ample.com."; size_t GetNumQueries(const test::DNSResponder& dns, const char* name); size_t GetNumQueriesForType(const test::DNSResponder& dns, ns_type type, const char* name); std::string ToString(const hostent* he); Loading