| OLD | NEW | 
|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "net/base/net_util.h" | 5 #include "net/base/net_util.h" | 
| 6 | 6 | 
| 7 #include <string.h> | 7 #include <string.h> | 
| 8 | 8 | 
| 9 #include <algorithm> | 9 #include <algorithm> | 
| 10 | 10 | 
| (...skipping 3480 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 3491     EXPECT_FALSE(IsSafePortableRelativePath(base::FilePath( | 3491     EXPECT_FALSE(IsSafePortableRelativePath(base::FilePath( | 
| 3492         kUnsafePortableBasenames[i]))) << kUnsafePortableBasenames[i]; | 3492         kUnsafePortableBasenames[i]))) << kUnsafePortableBasenames[i]; | 
| 3493     if (!base::FilePath::StringType(kUnsafePortableBasenames[i]).empty()) { | 3493     if (!base::FilePath::StringType(kUnsafePortableBasenames[i]).empty()) { | 
| 3494       EXPECT_FALSE(IsSafePortableRelativePath(safe_dirname.Append( | 3494       EXPECT_FALSE(IsSafePortableRelativePath(safe_dirname.Append( | 
| 3495           base::FilePath(kUnsafePortableBasenames[i])))) | 3495           base::FilePath(kUnsafePortableBasenames[i])))) | 
| 3496         << kUnsafePortableBasenames[i]; | 3496         << kUnsafePortableBasenames[i]; | 
| 3497     } | 3497     } | 
| 3498   } | 3498   } | 
| 3499 } | 3499 } | 
| 3500 | 3500 | 
|  | 3501 struct NonUniqueNameTestData { | 
|  | 3502   bool is_unique; | 
|  | 3503   const char* hostname; | 
|  | 3504 }; | 
|  | 3505 | 
|  | 3506 // Google Test pretty-printer. | 
|  | 3507 void PrintTo(const NonUniqueNameTestData& data, std::ostream* os) { | 
|  | 3508   ASSERT_TRUE(data.hostname); | 
|  | 3509   *os << " hostname: " << testing::PrintToString(data.hostname) | 
|  | 3510       << "; is_unique: " << testing::PrintToString(data.is_unique); | 
|  | 3511 } | 
|  | 3512 | 
|  | 3513 const NonUniqueNameTestData kNonUniqueNameTestData[] = { | 
|  | 3514     // Domains under ICANN-assigned domains. | 
|  | 3515     { true, "google.com" }, | 
|  | 3516     { true, "google.co.uk" }, | 
|  | 3517     // Domains under private registries. | 
|  | 3518     { true, "appspot.com" }, | 
|  | 3519     { true, "test.appspot.com" }, | 
|  | 3520     // IPv4 addresses (in various forms). | 
|  | 3521     { true, "8.8.8.8" }, | 
|  | 3522     { true, "1.2.3" }, | 
|  | 3523     { true, "14.15" }, | 
|  | 3524     { true, "676768" }, | 
|  | 3525     // IPv6 addresses. | 
|  | 3526     { true, "FEDC:ba98:7654:3210:FEDC:BA98:7654:3210" }, | 
|  | 3527     { true, "::192.9.5.5" }, | 
|  | 3528     { true, "FEED::BEEF" }, | 
|  | 3529     // 'internal'/non-IANA assigned domains. | 
|  | 3530     { false, "intranet" }, | 
|  | 3531     { false, "intranet." }, | 
|  | 3532     { false, "intranet.example" }, | 
|  | 3533     { false, "host.intranet.example" }, | 
|  | 3534     // gTLDs under discussion, but not yet assigned. | 
|  | 3535     { false, "intranet.corp" }, | 
|  | 3536     { false, "example.tech" }, | 
|  | 3537     { false, "intranet.internal" }, | 
|  | 3538     // Invalid host names are treated as unique - but expected to be | 
|  | 3539     // filtered out before then. | 
|  | 3540     { true, "junk)(£)$*!@~#" }, | 
|  | 3541     { true, "w$w.example.com" }, | 
|  | 3542     { true, "nocolonsallowed:example" }, | 
|  | 3543     { true, "[::4.5.6.9]" }, | 
|  | 3544 }; | 
|  | 3545 | 
|  | 3546 class NetUtilNonUniqueNameTest | 
|  | 3547     : public testing::TestWithParam<NonUniqueNameTestData> { | 
|  | 3548  public: | 
|  | 3549   virtual ~NetUtilNonUniqueNameTest() {} | 
|  | 3550 | 
|  | 3551  protected: | 
|  | 3552   bool IsUnique(const std::string& hostname) { | 
|  | 3553     return !IsHostnameNonUnique(hostname); | 
|  | 3554   } | 
|  | 3555 }; | 
|  | 3556 | 
|  | 3557 // Test that internal/non-unique names are properly identified as such, but | 
|  | 3558 // that IP addresses and hosts beneath registry-controlled domains are flagged | 
|  | 3559 // as unique names. | 
|  | 3560 TEST_P(NetUtilNonUniqueNameTest, IsHostnameNonUnique) { | 
|  | 3561   const NonUniqueNameTestData& test_data = GetParam(); | 
|  | 3562 | 
|  | 3563   EXPECT_EQ(test_data.is_unique, IsUnique(test_data.hostname)); | 
|  | 3564 } | 
|  | 3565 | 
|  | 3566 INSTANTIATE_TEST_CASE_P(, NetUtilNonUniqueNameTest, | 
|  | 3567                         testing::ValuesIn(kNonUniqueNameTestData)); | 
|  | 3568 | 
| 3501 }  // namespace net | 3569 }  // namespace net | 
| OLD | NEW | 
|---|