Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Unified Diff: net/base/url_util_unittest.cc

Issue 1629733002: net: move IsHostnameNonUnique() into url_util.h (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix ssl_errors Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/base/url_util.cc ('k') | net/cert/cert_verify_proc.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/url_util_unittest.cc
diff --git a/net/base/url_util_unittest.cc b/net/base/url_util_unittest.cc
index 8140e3ab15e9f7f8030ec5dd1ea08c84bea46a18..b670165ad9dd17f6857336d1e799a2f67be4469e 100644
--- a/net/base/url_util_unittest.cc
+++ b/net/base/url_util_unittest.cc
@@ -4,6 +4,8 @@
#include "net/base/url_util.h"
+#include <ostream>
+
#include "base/format_macros.h"
#include "base/strings/utf_string_conversions.h"
#include "base/strings/stringprintf.h"
@@ -306,6 +308,85 @@ TEST(UrlUtilTest, CompliantHost) {
}
}
+struct NonUniqueNameTestData {
+ bool is_unique;
+ const char* const hostname;
+};
+
+// Google Test pretty-printer.
+void PrintTo(const NonUniqueNameTestData& data, std::ostream* os) {
+ ASSERT_TRUE(data.hostname);
+ *os << " hostname: " << testing::PrintToString(data.hostname)
+ << "; is_unique: " << testing::PrintToString(data.is_unique);
+}
+
+const NonUniqueNameTestData kNonUniqueNameTestData[] = {
+ // Domains under ICANN-assigned domains.
+ { true, "google.com" },
+ { true, "google.co.uk" },
+ // Domains under private registries.
+ { true, "appspot.com" },
+ { true, "test.appspot.com" },
+ // Unreserved IPv4 addresses (in various forms).
+ { true, "8.8.8.8" },
+ { true, "99.64.0.0" },
+ { true, "212.15.0.0" },
+ { true, "212.15" },
+ { true, "212.15.0" },
+ { true, "3557752832" },
+ // Reserved IPv4 addresses (in various forms).
+ { false, "192.168.0.0" },
+ { false, "192.168.0.6" },
+ { false, "10.0.0.5" },
+ { false, "10.0" },
+ { false, "10.0.0" },
+ { false, "3232235526" },
+ // Unreserved IPv6 addresses.
+ { true, "FFC0:ba98:7654:3210:FEDC:BA98:7654:3210" },
+ { true, "2000:ba98:7654:2301:EFCD:BA98:7654:3210" },
+ // Reserved IPv6 addresses.
+ { false, "::192.9.5.5" },
+ { false, "FEED::BEEF" },
+ { false, "FEC0:ba98:7654:3210:FEDC:BA98:7654:3210" },
+ // 'internal'/non-IANA assigned domains.
+ { false, "intranet" },
+ { false, "intranet." },
+ { false, "intranet.example" },
+ { false, "host.intranet.example" },
+ // gTLDs under discussion, but not yet assigned.
+ { false, "intranet.corp" },
+ { false, "intranet.internal" },
+ // Invalid host names are treated as unique - but expected to be
+ // filtered out before then.
+ { true, "junk)(£)$*!@~#" },
+ { true, "w$w.example.com" },
+ { true, "nocolonsallowed:example" },
+ { true, "[::4.5.6.9]" },
+};
+
+class UrlUtilNonUniqueNameTest
+ : public testing::TestWithParam<NonUniqueNameTestData> {
+ public:
+ virtual ~UrlUtilNonUniqueNameTest() {}
+
+ protected:
+ bool IsUnique(const std::string& hostname) {
+ return !IsHostnameNonUnique(hostname);
+ }
+};
+
+// Test that internal/non-unique names are properly identified as such, but
+// that IP addresses and hosts beneath registry-controlled domains are flagged
+// as unique names.
+TEST_P(UrlUtilNonUniqueNameTest, IsHostnameNonUnique) {
+ const NonUniqueNameTestData& test_data = GetParam();
+
+ EXPECT_EQ(test_data.is_unique, IsUnique(test_data.hostname));
+}
+
+INSTANTIATE_TEST_CASE_P(, UrlUtilNonUniqueNameTest,
+ testing::ValuesIn(kNonUniqueNameTestData));
+
TEST(UrlUtilTest, SimplifyUrlForRequest) {
struct {
const char* const input_url;
« no previous file with comments | « net/base/url_util.cc ('k') | net/cert/cert_verify_proc.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698