Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: components/password_manager/core/browser/password_store_unittest.cc

Issue 2913323004: Implementation of sync password hash clearing. (Closed)
Patch Set: addressed reviewer's comments Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/password_manager/core/browser/password_store.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // The passwords in the tests below are all empty because PasswordStoreDefault 5 // The passwords in the tests below are all empty because PasswordStoreDefault
6 // does not store the actual passwords on OS X (they are stored in the Keychain 6 // does not store the actual passwords on OS X (they are stored in the Keychain
7 // instead). We could special-case it, but it is easier to just have empty 7 // instead). We could special-case it, but it is easier to just have empty
8 // passwords. This will not be needed anymore if crbug.com/466638 is fixed. 8 // passwords. This will not be needed anymore if crbug.com/466638 is fixed.
9 9
10 #include <stddef.h> 10 #include <stddef.h>
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 }; 96 };
97 97
98 } // namespace 98 } // namespace
99 99
100 class PasswordStoreTest : public testing::Test { 100 class PasswordStoreTest : public testing::Test {
101 protected: 101 protected:
102 PasswordStoreTest() 102 PasswordStoreTest()
103 : scoped_task_environment_( 103 : scoped_task_environment_(
104 base::test::ScopedTaskEnvironment::MainThreadType::UI) {} 104 base::test::ScopedTaskEnvironment::MainThreadType::UI) {}
105 105
106 void SetUp() override { ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); } 106 void SetUp() override {
107 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
108 #if defined(OS_MACOSX)
109 // Mock Keychain. There is a call to Keychain on initializling
110 // PasswordReuseDetector, so it should be mocked.
111 OSCryptMocker::SetUpWithSingleton();
112 #endif
113 }
107 114
108 void TearDown() override { ASSERT_TRUE(temp_dir_.Delete()); } 115 void TearDown() override {
116 ASSERT_TRUE(temp_dir_.Delete());
117 #if defined(OS_MACOSX)
118 OSCryptMocker::TearDown();
119 #endif
120 }
109 121
110 base::FilePath test_login_db_file_path() const { 122 base::FilePath test_login_db_file_path() const {
111 return temp_dir_.GetPath().Append(FILE_PATH_LITERAL("login_test")); 123 return temp_dir_.GetPath().Append(FILE_PATH_LITERAL("login_test"));
112 } 124 }
113 125
114 base::test::ScopedTaskEnvironment scoped_task_environment_; 126 base::test::ScopedTaskEnvironment scoped_task_environment_;
115 base::ScopedTempDir temp_dir_; 127 base::ScopedTempDir temp_dir_;
116 }; 128 };
117 129
118 TEST_F(PasswordStoreTest, IgnoreOldWwwGoogleLogins) { 130 TEST_F(PasswordStoreTest, IgnoreOldWwwGoogleLogins) {
(...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after
916 928
917 // TODO(crbug.com/706392): Fix password reuse detection for Android. 929 // TODO(crbug.com/706392): Fix password reuse detection for Android.
918 #if !defined(OS_ANDROID) && !defined(OS_IOS) 930 #if !defined(OS_ANDROID) && !defined(OS_IOS)
919 TEST_F(PasswordStoreTest, CheckPasswordReuse) { 931 TEST_F(PasswordStoreTest, CheckPasswordReuse) {
920 static constexpr PasswordFormData kTestCredentials[] = { 932 static constexpr PasswordFormData kTestCredentials[] = {
921 {PasswordForm::SCHEME_HTML, "https://www.google.com", 933 {PasswordForm::SCHEME_HTML, "https://www.google.com",
922 "https://www.google.com", "", L"", L"", L"", L"", L"password", true, 1}, 934 "https://www.google.com", "", L"", L"", L"", L"", L"password", true, 1},
923 {PasswordForm::SCHEME_HTML, "https://facebook.com", 935 {PasswordForm::SCHEME_HTML, "https://facebook.com",
924 "https://facebook.com", "", L"", L"", L"", L"", L"topsecret", true, 1}}; 936 "https://facebook.com", "", L"", L"", L"", L"", L"topsecret", true, 1}};
925 937
926 #if defined(OS_MACOSX)
927 // Mock Keychain. There is a call to Keychain on initializling
928 // PasswordReuseDetector, so it should be mocked.
929 OSCryptMocker::SetUpWithSingleton();
930 #endif
931 scoped_refptr<PasswordStoreDefault> store(new PasswordStoreDefault( 938 scoped_refptr<PasswordStoreDefault> store(new PasswordStoreDefault(
932 base::ThreadTaskRunnerHandle::Get(), base::ThreadTaskRunnerHandle::Get(), 939 base::ThreadTaskRunnerHandle::Get(), base::ThreadTaskRunnerHandle::Get(),
933 base::MakeUnique<LoginDatabase>(test_login_db_file_path()))); 940 base::MakeUnique<LoginDatabase>(test_login_db_file_path())));
934 store->Init(syncer::SyncableService::StartSyncFlare(), nullptr); 941 store->Init(syncer::SyncableService::StartSyncFlare(), nullptr);
935 942
936 for (const auto& test_credentials : kTestCredentials) { 943 for (const auto& test_credentials : kTestCredentials) {
937 auto credentials = CreatePasswordFormFromDataForTesting(test_credentials); 944 auto credentials = CreatePasswordFormFromDataForTesting(test_credentials);
938 store->AddLogin(*credentials); 945 store->AddLogin(*credentials);
939 base::RunLoop().RunUntilIdle(); 946 base::RunLoop().RunUntilIdle();
940 } 947 }
(...skipping 19 matching lines...) Expand all
960 EXPECT_CALL(mock_consumer, OnReuseFound(_, _, _, _)).Times(0); 967 EXPECT_CALL(mock_consumer, OnReuseFound(_, _, _, _)).Times(0);
961 } 968 }
962 969
963 store->CheckReuse(base::WideToUTF16(test_data.input), test_data.domain, 970 store->CheckReuse(base::WideToUTF16(test_data.input), test_data.domain,
964 &mock_consumer); 971 &mock_consumer);
965 base::RunLoop().RunUntilIdle(); 972 base::RunLoop().RunUntilIdle();
966 } 973 }
967 974
968 store->ShutdownOnUIThread(); 975 store->ShutdownOnUIThread();
969 base::RunLoop().RunUntilIdle(); 976 base::RunLoop().RunUntilIdle();
970 #if defined(OS_MACOSX) 977 }
971 OSCryptMocker::TearDown(); 978
972 #endif 979 TEST_F(PasswordStoreTest, SavingClearingSyncPassword) {
980 scoped_refptr<PasswordStoreDefault> store(new PasswordStoreDefault(
981 base::ThreadTaskRunnerHandle::Get(), base::ThreadTaskRunnerHandle::Get(),
982 base::MakeUnique<LoginDatabase>(test_login_db_file_path())));
983 store->Init(syncer::SyncableService::StartSyncFlare(), nullptr);
984
985 const base::string16 sync_password = base::ASCIIToUTF16("password");
986 const base::string16 input = base::ASCIIToUTF16("123password");
987 store->SaveSyncPasswordHash(sync_password);
988 base::RunLoop().RunUntilIdle();
989
990 // Check that sync password reuse is found.
991 MockPasswordReuseDetectorConsumer mock_consumer;
992 EXPECT_CALL(mock_consumer,
993 OnReuseFound(sync_password, "accounts.google.com", 1, 0));
994 store->CheckReuse(input, "https://facebook.com", &mock_consumer);
995 base::RunLoop().RunUntilIdle();
996 testing::Mock::VerifyAndClearExpectations(&mock_consumer);
997
998 // Check that no sync password reuse is found after clearing the saved sync
999 // password hash.
1000 store->ClearSyncPasswordHash();
1001 EXPECT_CALL(mock_consumer, OnReuseFound(_, _, _, _)).Times(0);
1002 store->CheckReuse(input, "https://facebook.com", &mock_consumer);
1003 base::RunLoop().RunUntilIdle();
1004
1005 store->ShutdownOnUIThread();
1006 base::RunLoop().RunUntilIdle();
973 } 1007 }
974 #endif 1008 #endif
975 1009
976 } // namespace password_manager 1010 } // namespace password_manager
OLDNEW
« no previous file with comments | « components/password_manager/core/browser/password_store.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698