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

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

Issue 1723583004: CREDENTIAL: Convert federations from URLs to origins throughout. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: iOS2 Created 4 years, 10 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
(...skipping 11 matching lines...) Expand all
22 #include "components/os_crypt/os_crypt.h" 22 #include "components/os_crypt/os_crypt.h"
23 #include "components/password_manager/core/browser/login_database.h" 23 #include "components/password_manager/core/browser/login_database.h"
24 #include "components/password_manager/core/browser/password_manager_test_utils.h " 24 #include "components/password_manager/core/browser/password_manager_test_utils.h "
25 #include "components/password_manager/core/browser/password_store_consumer.h" 25 #include "components/password_manager/core/browser/password_store_consumer.h"
26 #include "components/password_manager/core/browser/password_store_origin_unittes t.h" 26 #include "components/password_manager/core/browser/password_store_origin_unittes t.h"
27 #include "content/public/test/test_browser_thread.h" 27 #include "content/public/test/test_browser_thread.h"
28 #include "content/public/test/test_utils.h" 28 #include "content/public/test/test_utils.h"
29 #include "crypto/mock_apple_keychain.h" 29 #include "crypto/mock_apple_keychain.h"
30 #include "testing/gmock/include/gmock/gmock.h" 30 #include "testing/gmock/include/gmock/gmock.h"
31 #include "testing/gtest/include/gtest/gtest.h" 31 #include "testing/gtest/include/gtest/gtest.h"
32 #include "url/origin.h"
32 33
33 using autofill::PasswordForm; 34 using autofill::PasswordForm;
34 using base::ASCIIToUTF16; 35 using base::ASCIIToUTF16;
35 using base::WideToUTF16; 36 using base::WideToUTF16;
36 using content::BrowserThread; 37 using content::BrowserThread;
37 using crypto::MockAppleKeychain; 38 using crypto::MockAppleKeychain;
38 using internal_keychain_helpers::FormsMatchForMerge; 39 using internal_keychain_helpers::FormsMatchForMerge;
39 using internal_keychain_helpers::STRICT_FORM_MATCH; 40 using internal_keychain_helpers::STRICT_FORM_MATCH;
40 using password_manager::CreatePasswordFormFromDataForTesting; 41 using password_manager::CreatePasswordFormFromDataForTesting;
41 using password_manager::LoginDatabase; 42 using password_manager::LoginDatabase;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 EXPECT_EQ(WideToUTF16(expectation->password_element), 137 EXPECT_EQ(WideToUTF16(expectation->password_element),
137 form->password_element); 138 form->password_element);
138 if (expectation->username_value) { 139 if (expectation->username_value) {
139 EXPECT_EQ(WideToUTF16(expectation->username_value), form->username_value); 140 EXPECT_EQ(WideToUTF16(expectation->username_value), form->username_value);
140 EXPECT_EQ(WideToUTF16(expectation->username_value), form->display_name); 141 EXPECT_EQ(WideToUTF16(expectation->username_value), form->display_name);
141 EXPECT_TRUE(form->skip_zero_click); 142 EXPECT_TRUE(form->skip_zero_click);
142 if (expectation->password_value && 143 if (expectation->password_value &&
143 wcscmp(expectation->password_value, 144 wcscmp(expectation->password_value,
144 password_manager::kTestingFederatedLoginMarker) == 0) { 145 password_manager::kTestingFederatedLoginMarker) == 0) {
145 EXPECT_TRUE(form->password_value.empty()); 146 EXPECT_TRUE(form->password_value.empty());
146 EXPECT_EQ(GURL(password_manager::kTestingFederationUrlSpec), 147 EXPECT_EQ(
147 form->federation_url); 148 url::Origin(GURL(password_manager::kTestingFederationUrlSpec)),
149 form->federation_origin);
148 } else { 150 } else {
149 EXPECT_EQ(WideToUTF16(expectation->password_value), 151 EXPECT_EQ(WideToUTF16(expectation->password_value),
150 form->password_value); 152 form->password_value);
151 EXPECT_TRUE(form->federation_url.is_empty()); 153 EXPECT_TRUE(form->federation_origin.unique());
152 } 154 }
153 } else { 155 } else {
154 EXPECT_TRUE(form->blacklisted_by_user); 156 EXPECT_TRUE(form->blacklisted_by_user);
155 } 157 }
156 EXPECT_EQ(expectation->preferred, form->preferred); 158 EXPECT_EQ(expectation->preferred, form->preferred);
157 EXPECT_EQ(expectation->ssl_valid, form->ssl_valid); 159 EXPECT_EQ(expectation->ssl_valid, form->ssl_valid);
158 EXPECT_DOUBLE_EQ(expectation->creation_time, 160 EXPECT_DOUBLE_EQ(expectation->creation_time,
159 form->date_created.ToDoubleT()); 161 form->date_created.ToDoubleT());
160 base::Time created = base::Time::FromDoubleT(expectation->creation_time); 162 base::Time created = base::Time::FromDoubleT(expectation->creation_time);
161 EXPECT_EQ( 163 EXPECT_EQ(
(...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 { 871 {
870 PasswordForm form_a(base_form); 872 PasswordForm form_a(base_form);
871 form_a.blacklisted_by_user = true; 873 form_a.blacklisted_by_user = true;
872 PasswordForm form_b(form_a); 874 PasswordForm form_b(form_a);
873 EXPECT_FALSE(FormsMatchForMerge(form_a, form_b, STRICT_FORM_MATCH)); 875 EXPECT_FALSE(FormsMatchForMerge(form_a, form_b, STRICT_FORM_MATCH));
874 } 876 }
875 877
876 // Federated login forms should never match for merging either. 878 // Federated login forms should never match for merging either.
877 { 879 {
878 PasswordForm form_b(base_form); 880 PasswordForm form_b(base_form);
879 form_b.federation_url = GURL(password_manager::kTestingFederationUrlSpec); 881 form_b.federation_origin =
882 url::Origin(GURL(password_manager::kTestingFederationUrlSpec));
880 EXPECT_FALSE(FormsMatchForMerge(base_form, form_b, STRICT_FORM_MATCH)); 883 EXPECT_FALSE(FormsMatchForMerge(base_form, form_b, STRICT_FORM_MATCH));
881 EXPECT_FALSE(FormsMatchForMerge(form_b, base_form, STRICT_FORM_MATCH)); 884 EXPECT_FALSE(FormsMatchForMerge(form_b, base_form, STRICT_FORM_MATCH));
882 EXPECT_FALSE(FormsMatchForMerge(form_b, form_b, STRICT_FORM_MATCH)); 885 EXPECT_FALSE(FormsMatchForMerge(form_b, form_b, STRICT_FORM_MATCH));
883 } 886 }
884 } 887 }
885 888
886 TEST_F(PasswordStoreMacInternalsTest, TestFormMerge) { 889 TEST_F(PasswordStoreMacInternalsTest, TestFormMerge) {
887 // Set up a bunch of test data to use in varying combinations. 890 // Set up a bunch of test data to use in varying combinations.
888 /* clang-format off */ 891 /* clang-format off */
889 PasswordFormData keychain_user_1 = 892 PasswordFormData keychain_user_1 =
(...skipping 908 matching lines...) Expand 10 before | Expand all | Expand 10 after
1798 form.username_value = base::UTF8ToUTF16("randomusername"); 1801 form.username_value = base::UTF8ToUTF16("randomusername");
1799 form.password_value = base::UTF8ToUTF16("password"); 1802 form.password_value = base::UTF8ToUTF16("password");
1800 1803
1801 VerifyCredentialLifecycle(form); 1804 VerifyCredentialLifecycle(form);
1802 } 1805 }
1803 1806
1804 // Verify that federated credentials can be stored, retrieved and deleted. 1807 // Verify that federated credentials can be stored, retrieved and deleted.
1805 TEST_F(PasswordStoreMacTest, StoringAndRetrievingFederatedCredentials) { 1808 TEST_F(PasswordStoreMacTest, StoringAndRetrievingFederatedCredentials) {
1806 PasswordForm form; 1809 PasswordForm form;
1807 form.signon_realm = "android://7x7IDboo8u9YKraUsbmVkuf1@net.rateflix.app/"; 1810 form.signon_realm = "android://7x7IDboo8u9YKraUsbmVkuf1@net.rateflix.app/";
1808 form.federation_url = GURL(password_manager::kTestingFederationUrlSpec); 1811 form.federation_origin =
1812 url::Origin(GURL(password_manager::kTestingFederationUrlSpec));
1809 form.username_value = base::UTF8ToUTF16("randomusername"); 1813 form.username_value = base::UTF8ToUTF16("randomusername");
1810 form.password_value = base::UTF8ToUTF16(""); // No password. 1814 form.password_value = base::UTF8ToUTF16(""); // No password.
1811 1815
1812 VerifyCredentialLifecycle(form); 1816 VerifyCredentialLifecycle(form);
1813 } 1817 }
1814 1818
1815 void CheckMigrationResult(PasswordStoreMac::MigrationResult expected_result, 1819 void CheckMigrationResult(PasswordStoreMac::MigrationResult expected_result,
1816 PasswordStoreMac::MigrationResult result) { 1820 PasswordStoreMac::MigrationResult result) {
1817 EXPECT_EQ(expected_result, result); 1821 EXPECT_EQ(expected_result, result);
1818 QuitUIMessageLoop(); 1822 QuitUIMessageLoop();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1868 histogram_tester_.reset(); 1872 histogram_tester_.reset();
1869 } 1873 }
1870 1874
1871 // Import a federated credential while the Keychain is locked. 1875 // Import a federated credential while the Keychain is locked.
1872 TEST_F(PasswordStoreMacTest, ImportFederatedFromLockedKeychain) { 1876 TEST_F(PasswordStoreMacTest, ImportFederatedFromLockedKeychain) {
1873 keychain()->set_locked(true); 1877 keychain()->set_locked(true);
1874 PasswordForm form1; 1878 PasswordForm form1;
1875 form1.origin = GURL("http://example.com/Login"); 1879 form1.origin = GURL("http://example.com/Login");
1876 form1.signon_realm = "http://example.com/"; 1880 form1.signon_realm = "http://example.com/";
1877 form1.username_value = ASCIIToUTF16("my_username"); 1881 form1.username_value = ASCIIToUTF16("my_username");
1878 form1.federation_url = GURL("https://accounts.google.com/"); 1882 form1.federation_origin = url::Origin(GURL("https://accounts.google.com/"));
1879 1883
1880 store()->AddLogin(form1); 1884 store()->AddLogin(form1);
1881 FinishAsyncProcessing(); 1885 FinishAsyncProcessing();
1882 ASSERT_TRUE(base::PostTaskAndReplyWithResult( 1886 ASSERT_TRUE(base::PostTaskAndReplyWithResult(
1883 thread_->task_runner().get(), FROM_HERE, 1887 thread_->task_runner().get(), FROM_HERE,
1884 base::Bind(&PasswordStoreMac::ImportFromKeychain, store()), 1888 base::Bind(&PasswordStoreMac::ImportFromKeychain, store()),
1885 base::Bind(&CheckMigrationResult, PasswordStoreMac::MIGRATION_OK))); 1889 base::Bind(&CheckMigrationResult, PasswordStoreMac::MIGRATION_OK)));
1886 FinishAsyncProcessing(); 1890 FinishAsyncProcessing();
1887 1891
1888 ScopedVector<PasswordForm> matching_items; 1892 ScopedVector<PasswordForm> matching_items;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1924 histogram_tester_->ExpectUniqueSample( 1928 histogram_tester_->ExpectUniqueSample(
1925 "PasswordManager.KeychainMigration.NumPasswordsOnFailure", 1, 1); 1929 "PasswordManager.KeychainMigration.NumPasswordsOnFailure", 1, 1);
1926 histogram_tester_->ExpectUniqueSample( 1930 histogram_tester_->ExpectUniqueSample(
1927 "PasswordManager.KeychainMigration.NumFailedPasswords", 1, 1); 1931 "PasswordManager.KeychainMigration.NumFailedPasswords", 1, 1);
1928 histogram_tester_->ExpectUniqueSample( 1932 histogram_tester_->ExpectUniqueSample(
1929 "PasswordManager.KeychainMigration.NumChromeOwnedInaccessiblePasswords", 1933 "PasswordManager.KeychainMigration.NumChromeOwnedInaccessiblePasswords",
1930 2, 1); 1934 2, 1);
1931 // Don't test the encryption key access. 1935 // Don't test the encryption key access.
1932 histogram_tester_.reset(); 1936 histogram_tester_.reset();
1933 } 1937 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698