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/scoped_observer.h" | 9 #include "base/scoped_observer.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 owned_keychain_adapter.SetFindsOnlyOwnedItems(true); | 484 owned_keychain_adapter.SetFindsOnlyOwnedItems(true); |
485 for (unsigned int i = 0; i < arraysize(test_data); ++i) { | 485 for (unsigned int i = 0; i < arraysize(test_data); ++i) { |
486 scoped_ptr<PasswordForm> query_form = | 486 scoped_ptr<PasswordForm> query_form = |
487 CreatePasswordFormFromDataForTesting(test_data[i].data); | 487 CreatePasswordFormFromDataForTesting(test_data[i].data); |
488 | 488 |
489 // Check matches treating the form as a fill target. | 489 // Check matches treating the form as a fill target. |
490 ScopedVector<autofill::PasswordForm> matching_items = | 490 ScopedVector<autofill::PasswordForm> matching_items = |
491 keychain_adapter.PasswordsFillingForm(query_form->signon_realm, | 491 keychain_adapter.PasswordsFillingForm(query_form->signon_realm, |
492 query_form->scheme); | 492 query_form->scheme); |
493 EXPECT_EQ(test_data[i].expected_fill_matches, matching_items.size()); | 493 EXPECT_EQ(test_data[i].expected_fill_matches, matching_items.size()); |
494 matching_items.clear(); | |
495 | 494 |
496 // Check matches treating the form as a merging target. | 495 // Check matches treating the form as a merging target. |
497 EXPECT_EQ(test_data[i].expected_merge_matches > 0, | 496 EXPECT_EQ(test_data[i].expected_merge_matches > 0, |
498 keychain_adapter.HasPasswordsMergeableWithForm(*query_form)); | 497 keychain_adapter.HasPasswordsMergeableWithForm(*query_form)); |
499 std::vector<SecKeychainItemRef> keychain_items; | 498 std::vector<SecKeychainItemRef> keychain_items; |
500 std::vector<internal_keychain_helpers::ItemFormPair> item_form_pairs = | 499 std::vector<internal_keychain_helpers::ItemFormPair> item_form_pairs = |
501 internal_keychain_helpers:: | 500 internal_keychain_helpers:: |
502 ExtractAllKeychainItemAttributesIntoPasswordForms(&keychain_items, | 501 ExtractAllKeychainItemAttributesIntoPasswordForms(&keychain_items, |
503 *keychain_); | 502 *keychain_); |
504 matching_items = | 503 matching_items = |
(...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1240 keychain_adapter.PasswordsFillingForm(query_form->signon_realm, | 1239 keychain_adapter.PasswordsFillingForm(query_form->signon_realm, |
1241 query_form->scheme); | 1240 query_form->scheme); |
1242 if (updates[i].password) { | 1241 if (updates[i].password) { |
1243 EXPECT_GT(matching_items.size(), 0U) << "iteration " << i; | 1242 EXPECT_GT(matching_items.size(), 0U) << "iteration " << i; |
1244 if (matching_items.size() >= 1) | 1243 if (matching_items.size() >= 1) |
1245 EXPECT_EQ(ASCIIToUTF16(updates[i].password), | 1244 EXPECT_EQ(ASCIIToUTF16(updates[i].password), |
1246 matching_items[0]->password_value) << "iteration " << i; | 1245 matching_items[0]->password_value) << "iteration " << i; |
1247 } else { | 1246 } else { |
1248 EXPECT_EQ(0U, matching_items.size()) << "iteration " << i; | 1247 EXPECT_EQ(0U, matching_items.size()) << "iteration " << i; |
1249 } | 1248 } |
1250 matching_items.clear(); | |
1251 | 1249 |
1252 login_db()->GetLogins(*query_form, &matching_items); | 1250 EXPECT_TRUE(login_db()->GetLogins(*query_form, &matching_items)); |
1253 EXPECT_EQ(updates[i].password ? 1U : 0U, matching_items.size()) | 1251 EXPECT_EQ(updates[i].password ? 1U : 0U, matching_items.size()) |
1254 << "iteration " << i; | 1252 << "iteration " << i; |
1255 } | 1253 } |
1256 } | 1254 } |
1257 | 1255 |
1258 TEST_F(PasswordStoreMacTest, TestDBKeychainAssociation) { | 1256 TEST_F(PasswordStoreMacTest, TestDBKeychainAssociation) { |
1259 // Tests that association between the keychain and login database parts of a | 1257 // Tests that association between the keychain and login database parts of a |
1260 // password added by fuzzy (PSL) matching works. | 1258 // password added by fuzzy (PSL) matching works. |
1261 // 1. Add a password for www.facebook.com | 1259 // 1. Add a password for www.facebook.com |
1262 // 2. Get a password for m.facebook.com. This fuzzy matches and returns the | 1260 // 2. Get a password for m.facebook.com. This fuzzy matches and returns the |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1305 // 4. Remove both passwords. | 1303 // 4. Remove both passwords. |
1306 store_->RemoveLogin(*www_form); | 1304 store_->RemoveLogin(*www_form); |
1307 store_->RemoveLogin(m_form); | 1305 store_->RemoveLogin(m_form); |
1308 FinishAsyncProcessing(); | 1306 FinishAsyncProcessing(); |
1309 | 1307 |
1310 // No trace of www.facebook.com. | 1308 // No trace of www.facebook.com. |
1311 ScopedVector<autofill::PasswordForm> matching_items = | 1309 ScopedVector<autofill::PasswordForm> matching_items = |
1312 owned_keychain_adapter.PasswordsFillingForm(www_form->signon_realm, | 1310 owned_keychain_adapter.PasswordsFillingForm(www_form->signon_realm, |
1313 www_form->scheme); | 1311 www_form->scheme); |
1314 EXPECT_EQ(0u, matching_items.size()); | 1312 EXPECT_EQ(0u, matching_items.size()); |
1315 login_db()->GetLogins(*www_form, &matching_items); | 1313 EXPECT_TRUE(login_db()->GetLogins(*www_form, &matching_items)); |
1316 EXPECT_EQ(0u, matching_items.size()); | 1314 EXPECT_EQ(0u, matching_items.size()); |
1317 // No trace of m.facebook.com. | 1315 // No trace of m.facebook.com. |
1318 matching_items = owned_keychain_adapter.PasswordsFillingForm( | 1316 matching_items = owned_keychain_adapter.PasswordsFillingForm( |
1319 m_form.signon_realm, m_form.scheme); | 1317 m_form.signon_realm, m_form.scheme); |
1320 EXPECT_EQ(0u, matching_items.size()); | 1318 EXPECT_EQ(0u, matching_items.size()); |
1321 login_db()->GetLogins(m_form, &matching_items); | 1319 EXPECT_TRUE(login_db()->GetLogins(m_form, &matching_items)); |
1322 EXPECT_EQ(0u, matching_items.size()); | 1320 EXPECT_EQ(0u, matching_items.size()); |
1323 } | 1321 } |
1324 | 1322 |
1325 namespace { | 1323 namespace { |
1326 | 1324 |
1327 class PasswordsChangeObserver : | 1325 class PasswordsChangeObserver : |
1328 public password_manager::PasswordStore::Observer { | 1326 public password_manager::PasswordStore::Observer { |
1329 public: | 1327 public: |
1330 PasswordsChangeObserver(TestPasswordStoreMac* store) : observer_(this) { | 1328 PasswordsChangeObserver(TestPasswordStoreMac* store) : observer_(this) { |
1331 observer_.Add(store); | 1329 observer_.Add(store); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1479 // Add a password from the current profile. | 1477 // Add a password from the current profile. |
1480 PasswordFormData www_form_data2 = { | 1478 PasswordFormData www_form_data2 = { |
1481 PasswordForm::SCHEME_HTML, "http://www.facebook.com/", | 1479 PasswordForm::SCHEME_HTML, "http://www.facebook.com/", |
1482 "http://www.facebook.com/index.html", "login", L"username", L"password", | 1480 "http://www.facebook.com/index.html", "login", L"username", L"password", |
1483 L"submit", L"not_joe_user", L"12345", true, false, 1 }; | 1481 L"submit", L"not_joe_user", L"12345", true, false, 1 }; |
1484 www_form = CreatePasswordFormFromDataForTesting(www_form_data2); | 1482 www_form = CreatePasswordFormFromDataForTesting(www_form_data2); |
1485 store_->AddLogin(*www_form); | 1483 store_->AddLogin(*www_form); |
1486 FinishAsyncProcessing(); | 1484 FinishAsyncProcessing(); |
1487 | 1485 |
1488 ScopedVector<PasswordForm> matching_items; | 1486 ScopedVector<PasswordForm> matching_items; |
1489 login_db()->GetLogins(*www_form, &matching_items); | 1487 EXPECT_TRUE(login_db()->GetLogins(*www_form, &matching_items)); |
1490 EXPECT_EQ(1u, matching_items.size()); | 1488 EXPECT_EQ(1u, matching_items.size()); |
1491 matching_items.clear(); | |
1492 | 1489 |
1493 store_->RemoveLoginsCreatedBetween(base::Time(), base::Time()); | 1490 store_->RemoveLoginsCreatedBetween(base::Time(), base::Time()); |
1494 FinishAsyncProcessing(); | 1491 FinishAsyncProcessing(); |
1495 | 1492 |
1496 // Check the second facebook form is gone. | 1493 // Check the second facebook form is gone. |
1497 login_db()->GetLogins(*www_form, &matching_items); | 1494 EXPECT_TRUE(login_db()->GetLogins(*www_form, &matching_items)); |
1498 EXPECT_EQ(0u, matching_items.size()); | 1495 EXPECT_EQ(0u, matching_items.size()); |
1499 | 1496 |
1500 // Check the first facebook form is still there. | 1497 // Check the first facebook form is still there. |
1501 matching_items = owned_keychain_adapter.PasswordsFillingForm( | 1498 matching_items = owned_keychain_adapter.PasswordsFillingForm( |
1502 www_form->signon_realm, www_form->scheme); | 1499 www_form->signon_realm, www_form->scheme); |
1503 ASSERT_EQ(1u, matching_items.size()); | 1500 ASSERT_EQ(1u, matching_items.size()); |
1504 EXPECT_EQ(ASCIIToUTF16("joe_user"), matching_items[0]->username_value); | 1501 EXPECT_EQ(ASCIIToUTF16("joe_user"), matching_items[0]->username_value); |
1505 matching_items.clear(); | |
1506 | 1502 |
1507 // Check the third-party password is still there. | 1503 // Check the third-party password is still there. |
1508 owned_keychain_adapter.SetFindsOnlyOwnedItems(false); | 1504 owned_keychain_adapter.SetFindsOnlyOwnedItems(false); |
1509 matching_items = owned_keychain_adapter.PasswordsFillingForm( | 1505 matching_items = owned_keychain_adapter.PasswordsFillingForm( |
1510 "http://some.domain.com/insecure.html", PasswordForm::SCHEME_HTML); | 1506 "http://some.domain.com/insecure.html", PasswordForm::SCHEME_HTML); |
1511 ASSERT_EQ(1u, matching_items.size()); | 1507 ASSERT_EQ(1u, matching_items.size()); |
1512 } | 1508 } |
1513 | 1509 |
1514 // Open the store and immediately write to it and try to read it back, without | 1510 // Open the store and immediately write to it and try to read it back, without |
1515 // first waiting for the initialization to finish. If tasks are processed in | 1511 // first waiting for the initialization to finish. If tasks are processed in |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1634 .WillByDefault(QuitUIMessageLoop()); | 1630 .WillByDefault(QuitUIMessageLoop()); |
1635 EXPECT_CALL(mock_observer, OnLoginsChanged(_)).Times(0); | 1631 EXPECT_CALL(mock_observer, OnLoginsChanged(_)).Times(0); |
1636 // The PSL-matched form isn't returned because there is no actual password in | 1632 // The PSL-matched form isn't returned because there is no actual password in |
1637 // the keychain. | 1633 // the keychain. |
1638 EXPECT_CALL(consumer, OnGetPasswordStoreResultsConstRef(IsEmpty())); | 1634 EXPECT_CALL(consumer, OnGetPasswordStoreResultsConstRef(IsEmpty())); |
1639 store_->GetLogins(m_form, PasswordStore::ALLOW_PROMPT, &consumer); | 1635 store_->GetLogins(m_form, PasswordStore::ALLOW_PROMPT, &consumer); |
1640 base::MessageLoop::current()->Run(); | 1636 base::MessageLoop::current()->Run(); |
1641 ScopedVector<autofill::PasswordForm> all_forms; | 1637 ScopedVector<autofill::PasswordForm> all_forms; |
1642 EXPECT_TRUE(login_db()->GetAutofillableLogins(&all_forms)); | 1638 EXPECT_TRUE(login_db()->GetAutofillableLogins(&all_forms)); |
1643 EXPECT_EQ(1u, all_forms.size()); | 1639 EXPECT_EQ(1u, all_forms.size()); |
1644 all_forms.clear(); | |
1645 ::testing::Mock::VerifyAndClearExpectations(&mock_observer); | 1640 ::testing::Mock::VerifyAndClearExpectations(&mock_observer); |
1646 | 1641 |
1647 // 3. Get a password for www.facebook.com. The form is implicitly removed and | 1642 // 3. Get a password for www.facebook.com. The form is implicitly removed and |
1648 // the observer is notified. | 1643 // the observer is notified. |
1649 password_manager::PasswordStoreChangeList list; | 1644 password_manager::PasswordStoreChangeList list; |
1650 list.push_back(password_manager::PasswordStoreChange( | 1645 list.push_back(password_manager::PasswordStoreChange( |
1651 password_manager::PasswordStoreChange::REMOVE, *www_form)); | 1646 password_manager::PasswordStoreChange::REMOVE, *www_form)); |
1652 EXPECT_CALL(mock_observer, OnLoginsChanged(list)); | 1647 EXPECT_CALL(mock_observer, OnLoginsChanged(list)); |
1653 EXPECT_CALL(consumer, OnGetPasswordStoreResultsConstRef(IsEmpty())); | 1648 EXPECT_CALL(consumer, OnGetPasswordStoreResultsConstRef(IsEmpty())); |
1654 store_->GetLogins(*www_form, PasswordStore::ALLOW_PROMPT, &consumer); | 1649 store_->GetLogins(*www_form, PasswordStore::ALLOW_PROMPT, &consumer); |
(...skipping 27 matching lines...) Expand all Loading... |
1682 query_form.password_value.clear(); | 1677 query_form.password_value.clear(); |
1683 query_form.username_value.clear(); | 1678 query_form.username_value.clear(); |
1684 EXPECT_CALL(mock_consumer, OnGetPasswordStoreResultsConstRef(SizeIs(1u))) | 1679 EXPECT_CALL(mock_consumer, OnGetPasswordStoreResultsConstRef(SizeIs(1u))) |
1685 .WillOnce( | 1680 .WillOnce( |
1686 DoAll(SaveACopyOfFirstForm(&returned_form), QuitUIMessageLoop())); | 1681 DoAll(SaveACopyOfFirstForm(&returned_form), QuitUIMessageLoop())); |
1687 store()->GetLogins(query_form, PasswordStore::ALLOW_PROMPT, &mock_consumer); | 1682 store()->GetLogins(query_form, PasswordStore::ALLOW_PROMPT, &mock_consumer); |
1688 base::MessageLoop::current()->Run(); | 1683 base::MessageLoop::current()->Run(); |
1689 ::testing::Mock::VerifyAndClearExpectations(&mock_consumer); | 1684 ::testing::Mock::VerifyAndClearExpectations(&mock_consumer); |
1690 EXPECT_EQ(form, returned_form); | 1685 EXPECT_EQ(form, returned_form); |
1691 } | 1686 } |
OLD | NEW |