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

Side by Side Diff: chrome/browser/password_manager/password_store_mac_unittest.cc

Issue 2323893002: Stop using the Keychain for passwords finally and clean up the Chrome entries there. (Closed)
Patch Set: add a comment Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/password_manager/password_store_mac.h" 5 #include "chrome/browser/password_manager/password_store_mac.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/run_loop.h" 14 #include "base/run_loop.h"
15 #include "base/scoped_observer.h" 15 #include "base/scoped_observer.h"
16 #include "base/stl_util.h" 16 #include "base/stl_util.h"
17 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
18 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
19 #include "base/synchronization/waitable_event.h" 19 #include "base/synchronization/waitable_event.h"
20 #include "base/test/histogram_tester.h" 20 #include "base/test/histogram_tester.h"
21 #include "base/threading/thread_task_runner_handle.h" 21 #include "base/threading/thread_task_runner_handle.h"
22 #include "chrome/browser/password_manager/password_store_mac_internal.h" 22 #include "chrome/browser/password_manager/password_store_mac_internal.h"
23 #include "chrome/common/chrome_paths.h" 23 #include "chrome/common/chrome_paths.h"
24 #include "components/os_crypt/os_crypt_mocker.h" 24 #include "components/os_crypt/os_crypt_mocker.h"
25 #include "components/password_manager/core/browser/login_database.h" 25 #include "components/password_manager/core/browser/login_database.h"
26 #include "components/password_manager/core/browser/password_manager_test_utils.h " 26 #include "components/password_manager/core/browser/password_manager_test_utils.h "
27 #include "components/password_manager/core/browser/password_manager_util.h"
27 #include "components/password_manager/core/browser/password_store_consumer.h" 28 #include "components/password_manager/core/browser/password_store_consumer.h"
28 #include "components/password_manager/core/browser/password_store_origin_unittes t.h" 29 #include "components/password_manager/core/browser/password_store_origin_unittes t.h"
29 #include "content/public/test/test_browser_thread.h" 30 #include "content/public/test/test_browser_thread.h"
30 #include "content/public/test/test_utils.h" 31 #include "content/public/test/test_utils.h"
31 #include "crypto/mock_apple_keychain.h" 32 #include "crypto/mock_apple_keychain.h"
32 #include "testing/gmock/include/gmock/gmock.h" 33 #include "testing/gmock/include/gmock/gmock.h"
33 #include "testing/gtest/include/gtest/gtest.h" 34 #include "testing/gtest/include/gtest/gtest.h"
34 #include "url/origin.h" 35 #include "url/origin.h"
35 36
36 using autofill::PasswordForm; 37 using autofill::PasswordForm;
(...skipping 1958 matching lines...) Expand 10 before | Expand all | Expand 10 after
1995 blacklisted_form.signon_realm = "http://badsite.com/"; 1996 blacklisted_form.signon_realm = "http://badsite.com/";
1996 blacklisted_form.blacklisted_by_user = true; 1997 blacklisted_form.blacklisted_by_user = true;
1997 1998
1998 store()->AddLogin(form1); 1999 store()->AddLogin(form1);
1999 store()->AddLogin(form2); 2000 store()->AddLogin(form2);
2000 store()->AddLogin(blacklisted_form); 2001 store()->AddLogin(blacklisted_form);
2001 FinishAsyncProcessing(); 2002 FinishAsyncProcessing();
2002 2003
2003 ASSERT_TRUE(base::PostTaskAndReplyWithResult( 2004 ASSERT_TRUE(base::PostTaskAndReplyWithResult(
2004 thread_->task_runner().get(), FROM_HERE, 2005 thread_->task_runner().get(), FROM_HERE,
2005 base::Bind(&PasswordStoreMac::ImportFromKeychain, store()), 2006 base::Bind(&PasswordStoreMac::ImportFromKeychain, login_db(), keychain()),
2006 base::Bind(&CheckMigrationResult, PasswordStoreMac::MIGRATION_OK))); 2007 base::Bind(&CheckMigrationResult, PasswordStoreMac::MIGRATION_OK)));
2007 FinishAsyncProcessing(); 2008 FinishAsyncProcessing();
2008 2009
2009 // The password should be stored in the database by now. 2010 // The password should be stored in the database by now.
2010 std::vector<std::unique_ptr<PasswordForm>> matching_items; 2011 std::vector<std::unique_ptr<PasswordForm>> matching_items;
2011 EXPECT_TRUE( 2012 EXPECT_TRUE(
2012 login_db()->GetLogins(PasswordStore::FormDigest(form1), &matching_items)); 2013 login_db()->GetLogins(PasswordStore::FormDigest(form1), &matching_items));
2013 ASSERT_EQ(1u, matching_items.size()); 2014 ASSERT_EQ(1u, matching_items.size());
2014 EXPECT_EQ(form1, *matching_items[0]); 2015 EXPECT_EQ(form1, *matching_items[0]);
2015 2016
(...skipping 20 matching lines...) Expand all
2036 PasswordForm form1; 2037 PasswordForm form1;
2037 form1.origin = GURL("http://example.com/Login"); 2038 form1.origin = GURL("http://example.com/Login");
2038 form1.signon_realm = "http://example.com/"; 2039 form1.signon_realm = "http://example.com/";
2039 form1.username_value = ASCIIToUTF16("my_username"); 2040 form1.username_value = ASCIIToUTF16("my_username");
2040 form1.federation_origin = url::Origin(GURL("https://accounts.google.com/")); 2041 form1.federation_origin = url::Origin(GURL("https://accounts.google.com/"));
2041 2042
2042 store()->AddLogin(form1); 2043 store()->AddLogin(form1);
2043 FinishAsyncProcessing(); 2044 FinishAsyncProcessing();
2044 ASSERT_TRUE(base::PostTaskAndReplyWithResult( 2045 ASSERT_TRUE(base::PostTaskAndReplyWithResult(
2045 thread_->task_runner().get(), FROM_HERE, 2046 thread_->task_runner().get(), FROM_HERE,
2046 base::Bind(&PasswordStoreMac::ImportFromKeychain, store()), 2047 base::Bind(&PasswordStoreMac::ImportFromKeychain, login_db(), keychain()),
2047 base::Bind(&CheckMigrationResult, PasswordStoreMac::MIGRATION_OK))); 2048 base::Bind(&CheckMigrationResult, PasswordStoreMac::MIGRATION_OK)));
2048 FinishAsyncProcessing(); 2049 FinishAsyncProcessing();
2049 2050
2050 std::vector<std::unique_ptr<PasswordForm>> matching_items; 2051 std::vector<std::unique_ptr<PasswordForm>> matching_items;
2051 EXPECT_TRUE( 2052 EXPECT_TRUE(
2052 login_db()->GetLogins(PasswordStore::FormDigest(form1), &matching_items)); 2053 login_db()->GetLogins(PasswordStore::FormDigest(form1), &matching_items));
2053 ASSERT_EQ(1u, matching_items.size()); 2054 ASSERT_EQ(1u, matching_items.size());
2054 EXPECT_EQ(form1, *matching_items[0]); 2055 EXPECT_EQ(form1, *matching_items[0]);
2055 } 2056 }
2056 2057
(...skipping 11 matching lines...) Expand all
2068 // Add a second keychain item matching the Database entry. 2069 // Add a second keychain item matching the Database entry.
2069 PasswordForm form2 = form1; 2070 PasswordForm form2 = form1;
2070 form2.origin = GURL("http://accounts.google.com/Login"); 2071 form2.origin = GURL("http://accounts.google.com/Login");
2071 form2.password_value = ASCIIToUTF16("1234"); 2072 form2.password_value = ASCIIToUTF16("1234");
2072 MacKeychainPasswordFormAdapter adapter(keychain()); 2073 MacKeychainPasswordFormAdapter adapter(keychain());
2073 EXPECT_TRUE(adapter.AddPassword(form2)); 2074 EXPECT_TRUE(adapter.AddPassword(form2));
2074 2075
2075 keychain()->set_locked(true); 2076 keychain()->set_locked(true);
2076 ASSERT_TRUE(base::PostTaskAndReplyWithResult( 2077 ASSERT_TRUE(base::PostTaskAndReplyWithResult(
2077 thread_->task_runner().get(), FROM_HERE, 2078 thread_->task_runner().get(), FROM_HERE,
2078 base::Bind(&PasswordStoreMac::ImportFromKeychain, store()), 2079 base::Bind(&PasswordStoreMac::ImportFromKeychain, login_db(), keychain()),
2079 base::Bind(&CheckMigrationResult, PasswordStoreMac::KEYCHAIN_BLOCKED))); 2080 base::Bind(&CheckMigrationResult, PasswordStoreMac::MIGRATION_PARTIAL)));
2080 FinishAsyncProcessing(); 2081 FinishAsyncProcessing();
2081 2082
2082 std::vector<std::unique_ptr<PasswordForm>> matching_items; 2083 std::vector<std::unique_ptr<PasswordForm>> matching_items;
2083 EXPECT_TRUE( 2084 EXPECT_TRUE(
2084 login_db()->GetLogins(PasswordStore::FormDigest(form1), &matching_items)); 2085 login_db()->GetLogins(PasswordStore::FormDigest(form1), &matching_items));
2085 ASSERT_EQ(1u, matching_items.size()); 2086 EXPECT_EQ(0u, matching_items.size());
2086 EXPECT_EQ(base::string16(), matching_items[0]->password_value);
2087 2087
2088 histogram_tester_->ExpectUniqueSample( 2088 histogram_tester_->ExpectUniqueSample(
2089 "PasswordManager.KeychainMigration.NumPasswordsOnFailure", 1, 1); 2089 "PasswordManager.KeychainMigration.NumPasswordsOnFailure", 1, 1);
2090 histogram_tester_->ExpectUniqueSample( 2090 histogram_tester_->ExpectUniqueSample(
2091 "PasswordManager.KeychainMigration.NumFailedPasswords", 1, 1); 2091 "PasswordManager.KeychainMigration.NumFailedPasswords", 1, 1);
2092 histogram_tester_->ExpectUniqueSample(
2093 "PasswordManager.KeychainMigration.NumChromeOwnedInaccessiblePasswords",
2094 2, 1);
2095 // Don't test the encryption key access. 2092 // Don't test the encryption key access.
2096 histogram_tester_.reset(); 2093 histogram_tester_.reset();
2097 } 2094 }
2095
2096 // Delete the Chrome-owned password from the Keychain.
2097 TEST_F(PasswordStoreMacTest, CleanUpKeychain) {
2098 MockAppleKeychain::KeychainTestData data1 = { kSecAuthenticationTypeHTMLForm,
2099 "some.domain.com", kSecProtocolTypeHTTP, NULL, 0, NULL, "20020601171500Z",
2100 "joe_user", "sekrit", false};
2101 keychain()->AddTestItem(data1);
2102
2103 MacKeychainPasswordFormAdapter keychain_adapter(keychain());
2104 PasswordFormData data2 = { PasswordForm::SCHEME_HTML, "http://web.site.com/",
2105 "http://web.site.com/path/to/page.html", NULL, NULL, NULL, NULL,
2106 L"anonymous", L"knock-knock", false, 0 };
2107 keychain_adapter.AddPassword(*CreatePasswordFormFromDataForTesting(data2));
2108 std::vector<std::unique_ptr<autofill::PasswordForm>> passwords =
2109 password_manager_util::ConvertScopedVector(
2110 keychain_adapter.GetAllPasswordFormPasswords());
2111 EXPECT_EQ(2u, passwords.size());
2112
2113 // Delete everyhting but only the Chrome-owned item should be affected.
2114 PasswordStoreMac::CleanUpKeychain(keychain(), passwords);
2115 passwords = password_manager_util::ConvertScopedVector(
2116 keychain_adapter.GetAllPasswordFormPasswords());
2117 ASSERT_EQ(1u, passwords.size());
2118 EXPECT_EQ("http://some.domain.com/", passwords[0]->signon_realm);
2119 EXPECT_EQ(ASCIIToUTF16("sekrit"), passwords[0]->password_value);
2120 }
OLDNEW
« no previous file with comments | « chrome/browser/password_manager/password_store_mac.cc ('k') | chrome/browser/password_manager/password_store_proxy_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698