| Index: components/password_manager/core/browser/psl_matching_helper_unittest.cc
|
| diff --git a/components/password_manager/core/browser/psl_matching_helper_unittest.cc b/components/password_manager/core/browser/psl_matching_helper_unittest.cc
|
| index 8c176b3c80289e0f9d4b18ec54b14cebf574155c..66c798df366b9877620e8a973b5f2c3981952550 100644
|
| --- a/components/password_manager/core/browser/psl_matching_helper_unittest.cc
|
| +++ b/components/password_manager/core/browser/psl_matching_helper_unittest.cc
|
| @@ -14,150 +14,245 @@ namespace password_manager {
|
|
|
| namespace {
|
|
|
| -TEST(PSLMatchingUtilsTest, GetMatchResult) {
|
| +TEST(PSLMatchingUtilsTest, GetMatchResultNormalCredentials) {
|
| struct TestData {
|
| - const char* form_signon_realm;
|
| - const char* form_federation_origin;
|
| - autofill::PasswordForm::Scheme digest_scheme;
|
| - const char* digest_signon_realm;
|
| + const char* form_origin;
|
| const char* digest_origin;
|
| MatchResult match_result;
|
| };
|
|
|
| const TestData cases[] = {
|
| // Test Exact Matches.
|
| - {"http://facebook.com/", "", autofill::PasswordForm::SCHEME_HTML,
|
| - "http://facebook.com/", "http://facebook.com", MatchResult::EXACT_MATCH},
|
| + {"http://facebook.com/p", "http://facebook.com/p1",
|
| + MatchResult::EXACT_MATCH},
|
|
|
| - {"http://m.facebook.com/", "", autofill::PasswordForm::SCHEME_HTML,
|
| - "http://m.facebook.com/", "http://m.facebook.com",
|
| + {"http://m.facebook.com/p", "http://m.facebook.com/p1",
|
| MatchResult::EXACT_MATCH},
|
|
|
| // Scheme mismatch.
|
| - {"http://www.example.com/", "", autofill::PasswordForm::SCHEME_HTML,
|
| - "https://www.example.com/", "https://www.example.com",
|
| + {"http://www.example.com", "https://www.example.com",
|
| MatchResult::NO_MATCH},
|
|
|
| // Host mismatch.
|
| - {"http://www.example.com/", "", autofill::PasswordForm::SCHEME_HTML,
|
| - "http://wwwexample.com/", "http://wwwexample.com",
|
| + {"http://www.example.com", "http://wwwexample.com",
|
| MatchResult::NO_MATCH},
|
|
|
| - {"http://www.example1.com/", "", autofill::PasswordForm::SCHEME_HTML,
|
| - "http://www.example2.com/", "http://www.example2.com",
|
| + {"http://www.example1.com", "http://www.example2.com",
|
| MatchResult::NO_MATCH},
|
|
|
| // Port mismatch.
|
| - {"http://www.example.com:123/", "", autofill::PasswordForm::SCHEME_HTML,
|
| - "http://www.example.com/", "http://www.example.com",
|
| + {"http://www.example.com:123/", "http://www.example.com",
|
| MatchResult::NO_MATCH},
|
|
|
| // TLD mismatch.
|
| - {"http://www.example.org/", "", autofill::PasswordForm::SCHEME_HTML,
|
| - "http://www.example.com/", "http://www.example.com",
|
| + {"http://www.example.org/", "http://www.example.com/",
|
| MatchResult::NO_MATCH},
|
|
|
| // URLs without registry controlled domains should not match.
|
| - {"http://localhost/", "", autofill::PasswordForm::SCHEME_HTML,
|
| - "http://127.0.0.1/", "http://127.0.0.1", MatchResult::NO_MATCH},
|
| + {"http://localhost/", "http://127.0.0.1/", MatchResult::NO_MATCH},
|
|
|
| // Invalid URLs don't match.
|
| - {"http://www.example.com/", "", autofill::PasswordForm::SCHEME_HTML,
|
| - "http://", "", MatchResult::NO_MATCH},
|
| + {"http://www.example.com/", "http://", MatchResult::NO_MATCH},
|
|
|
| - {"", "", autofill::PasswordForm::SCHEME_HTML, "http://www.example.com/",
|
| - "http://www.example.com", MatchResult::NO_MATCH},
|
| + {"", "http://www.example.com/", MatchResult::NO_MATCH},
|
|
|
| - {"http://www.example.com", "", autofill::PasswordForm::SCHEME_HTML,
|
| - "bad url", "", MatchResult::NO_MATCH},
|
| + {"http://www.example.com", "bad url", MatchResult::NO_MATCH}};
|
|
|
| - // Test PSL Matches.
|
| - {"http://facebook.com/", "", autofill::PasswordForm::SCHEME_HTML,
|
| - "http://m.facebook.com/", "http://m.facebook.com",
|
| - MatchResult::PSL_MATCH},
|
| + for (const TestData& data : cases) {
|
| + autofill::PasswordForm form;
|
| + form.origin = GURL(data.form_origin);
|
| + form.signon_realm = form.origin.GetOrigin().spec();
|
| + PasswordStore::FormDigest digest(
|
| + autofill::PasswordForm::SCHEME_HTML,
|
| + GURL(data.digest_origin).GetOrigin().spec(), GURL(data.digest_origin));
|
|
|
| - {"https://facebook.com/", "", autofill::PasswordForm::SCHEME_HTML,
|
| - "https://m.facebook.com/", "https://m.facebook.com",
|
| + EXPECT_EQ(data.match_result, GetMatchResult(form, digest))
|
| + << "form_origin = " << data.form_origin << ", digest = " << digest;
|
| + }
|
| +}
|
| +
|
| +TEST(PSLMatchingUtilsTest, GetMatchResultPSL) {
|
| + struct TestData {
|
| + const char* form_origin;
|
| + const char* digest_origin;
|
| + MatchResult match_result;
|
| + };
|
| +
|
| + const TestData cases[] = {
|
| + // Test PSL Matches.
|
| + {"http://facebook.com/p1", "http://m.facebook.com/p2",
|
| MatchResult::PSL_MATCH},
|
|
|
| - {"https://www.facebook.com/", "", autofill::PasswordForm::SCHEME_HTML,
|
| - "https://m.facebook.com/", "https://m.facebook.com",
|
| + {"https://www.facebook.com/", "https://m.facebook.com",
|
| MatchResult::PSL_MATCH},
|
|
|
| // Don't apply PSL matching to Google domains.
|
| - {"https://google.com/", "", autofill::PasswordForm::SCHEME_HTML,
|
| - "https://maps.google.com/", "https://maps.google.com",
|
| + {"https://google.com/", "https://maps.google.com/",
|
| + MatchResult::NO_MATCH},
|
| +
|
| + // Scheme mismatch.
|
| + {"http://facebook.com/", "https://m.facebook.com/",
|
| + MatchResult::NO_MATCH},
|
| +
|
| + {"https://facebook.com/", "http://m.facebook.com/",
|
| + MatchResult::NO_MATCH},
|
| +
|
| + // Port mismatch.
|
| + {"http://facebook.com/", "https://m.facebook.com:8080/",
|
| MatchResult::NO_MATCH},
|
|
|
| - {"https://google.com/", "", autofill::PasswordForm::SCHEME_HTML,
|
| - "https://maps.google.com/", "https://maps.google.com",
|
| + {"http://facebook.com:8080/", "https://m.facebook.com/",
|
| MatchResult::NO_MATCH},
|
|
|
| + // Port match.
|
| + {"http://facebook.com:8080/p1", "http://m.facebook.com:8080/p2",
|
| + MatchResult::PSL_MATCH},
|
| + };
|
| +
|
| + for (const TestData& data : cases) {
|
| + autofill::PasswordForm form;
|
| + form.origin = GURL(data.form_origin);
|
| + form.signon_realm = form.origin.GetOrigin().spec();
|
| + PasswordStore::FormDigest digest(
|
| + autofill::PasswordForm::SCHEME_HTML,
|
| + GURL(data.digest_origin).GetOrigin().spec(), GURL(data.digest_origin));
|
| +
|
| + EXPECT_EQ(data.match_result, GetMatchResult(form, digest))
|
| + << "form_origin = " << data.form_origin << ", digest = " << digest;
|
| + }
|
| +}
|
| +
|
| +TEST(PSLMatchingUtilsTest, GetMatchResultFederated) {
|
| + struct TestData {
|
| + const char* form_origin;
|
| + const char* form_federation_origin;
|
| + const char* digest_origin;
|
| + MatchResult match_result;
|
| + };
|
| +
|
| + const TestData cases[] = {
|
| // Test Federated Matches.
|
| - {"federation://example.com/google.com", "https://google.com",
|
| - autofill::PasswordForm::SCHEME_HTML, "https://example.com/",
|
| - "https://example.com", MatchResult::FEDERATED_MATCH},
|
| + {"https://example.com/p", "https://google.com", "https://example.com/p2",
|
| + MatchResult::FEDERATED_MATCH},
|
|
|
| // Empty federation providers don't match.
|
| - {"federation://example.com/", "", autofill::PasswordForm::SCHEME_HTML,
|
| - "https://example.com/", "https://example.com", MatchResult::NO_MATCH},
|
| + {"https://example.com/", "", "https://example.com",
|
| + MatchResult::NO_MATCH},
|
|
|
| // Invalid origins don't match.
|
| - {"federation://example.com/google.com", "https://google.com",
|
| - autofill::PasswordForm::SCHEME_HTML, "https://example.com",
|
| - "example.com", MatchResult::NO_MATCH},
|
| + {"https://example.com/", "https://google.com", "example.com",
|
| + MatchResult::NO_MATCH},
|
| +
|
| + {"https://example.com/", "https://google.com", "example",
|
| + MatchResult::NO_MATCH},
|
| +
|
| + // TLD Mismatch.
|
| + {"https://example.com/", "https://google.com", "https://example.org",
|
| + MatchResult::NO_MATCH},
|
| +
|
| + // Scheme mismatch.
|
| + {"http://example.com/", "https://google.com", "https://example.com/",
|
| + MatchResult::NO_MATCH},
|
| +
|
| + {"https://example.com/", "https://google.com", "http://example.com/",
|
| + MatchResult::NO_MATCH},
|
| +
|
| + // Port mismatch.
|
| + {"https://localhost/", "https://google.com", "http://localhost:8080",
|
| + MatchResult::NO_MATCH},
|
|
|
| - {"federation://example.com/google.com", "https://google.com",
|
| - autofill::PasswordForm::SCHEME_HTML, "https://example.com", "example",
|
| + {"https://localhost:8080", "https://google.com", "http://localhost",
|
| MatchResult::NO_MATCH},
|
|
|
| + // Port match.
|
| + {"https://localhost:8080/p", "https://google.com",
|
| + "https://localhost:8080/p2", MatchResult::FEDERATED_MATCH},
|
| + };
|
| +
|
| + for (const TestData& data : cases) {
|
| + autofill::PasswordForm form;
|
| + form.origin = GURL(data.form_origin);
|
| + form.federation_origin = url::Origin(GURL(data.form_federation_origin));
|
| + form.signon_realm = "federation://" + form.origin.host() + "/" +
|
| + form.federation_origin.host();
|
| +
|
| + PasswordStore::FormDigest digest(
|
| + autofill::PasswordForm::SCHEME_HTML,
|
| + GURL(data.digest_origin).GetOrigin().spec(), GURL(data.digest_origin));
|
| +
|
| + EXPECT_EQ(data.match_result, GetMatchResult(form, digest))
|
| + << "form_origin = " << data.form_origin
|
| + << ", form_federation_origin = " << data.form_federation_origin
|
| + << ", digest = " << digest;
|
| + }
|
| +}
|
| +
|
| +TEST(PSLMatchingUtilsTest, GetMatchResultFederatedPSL) {
|
| + struct TestData {
|
| + const char* form_origin;
|
| + const char* form_federation_origin;
|
| + const char* digest_origin;
|
| + MatchResult match_result;
|
| + };
|
| +
|
| + const TestData cases[] = {
|
| // Test Federated PSL Matches.
|
| - {"federation://sub.example.com/google.com", "https://google.com",
|
| - autofill::PasswordForm::SCHEME_HTML, "https://sub.example.com/",
|
| - "https://sub.example.com", MatchResult::FEDERATED_MATCH},
|
| + {"https://sub.example.com/p2", "https://google.com",
|
| + "https://sub.example.com/p1", MatchResult::FEDERATED_MATCH},
|
|
|
| - {"federation://sub1.example.com/google.com", "https://google.com",
|
| - autofill::PasswordForm::SCHEME_HTML, "https://sub2.example.com/",
|
| - "https://sub2.example.com", MatchResult::FEDERATED_PSL_MATCH},
|
| + {"https://sub1.example.com/p1", "https://google.com",
|
| + "https://sub2.example.com/p2", MatchResult::FEDERATED_PSL_MATCH},
|
|
|
| - {"federation://example.com/google.com", "https://google.com",
|
| - autofill::PasswordForm::SCHEME_HTML, "https://sub.example.com/",
|
| - "https://sub.example.com", MatchResult::FEDERATED_PSL_MATCH},
|
| + {"https://example.com/", "https://google.com", "https://sub.example.com",
|
| + MatchResult::FEDERATED_PSL_MATCH},
|
|
|
| // Federated PSL matches do not apply to HTTP.
|
| - {"federation://sub1.example.com/google.com", "https://google.com",
|
| - autofill::PasswordForm::SCHEME_HTML, "http://sub2.example.com/",
|
| + {"https://sub1.example.com/", "https://google.com",
|
| "http://sub2.example.com", MatchResult::NO_MATCH},
|
|
|
| - {"federation://example.com/google.com", "https://google.com",
|
| - autofill::PasswordForm::SCHEME_HTML, "http://sub.example.com/",
|
| - "http://sub.example.com", MatchResult::NO_MATCH},
|
| + {"https://example.com/", "https://google.com", "http://sub.example.com",
|
| + MatchResult::NO_MATCH},
|
| +
|
| + {"http://example.com/", "https://google.com", "https://example.com/",
|
| + MatchResult::NO_MATCH},
|
|
|
| // Federated PSL matches do not apply to Google on HTTP or HTTPS.
|
| - {"federation://accounts.google.com/facebook.com", "https://facebook.com",
|
| - autofill::PasswordForm::SCHEME_HTML, "https://maps.google.com/",
|
| + {"https://accounts.google.com/", "https://facebook.com",
|
| "https://maps.google.com", MatchResult::NO_MATCH},
|
|
|
| - {"federation://accounts.google.com/facebook.com", "https://facebook.com",
|
| - autofill::PasswordForm::SCHEME_HTML, "http://maps.google.com/",
|
| + {"https://accounts.google.com/facebook.com", "https://facebook.com",
|
| "http://maps.google.com", MatchResult::NO_MATCH},
|
|
|
| // TLD Mismatch.
|
| - {"federation://sub.example.com/google.com", "https://google.com",
|
| - autofill::PasswordForm::SCHEME_HTML, "https://sub.example.org/",
|
| + {"https://sub.example.com/google.com", "https://google.com",
|
| "https://sub.example.org", MatchResult::NO_MATCH},
|
| +
|
| + // Port mismatch.
|
| + {"https://example.com/", "https://google.com", "https://example.com:8080",
|
| + MatchResult::NO_MATCH},
|
| +
|
| + {"https://example.com:8080", "https://google.com", "https://example.com",
|
| + MatchResult::NO_MATCH},
|
| +
|
| + // Port match.
|
| + {"https://sub.example.com:8080/p", "https://google.com",
|
| + "https://sub2.example.com:8080/p2", MatchResult::FEDERATED_PSL_MATCH},
|
| };
|
|
|
| for (const TestData& data : cases) {
|
| autofill::PasswordForm form;
|
| - form.signon_realm = data.form_signon_realm;
|
| + form.origin = GURL(data.form_origin);
|
| form.federation_origin = url::Origin(GURL(data.form_federation_origin));
|
| + form.signon_realm = "federation://" + form.origin.host() + "/" +
|
| + form.federation_origin.host();
|
| +
|
| PasswordStore::FormDigest digest(
|
| - data.digest_scheme, data.digest_signon_realm, GURL(data.digest_origin));
|
| + autofill::PasswordForm::SCHEME_HTML,
|
| + GURL(data.digest_origin).GetOrigin().spec(), GURL(data.digest_origin));
|
|
|
| EXPECT_EQ(data.match_result, GetMatchResult(form, digest))
|
| - << "signon_realm = " << data.form_signon_realm
|
| - << ", federation_origin = " << data.form_federation_origin
|
| + << "form_origin = " << data.form_origin
|
| + << ", form_federation_origin = " << data.form_federation_origin
|
| << ", digest = " << digest;
|
| }
|
| }
|
| @@ -206,9 +301,9 @@ TEST(PSLMatchingUtilsTest, IsPublicSuffixDomainMatch) {
|
| }
|
| }
|
|
|
| -TEST(PSLMatchingUtilsTest, IsFederatedMatch) {
|
| +TEST(PSLMatchingUtilsTest, IsFederatedRealm) {
|
| struct TestPair {
|
| - const char* signon_realm;
|
| + const char* form_signon_realm;
|
| const char* origin;
|
| bool should_match;
|
| };
|
| @@ -219,55 +314,76 @@ TEST(PSLMatchingUtilsTest, IsFederatedMatch) {
|
| {"", "https://facebook.com/", false},
|
| {"https://facebook.com/", "", false},
|
| {"federation://example.com/google.com", "https://example.com/", true},
|
| - {"federation://example.com/google.com", "http://example.com/", false},
|
| + {"federation://example.com/google.com", "http://example.com/", true},
|
| {"federation://example.com/google.com", "example.com", false},
|
| {"federation://example.com/", "http://example.com/", false},
|
| {"federation://example.com/google.com", "example", false},
|
| +
|
| + {"federation://localhost/google.com", "http://localhost/", true},
|
| + {"federation://localhost/google.com", "http://localhost:8000/", true},
|
| };
|
|
|
| for (const TestPair& pair : pairs) {
|
| - std::string signon_realm = pair.signon_realm;
|
| - GURL origin(pair.origin);
|
| - EXPECT_EQ(pair.should_match, IsFederatedMatch(signon_realm, origin))
|
| - << "signon_realm = " << pair.signon_realm
|
| + EXPECT_EQ(pair.should_match,
|
| + IsFederatedRealm(pair.form_signon_realm, GURL(pair.origin)))
|
| + << "form_signon_realm = " << pair.form_signon_realm
|
| << ", origin = " << pair.origin;
|
| }
|
| }
|
|
|
| TEST(PSLMatchingUtilsTest, IsFederatedPSLMatch) {
|
| struct TestPair {
|
| - const char* signon_realm;
|
| + const char* form_signon_realm;
|
| + const char* form_origin;
|
| const char* origin;
|
| bool should_match;
|
| };
|
|
|
| const TestPair pairs[] = {
|
| - {"https://facebook.com", "https://facebook.com", false},
|
| - {"", "", false},
|
| - {"", "https://facebook.com/", false},
|
| - {"https://facebook.com/", "", false},
|
| -
|
| - {"federation://example.com/google.com", "https://example.com/", true},
|
| - {"federation://example.com/google.com", "http://example.com/", false},
|
| - {"federation://example.com/google.com", "example.com", false},
|
| - {"federation://example.com/", "http://example.com/", false},
|
| - {"federation://example.com/google.com", "example", false},
|
| -
|
| - {"federation://sub.example.com/google.com", "https://sub.example.com/",
|
| - true},
|
| - {"federation://sub1.example.com/google.com", "https://sub2.example.com/",
|
| - true},
|
| - {"federation://example.com/google.com", "https://sub.example.com/", true},
|
| - {"federation://example.com/google.com", "http://sub.example.com/", false},
|
| - {"federation://sub.example.com/", "https://sub.example.com/", false},
|
| + {"https://facebook.com", "https://facebook.com", "https://facebook.com",
|
| + false},
|
| + {"", "", "", false},
|
| + {"", "", "https://facebook.com/", false},
|
| + {"https://facebook.com/", "https://facebook.com/", "", false},
|
| +
|
| + {"federation://example.com/google.com", "https://example.com/p1",
|
| + "https://example.com/p2", true},
|
| + {"federation://example.com/google.com", "https://example.com/",
|
| + "http://example.com/", false},
|
| + {"federation://example.com/google.com", "https://example.com/",
|
| + "example.com", false},
|
| + {"federation://example.com/", "https://example.com/",
|
| + "https://example.com/", false},
|
| + {"federation://example.com/google.com", "https://example.com/", "example",
|
| + false},
|
| +
|
| + {"federation://sub.example.com/google.com", "https://sub.example.com/p1",
|
| + "https://sub.example.com/p2", true},
|
| + {"federation://sub.example.com/google.com", "https://sub.example.com/p1",
|
| + "https://sub2.example.com/p2", true},
|
| + {"federation://example.com/google.com", "https://example.com/p1",
|
| + "https://sub.example.com/", true},
|
| + {"federation://example.com/google.com", "https://example.com/",
|
| + "http://sub.example.com/", false},
|
| + {"federation://sub.example.com/", "https://sub.example.com/",
|
| + "https://sub.example.com/", false},
|
| +
|
| + {"federation://localhost/google.com", "http://localhost/",
|
| + "http://localhost/", true},
|
| + {"federation://localhost/google.com", "http://localhost:8000/",
|
| + "http://localhost:8000/", true},
|
| + {"federation://localhost/google.com", "http://localhost:8000/",
|
| + "http://localhost/", false},
|
| + {"federation://localhost/google.com", "http://localhost/",
|
| + "http://localhost:8000/", false},
|
| };
|
|
|
| for (const TestPair& pair : pairs) {
|
| - std::string signon_realm = pair.signon_realm;
|
| - GURL origin(pair.origin);
|
| - EXPECT_EQ(pair.should_match, IsFederatedPSLMatch(signon_realm, origin))
|
| - << "signon_realm = " << pair.signon_realm
|
| - << ", origin = " << pair.origin;
|
| + EXPECT_EQ(pair.should_match,
|
| + IsFederatedPSLMatch(pair.form_signon_realm,
|
| + GURL(pair.form_origin), GURL(pair.origin)))
|
| + << "form_signon_realm = " << pair.form_signon_realm
|
| + << "form_origin = " << pair.form_origin << ", origin = " << pair.origin;
|
| }
|
| }
|
|
|
|
|