Chromium Code Reviews| 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" | |
| 10 #include "base/scoped_observer.h" | 9 #include "base/scoped_observer.h" |
| 11 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 12 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/synchronization/waitable_event.h" | 13 #include "base/synchronization/waitable_event.h" |
| 15 #include "chrome/browser/password_manager/password_store_mac_internal.h" | 14 #include "chrome/browser/password_manager/password_store_mac_internal.h" |
| 16 #include "chrome/common/chrome_paths.h" | 15 #include "chrome/common/chrome_paths.h" |
| 17 #include "components/password_manager/core/browser/login_database.h" | 16 #include "components/password_manager/core/browser/login_database.h" |
| 18 #include "components/password_manager/core/browser/password_store_consumer.h" | 17 #include "components/password_manager/core/browser/password_store_consumer.h" |
| 19 #include "content/public/test/test_browser_thread.h" | 18 #include "content/public/test/test_browser_thread.h" |
| (...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 475 }; | 474 }; |
| 476 | 475 |
| 477 MacKeychainPasswordFormAdapter keychain_adapter(keychain_); | 476 MacKeychainPasswordFormAdapter keychain_adapter(keychain_); |
| 478 MacKeychainPasswordFormAdapter owned_keychain_adapter(keychain_); | 477 MacKeychainPasswordFormAdapter owned_keychain_adapter(keychain_); |
| 479 owned_keychain_adapter.SetFindsOnlyOwnedItems(true); | 478 owned_keychain_adapter.SetFindsOnlyOwnedItems(true); |
| 480 for (unsigned int i = 0; i < arraysize(test_data); ++i) { | 479 for (unsigned int i = 0; i < arraysize(test_data); ++i) { |
| 481 scoped_ptr<PasswordForm> query_form( | 480 scoped_ptr<PasswordForm> query_form( |
| 482 CreatePasswordFormFromData(test_data[i].data)); | 481 CreatePasswordFormFromData(test_data[i].data)); |
| 483 | 482 |
| 484 // Check matches treating the form as a fill target. | 483 // Check matches treating the form as a fill target. |
| 485 std::vector<PasswordForm*> matching_items = | 484 ScopedVector<autofill::PasswordForm> matching_items( |
| 486 keychain_adapter.PasswordsFillingForm(query_form->signon_realm, | 485 keychain_adapter.PasswordsFillingForm(query_form->signon_realm, |
| 487 query_form->scheme); | 486 query_form->scheme)); |
| 488 EXPECT_EQ(test_data[i].expected_fill_matches, matching_items.size()); | 487 EXPECT_EQ(test_data[i].expected_fill_matches, matching_items.size()); |
| 489 STLDeleteElements(&matching_items); | 488 matching_items.clear(); |
| 490 | 489 |
| 491 // Check matches treating the form as a merging target. | 490 // Check matches treating the form as a merging target. |
| 492 EXPECT_EQ(test_data[i].expected_merge_matches > 0, | 491 EXPECT_EQ(test_data[i].expected_merge_matches > 0, |
| 493 keychain_adapter.HasPasswordsMergeableWithForm(*query_form)); | 492 keychain_adapter.HasPasswordsMergeableWithForm(*query_form)); |
| 494 std::vector<SecKeychainItemRef> keychain_items; | 493 std::vector<SecKeychainItemRef> keychain_items; |
| 495 std::vector<internal_keychain_helpers::ItemFormPair> item_form_pairs = | 494 std::vector<internal_keychain_helpers::ItemFormPair> item_form_pairs = |
| 496 internal_keychain_helpers:: | 495 internal_keychain_helpers:: |
| 497 ExtractAllKeychainItemAttributesIntoPasswordForms(&keychain_items, | 496 ExtractAllKeychainItemAttributesIntoPasswordForms(&keychain_items, |
| 498 *keychain_); | 497 *keychain_); |
| 499 matching_items = | 498 matching_items = |
| 500 internal_keychain_helpers::ExtractPasswordsMergeableWithForm( | 499 internal_keychain_helpers::ExtractPasswordsMergeableWithForm( |
| 501 *keychain_, item_form_pairs, *query_form); | 500 *keychain_, item_form_pairs, *query_form); |
| 502 EXPECT_EQ(test_data[i].expected_merge_matches, matching_items.size()); | 501 EXPECT_EQ(test_data[i].expected_merge_matches, matching_items.size()); |
| 503 STLDeleteContainerPairSecondPointers(item_form_pairs.begin(), | 502 STLDeleteContainerPairSecondPointers(item_form_pairs.begin(), |
| 504 item_form_pairs.end()); | 503 item_form_pairs.end()); |
| 505 for (std::vector<SecKeychainItemRef>::iterator i = keychain_items.begin(); | 504 for (std::vector<SecKeychainItemRef>::iterator i = keychain_items.begin(); |
| 506 i != keychain_items.end(); ++i) { | 505 i != keychain_items.end(); ++i) { |
| 507 keychain_->Free(*i); | 506 keychain_->Free(*i); |
| 508 } | 507 } |
| 509 STLDeleteElements(&matching_items); | |
| 510 | 508 |
| 511 // None of the pre-seeded items are owned by us, so none should match an | 509 // None of the pre-seeded items are owned by us, so none should match an |
| 512 // owned-passwords-only search. | 510 // owned-passwords-only search. |
| 513 matching_items = owned_keychain_adapter.PasswordsFillingForm( | 511 matching_items = owned_keychain_adapter.PasswordsFillingForm( |
| 514 query_form->signon_realm, query_form->scheme); | 512 query_form->signon_realm, query_form->scheme); |
| 515 EXPECT_EQ(0U, matching_items.size()); | 513 EXPECT_EQ(0U, matching_items.size()); |
| 516 STLDeleteElements(&matching_items); | |
| 517 } | 514 } |
| 518 } | 515 } |
| 519 | 516 |
| 520 // Changes just the origin path of |form|. | 517 // Changes just the origin path of |form|. |
| 521 static void SetPasswordFormPath(PasswordForm* form, const char* path) { | 518 static void SetPasswordFormPath(PasswordForm* form, const char* path) { |
| 522 GURL::Replacements replacement; | 519 GURL::Replacements replacement; |
| 523 std::string new_value(path); | 520 std::string new_value(path); |
| 524 replacement.SetPathStr(new_value); | 521 replacement.SetPathStr(new_value); |
| 525 form->origin = form->origin.ReplaceComponents(replacement); | 522 form->origin = form->origin.ReplaceComponents(replacement); |
| 526 } | 523 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 560 | 557 |
| 561 for (unsigned int i = 0; i < arraysize(base_form_data); ++i) { | 558 for (unsigned int i = 0; i < arraysize(base_form_data); ++i) { |
| 562 // Create a base form and make sure we find a match. | 559 // Create a base form and make sure we find a match. |
| 563 scoped_ptr<PasswordForm> base_form(CreatePasswordFormFromData( | 560 scoped_ptr<PasswordForm> base_form(CreatePasswordFormFromData( |
| 564 base_form_data[i])); | 561 base_form_data[i])); |
| 565 EXPECT_TRUE(keychain_adapter.HasPasswordsMergeableWithForm(*base_form)); | 562 EXPECT_TRUE(keychain_adapter.HasPasswordsMergeableWithForm(*base_form)); |
| 566 EXPECT_TRUE(keychain_adapter.HasPasswordExactlyMatchingForm(*base_form)); | 563 EXPECT_TRUE(keychain_adapter.HasPasswordExactlyMatchingForm(*base_form)); |
| 567 | 564 |
| 568 // Make sure that the matching isn't looser than it should be by checking | 565 // Make sure that the matching isn't looser than it should be by checking |
| 569 // that slightly altered forms don't match. | 566 // that slightly altered forms don't match. |
| 570 std::vector<PasswordForm*> modified_forms; | 567 ScopedVector<autofill::PasswordForm> modified_forms; |
| 571 | 568 |
| 572 modified_forms.push_back(new PasswordForm(*base_form)); | 569 modified_forms.push_back(new PasswordForm(*base_form)); |
| 573 modified_forms.back()->username_value = ASCIIToUTF16("wrong_user"); | 570 modified_forms.back()->username_value = ASCIIToUTF16("wrong_user"); |
| 574 | 571 |
| 575 modified_forms.push_back(new PasswordForm(*base_form)); | 572 modified_forms.push_back(new PasswordForm(*base_form)); |
| 576 SetPasswordFormPath(modified_forms.back(), "elsewhere.html"); | 573 SetPasswordFormPath(modified_forms.back(), "elsewhere.html"); |
| 577 | 574 |
| 578 modified_forms.push_back(new PasswordForm(*base_form)); | 575 modified_forms.push_back(new PasswordForm(*base_form)); |
| 579 modified_forms.back()->scheme = PasswordForm::SCHEME_OTHER; | 576 modified_forms.back()->scheme = PasswordForm::SCHEME_OTHER; |
| 580 | 577 |
| 581 modified_forms.push_back(new PasswordForm(*base_form)); | 578 modified_forms.push_back(new PasswordForm(*base_form)); |
| 582 SetPasswordFormPort(modified_forms.back(), "1234"); | 579 SetPasswordFormPort(modified_forms.back(), "1234"); |
| 583 | 580 |
| 584 modified_forms.push_back(new PasswordForm(*base_form)); | 581 modified_forms.push_back(new PasswordForm(*base_form)); |
| 585 modified_forms.back()->blacklisted_by_user = true; | 582 modified_forms.back()->blacklisted_by_user = true; |
| 586 | 583 |
| 587 if (base_form->scheme == PasswordForm::SCHEME_BASIC || | 584 if (base_form->scheme == PasswordForm::SCHEME_BASIC || |
| 588 base_form->scheme == PasswordForm::SCHEME_DIGEST) { | 585 base_form->scheme == PasswordForm::SCHEME_DIGEST) { |
| 589 modified_forms.push_back(new PasswordForm(*base_form)); | 586 modified_forms.push_back(new PasswordForm(*base_form)); |
| 590 SetPasswordFormRealm(modified_forms.back(), "incorrect"); | 587 SetPasswordFormRealm(modified_forms.back(), "incorrect"); |
| 591 } | 588 } |
| 592 | 589 |
| 593 for (unsigned int j = 0; j < modified_forms.size(); ++j) { | 590 for (unsigned int j = 0; j < modified_forms.size(); ++j) { |
| 594 bool match = keychain_adapter.HasPasswordExactlyMatchingForm( | 591 bool match = keychain_adapter.HasPasswordExactlyMatchingForm( |
| 595 *modified_forms[j]); | 592 *modified_forms[j]); |
| 596 EXPECT_FALSE(match) << "In modified version " << j | 593 EXPECT_FALSE(match) << "In modified version " << j |
| 597 << " of base form " << i; | 594 << " of base form " << i; |
| 598 } | 595 } |
| 599 STLDeleteElements(&modified_forms); | |
| 600 } | 596 } |
| 601 } | 597 } |
| 602 | 598 |
| 603 TEST_F(PasswordStoreMacInternalsTest, TestKeychainAdd) { | 599 TEST_F(PasswordStoreMacInternalsTest, TestKeychainAdd) { |
| 604 struct TestDataAndExpectation { | 600 struct TestDataAndExpectation { |
| 605 PasswordFormData data; | 601 PasswordFormData data; |
| 606 bool should_succeed; | 602 bool should_succeed; |
| 607 }; | 603 }; |
| 608 TestDataAndExpectation test_data[] = { | 604 TestDataAndExpectation test_data[] = { |
| 609 // Test a variety of scheme/port/protocol/path variations. | 605 // Test a variety of scheme/port/protocol/path variations. |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 883 CHECK(current_test < kTestCount); | 879 CHECK(current_test < kTestCount); |
| 884 test_data[KEYCHAIN_INPUT][current_test].push_back(&keychain_user_1); | 880 test_data[KEYCHAIN_INPUT][current_test].push_back(&keychain_user_1); |
| 885 test_data[KEYCHAIN_INPUT][current_test].push_back(&keychain_user_1_with_path); | 881 test_data[KEYCHAIN_INPUT][current_test].push_back(&keychain_user_1_with_path); |
| 886 test_data[DATABASE_INPUT][current_test].push_back(&db_user_1); | 882 test_data[DATABASE_INPUT][current_test].push_back(&db_user_1); |
| 887 test_data[DATABASE_INPUT][current_test].push_back(&db_user_1_with_path); | 883 test_data[DATABASE_INPUT][current_test].push_back(&db_user_1_with_path); |
| 888 test_data[MERGE_OUTPUT][current_test].push_back(&merged_user_1); | 884 test_data[MERGE_OUTPUT][current_test].push_back(&merged_user_1); |
| 889 test_data[MERGE_OUTPUT][current_test].push_back( | 885 test_data[MERGE_OUTPUT][current_test].push_back( |
| 890 &merged_user_1_with_both_paths); | 886 &merged_user_1_with_both_paths); |
| 891 | 887 |
| 892 for (unsigned int test_case = 0; test_case <= current_test; ++test_case) { | 888 for (unsigned int test_case = 0; test_case <= current_test; ++test_case) { |
| 893 std::vector<PasswordForm*> keychain_forms; | 889 ScopedVector<autofill::PasswordForm> keychain_forms; |
| 894 for (std::vector<PasswordFormData*>::iterator i = | 890 for (std::vector<PasswordFormData*>::iterator i = |
| 895 test_data[KEYCHAIN_INPUT][test_case].begin(); | 891 test_data[KEYCHAIN_INPUT][test_case].begin(); |
| 896 i != test_data[KEYCHAIN_INPUT][test_case].end(); ++i) { | 892 i != test_data[KEYCHAIN_INPUT][test_case].end(); ++i) { |
| 897 keychain_forms.push_back(CreatePasswordFormFromData(*(*i))); | 893 keychain_forms.push_back(CreatePasswordFormFromData(*(*i))); |
| 898 } | 894 } |
| 899 std::vector<PasswordForm*> database_forms; | 895 ScopedVector<autofill::PasswordForm> database_forms; |
| 900 for (std::vector<PasswordFormData*>::iterator i = | 896 for (std::vector<PasswordFormData*>::iterator i = |
| 901 test_data[DATABASE_INPUT][test_case].begin(); | 897 test_data[DATABASE_INPUT][test_case].begin(); |
| 902 i != test_data[DATABASE_INPUT][test_case].end(); ++i) { | 898 i != test_data[DATABASE_INPUT][test_case].end(); ++i) { |
| 903 database_forms.push_back(CreatePasswordFormFromData(*(*i))); | 899 database_forms.push_back(CreatePasswordFormFromData(*(*i))); |
| 904 } | 900 } |
| 905 | 901 |
| 906 std::vector<PasswordForm*> merged_forms; | 902 ScopedVector<autofill::PasswordForm> merged_forms; |
| 907 internal_keychain_helpers::MergePasswordForms(&keychain_forms, | 903 internal_keychain_helpers::MergePasswordForms(&keychain_forms, |
| 908 &database_forms, | 904 &database_forms, |
| 909 &merged_forms); | 905 &merged_forms); |
| 910 | 906 |
| 911 CHECK_FORMS(keychain_forms, test_data[KEYCHAIN_OUTPUT][test_case], | 907 CHECK_FORMS(keychain_forms.get(), test_data[KEYCHAIN_OUTPUT][test_case], |
| 912 test_case); | 908 test_case); |
| 913 CHECK_FORMS(database_forms, test_data[DATABASE_OUTPUT][test_case], | 909 CHECK_FORMS(database_forms.get(), test_data[DATABASE_OUTPUT][test_case], |
| 914 test_case); | 910 test_case); |
| 915 CHECK_FORMS(merged_forms, test_data[MERGE_OUTPUT][test_case], test_case); | 911 CHECK_FORMS(merged_forms.get(), test_data[MERGE_OUTPUT][test_case], |
| 916 | 912 test_case); |
| 917 STLDeleteElements(&keychain_forms); | |
| 918 STLDeleteElements(&database_forms); | |
| 919 STLDeleteElements(&merged_forms); | |
| 920 } | 913 } |
| 921 } | 914 } |
| 922 | 915 |
| 923 TEST_F(PasswordStoreMacInternalsTest, TestPasswordBulkLookup) { | 916 TEST_F(PasswordStoreMacInternalsTest, TestPasswordBulkLookup) { |
| 924 PasswordFormData db_data[] = { | 917 PasswordFormData db_data[] = { |
| 925 { PasswordForm::SCHEME_HTML, "http://some.domain.com/", | 918 { PasswordForm::SCHEME_HTML, "http://some.domain.com/", |
| 926 "http://some.domain.com/", "http://some.domain.com/action.cgi", | 919 "http://some.domain.com/", "http://some.domain.com/action.cgi", |
| 927 L"submit", L"username", L"password", L"joe_user", L"", | 920 L"submit", L"username", L"password", L"joe_user", L"", |
| 928 true, false, 1212121212 }, | 921 true, false, 1212121212 }, |
| 929 { PasswordForm::SCHEME_HTML, "http://some.domain.com/", | 922 { PasswordForm::SCHEME_HTML, "http://some.domain.com/", |
| 930 "http://some.domain.com/page.html", | 923 "http://some.domain.com/page.html", |
| 931 "http://some.domain.com/handlepage.cgi", | 924 "http://some.domain.com/handlepage.cgi", |
| 932 L"submit", L"username", L"password", L"joe_user", L"", | 925 L"submit", L"username", L"password", L"joe_user", L"", |
| 933 true, false, 1234567890 }, | 926 true, false, 1234567890 }, |
| 934 { PasswordForm::SCHEME_HTML, "http://some.domain.com/", | 927 { PasswordForm::SCHEME_HTML, "http://some.domain.com/", |
| 935 "http://some.domain.com/page.html", | 928 "http://some.domain.com/page.html", |
| 936 "http://some.domain.com/handlepage.cgi", | 929 "http://some.domain.com/handlepage.cgi", |
| 937 L"submit", L"username", L"password", L"second-account", L"", | 930 L"submit", L"username", L"password", L"second-account", L"", |
| 938 true, false, 1240000000 }, | 931 true, false, 1240000000 }, |
| 939 { PasswordForm::SCHEME_HTML, "http://dont.remember.com/", | 932 { PasswordForm::SCHEME_HTML, "http://dont.remember.com/", |
| 940 "http://dont.remember.com/", | 933 "http://dont.remember.com/", |
| 941 "http://dont.remember.com/handlepage.cgi", | 934 "http://dont.remember.com/handlepage.cgi", |
| 942 L"submit", L"username", L"password", L"joe_user", L"", | 935 L"submit", L"username", L"password", L"joe_user", L"", |
| 943 true, false, 1240000000 }, | 936 true, false, 1240000000 }, |
| 944 { PasswordForm::SCHEME_HTML, "http://some.domain.com/", | 937 { PasswordForm::SCHEME_HTML, "http://some.domain.com/", |
| 945 "http://some.domain.com/path.html", "http://some.domain.com/action.cgi", | 938 "http://some.domain.com/path.html", "http://some.domain.com/action.cgi", |
| 946 L"submit", L"username", L"password", NULL, NULL, | 939 L"submit", L"username", L"password", NULL, NULL, |
| 947 true, false, 1212121212 }, | 940 true, false, 1212121212 }, |
| 948 }; | 941 }; |
| 949 std::vector<PasswordForm*> database_forms; | 942 ScopedVector<autofill::PasswordForm> database_forms; |
| 950 for (unsigned int i = 0; i < arraysize(db_data); ++i) { | 943 for (unsigned int i = 0; i < arraysize(db_data); ++i) { |
| 951 database_forms.push_back(CreatePasswordFormFromData(db_data[i])); | 944 database_forms.push_back(CreatePasswordFormFromData(db_data[i])); |
| 952 } | 945 } |
| 953 std::vector<PasswordForm*> merged_forms = | 946 ScopedVector<autofill::PasswordForm> merged_forms; |
| 954 internal_keychain_helpers::GetPasswordsForForms(*keychain_, | 947 internal_keychain_helpers::GetPasswordsForForms(*keychain_, &database_forms, |
| 955 &database_forms); | 948 &merged_forms); |
| 956 EXPECT_EQ(2U, database_forms.size()); | 949 EXPECT_EQ(2U, database_forms.size()); |
| 957 ASSERT_EQ(3U, merged_forms.size()); | 950 ASSERT_EQ(3U, merged_forms.size()); |
| 958 EXPECT_EQ(ASCIIToUTF16("sekrit"), merged_forms[0]->password_value); | 951 EXPECT_EQ(ASCIIToUTF16("sekrit"), merged_forms[0]->password_value); |
| 959 EXPECT_EQ(ASCIIToUTF16("sekrit"), merged_forms[1]->password_value); | 952 EXPECT_EQ(ASCIIToUTF16("sekrit"), merged_forms[1]->password_value); |
| 960 EXPECT_TRUE(merged_forms[2]->blacklisted_by_user); | 953 EXPECT_TRUE(merged_forms[2]->blacklisted_by_user); |
| 961 | |
| 962 STLDeleteElements(&database_forms); | |
| 963 STLDeleteElements(&merged_forms); | |
| 964 } | 954 } |
| 965 | 955 |
| 966 TEST_F(PasswordStoreMacInternalsTest, TestBlacklistedFiltering) { | 956 TEST_F(PasswordStoreMacInternalsTest, TestBlacklistedFiltering) { |
| 967 PasswordFormData db_data[] = { | 957 PasswordFormData db_data[] = { |
| 968 { PasswordForm::SCHEME_HTML, "http://dont.remember.com/", | 958 { PasswordForm::SCHEME_HTML, "http://dont.remember.com/", |
| 969 "http://dont.remember.com/", | 959 "http://dont.remember.com/", |
| 970 "http://dont.remember.com/handlepage.cgi", | 960 "http://dont.remember.com/handlepage.cgi", |
| 971 L"submit", L"username", L"password", L"joe_user", L"non_empty_password", | 961 L"submit", L"username", L"password", L"joe_user", L"non_empty_password", |
| 972 true, false, 1240000000 }, | 962 true, false, 1240000000 }, |
| 973 { PasswordForm::SCHEME_HTML, "https://dont.remember.com/", | 963 { PasswordForm::SCHEME_HTML, "https://dont.remember.com/", |
| 974 "https://dont.remember.com/", | 964 "https://dont.remember.com/", |
| 975 "https://dont.remember.com/handlepage_secure.cgi", | 965 "https://dont.remember.com/handlepage_secure.cgi", |
| 976 L"submit", L"username", L"password", L"joe_user", L"non_empty_password", | 966 L"submit", L"username", L"password", L"joe_user", L"non_empty_password", |
| 977 true, false, 1240000000 }, | 967 true, false, 1240000000 }, |
| 978 }; | 968 }; |
| 979 std::vector<PasswordForm*> database_forms; | 969 ScopedVector<autofill::PasswordForm> database_forms; |
| 980 for (unsigned int i = 0; i < arraysize(db_data); ++i) { | 970 for (unsigned int i = 0; i < arraysize(db_data); ++i) { |
| 981 database_forms.push_back(CreatePasswordFormFromData(db_data[i])); | 971 database_forms.push_back(CreatePasswordFormFromData(db_data[i])); |
| 982 } | 972 } |
| 983 std::vector<PasswordForm*> merged_forms = | 973 ScopedVector<autofill::PasswordForm> merged_forms; |
| 984 internal_keychain_helpers::GetPasswordsForForms(*keychain_, | 974 internal_keychain_helpers::GetPasswordsForForms(*keychain_, &database_forms, |
| 985 &database_forms); | 975 &merged_forms); |
| 986 EXPECT_EQ(2U, database_forms.size()); | 976 EXPECT_EQ(2U, database_forms.size()); |
| 987 ASSERT_EQ(0U, merged_forms.size()); | 977 ASSERT_EQ(0U, merged_forms.size()); |
| 988 | |
| 989 STLDeleteElements(&database_forms); | |
| 990 STLDeleteElements(&merged_forms); | |
| 991 } | 978 } |
| 992 | 979 |
| 993 TEST_F(PasswordStoreMacInternalsTest, TestFillPasswordFormFromKeychainItem) { | 980 TEST_F(PasswordStoreMacInternalsTest, TestFillPasswordFormFromKeychainItem) { |
| 994 // When |extract_password_data| is false, the password field must be empty, | 981 // When |extract_password_data| is false, the password field must be empty, |
| 995 // and |blacklisted_by_user| must be false. | 982 // and |blacklisted_by_user| must be false. |
| 996 SecKeychainItemRef keychain_item = reinterpret_cast<SecKeychainItemRef>(1); | 983 SecKeychainItemRef keychain_item = reinterpret_cast<SecKeychainItemRef>(1); |
| 997 PasswordForm form_without_extracted_password; | 984 PasswordForm form_without_extracted_password; |
| 998 bool parsed = internal_keychain_helpers::FillPasswordFormFromKeychainItem( | 985 bool parsed = internal_keychain_helpers::FillPasswordFormFromKeychainItem( |
| 999 *keychain_, | 986 *keychain_, |
| 1000 keychain_item, | 987 keychain_item, |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1080 { PasswordForm::SCHEME_DIGEST, "https://digest.site.com/differentrealm", | 1067 { PasswordForm::SCHEME_DIGEST, "https://digest.site.com/differentrealm", |
| 1081 "https://digest.site.com/secure.html", NULL, NULL, NULL, NULL, | 1068 "https://digest.site.com/secure.html", NULL, NULL, NULL, NULL, |
| 1082 L"testname", L"testpass", false, false, 0 }, | 1069 L"testname", L"testpass", false, false, 0 }, |
| 1083 }; | 1070 }; |
| 1084 for (unsigned int i = 0; i < arraysize(owned_password_data); ++i) { | 1071 for (unsigned int i = 0; i < arraysize(owned_password_data); ++i) { |
| 1085 scoped_ptr<PasswordForm> form(CreatePasswordFormFromData( | 1072 scoped_ptr<PasswordForm> form(CreatePasswordFormFromData( |
| 1086 owned_password_data[i])); | 1073 owned_password_data[i])); |
| 1087 owned_keychain_adapter.AddPassword(*form); | 1074 owned_keychain_adapter.AddPassword(*form); |
| 1088 } | 1075 } |
| 1089 | 1076 |
| 1090 std::vector<PasswordForm*> all_passwords = | 1077 ScopedVector<autofill::PasswordForm> all_passwords( |
|
vasilii
2015/01/28 15:09:03
nit: here and below I'd prefer ScopedVector<autofi
vabr (Chromium)
2015/01/28 16:36:27
Done.
| |
| 1091 keychain_adapter.GetAllPasswordFormPasswords(); | 1078 keychain_adapter.GetAllPasswordFormPasswords()); |
| 1092 EXPECT_EQ(8 + arraysize(owned_password_data), all_passwords.size()); | 1079 EXPECT_EQ(8 + arraysize(owned_password_data), all_passwords.size()); |
| 1093 STLDeleteElements(&all_passwords); | |
| 1094 | 1080 |
| 1095 std::vector<PasswordForm*> owned_passwords = | 1081 ScopedVector<autofill::PasswordForm> owned_passwords( |
| 1096 owned_keychain_adapter.GetAllPasswordFormPasswords(); | 1082 owned_keychain_adapter.GetAllPasswordFormPasswords()); |
| 1097 EXPECT_EQ(arraysize(owned_password_data), owned_passwords.size()); | 1083 EXPECT_EQ(arraysize(owned_password_data), owned_passwords.size()); |
| 1098 STLDeleteElements(&owned_passwords); | |
| 1099 } | 1084 } |
| 1100 | 1085 |
| 1101 #pragma mark - | 1086 #pragma mark - |
| 1102 | 1087 |
| 1103 class PasswordStoreMacTest : public testing::Test { | 1088 class PasswordStoreMacTest : public testing::Test { |
| 1104 public: | 1089 public: |
| 1105 PasswordStoreMacTest() : ui_thread_(BrowserThread::UI, &message_loop_) {} | 1090 PasswordStoreMacTest() : ui_thread_(BrowserThread::UI, &message_loop_) {} |
| 1106 | 1091 |
| 1107 void SetUp() override { | 1092 void SetUp() override { |
| 1108 ASSERT_TRUE(db_dir_.CreateUniqueTempDir()); | 1093 ASSERT_TRUE(db_dir_.CreateUniqueTempDir()); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1230 store_->UpdateLogin(*form); | 1215 store_->UpdateLogin(*form); |
| 1231 } | 1216 } |
| 1232 | 1217 |
| 1233 FinishAsyncProcessing(); | 1218 FinishAsyncProcessing(); |
| 1234 | 1219 |
| 1235 MacKeychainPasswordFormAdapter keychain_adapter(keychain()); | 1220 MacKeychainPasswordFormAdapter keychain_adapter(keychain()); |
| 1236 for (unsigned int i = 0; i < arraysize(updates); ++i) { | 1221 for (unsigned int i = 0; i < arraysize(updates); ++i) { |
| 1237 scoped_ptr<PasswordForm> query_form( | 1222 scoped_ptr<PasswordForm> query_form( |
| 1238 CreatePasswordFormFromData(updates[i].form_data)); | 1223 CreatePasswordFormFromData(updates[i].form_data)); |
| 1239 | 1224 |
| 1240 std::vector<PasswordForm*> matching_items = | 1225 ScopedVector<autofill::PasswordForm> matching_items( |
| 1241 keychain_adapter.PasswordsFillingForm(query_form->signon_realm, | 1226 keychain_adapter.PasswordsFillingForm(query_form->signon_realm, |
| 1242 query_form->scheme); | 1227 query_form->scheme)); |
| 1243 if (updates[i].password) { | 1228 if (updates[i].password) { |
| 1244 EXPECT_GT(matching_items.size(), 0U) << "iteration " << i; | 1229 EXPECT_GT(matching_items.size(), 0U) << "iteration " << i; |
| 1245 if (matching_items.size() >= 1) | 1230 if (matching_items.size() >= 1) |
| 1246 EXPECT_EQ(ASCIIToUTF16(updates[i].password), | 1231 EXPECT_EQ(ASCIIToUTF16(updates[i].password), |
| 1247 matching_items[0]->password_value) << "iteration " << i; | 1232 matching_items[0]->password_value) << "iteration " << i; |
| 1248 } else { | 1233 } else { |
| 1249 EXPECT_EQ(0U, matching_items.size()) << "iteration " << i; | 1234 EXPECT_EQ(0U, matching_items.size()) << "iteration " << i; |
| 1250 } | 1235 } |
| 1251 STLDeleteElements(&matching_items); | 1236 matching_items.clear(); |
| 1252 | 1237 |
| 1253 login_db()->GetLogins(*query_form, &matching_items); | 1238 login_db()->GetLogins(*query_form, &matching_items); |
| 1254 EXPECT_EQ(updates[i].password ? 1U : 0U, matching_items.size()) | 1239 EXPECT_EQ(updates[i].password ? 1U : 0U, matching_items.size()) |
| 1255 << "iteration " << i; | 1240 << "iteration " << i; |
| 1256 STLDeleteElements(&matching_items); | |
| 1257 } | 1241 } |
| 1258 } | 1242 } |
| 1259 | 1243 |
| 1260 TEST_F(PasswordStoreMacTest, TestDBKeychainAssociation) { | 1244 TEST_F(PasswordStoreMacTest, TestDBKeychainAssociation) { |
| 1261 // Tests that association between the keychain and login database parts of a | 1245 // Tests that association between the keychain and login database parts of a |
| 1262 // password added by fuzzy (PSL) matching works. | 1246 // password added by fuzzy (PSL) matching works. |
| 1263 // 1. Add a password for www.facebook.com | 1247 // 1. Add a password for www.facebook.com |
| 1264 // 2. Get a password for m.facebook.com. This fuzzy matches and returns the | 1248 // 2. Get a password for m.facebook.com. This fuzzy matches and returns the |
| 1265 // www.facebook.com password. | 1249 // www.facebook.com password. |
| 1266 // 3. Add the returned password for m.facebook.com. | 1250 // 3. Add the returned password for m.facebook.com. |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 1297 | 1281 |
| 1298 // 3. Add the returned password for m.facebook.com. | 1282 // 3. Add the returned password for m.facebook.com. |
| 1299 login_db()->AddLogin(consumer.last_result[0]); | 1283 login_db()->AddLogin(consumer.last_result[0]); |
| 1300 owned_keychain_adapter.AddPassword(m_form); | 1284 owned_keychain_adapter.AddPassword(m_form); |
| 1301 | 1285 |
| 1302 // 4. Remove both passwords. | 1286 // 4. Remove both passwords. |
| 1303 store_->RemoveLogin(*www_form); | 1287 store_->RemoveLogin(*www_form); |
| 1304 store_->RemoveLogin(m_form); | 1288 store_->RemoveLogin(m_form); |
| 1305 FinishAsyncProcessing(); | 1289 FinishAsyncProcessing(); |
| 1306 | 1290 |
| 1307 std::vector<PasswordForm*> matching_items; | |
| 1308 // No trace of www.facebook.com. | 1291 // No trace of www.facebook.com. |
| 1309 matching_items = owned_keychain_adapter.PasswordsFillingForm( | 1292 ScopedVector<autofill::PasswordForm> matching_items( |
| 1310 www_form->signon_realm, www_form->scheme); | 1293 owned_keychain_adapter.PasswordsFillingForm(www_form->signon_realm, |
| 1294 www_form->scheme)); | |
| 1311 EXPECT_EQ(0u, matching_items.size()); | 1295 EXPECT_EQ(0u, matching_items.size()); |
| 1312 login_db()->GetLogins(*www_form, &matching_items); | 1296 login_db()->GetLogins(*www_form, &matching_items); |
| 1313 EXPECT_EQ(0u, matching_items.size()); | 1297 EXPECT_EQ(0u, matching_items.size()); |
| 1314 // No trace of m.facebook.com. | 1298 // No trace of m.facebook.com. |
| 1315 matching_items = owned_keychain_adapter.PasswordsFillingForm( | 1299 matching_items = owned_keychain_adapter.PasswordsFillingForm( |
| 1316 m_form.signon_realm, m_form.scheme); | 1300 m_form.signon_realm, m_form.scheme); |
| 1317 EXPECT_EQ(0u, matching_items.size()); | 1301 EXPECT_EQ(0u, matching_items.size()); |
| 1318 login_db()->GetLogins(m_form, &matching_items); | 1302 login_db()->GetLogins(m_form, &matching_items); |
| 1319 EXPECT_EQ(0u, matching_items.size()); | 1303 EXPECT_EQ(0u, matching_items.size()); |
| 1320 } | 1304 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1390 test->store()->AddLogin(*form_facebook); | 1374 test->store()->AddLogin(*form_facebook); |
| 1391 test->store()->AddLogin(*form_other); | 1375 test->store()->AddLogin(*form_other); |
| 1392 EXPECT_CALL(observer, OnLoginsChanged(GetAddChangeList(*form_facebook_old))); | 1376 EXPECT_CALL(observer, OnLoginsChanged(GetAddChangeList(*form_facebook_old))); |
| 1393 EXPECT_CALL(observer, OnLoginsChanged(GetAddChangeList(*form_facebook))); | 1377 EXPECT_CALL(observer, OnLoginsChanged(GetAddChangeList(*form_facebook))); |
| 1394 EXPECT_CALL(observer, OnLoginsChanged(GetAddChangeList(*form_other))); | 1378 EXPECT_CALL(observer, OnLoginsChanged(GetAddChangeList(*form_other))); |
| 1395 observer.WaitAndVerify(test); | 1379 observer.WaitAndVerify(test); |
| 1396 | 1380 |
| 1397 // Check the keychain content. | 1381 // Check the keychain content. |
| 1398 MacKeychainPasswordFormAdapter owned_keychain_adapter(test->keychain()); | 1382 MacKeychainPasswordFormAdapter owned_keychain_adapter(test->keychain()); |
| 1399 owned_keychain_adapter.SetFindsOnlyOwnedItems(false); | 1383 owned_keychain_adapter.SetFindsOnlyOwnedItems(false); |
| 1400 ScopedVector<PasswordForm> matching_items; | 1384 ScopedVector<PasswordForm> matching_items( |
| 1401 matching_items.get() = owned_keychain_adapter.PasswordsFillingForm( | 1385 owned_keychain_adapter.PasswordsFillingForm(form_facebook->signon_realm, |
| 1402 form_facebook->signon_realm, form_facebook->scheme); | 1386 form_facebook->scheme)); |
| 1403 EXPECT_EQ(1u, matching_items.size()); | 1387 EXPECT_EQ(1u, matching_items.size()); |
| 1404 matching_items.clear(); | 1388 matching_items = owned_keychain_adapter.PasswordsFillingForm( |
| 1405 matching_items.get() = owned_keychain_adapter.PasswordsFillingForm( | |
| 1406 form_other->signon_realm, form_other->scheme); | 1389 form_other->signon_realm, form_other->scheme); |
| 1407 EXPECT_EQ(1u, matching_items.size()); | 1390 EXPECT_EQ(1u, matching_items.size()); |
| 1408 matching_items.clear(); | |
| 1409 | 1391 |
| 1410 // Remove facebook. | 1392 // Remove facebook. |
| 1411 void (PasswordStore::*method)(base::Time, base::Time) = | 1393 void (PasswordStore::*method)(base::Time, base::Time) = |
| 1412 check_created ? &PasswordStore::RemoveLoginsCreatedBetween | 1394 check_created ? &PasswordStore::RemoveLoginsCreatedBetween |
| 1413 : &PasswordStore::RemoveLoginsSyncedBetween; | 1395 : &PasswordStore::RemoveLoginsSyncedBetween; |
| 1414 (test->store()->*method)(base::Time(), next_day); | 1396 (test->store()->*method)(base::Time(), next_day); |
| 1415 password_manager::PasswordStoreChangeList list; | 1397 password_manager::PasswordStoreChangeList list; |
| 1416 form_facebook_old->password_value.clear(); | 1398 form_facebook_old->password_value.clear(); |
| 1417 form_facebook->password_value.clear(); | 1399 form_facebook->password_value.clear(); |
| 1418 list.push_back(password_manager::PasswordStoreChange( | 1400 list.push_back(password_manager::PasswordStoreChange( |
| 1419 password_manager::PasswordStoreChange::REMOVE, *form_facebook_old)); | 1401 password_manager::PasswordStoreChange::REMOVE, *form_facebook_old)); |
| 1420 list.push_back(password_manager::PasswordStoreChange( | 1402 list.push_back(password_manager::PasswordStoreChange( |
| 1421 password_manager::PasswordStoreChange::REMOVE, *form_facebook)); | 1403 password_manager::PasswordStoreChange::REMOVE, *form_facebook)); |
| 1422 EXPECT_CALL(observer, OnLoginsChanged(list)); | 1404 EXPECT_CALL(observer, OnLoginsChanged(list)); |
| 1423 list.clear(); | 1405 list.clear(); |
| 1424 observer.WaitAndVerify(test); | 1406 observer.WaitAndVerify(test); |
| 1425 | 1407 |
| 1426 matching_items.get() = owned_keychain_adapter.PasswordsFillingForm( | 1408 matching_items = owned_keychain_adapter.PasswordsFillingForm( |
| 1427 form_facebook->signon_realm, form_facebook->scheme); | 1409 form_facebook->signon_realm, form_facebook->scheme); |
| 1428 EXPECT_EQ(0u, matching_items.size()); | 1410 EXPECT_EQ(0u, matching_items.size()); |
| 1429 matching_items.get() = owned_keychain_adapter.PasswordsFillingForm( | 1411 matching_items = owned_keychain_adapter.PasswordsFillingForm( |
| 1430 form_other->signon_realm, form_other->scheme); | 1412 form_other->signon_realm, form_other->scheme); |
| 1431 EXPECT_EQ(1u, matching_items.size()); | 1413 EXPECT_EQ(1u, matching_items.size()); |
| 1432 matching_items.clear(); | |
| 1433 | 1414 |
| 1434 // Remove form_other. | 1415 // Remove form_other. |
| 1435 (test->store()->*method)(next_day, base::Time()); | 1416 (test->store()->*method)(next_day, base::Time()); |
| 1436 form_other->password_value.clear(); | 1417 form_other->password_value.clear(); |
| 1437 list.push_back(password_manager::PasswordStoreChange( | 1418 list.push_back(password_manager::PasswordStoreChange( |
| 1438 password_manager::PasswordStoreChange::REMOVE, *form_other)); | 1419 password_manager::PasswordStoreChange::REMOVE, *form_other)); |
| 1439 EXPECT_CALL(observer, OnLoginsChanged(list)); | 1420 EXPECT_CALL(observer, OnLoginsChanged(list)); |
| 1440 observer.WaitAndVerify(test); | 1421 observer.WaitAndVerify(test); |
| 1441 matching_items.get() = owned_keychain_adapter.PasswordsFillingForm( | 1422 matching_items = owned_keychain_adapter.PasswordsFillingForm( |
| 1442 form_other->signon_realm, form_other->scheme); | 1423 form_other->signon_realm, form_other->scheme); |
| 1443 EXPECT_EQ(0u, matching_items.size()); | 1424 EXPECT_EQ(0u, matching_items.size()); |
| 1444 } | 1425 } |
| 1445 | 1426 |
| 1446 } // namespace | 1427 } // namespace |
| 1447 | 1428 |
| 1448 TEST_F(PasswordStoreMacTest, TestRemoveLoginsCreatedBetween) { | 1429 TEST_F(PasswordStoreMacTest, TestRemoveLoginsCreatedBetween) { |
| 1449 CheckRemoveLoginsBetween(this, true); | 1430 CheckRemoveLoginsBetween(this, true); |
| 1450 } | 1431 } |
| 1451 | 1432 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 1478 // Add a password from the current profile. | 1459 // Add a password from the current profile. |
| 1479 PasswordFormData www_form_data2 = { | 1460 PasswordFormData www_form_data2 = { |
| 1480 PasswordForm::SCHEME_HTML, "http://www.facebook.com/", | 1461 PasswordForm::SCHEME_HTML, "http://www.facebook.com/", |
| 1481 "http://www.facebook.com/index.html", "login", L"username", L"password", | 1462 "http://www.facebook.com/index.html", "login", L"username", L"password", |
| 1482 L"submit", L"not_joe_user", L"12345", true, false, 1 }; | 1463 L"submit", L"not_joe_user", L"12345", true, false, 1 }; |
| 1483 www_form.reset(CreatePasswordFormFromData(www_form_data2)); | 1464 www_form.reset(CreatePasswordFormFromData(www_form_data2)); |
| 1484 store_->AddLogin(*www_form); | 1465 store_->AddLogin(*www_form); |
| 1485 FinishAsyncProcessing(); | 1466 FinishAsyncProcessing(); |
| 1486 | 1467 |
| 1487 ScopedVector<PasswordForm> matching_items; | 1468 ScopedVector<PasswordForm> matching_items; |
| 1488 login_db()->GetLogins(*www_form, &matching_items.get()); | 1469 login_db()->GetLogins(*www_form, &matching_items); |
| 1489 EXPECT_EQ(1u, matching_items.size()); | 1470 EXPECT_EQ(1u, matching_items.size()); |
| 1490 matching_items.clear(); | 1471 matching_items.clear(); |
| 1491 | 1472 |
| 1492 store_->RemoveLoginsCreatedBetween(base::Time(), base::Time()); | 1473 store_->RemoveLoginsCreatedBetween(base::Time(), base::Time()); |
| 1493 FinishAsyncProcessing(); | 1474 FinishAsyncProcessing(); |
| 1494 | 1475 |
| 1495 // Check the second facebook form is gone. | 1476 // Check the second facebook form is gone. |
| 1496 login_db()->GetLogins(*www_form, &matching_items.get()); | 1477 login_db()->GetLogins(*www_form, &matching_items); |
| 1497 EXPECT_EQ(0u, matching_items.size()); | 1478 EXPECT_EQ(0u, matching_items.size()); |
| 1498 | 1479 |
| 1499 // Check the first facebook form is still there. | 1480 // Check the first facebook form is still there. |
| 1500 matching_items.get() = owned_keychain_adapter.PasswordsFillingForm( | 1481 matching_items = owned_keychain_adapter.PasswordsFillingForm( |
| 1501 www_form->signon_realm, www_form->scheme); | 1482 www_form->signon_realm, www_form->scheme); |
| 1502 ASSERT_EQ(1u, matching_items.size()); | 1483 ASSERT_EQ(1u, matching_items.size()); |
| 1503 EXPECT_EQ(ASCIIToUTF16("joe_user"), matching_items[0]->username_value); | 1484 EXPECT_EQ(ASCIIToUTF16("joe_user"), matching_items[0]->username_value); |
| 1504 matching_items.clear(); | 1485 matching_items.clear(); |
| 1505 | 1486 |
| 1506 // Check the third-party password is still there. | 1487 // Check the third-party password is still there. |
| 1507 owned_keychain_adapter.SetFindsOnlyOwnedItems(false); | 1488 owned_keychain_adapter.SetFindsOnlyOwnedItems(false); |
| 1508 matching_items.get() = owned_keychain_adapter.PasswordsFillingForm( | 1489 matching_items = owned_keychain_adapter.PasswordsFillingForm( |
| 1509 "http://some.domain.com/insecure.html", PasswordForm::SCHEME_HTML); | 1490 "http://some.domain.com/insecure.html", PasswordForm::SCHEME_HTML); |
| 1510 ASSERT_EQ(1u, matching_items.size()); | 1491 ASSERT_EQ(1u, matching_items.size()); |
| 1511 } | 1492 } |
| 1512 | 1493 |
| 1513 // Open the store and immediately write to it and try to read it back, without | 1494 // Open the store and immediately write to it and try to read it back, without |
| 1514 // first waiting for the initialization to finish. If tasks are processed in | 1495 // first waiting for the initialization to finish. If tasks are processed in |
| 1515 // order, read/write operations will correctly be performed only after the | 1496 // order, read/write operations will correctly be performed only after the |
| 1516 // initialization has finished. | 1497 // initialization has finished. |
| 1517 TEST_F(PasswordStoreMacTest, StoreIsUsableImmediatelyAfterConstruction) { | 1498 TEST_F(PasswordStoreMacTest, StoreIsUsableImmediatelyAfterConstruction) { |
| 1518 ClosePasswordStore(); | 1499 ClosePasswordStore(); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1590 | 1571 |
| 1591 // Delete one login; a range of logins. | 1572 // Delete one login; a range of logins. |
| 1592 store()->RemoveLogin(*form); | 1573 store()->RemoveLogin(*form); |
| 1593 store()->RemoveLoginsCreatedBetween(base::Time(), base::Time::Max()); | 1574 store()->RemoveLoginsCreatedBetween(base::Time(), base::Time::Max()); |
| 1594 store()->RemoveLoginsSyncedBetween(base::Time(), base::Time::Max()); | 1575 store()->RemoveLoginsSyncedBetween(base::Time(), base::Time::Max()); |
| 1595 FinishAsyncProcessing(); | 1576 FinishAsyncProcessing(); |
| 1596 | 1577 |
| 1597 // Verify no notifications are fired during shutdown either. | 1578 // Verify no notifications are fired during shutdown either. |
| 1598 ClosePasswordStore(); | 1579 ClosePasswordStore(); |
| 1599 } | 1580 } |
| OLD | NEW |