| Index: components/password_manager/core/browser/password_reuse_detector_unittest.cc
|
| diff --git a/components/password_manager/core/browser/password_reuse_detector_unittest.cc b/components/password_manager/core/browser/password_reuse_detector_unittest.cc
|
| index 7e8331ec440166a8a01c05612861cd199e789671..dac4dd694cb000f0dc3ec6b6e3486778c3bbc81a 100644
|
| --- a/components/password_manager/core/browser/password_reuse_detector_unittest.cc
|
| +++ b/components/password_manager/core/browser/password_reuse_detector_unittest.cc
|
| @@ -22,21 +22,30 @@ namespace password_manager {
|
|
|
| namespace {
|
|
|
| -std::vector<std::unique_ptr<PasswordForm>> GetSavedForms() {
|
| - std::vector<std::unique_ptr<PasswordForm>> result;
|
| - std::vector<std::pair<std::string, std::string>> domains_passwords = {
|
| +std::vector<std::pair<std::string, std::string>> GetTestDomainsPasswords() {
|
| + return {
|
| {"https://accounts.google.com", "password"},
|
| {"https://facebook.com", "123456789"},
|
| {"https://a.appspot.com", "abcdefghi"},
|
| {"https://twitter.com", "short"},
|
| + {"https://example1.com", "secretword"},
|
| + {"https://example2.com", "secretword"},
|
| };
|
| +}
|
|
|
| - for (const auto& domain_password : domains_passwords) {
|
| - std::unique_ptr<PasswordForm> form(new PasswordForm);
|
| - form->signon_realm = domain_password.first;
|
| - form->password_value = ASCIIToUTF16(domain_password.second);
|
| - result.push_back(std::move(form));
|
| - }
|
| +std::unique_ptr<PasswordForm> GetForm(
|
| + const std::pair<std::string, std::string>& domain_password) {
|
| + std::unique_ptr<PasswordForm> form(new PasswordForm);
|
| + form->signon_realm = domain_password.first;
|
| + form->password_value = ASCIIToUTF16(domain_password.second);
|
| + return form;
|
| +}
|
| +
|
| +std::vector<std::unique_ptr<PasswordForm>> GetForms(
|
| + const std::vector<std::pair<std::string, std::string>>& domains_passwords) {
|
| + std::vector<std::unique_ptr<PasswordForm>> result;
|
| + for (const auto& domain_password : domains_passwords)
|
| + result.push_back(GetForm(domain_password));
|
| return result;
|
| }
|
|
|
| @@ -52,7 +61,7 @@ PasswordStoreChangeList GetChangeList(
|
|
|
| TEST(PasswordReuseDetectorTest, TypingPasswordOnDifferentSite) {
|
| PasswordReuseDetector reuse_detector;
|
| - reuse_detector.OnGetPasswordStoreResults(GetSavedForms());
|
| + reuse_detector.OnGetPasswordStoreResults(GetForms(GetTestDomainsPasswords()));
|
| MockPasswordReuseDetectorConsumer mockConsumer;
|
|
|
| EXPECT_CALL(mockConsumer, OnReuseFound(_, _, _, _)).Times(0);
|
| @@ -63,14 +72,27 @@ TEST(PasswordReuseDetectorTest, TypingPasswordOnDifferentSite) {
|
| testing::Mock::VerifyAndClearExpectations(&mockConsumer);
|
|
|
| EXPECT_CALL(mockConsumer,
|
| - OnReuseFound(ASCIIToUTF16("password"), "google.com", 3, 1));
|
| + OnReuseFound(ASCIIToUTF16("password"), "google.com", 5, 1));
|
| reuse_detector.CheckReuse(ASCIIToUTF16("123password"), "https://evil.com",
|
| &mockConsumer);
|
| + testing::Mock::VerifyAndClearExpectations(&mockConsumer);
|
| +
|
| + EXPECT_CALL(mockConsumer,
|
| + OnReuseFound(ASCIIToUTF16("password"), "google.com", 5, 1));
|
| + reuse_detector.CheckReuse(ASCIIToUTF16("password"), "https://evil.com",
|
| + &mockConsumer);
|
| +
|
| + testing::Mock::VerifyAndClearExpectations(&mockConsumer);
|
| +
|
| + EXPECT_CALL(mockConsumer,
|
| + OnReuseFound(ASCIIToUTF16("secretword"), "example1.com", 5, 2));
|
| + reuse_detector.CheckReuse(ASCIIToUTF16("abcdsecretword"), "https://evil.com",
|
| + &mockConsumer);
|
| }
|
|
|
| TEST(PasswordReuseDetectorTest, PSLMatchNoReuseEvent) {
|
| PasswordReuseDetector reuse_detector;
|
| - reuse_detector.OnGetPasswordStoreResults(GetSavedForms());
|
| + reuse_detector.OnGetPasswordStoreResults(GetForms(GetTestDomainsPasswords()));
|
| MockPasswordReuseDetectorConsumer mockConsumer;
|
|
|
| EXPECT_CALL(mockConsumer, OnReuseFound(_, _, _, _)).Times(0);
|
| @@ -80,20 +102,20 @@ TEST(PasswordReuseDetectorTest, PSLMatchNoReuseEvent) {
|
|
|
| TEST(PasswordReuseDetectorTest, NoPSLMatchReuseEvent) {
|
| PasswordReuseDetector reuse_detector;
|
| - reuse_detector.OnGetPasswordStoreResults(GetSavedForms());
|
| + reuse_detector.OnGetPasswordStoreResults(GetForms(GetTestDomainsPasswords()));
|
| MockPasswordReuseDetectorConsumer mockConsumer;
|
|
|
| // a.appspot.com and b.appspot.com are not PSL matches. So reuse event should
|
| // be raised.
|
| EXPECT_CALL(mockConsumer,
|
| - OnReuseFound(ASCIIToUTF16("abcdefghi"), "a.appspot.com", 3, 1));
|
| + OnReuseFound(ASCIIToUTF16("abcdefghi"), "a.appspot.com", 5, 1));
|
| reuse_detector.CheckReuse(ASCIIToUTF16("abcdefghi"), "https://b.appspot.com",
|
| &mockConsumer);
|
| }
|
|
|
| TEST(PasswordReuseDetectorTest, TooShortPasswordNoReuseEvent) {
|
| PasswordReuseDetector reuse_detector;
|
| - reuse_detector.OnGetPasswordStoreResults(GetSavedForms());
|
| + reuse_detector.OnGetPasswordStoreResults(GetForms(GetTestDomainsPasswords()));
|
| MockPasswordReuseDetectorConsumer mockConsumer;
|
|
|
| EXPECT_CALL(mockConsumer, OnReuseFound(_, _, _, _)).Times(0);
|
| @@ -102,7 +124,7 @@ TEST(PasswordReuseDetectorTest, TooShortPasswordNoReuseEvent) {
|
|
|
| TEST(PasswordReuseDetectorTest, PasswordNotInputSuffixNoReuseEvent) {
|
| PasswordReuseDetector reuse_detector;
|
| - reuse_detector.OnGetPasswordStoreResults(GetSavedForms());
|
| + reuse_detector.OnGetPasswordStoreResults(GetForms(GetTestDomainsPasswords()));
|
| MockPasswordReuseDetectorConsumer mockConsumer;
|
|
|
| EXPECT_CALL(mockConsumer, OnReuseFound(_, _, _, _)).Times(0);
|
| @@ -117,7 +139,8 @@ TEST(PasswordReuseDetectorTest, OnLoginsChanged) {
|
| {PasswordStoreChange::ADD, PasswordStoreChange::UPDATE,
|
| PasswordStoreChange::REMOVE}) {
|
| PasswordReuseDetector reuse_detector;
|
| - PasswordStoreChangeList changes = GetChangeList(type, GetSavedForms());
|
| + PasswordStoreChangeList changes =
|
| + GetChangeList(type, GetForms(GetTestDomainsPasswords()));
|
| reuse_detector.OnLoginsChanged(changes);
|
| MockPasswordReuseDetectorConsumer mockConsumer;
|
|
|
| @@ -125,13 +148,42 @@ TEST(PasswordReuseDetectorTest, OnLoginsChanged) {
|
| EXPECT_CALL(mockConsumer, OnReuseFound(_, _, _, _)).Times(0);
|
| } else {
|
| EXPECT_CALL(mockConsumer,
|
| - OnReuseFound(ASCIIToUTF16("password"), "google.com", 3, 1));
|
| + OnReuseFound(ASCIIToUTF16("password"), "google.com", 5, 1));
|
| }
|
| reuse_detector.CheckReuse(ASCIIToUTF16("123password"), "https://evil.com",
|
| &mockConsumer);
|
| }
|
| }
|
|
|
| +TEST(PasswordReuseDetectorTest, CheckLongestPasswordMatchReturn) {
|
| + const std::vector<std::pair<std::string, std::string>> domain_passwords = {
|
| + {"https://example1.com", "234567890"},
|
| + {"https://example2.com", "01234567890"},
|
| + {"https://example3.com", "1234567890"},
|
| + };
|
| +
|
| + PasswordReuseDetector reuse_detector;
|
| + reuse_detector.OnGetPasswordStoreResults(GetForms(domain_passwords));
|
| +
|
| + MockPasswordReuseDetectorConsumer mockConsumer;
|
| +
|
| + EXPECT_CALL(mockConsumer,
|
| + OnReuseFound(ASCIIToUTF16("01234567890"), "example2.com", 3, 1));
|
| + reuse_detector.CheckReuse(ASCIIToUTF16("abcd01234567890"), "https://evil.com",
|
| + &mockConsumer);
|
| + testing::Mock::VerifyAndClearExpectations(&mockConsumer);
|
| +
|
| + EXPECT_CALL(mockConsumer,
|
| + OnReuseFound(ASCIIToUTF16("1234567890"), "example3.com", 3, 1));
|
| + reuse_detector.CheckReuse(ASCIIToUTF16("1234567890"), "https://evil.com",
|
| + &mockConsumer);
|
| + testing::Mock::VerifyAndClearExpectations(&mockConsumer);
|
| +
|
| + EXPECT_CALL(mockConsumer, OnReuseFound(_, _, _, _)).Times(0);
|
| + reuse_detector.CheckReuse(ASCIIToUTF16("34567890"), "https://evil.com",
|
| + &mockConsumer);
|
| +}
|
| +
|
| } // namespace
|
|
|
| } // namespace password_manager
|
|
|