| 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 "chrome/browser/password_manager/password_store_mac.h" | 5 #include "chrome/browser/password_manager/password_store_mac.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
| 10 #include "base/scoped_observer.h" | 10 #include "base/scoped_observer.h" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "chrome/browser/password_manager/password_store_mac_internal.h" | 14 #include "chrome/browser/password_manager/password_store_mac_internal.h" |
| 15 #include "chrome/common/chrome_paths.h" | 15 #include "chrome/common/chrome_paths.h" |
| 16 #include "components/password_manager/core/browser/login_database.h" |
| 16 #include "components/password_manager/core/browser/password_store_consumer.h" | 17 #include "components/password_manager/core/browser/password_store_consumer.h" |
| 17 #include "content/public/test/test_browser_thread.h" | 18 #include "content/public/test/test_browser_thread.h" |
| 18 #include "crypto/mock_apple_keychain.h" | 19 #include "crypto/mock_apple_keychain.h" |
| 19 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 22 |
| 22 using autofill::PasswordForm; | 23 using autofill::PasswordForm; |
| 23 using base::ASCIIToUTF16; | 24 using base::ASCIIToUTF16; |
| 24 using base::WideToUTF16; | 25 using base::WideToUTF16; |
| 25 using content::BrowserThread; | 26 using content::BrowserThread; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 53 | 54 |
| 54 ACTION(STLDeleteElements0) { | 55 ACTION(STLDeleteElements0) { |
| 55 STLDeleteContainerPointers(arg0.begin(), arg0.end()); | 56 STLDeleteContainerPointers(arg0.begin(), arg0.end()); |
| 56 } | 57 } |
| 57 | 58 |
| 58 ACTION(QuitUIMessageLoop) { | 59 ACTION(QuitUIMessageLoop) { |
| 59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 60 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 60 base::MessageLoop::current()->Quit(); | 61 base::MessageLoop::current()->Quit(); |
| 61 } | 62 } |
| 62 | 63 |
| 64 class MockPasswordStoreObserver : public PasswordStore::Observer { |
| 65 public: |
| 66 MOCK_METHOD1(OnLoginsChanged, |
| 67 void(const password_manager::PasswordStoreChangeList& changes)); |
| 68 }; |
| 69 |
| 70 // A mock LoginDatabase that simulates a failing Init() method. |
| 71 class BadLoginDatabase : public password_manager::LoginDatabase { |
| 72 public: |
| 73 BadLoginDatabase() : password_manager::LoginDatabase(base::FilePath()) {} |
| 74 ~BadLoginDatabase() override {} |
| 75 |
| 76 // LoginDatabase: |
| 77 bool Init() override { return false; } |
| 78 |
| 79 private: |
| 80 DISALLOW_COPY_AND_ASSIGN(BadLoginDatabase); |
| 81 }; |
| 82 |
| 63 class TestPasswordStoreMac : public PasswordStoreMac { | 83 class TestPasswordStoreMac : public PasswordStoreMac { |
| 64 public: | 84 public: |
| 65 TestPasswordStoreMac( | 85 TestPasswordStoreMac( |
| 66 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner, | 86 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner, |
| 67 scoped_refptr<base::SingleThreadTaskRunner> db_thread_runner, | 87 scoped_refptr<base::SingleThreadTaskRunner> db_thread_runner, |
| 68 crypto::AppleKeychain* keychain, | 88 scoped_ptr<crypto::AppleKeychain> keychain, |
| 69 LoginDatabase* login_db) | 89 scoped_ptr<password_manager::LoginDatabase> login_db) |
| 70 : PasswordStoreMac(main_thread_runner, | 90 : PasswordStoreMac(main_thread_runner, |
| 71 db_thread_runner, | 91 db_thread_runner, |
| 72 keychain, | 92 keychain.Pass(), |
| 73 login_db) { | 93 login_db.Pass()) {} |
| 74 } | |
| 75 | 94 |
| 76 using PasswordStoreMac::GetBackgroundTaskRunner; | 95 using PasswordStoreMac::GetBackgroundTaskRunner; |
| 77 | 96 |
| 78 private: | 97 private: |
| 79 ~TestPasswordStoreMac() override {} | 98 ~TestPasswordStoreMac() override {} |
| 80 | 99 |
| 81 DISALLOW_COPY_AND_ASSIGN(TestPasswordStoreMac); | 100 DISALLOW_COPY_AND_ASSIGN(TestPasswordStoreMac); |
| 82 }; | 101 }; |
| 83 | 102 |
| 84 } // namespace | 103 } // namespace |
| (...skipping 960 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1045 STLDeleteElements(&owned_passwords); | 1064 STLDeleteElements(&owned_passwords); |
| 1046 } | 1065 } |
| 1047 | 1066 |
| 1048 #pragma mark - | 1067 #pragma mark - |
| 1049 | 1068 |
| 1050 class PasswordStoreMacTest : public testing::Test { | 1069 class PasswordStoreMacTest : public testing::Test { |
| 1051 public: | 1070 public: |
| 1052 PasswordStoreMacTest() : ui_thread_(BrowserThread::UI, &message_loop_) {} | 1071 PasswordStoreMacTest() : ui_thread_(BrowserThread::UI, &message_loop_) {} |
| 1053 | 1072 |
| 1054 void SetUp() override { | 1073 void SetUp() override { |
| 1055 login_db_ = new LoginDatabase(); | |
| 1056 ASSERT_TRUE(db_dir_.CreateUniqueTempDir()); | 1074 ASSERT_TRUE(db_dir_.CreateUniqueTempDir()); |
| 1057 base::FilePath db_file = db_dir_.path().AppendASCII("login.db"); | |
| 1058 ASSERT_TRUE(login_db_->Init(db_file)); | |
| 1059 | 1075 |
| 1060 keychain_ = new MockAppleKeychain(); | 1076 scoped_ptr<password_manager::LoginDatabase> login_db( |
| 1061 | 1077 new password_manager::LoginDatabase(test_login_db_file_path())); |
| 1062 store_ = new TestPasswordStoreMac( | 1078 store_ = new TestPasswordStoreMac( |
| 1063 base::MessageLoopProxy::current(), | 1079 base::MessageLoopProxy::current(), base::MessageLoopProxy::current(), |
| 1064 base::MessageLoopProxy::current(), | 1080 make_scoped_ptr<AppleKeychain>(new MockAppleKeychain), login_db.Pass()); |
| 1065 keychain_, | |
| 1066 login_db_); | |
| 1067 ASSERT_TRUE(store_->Init(syncer::SyncableService::StartSyncFlare())); | 1081 ASSERT_TRUE(store_->Init(syncer::SyncableService::StartSyncFlare())); |
| 1068 } | 1082 } |
| 1069 | 1083 |
| 1070 void TearDown() override { | 1084 void TearDown() override { |
| 1071 store_->Shutdown(); | 1085 store_->Shutdown(); |
| 1072 EXPECT_FALSE(store_->GetBackgroundTaskRunner().get()); | 1086 EXPECT_FALSE(store_->GetBackgroundTaskRunner().get()); |
| 1073 } | 1087 } |
| 1074 | 1088 |
| 1089 base::FilePath test_login_db_file_path() const { |
| 1090 return db_dir_.path().Append(FILE_PATH_LITERAL("login.db")); |
| 1091 } |
| 1092 |
| 1093 password_manager::LoginDatabase* login_db() const { |
| 1094 return store_->login_metadata_db(); |
| 1095 } |
| 1096 |
| 1097 MockAppleKeychain* keychain() { |
| 1098 return static_cast<MockAppleKeychain*>(store_->keychain()); |
| 1099 } |
| 1100 |
| 1075 void WaitForStoreUpdate() { | 1101 void WaitForStoreUpdate() { |
| 1076 // Do a store-level query to wait for all the operations above to be done. | 1102 // Do a store-level query to wait for all the operations above to be done. |
| 1077 MockPasswordStoreConsumer consumer; | 1103 MockPasswordStoreConsumer consumer; |
| 1078 EXPECT_CALL(consumer, OnGetPasswordStoreResults(_)) | 1104 EXPECT_CALL(consumer, OnGetPasswordStoreResults(_)) |
| 1079 .WillOnce(DoAll(WithArg<0>(STLDeleteElements0()), QuitUIMessageLoop())); | 1105 .WillOnce(DoAll(WithArg<0>(STLDeleteElements0()), QuitUIMessageLoop())); |
| 1080 store_->GetLogins(PasswordForm(), PasswordStore::ALLOW_PROMPT, &consumer); | 1106 store_->GetLogins(PasswordForm(), PasswordStore::ALLOW_PROMPT, &consumer); |
| 1081 base::MessageLoop::current()->Run(); | 1107 base::MessageLoop::current()->Run(); |
| 1082 } | 1108 } |
| 1083 | 1109 |
| 1084 TestPasswordStoreMac* store() { return store_.get(); } | 1110 TestPasswordStoreMac* store() { return store_.get(); } |
| 1085 | 1111 |
| 1086 MockAppleKeychain* keychain() { return keychain_; } | |
| 1087 | |
| 1088 protected: | 1112 protected: |
| 1089 base::MessageLoopForUI message_loop_; | 1113 base::MessageLoopForUI message_loop_; |
| 1090 content::TestBrowserThread ui_thread_; | 1114 content::TestBrowserThread ui_thread_; |
| 1091 | 1115 |
| 1092 MockAppleKeychain* keychain_; // Owned by store_. | 1116 base::ScopedTempDir db_dir_; |
| 1093 LoginDatabase* login_db_; // Owned by store_. | |
| 1094 scoped_refptr<TestPasswordStoreMac> store_; | 1117 scoped_refptr<TestPasswordStoreMac> store_; |
| 1095 base::ScopedTempDir db_dir_; | |
| 1096 }; | 1118 }; |
| 1097 | 1119 |
| 1098 TEST_F(PasswordStoreMacTest, TestStoreUpdate) { | 1120 TEST_F(PasswordStoreMacTest, TestStoreUpdate) { |
| 1099 // Insert a password into both the database and the keychain. | 1121 // Insert a password into both the database and the keychain. |
| 1100 // This is done manually, rather than through store_->AddLogin, because the | 1122 // This is done manually, rather than through store_->AddLogin, because the |
| 1101 // Mock Keychain isn't smart enough to be able to support update generically, | 1123 // Mock Keychain isn't smart enough to be able to support update generically, |
| 1102 // so some.domain.com triggers special handling to test it that make inserting | 1124 // so some.domain.com triggers special handling to test it that make inserting |
| 1103 // fail. | 1125 // fail. |
| 1104 PasswordFormData joint_data = { | 1126 PasswordFormData joint_data = { |
| 1105 PasswordForm::SCHEME_HTML, "http://some.domain.com/", | 1127 PasswordForm::SCHEME_HTML, "http://some.domain.com/", |
| 1106 "http://some.domain.com/insecure.html", "login.cgi", | 1128 "http://some.domain.com/insecure.html", "login.cgi", |
| 1107 L"username", L"password", L"submit", L"joe_user", L"sekrit", true, false, 1 | 1129 L"username", L"password", L"submit", L"joe_user", L"sekrit", true, false, 1 |
| 1108 }; | 1130 }; |
| 1109 scoped_ptr<PasswordForm> joint_form(CreatePasswordFormFromData(joint_data)); | 1131 scoped_ptr<PasswordForm> joint_form(CreatePasswordFormFromData(joint_data)); |
| 1110 login_db_->AddLogin(*joint_form); | 1132 login_db()->AddLogin(*joint_form); |
| 1111 MockAppleKeychain::KeychainTestData joint_keychain_data = { | 1133 MockAppleKeychain::KeychainTestData joint_keychain_data = { |
| 1112 kSecAuthenticationTypeHTMLForm, "some.domain.com", | 1134 kSecAuthenticationTypeHTMLForm, "some.domain.com", |
| 1113 kSecProtocolTypeHTTP, "/insecure.html", 0, NULL, "20020601171500Z", | 1135 kSecProtocolTypeHTTP, "/insecure.html", 0, NULL, "20020601171500Z", |
| 1114 "joe_user", "sekrit", false }; | 1136 "joe_user", "sekrit", false }; |
| 1115 keychain_->AddTestItem(joint_keychain_data); | 1137 keychain()->AddTestItem(joint_keychain_data); |
| 1116 | 1138 |
| 1117 // Insert a password into the keychain only. | 1139 // Insert a password into the keychain only. |
| 1118 MockAppleKeychain::KeychainTestData keychain_only_data = { | 1140 MockAppleKeychain::KeychainTestData keychain_only_data = { |
| 1119 kSecAuthenticationTypeHTMLForm, "keychain.only.com", | 1141 kSecAuthenticationTypeHTMLForm, "keychain.only.com", |
| 1120 kSecProtocolTypeHTTP, NULL, 0, NULL, "20020601171500Z", | 1142 kSecProtocolTypeHTTP, NULL, 0, NULL, "20020601171500Z", |
| 1121 "keychain", "only", false | 1143 "keychain", "only", false |
| 1122 }; | 1144 }; |
| 1123 keychain_->AddTestItem(keychain_only_data); | 1145 keychain()->AddTestItem(keychain_only_data); |
| 1124 | 1146 |
| 1125 struct UpdateData { | 1147 struct UpdateData { |
| 1126 PasswordFormData form_data; | 1148 PasswordFormData form_data; |
| 1127 const char* password; // NULL indicates no entry should be present. | 1149 const char* password; // NULL indicates no entry should be present. |
| 1128 }; | 1150 }; |
| 1129 | 1151 |
| 1130 // Make a series of update calls. | 1152 // Make a series of update calls. |
| 1131 UpdateData updates[] = { | 1153 UpdateData updates[] = { |
| 1132 // Update the keychain+db passwords (the normal password update case). | 1154 // Update the keychain+db passwords (the normal password update case). |
| 1133 { { PasswordForm::SCHEME_HTML, "http://some.domain.com/", | 1155 { { PasswordForm::SCHEME_HTML, "http://some.domain.com/", |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1155 }, | 1177 }, |
| 1156 }; | 1178 }; |
| 1157 for (unsigned int i = 0; i < arraysize(updates); ++i) { | 1179 for (unsigned int i = 0; i < arraysize(updates); ++i) { |
| 1158 scoped_ptr<PasswordForm> form(CreatePasswordFormFromData( | 1180 scoped_ptr<PasswordForm> form(CreatePasswordFormFromData( |
| 1159 updates[i].form_data)); | 1181 updates[i].form_data)); |
| 1160 store_->UpdateLogin(*form); | 1182 store_->UpdateLogin(*form); |
| 1161 } | 1183 } |
| 1162 | 1184 |
| 1163 WaitForStoreUpdate(); | 1185 WaitForStoreUpdate(); |
| 1164 | 1186 |
| 1165 MacKeychainPasswordFormAdapter keychain_adapter(keychain_); | 1187 MacKeychainPasswordFormAdapter keychain_adapter(keychain()); |
| 1166 for (unsigned int i = 0; i < arraysize(updates); ++i) { | 1188 for (unsigned int i = 0; i < arraysize(updates); ++i) { |
| 1167 scoped_ptr<PasswordForm> query_form( | 1189 scoped_ptr<PasswordForm> query_form( |
| 1168 CreatePasswordFormFromData(updates[i].form_data)); | 1190 CreatePasswordFormFromData(updates[i].form_data)); |
| 1169 | 1191 |
| 1170 std::vector<PasswordForm*> matching_items = | 1192 std::vector<PasswordForm*> matching_items = |
| 1171 keychain_adapter.PasswordsFillingForm(query_form->signon_realm, | 1193 keychain_adapter.PasswordsFillingForm(query_form->signon_realm, |
| 1172 query_form->scheme); | 1194 query_form->scheme); |
| 1173 if (updates[i].password) { | 1195 if (updates[i].password) { |
| 1174 EXPECT_GT(matching_items.size(), 0U) << "iteration " << i; | 1196 EXPECT_GT(matching_items.size(), 0U) << "iteration " << i; |
| 1175 if (matching_items.size() >= 1) | 1197 if (matching_items.size() >= 1) |
| 1176 EXPECT_EQ(ASCIIToUTF16(updates[i].password), | 1198 EXPECT_EQ(ASCIIToUTF16(updates[i].password), |
| 1177 matching_items[0]->password_value) << "iteration " << i; | 1199 matching_items[0]->password_value) << "iteration " << i; |
| 1178 } else { | 1200 } else { |
| 1179 EXPECT_EQ(0U, matching_items.size()) << "iteration " << i; | 1201 EXPECT_EQ(0U, matching_items.size()) << "iteration " << i; |
| 1180 } | 1202 } |
| 1181 STLDeleteElements(&matching_items); | 1203 STLDeleteElements(&matching_items); |
| 1182 | 1204 |
| 1183 login_db_->GetLogins(*query_form, &matching_items); | 1205 login_db()->GetLogins(*query_form, &matching_items); |
| 1184 EXPECT_EQ(updates[i].password ? 1U : 0U, matching_items.size()) | 1206 EXPECT_EQ(updates[i].password ? 1U : 0U, matching_items.size()) |
| 1185 << "iteration " << i; | 1207 << "iteration " << i; |
| 1186 STLDeleteElements(&matching_items); | 1208 STLDeleteElements(&matching_items); |
| 1187 } | 1209 } |
| 1188 } | 1210 } |
| 1189 | 1211 |
| 1190 TEST_F(PasswordStoreMacTest, TestDBKeychainAssociation) { | 1212 TEST_F(PasswordStoreMacTest, TestDBKeychainAssociation) { |
| 1191 // Tests that association between the keychain and login database parts of a | 1213 // Tests that association between the keychain and login database parts of a |
| 1192 // password added by fuzzy (PSL) matching works. | 1214 // password added by fuzzy (PSL) matching works. |
| 1193 // 1. Add a password for www.facebook.com | 1215 // 1. Add a password for www.facebook.com |
| 1194 // 2. Get a password for m.facebook.com. This fuzzy matches and returns the | 1216 // 2. Get a password for m.facebook.com. This fuzzy matches and returns the |
| 1195 // www.facebook.com password. | 1217 // www.facebook.com password. |
| 1196 // 3. Add the returned password for m.facebook.com. | 1218 // 3. Add the returned password for m.facebook.com. |
| 1197 // 4. Remove both passwords. | 1219 // 4. Remove both passwords. |
| 1198 // -> check: that both are gone from the login DB and the keychain | 1220 // -> check: that both are gone from the login DB and the keychain |
| 1199 // This test should in particular ensure that we don't keep passwords in the | 1221 // This test should in particular ensure that we don't keep passwords in the |
| 1200 // keychain just before we think we still have other (fuzzy-)matching entries | 1222 // keychain just before we think we still have other (fuzzy-)matching entries |
| 1201 // for them in the login database. (For example, here if we deleted the | 1223 // for them in the login database. (For example, here if we deleted the |
| 1202 // www.facebook.com password from the login database, we should not be blocked | 1224 // www.facebook.com password from the login database, we should not be blocked |
| 1203 // from deleting it from the keystore just becaus the m.facebook.com password | 1225 // from deleting it from the keystore just becaus the m.facebook.com password |
| 1204 // fuzzy-matches the www.facebook.com one.) | 1226 // fuzzy-matches the www.facebook.com one.) |
| 1205 | 1227 |
| 1206 // 1. Add a password for www.facebook.com | 1228 // 1. Add a password for www.facebook.com |
| 1207 PasswordFormData www_form_data = { | 1229 PasswordFormData www_form_data = { |
| 1208 PasswordForm::SCHEME_HTML, "http://www.facebook.com/", | 1230 PasswordForm::SCHEME_HTML, "http://www.facebook.com/", |
| 1209 "http://www.facebook.com/index.html", "login", | 1231 "http://www.facebook.com/index.html", "login", |
| 1210 L"username", L"password", L"submit", L"joe_user", L"sekrit", true, false, 1 | 1232 L"username", L"password", L"submit", L"joe_user", L"sekrit", true, false, 1 |
| 1211 }; | 1233 }; |
| 1212 scoped_ptr<PasswordForm> www_form(CreatePasswordFormFromData(www_form_data)); | 1234 scoped_ptr<PasswordForm> www_form(CreatePasswordFormFromData(www_form_data)); |
| 1213 login_db_->AddLogin(*www_form); | 1235 login_db()->AddLogin(*www_form); |
| 1214 MacKeychainPasswordFormAdapter owned_keychain_adapter(keychain_); | 1236 MacKeychainPasswordFormAdapter owned_keychain_adapter(keychain()); |
| 1215 owned_keychain_adapter.SetFindsOnlyOwnedItems(true); | 1237 owned_keychain_adapter.SetFindsOnlyOwnedItems(true); |
| 1216 owned_keychain_adapter.AddPassword(*www_form); | 1238 owned_keychain_adapter.AddPassword(*www_form); |
| 1217 | 1239 |
| 1218 // 2. Get a password for m.facebook.com. | 1240 // 2. Get a password for m.facebook.com. |
| 1219 PasswordForm m_form(*www_form); | 1241 PasswordForm m_form(*www_form); |
| 1220 m_form.signon_realm = "http://m.facebook.com"; | 1242 m_form.signon_realm = "http://m.facebook.com"; |
| 1221 m_form.origin = GURL("http://m.facebook.com/index.html"); | 1243 m_form.origin = GURL("http://m.facebook.com/index.html"); |
| 1222 MockPasswordStoreConsumer consumer; | 1244 MockPasswordStoreConsumer consumer; |
| 1223 EXPECT_CALL(consumer, OnGetPasswordStoreResults(_)).WillOnce(DoAll( | 1245 EXPECT_CALL(consumer, OnGetPasswordStoreResults(_)).WillOnce(DoAll( |
| 1224 WithArg<0>(Invoke(&consumer, &MockPasswordStoreConsumer::CopyElements)), | 1246 WithArg<0>(Invoke(&consumer, &MockPasswordStoreConsumer::CopyElements)), |
| 1225 WithArg<0>(STLDeleteElements0()), | 1247 WithArg<0>(STLDeleteElements0()), |
| 1226 QuitUIMessageLoop())); | 1248 QuitUIMessageLoop())); |
| 1227 store_->GetLogins(m_form, PasswordStore::ALLOW_PROMPT, &consumer); | 1249 store_->GetLogins(m_form, PasswordStore::ALLOW_PROMPT, &consumer); |
| 1228 base::MessageLoop::current()->Run(); | 1250 base::MessageLoop::current()->Run(); |
| 1229 EXPECT_EQ(1u, consumer.last_result.size()); | 1251 EXPECT_EQ(1u, consumer.last_result.size()); |
| 1230 | 1252 |
| 1231 // 3. Add the returned password for m.facebook.com. | 1253 // 3. Add the returned password for m.facebook.com. |
| 1232 login_db_->AddLogin(consumer.last_result[0]); | 1254 login_db()->AddLogin(consumer.last_result[0]); |
| 1233 owned_keychain_adapter.AddPassword(m_form); | 1255 owned_keychain_adapter.AddPassword(m_form); |
| 1234 | 1256 |
| 1235 // 4. Remove both passwords. | 1257 // 4. Remove both passwords. |
| 1236 store_->RemoveLogin(*www_form); | 1258 store_->RemoveLogin(*www_form); |
| 1237 store_->RemoveLogin(m_form); | 1259 store_->RemoveLogin(m_form); |
| 1238 WaitForStoreUpdate(); | 1260 WaitForStoreUpdate(); |
| 1239 | 1261 |
| 1240 std::vector<PasswordForm*> matching_items; | 1262 std::vector<PasswordForm*> matching_items; |
| 1241 // No trace of www.facebook.com. | 1263 // No trace of www.facebook.com. |
| 1242 matching_items = owned_keychain_adapter.PasswordsFillingForm( | 1264 matching_items = owned_keychain_adapter.PasswordsFillingForm( |
| 1243 www_form->signon_realm, www_form->scheme); | 1265 www_form->signon_realm, www_form->scheme); |
| 1244 EXPECT_EQ(0u, matching_items.size()); | 1266 EXPECT_EQ(0u, matching_items.size()); |
| 1245 login_db_->GetLogins(*www_form, &matching_items); | 1267 login_db()->GetLogins(*www_form, &matching_items); |
| 1246 EXPECT_EQ(0u, matching_items.size()); | 1268 EXPECT_EQ(0u, matching_items.size()); |
| 1247 // No trace of m.facebook.com. | 1269 // No trace of m.facebook.com. |
| 1248 matching_items = owned_keychain_adapter.PasswordsFillingForm( | 1270 matching_items = owned_keychain_adapter.PasswordsFillingForm( |
| 1249 m_form.signon_realm, m_form.scheme); | 1271 m_form.signon_realm, m_form.scheme); |
| 1250 EXPECT_EQ(0u, matching_items.size()); | 1272 EXPECT_EQ(0u, matching_items.size()); |
| 1251 login_db_->GetLogins(m_form, &matching_items); | 1273 login_db()->GetLogins(m_form, &matching_items); |
| 1252 EXPECT_EQ(0u, matching_items.size()); | 1274 EXPECT_EQ(0u, matching_items.size()); |
| 1253 } | 1275 } |
| 1254 | 1276 |
| 1255 namespace { | 1277 namespace { |
| 1256 | 1278 |
| 1257 class PasswordsChangeObserver : | 1279 class PasswordsChangeObserver : |
| 1258 public password_manager::PasswordStore::Observer { | 1280 public password_manager::PasswordStore::Observer { |
| 1259 public: | 1281 public: |
| 1260 PasswordsChangeObserver(TestPasswordStoreMac* store) : observer_(this) { | 1282 PasswordsChangeObserver(TestPasswordStoreMac* store) : observer_(this) { |
| 1261 observer_.Add(store); | 1283 observer_.Add(store); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1388 | 1410 |
| 1389 TEST_F(PasswordStoreMacTest, TestRemoveLoginsMultiProfile) { | 1411 TEST_F(PasswordStoreMacTest, TestRemoveLoginsMultiProfile) { |
| 1390 // Make sure that RemoveLoginsCreatedBetween does affect only the correct | 1412 // Make sure that RemoveLoginsCreatedBetween does affect only the correct |
| 1391 // profile. | 1413 // profile. |
| 1392 | 1414 |
| 1393 // Add a third-party password. | 1415 // Add a third-party password. |
| 1394 MockAppleKeychain::KeychainTestData keychain_data = { | 1416 MockAppleKeychain::KeychainTestData keychain_data = { |
| 1395 kSecAuthenticationTypeHTMLForm, "some.domain.com", | 1417 kSecAuthenticationTypeHTMLForm, "some.domain.com", |
| 1396 kSecProtocolTypeHTTP, "/insecure.html", 0, NULL, "20020601171500Z", | 1418 kSecProtocolTypeHTTP, "/insecure.html", 0, NULL, "20020601171500Z", |
| 1397 "joe_user", "sekrit", false }; | 1419 "joe_user", "sekrit", false }; |
| 1398 keychain_->AddTestItem(keychain_data); | 1420 keychain()->AddTestItem(keychain_data); |
| 1399 | 1421 |
| 1400 // Add a password through the adapter. It has the "Chrome" creator tag. | 1422 // Add a password through the adapter. It has the "Chrome" creator tag. |
| 1401 // However, it's not referenced by the password database. | 1423 // However, it's not referenced by the password database. |
| 1402 MacKeychainPasswordFormAdapter owned_keychain_adapter(keychain_); | 1424 MacKeychainPasswordFormAdapter owned_keychain_adapter(keychain()); |
| 1403 owned_keychain_adapter.SetFindsOnlyOwnedItems(true); | 1425 owned_keychain_adapter.SetFindsOnlyOwnedItems(true); |
| 1404 PasswordFormData www_form_data1 = { | 1426 PasswordFormData www_form_data1 = { |
| 1405 PasswordForm::SCHEME_HTML, "http://www.facebook.com/", | 1427 PasswordForm::SCHEME_HTML, "http://www.facebook.com/", |
| 1406 "http://www.facebook.com/index.html", "login", L"username", L"password", | 1428 "http://www.facebook.com/index.html", "login", L"username", L"password", |
| 1407 L"submit", L"joe_user", L"sekrit", true, false, 1 }; | 1429 L"submit", L"joe_user", L"sekrit", true, false, 1 }; |
| 1408 scoped_ptr<PasswordForm> www_form(CreatePasswordFormFromData(www_form_data1)); | 1430 scoped_ptr<PasswordForm> www_form(CreatePasswordFormFromData(www_form_data1)); |
| 1409 EXPECT_TRUE(owned_keychain_adapter.AddPassword(*www_form)); | 1431 EXPECT_TRUE(owned_keychain_adapter.AddPassword(*www_form)); |
| 1410 | 1432 |
| 1411 // Add a password from the current profile. | 1433 // Add a password from the current profile. |
| 1412 PasswordFormData www_form_data2 = { | 1434 PasswordFormData www_form_data2 = { |
| 1413 PasswordForm::SCHEME_HTML, "http://www.facebook.com/", | 1435 PasswordForm::SCHEME_HTML, "http://www.facebook.com/", |
| 1414 "http://www.facebook.com/index.html", "login", L"username", L"password", | 1436 "http://www.facebook.com/index.html", "login", L"username", L"password", |
| 1415 L"submit", L"not_joe_user", L"12345", true, false, 1 }; | 1437 L"submit", L"not_joe_user", L"12345", true, false, 1 }; |
| 1416 www_form.reset(CreatePasswordFormFromData(www_form_data2)); | 1438 www_form.reset(CreatePasswordFormFromData(www_form_data2)); |
| 1417 store_->AddLogin(*www_form); | 1439 store_->AddLogin(*www_form); |
| 1418 WaitForStoreUpdate(); | 1440 WaitForStoreUpdate(); |
| 1419 | 1441 |
| 1420 ScopedVector<PasswordForm> matching_items; | 1442 ScopedVector<PasswordForm> matching_items; |
| 1421 login_db_->GetLogins(*www_form, &matching_items.get()); | 1443 login_db()->GetLogins(*www_form, &matching_items.get()); |
| 1422 EXPECT_EQ(1u, matching_items.size()); | 1444 EXPECT_EQ(1u, matching_items.size()); |
| 1423 matching_items.clear(); | 1445 matching_items.clear(); |
| 1424 | 1446 |
| 1425 store_->RemoveLoginsCreatedBetween(base::Time(), base::Time()); | 1447 store_->RemoveLoginsCreatedBetween(base::Time(), base::Time()); |
| 1426 WaitForStoreUpdate(); | 1448 WaitForStoreUpdate(); |
| 1427 | 1449 |
| 1428 // Check the second facebook form is gone. | 1450 // Check the second facebook form is gone. |
| 1429 login_db_->GetLogins(*www_form, &matching_items.get()); | 1451 login_db()->GetLogins(*www_form, &matching_items.get()); |
| 1430 EXPECT_EQ(0u, matching_items.size()); | 1452 EXPECT_EQ(0u, matching_items.size()); |
| 1431 | 1453 |
| 1432 // Check the first facebook form is still there. | 1454 // Check the first facebook form is still there. |
| 1433 matching_items.get() = owned_keychain_adapter.PasswordsFillingForm( | 1455 matching_items.get() = owned_keychain_adapter.PasswordsFillingForm( |
| 1434 www_form->signon_realm, www_form->scheme); | 1456 www_form->signon_realm, www_form->scheme); |
| 1435 ASSERT_EQ(1u, matching_items.size()); | 1457 ASSERT_EQ(1u, matching_items.size()); |
| 1436 EXPECT_EQ(ASCIIToUTF16("joe_user"), matching_items[0]->username_value); | 1458 EXPECT_EQ(ASCIIToUTF16("joe_user"), matching_items[0]->username_value); |
| 1437 matching_items.clear(); | 1459 matching_items.clear(); |
| 1438 | 1460 |
| 1439 // Check the third-party password is still there. | 1461 // Check the third-party password is still there. |
| 1440 owned_keychain_adapter.SetFindsOnlyOwnedItems(false); | 1462 owned_keychain_adapter.SetFindsOnlyOwnedItems(false); |
| 1441 matching_items.get() = owned_keychain_adapter.PasswordsFillingForm( | 1463 matching_items.get() = owned_keychain_adapter.PasswordsFillingForm( |
| 1442 "http://some.domain.com/insecure.html", PasswordForm::SCHEME_HTML); | 1464 "http://some.domain.com/insecure.html", PasswordForm::SCHEME_HTML); |
| 1443 ASSERT_EQ(1u, matching_items.size()); | 1465 ASSERT_EQ(1u, matching_items.size()); |
| 1444 } | 1466 } |
| 1467 |
| 1468 // Verify that operations on a PasswordStore with a bad database cause no |
| 1469 // explosions, but fail without side effect, return no data and trigger no |
| 1470 // notifications. |
| 1471 TEST_F(PasswordStoreMacTest, OperationsOnABadDatabaseSilentlyFail) { |
| 1472 scoped_refptr<TestPasswordStoreMac> bad_store(new TestPasswordStoreMac( |
| 1473 base::MessageLoopProxy::current(), base::MessageLoopProxy::current(), |
| 1474 make_scoped_ptr<crypto::AppleKeychain>(new MockAppleKeychain), |
| 1475 make_scoped_ptr<password_manager::LoginDatabase>(new BadLoginDatabase))); |
| 1476 |
| 1477 bad_store->Init(syncer::SyncableService::StartSyncFlare()); |
| 1478 base::MessageLoop::current()->RunUntilIdle(); |
| 1479 ASSERT_EQ(nullptr, bad_store->login_metadata_db()); |
| 1480 |
| 1481 testing::StrictMock<MockPasswordStoreObserver> mock_observer; |
| 1482 bad_store->AddObserver(&mock_observer); |
| 1483 |
| 1484 // Add a new autofillable login + a blacklisted login. |
| 1485 PasswordFormData www_form_data = { |
| 1486 PasswordForm::SCHEME_HTML, "http://www.facebook.com/", |
| 1487 "http://www.facebook.com/index.html", "login", L"username", L"password", |
| 1488 L"submit", L"not_joe_user", L"12345", true, false, 1}; |
| 1489 scoped_ptr<PasswordForm> form(CreatePasswordFormFromData(www_form_data)); |
| 1490 scoped_ptr<PasswordForm> blacklisted_form(new PasswordForm(*form)); |
| 1491 blacklisted_form->signon_realm = "http://foo.example.com"; |
| 1492 blacklisted_form->origin = GURL("http://foo.example.com/origin"); |
| 1493 blacklisted_form->action = GURL("http://foo.example.com/action"); |
| 1494 blacklisted_form->blacklisted_by_user = true; |
| 1495 bad_store->AddLogin(*form); |
| 1496 bad_store->AddLogin(*blacklisted_form); |
| 1497 base::MessageLoop::current()->RunUntilIdle(); |
| 1498 |
| 1499 // Get all logins; autofillable logins; blacklisted logins. |
| 1500 testing::StrictMock<MockPasswordStoreConsumer> mock_consumer; |
| 1501 EXPECT_CALL(mock_consumer, OnGetPasswordStoreResults(testing::ElementsAre())); |
| 1502 bad_store->GetLogins(*form, PasswordStore::DISALLOW_PROMPT, &mock_consumer); |
| 1503 base::MessageLoop::current()->RunUntilIdle(); |
| 1504 testing::Mock::VerifyAndClearExpectations(&mock_consumer); |
| 1505 EXPECT_CALL(mock_consumer, OnGetPasswordStoreResults(testing::ElementsAre())); |
| 1506 bad_store->GetAutofillableLogins(&mock_consumer); |
| 1507 base::MessageLoop::current()->RunUntilIdle(); |
| 1508 testing::Mock::VerifyAndClearExpectations(&mock_consumer); |
| 1509 EXPECT_CALL(mock_consumer, OnGetPasswordStoreResults(testing::ElementsAre())); |
| 1510 bad_store->GetBlacklistLogins(&mock_consumer); |
| 1511 base::MessageLoop::current()->RunUntilIdle(); |
| 1512 |
| 1513 // Report metrics. |
| 1514 bad_store->ReportMetrics("Test Username", true); |
| 1515 base::MessageLoop::current()->RunUntilIdle(); |
| 1516 |
| 1517 // Change the login. |
| 1518 form->password_value = base::ASCIIToUTF16("a different password"); |
| 1519 bad_store->UpdateLogin(*form); |
| 1520 base::MessageLoop::current()->RunUntilIdle(); |
| 1521 |
| 1522 // Delete one login; a range of logins. |
| 1523 bad_store->RemoveLogin(*form); |
| 1524 base::MessageLoop::current()->RunUntilIdle(); |
| 1525 bad_store->RemoveLoginsCreatedBetween(base::Time(), base::Time::Max()); |
| 1526 base::MessageLoop::current()->RunUntilIdle(); |
| 1527 bad_store->RemoveLoginsSyncedBetween(base::Time(), base::Time::Max()); |
| 1528 base::MessageLoop::current()->RunUntilIdle(); |
| 1529 |
| 1530 // Ensure no notifications and no explosions during shutdown either. |
| 1531 bad_store->RemoveObserver(&mock_observer); |
| 1532 bad_store->Shutdown(); |
| 1533 base::MessageLoop::current()->RunUntilIdle(); |
| 1534 } |
| OLD | NEW |