Chromium Code Reviews| 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 3501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3512 | 3512 |
| 3513 const NonUniqueNameTestData kNonUniqueNameTestData[] = { | 3513 const NonUniqueNameTestData kNonUniqueNameTestData[] = { |
| 3514 // Domains under ICANN-assigned domains. | 3514 // Domains under ICANN-assigned domains. |
| 3515 { true, "google.com" }, | 3515 { true, "google.com" }, |
| 3516 { true, "google.co.uk" }, | 3516 { true, "google.co.uk" }, |
| 3517 // Domains under private registries. | 3517 // Domains under private registries. |
| 3518 { true, "appspot.com" }, | 3518 { true, "appspot.com" }, |
| 3519 { true, "test.appspot.com" }, | 3519 { true, "test.appspot.com" }, |
| 3520 // IPv4 addresses (in various forms). | 3520 // IPv4 addresses (in various forms). |
| 3521 { true, "8.8.8.8" }, | 3521 { true, "8.8.8.8" }, |
| 3522 { true, "1.2.3" }, | 3522 { true, "99.64.0.0/10" }, |
| 3523 { true, "14.15" }, | 3523 { true, "212.15" }, |
| 3524 { true, "676768" }, | 3524 { false, "192.168.0.0" }, |
| 3525 { false, "192.168.0.6" }, | |
| 3526 //{ true, "676768" }, apparently this is valid & matches 0.0.0.0/8? | |
|
Ryan Sleevi
2013/08/07 19:04:44
This was just me banging on the keyboard.
felt
2013/08/08 19:35:33
ack
| |
| 3525 // IPv6 addresses. | 3527 // IPv6 addresses. |
| 3526 { true, "FEDC:ba98:7654:3210:FEDC:BA98:7654:3210" }, | 3528 { true, "FFC0:ba98:7654:3210:FEDC:BA98:7654:3210" }, |
| 3527 { true, "::192.9.5.5" }, | 3529 { true, "2000:ba98:7654:2301:EFCD:BA98:7654:3210" }, |
| 3528 { true, "FEED::BEEF" }, | 3530 { false, "::192.9.5.5" }, |
| 3531 { false, "FEED::BEEF" }, | |
| 3532 { false, "FEC0:ba98:7654:3210:FEDC:BA98:7654:3210" }, | |
| 3529 // 'internal'/non-IANA assigned domains. | 3533 // 'internal'/non-IANA assigned domains. |
| 3530 { false, "intranet" }, | 3534 { false, "intranet" }, |
| 3531 { false, "intranet." }, | 3535 { false, "intranet." }, |
| 3532 { false, "intranet.example" }, | 3536 { false, "intranet.example" }, |
| 3533 { false, "host.intranet.example" }, | 3537 { false, "host.intranet.example" }, |
| 3534 // gTLDs under discussion, but not yet assigned. | 3538 // gTLDs under discussion, but not yet assigned. |
| 3535 { false, "intranet.corp" }, | 3539 { false, "intranet.corp" }, |
| 3536 { false, "example.tech" }, | 3540 { false, "example.tech" }, |
| 3537 { false, "intranet.internal" }, | 3541 { false, "intranet.internal" }, |
| 3538 // Invalid host names are treated as unique - but expected to be | 3542 // Invalid host names are treated as unique - but expected to be |
| 3539 // filtered out before then. | 3543 // filtered out before then. |
| 3540 { true, "junk)(£)$*!@~#" }, | 3544 { true, "junk)(£)$*!@~#" }, |
| 3541 { true, "w$w.example.com" }, | 3545 { true, "w$w.example.com" }, |
| 3542 { true, "nocolonsallowed:example" }, | 3546 { true, "nocolonsallowed:example" }, |
| 3543 { true, "[::4.5.6.9]" }, | 3547 { true, "[::4.5.6.9]" }, |
| 3544 }; | 3548 }; |
| 3545 | 3549 |
| 3546 class NetUtilNonUniqueNameTest | 3550 class NetUtilNonUniqueNameTest |
| 3547 : public testing::TestWithParam<NonUniqueNameTestData> { | 3551 : public testing::TestWithParam<NonUniqueNameTestData> { |
| 3548 public: | 3552 public: |
| 3549 virtual ~NetUtilNonUniqueNameTest() {} | 3553 virtual ~NetUtilNonUniqueNameTest() {} |
| 3550 | 3554 |
| 3551 protected: | 3555 protected: |
| 3552 bool IsUnique(const std::string& hostname) { | 3556 bool IsUnique(const std::string& hostname) { |
| 3557 LOG(INFO) << hostname; | |
| 3553 return !IsHostnameNonUnique(hostname); | 3558 return !IsHostnameNonUnique(hostname); |
| 3554 } | 3559 } |
| 3555 }; | 3560 }; |
| 3556 | 3561 |
| 3557 // Test that internal/non-unique names are properly identified as such, but | 3562 // Test that internal/non-unique names are properly identified as such, but |
| 3558 // that IP addresses and hosts beneath registry-controlled domains are flagged | 3563 // that IP addresses and hosts beneath registry-controlled domains are flagged |
| 3559 // as unique names. | 3564 // as unique names. |
| 3560 TEST_P(NetUtilNonUniqueNameTest, IsHostnameNonUnique) { | 3565 TEST_P(NetUtilNonUniqueNameTest, IsHostnameNonUnique) { |
| 3561 const NonUniqueNameTestData& test_data = GetParam(); | 3566 const NonUniqueNameTestData& test_data = GetParam(); |
| 3562 | 3567 |
| 3563 EXPECT_EQ(test_data.is_unique, IsUnique(test_data.hostname)); | 3568 EXPECT_EQ(test_data.is_unique, IsUnique(test_data.hostname)); |
| 3564 } | 3569 } |
| 3565 | 3570 |
| 3566 INSTANTIATE_TEST_CASE_P(, NetUtilNonUniqueNameTest, | 3571 INSTANTIATE_TEST_CASE_P(, NetUtilNonUniqueNameTest, |
| 3567 testing::ValuesIn(kNonUniqueNameTestData)); | 3572 testing::ValuesIn(kNonUniqueNameTestData)); |
| 3568 | 3573 |
| 3569 } // namespace net | 3574 } // namespace net |
| OLD | NEW |