Commit 9ef1b71c authored by Matthias Körber's avatar Matthias Körber Committed by Commit Bot

Removed unused methods from |PslMatchingHelper|.

Change-Id: If34a5e85087efd2822d6bf9e91f30983f548d5ee
Bug: 875768
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1824086Reviewed-by: default avatarMatthias Körber <koerber@google.com>
Reviewed-by: default avatarVadym Doroshenko <dvadym@chromium.org>
Commit-Queue: Vadym Doroshenko <dvadym@chromium.org>
Cr-Commit-Position: refs/heads/master@{#699819}
parent b083f936
...@@ -124,27 +124,4 @@ std::string GetRegistryControlledDomain(const GURL& signon_realm) { ...@@ -124,27 +124,4 @@ std::string GetRegistryControlledDomain(const GURL& signon_realm) {
net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
} }
std::string GetOrganizationIdentifyingName(const GURL& url) {
if (!url.is_valid())
return std::string();
const std::string organization_and_registrar =
net::registry_controlled_domains::GetDomainAndRegistry(
url, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
const size_t registrar_length =
net::registry_controlled_domains::GetRegistryLength(
url, net::registry_controlled_domains::INCLUDE_UNKNOWN_REGISTRIES,
net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
if (organization_and_registrar.empty() || !registrar_length ||
registrar_length == std::string::npos) {
return std::string();
}
// No CHECK, std::string::substr gracefully handles an underflow there.
DCHECK_LT(registrar_length, organization_and_registrar.size());
return organization_and_registrar.substr(
0, organization_and_registrar.size() - registrar_length - 1);
}
} // namespace password_manager } // namespace password_manager
...@@ -64,11 +64,6 @@ bool IsPublicSuffixDomainMatch(const std::string& url1, ...@@ -64,11 +64,6 @@ bool IsPublicSuffixDomainMatch(const std::string& url1,
// registry-controlled domain part. // registry-controlled domain part.
std::string GetRegistryControlledDomain(const GURL& signon_realm); std::string GetRegistryControlledDomain(const GURL& signon_realm);
// Returns the organization-identifying name of the host of |url|, that is, the
// first domain name label below the effective TLD. Returns the empty string for
// URLs where these concepts are ill-defined, as well as for invalid URLs.
std::string GetOrganizationIdentifyingName(const GURL& url);
} // namespace password_manager } // namespace password_manager
#endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PSL_MATCHING_HELPER_H_ #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PSL_MATCHING_HELPER_H_
...@@ -400,102 +400,6 @@ TEST(PSLMatchingUtilsTest, IsFederatedPSLMatch) { ...@@ -400,102 +400,6 @@ TEST(PSLMatchingUtilsTest, IsFederatedPSLMatch) {
} }
} }
TEST(PSLMatchingUtilsTest, GetOrganizationIdentifyingName) {
static constexpr const struct {
const char* url;
const char* expected_organization_name;
} kTestCases[] = {
{"http://example.com/login", "example"},
{"https://example.com", "example"},
{"ftp://example.com/ftp_realm", "example"},
{"http://foo.bar.example.com", "example"},
{"http://example.co.uk", "example"},
{"http://bar.example.appspot.com", "example"},
{"http://foo.bar", "foo"},
{"https://user:pass@www.example.com:80/path?query#ref", "example"},
{"http://www.foo+bar.com", "foo+bar"},
{"http://www.foo-bar.com", "foo-bar"},
{"https://foo_bar.com", "foo_bar"},
{"http://www.foo%2Bbar.com", "foo+bar"},
{"http://www.foo%2Dbar.com", "foo-bar"},
{"https://foo%5Fbar.com", "foo_bar"},
{"http://www.foo%2Ebar.com", "bar"},
// Internationalized Domain Names: each dot-separated label of the domain
// name is individually Punycode-encoded, so the organization-identifying
// name is still well-defined and can be determined as normal.
// , ,
// szotar = sz\xc3\xb3t\xc3\xa1r (UTF-8) = xn--sztr-7na0i (IDN)
// | |
// U+00E1 U+00F3
{"https://www.sz\xc3\xb3t\xc3\xa1r.appspot.com", "xn--sztr-7na0i"},
{"http://www.foo!bar.com", "foo%21bar"},
{"http://www.foo%21bar.com", "foo%21bar"},
{"http://www.foo$bar.com", "foo%24bar"},
{"http://www.foo&bar.com", "foo%26bar"},
{"http://www.foo\'bar.com", "foo%27bar"},
{"http://www.foo(bar.com", "foo%28bar"},
{"http://www.foo)bar.com", "foo%29bar"},
{"http://www.foo*bar.com", "foo%2Abar"},
{"http://www.foo,bar.com", "foo%2Cbar"},
{"http://www.foo=bar.com", "foo%3Dbar"},
// URLs without host portions, hosts without registry controlled domains
// should, or hosts consisting of a registry yield the empty string.
{"http://localhost", ""},
{"http://co.uk", ""},
{"http://google", ""},
{"http://127.0.0.1", ""},
{"file:///usr/bin/stuff", ""},
{"federation://example.com/google.com", ""},
{"android://hash@com.example/", ""},
{"http://[1080:0:0:0:8:800:200C:417A]/", ""},
{"http://[3ffe:2a00:100:7031::1]", ""},
{"http://[::192.9.5.5]/", ""},
// Invalid URLs should yield the empty string.
{"", ""},
{"http://", ""},
{"bad url", ""},
{"http://www.example.com/%00", ""},
{"http://www.foo;bar.com", ""},
{"http://www.foo~bar.com", ""},
};
for (const auto& test_case : kTestCases) {
SCOPED_TRACE(test_case.url);
GURL url(test_case.url);
EXPECT_EQ(test_case.expected_organization_name,
GetOrganizationIdentifyingName(url));
}
}
// Apart from alphanumeric characters and '.', only |kExpectedUnescapedChars|
// are expected to appear without percent-encoding in the domain of a valid,
// canonicalized URL.
//
// The purpose of this test is to ensure that the test cases around unescaped
// special characters in `GetOrganizationIdentifyingName` are exhaustive.
TEST(PSLMatchingUtilsTest,
GetOrganizationIdentifyingName_UnescapedSpecialChars) {
static constexpr const char kExpectedNonAlnumChars[] = {'+', '-', '_', '.'};
for (int chr = 0; chr <= 255; ++chr) {
const auto percent_encoded = base::StringPrintf("http://a%%%02Xb.hu/", chr);
const GURL url(percent_encoded);
if (isalnum(chr) || base::Contains(kExpectedNonAlnumChars, chr)) {
ASSERT_TRUE(url.is_valid());
const auto percent_decoded = base::StringPrintf(
"http://a%cb.hu/", base::ToLowerASCII(static_cast<char>(chr)));
EXPECT_EQ(percent_decoded, url.spec());
} else if (url.is_valid()) {
EXPECT_EQ(percent_encoded, url.spec());
}
}
}
} // namespace } // namespace
} // namespace password_manager } // namespace password_manager
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment