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