| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "components/password_manager/core/browser/login_database.h" | 5 #include "components/password_manager/core/browser/login_database.h" |
| 6 | 6 |
| 7 #include <Security/Security.h> | 7 #include <Security/Security.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 if (status == errSecItemNotFound) | 75 if (status == errSecItemNotFound) |
| 76 return 0; | 76 return 0; |
| 77 | 77 |
| 78 EXPECT_EQ(errSecSuccess, status); | 78 EXPECT_EQ(errSecSuccess, status); |
| 79 size_t size = CFArrayGetCount((CFArrayRef)result); | 79 size_t size = CFArrayGetCount((CFArrayRef)result); |
| 80 CFRelease(result); | 80 CFRelease(result); |
| 81 return size; | 81 return size; |
| 82 } | 82 } |
| 83 | 83 |
| 84 TEST_F(LoginDatabaseIOSTest, KeychainStorage) { | 84 TEST_F(LoginDatabaseIOSTest, KeychainStorage) { |
| 85 #if TARGET_IPHONE_SIMULATOR | |
| 86 // TODO(crbug.com/619982): Broken by iOS10. | |
| 87 if (base::ios::IsRunningOnIOS10OrLater()) { | |
| 88 return; | |
| 89 } | |
| 90 #endif | |
| 91 | |
| 92 base::string16 test_passwords[] = { | 85 base::string16 test_passwords[] = { |
| 93 base::ASCIIToUTF16("foo"), base::ASCIIToUTF16("bar"), | 86 base::ASCIIToUTF16("foo"), base::ASCIIToUTF16("bar"), |
| 94 base::WideToUTF16(L"\u043F\u0430\u0440\u043E\u043B\u044C"), | 87 base::WideToUTF16(L"\u043F\u0430\u0440\u043E\u043B\u044C"), |
| 95 base::string16(), | 88 base::string16(), |
| 96 }; | 89 }; |
| 97 | 90 |
| 98 for (unsigned int i = 0; i < arraysize(test_passwords); i++) { | 91 for (unsigned int i = 0; i < arraysize(test_passwords); i++) { |
| 99 std::string encrypted; | 92 std::string encrypted; |
| 100 EXPECT_EQ(LoginDatabase::ENCRYPTION_RESULT_SUCCESS, | 93 EXPECT_EQ(LoginDatabase::ENCRYPTION_RESULT_SUCCESS, |
| 101 login_db_->EncryptedString(test_passwords[i], &encrypted)); | 94 login_db_->EncryptedString(test_passwords[i], &encrypted)); |
| 102 base::string16 decrypted; | 95 base::string16 decrypted; |
| 103 EXPECT_EQ(LoginDatabase::ENCRYPTION_RESULT_SUCCESS, | 96 EXPECT_EQ(LoginDatabase::ENCRYPTION_RESULT_SUCCESS, |
| 104 login_db_->DecryptedString(encrypted, &decrypted)); | 97 login_db_->DecryptedString(encrypted, &decrypted)); |
| 105 EXPECT_STREQ(UTF16ToUTF8(test_passwords[i]).c_str(), | 98 EXPECT_STREQ(UTF16ToUTF8(test_passwords[i]).c_str(), |
| 106 UTF16ToUTF8(decrypted).c_str()); | 99 UTF16ToUTF8(decrypted).c_str()); |
| 107 } | 100 } |
| 108 } | 101 } |
| 109 | 102 |
| 110 TEST_F(LoginDatabaseIOSTest, UpdateLogin) { | 103 TEST_F(LoginDatabaseIOSTest, UpdateLogin) { |
| 111 #if TARGET_IPHONE_SIMULATOR | |
| 112 // TODO(crbug.com/619982): Broken by iOS10. | |
| 113 if (base::ios::IsRunningOnIOS10OrLater()) { | |
| 114 return; | |
| 115 } | |
| 116 #endif | |
| 117 | |
| 118 PasswordForm form; | 104 PasswordForm form; |
| 119 form.origin = GURL("http://0.com"); | 105 form.origin = GURL("http://0.com"); |
| 120 form.signon_realm = "http://www.example.com"; | 106 form.signon_realm = "http://www.example.com"; |
| 121 form.action = GURL("http://www.example.com/action"); | 107 form.action = GURL("http://www.example.com/action"); |
| 122 form.password_element = base::ASCIIToUTF16("pwd"); | 108 form.password_element = base::ASCIIToUTF16("pwd"); |
| 123 form.password_value = base::ASCIIToUTF16("example"); | 109 form.password_value = base::ASCIIToUTF16("example"); |
| 124 | 110 |
| 125 ignore_result(login_db_->AddLogin(form)); | 111 ignore_result(login_db_->AddLogin(form)); |
| 126 | 112 |
| 127 form.password_value = base::ASCIIToUTF16("secret"); | 113 form.password_value = base::ASCIIToUTF16("secret"); |
| 128 | 114 |
| 129 password_manager::PasswordStoreChangeList changes = | 115 password_manager::PasswordStoreChangeList changes = |
| 130 login_db_->UpdateLogin(form); | 116 login_db_->UpdateLogin(form); |
| 131 ASSERT_EQ(1u, changes.size()); | 117 ASSERT_EQ(1u, changes.size()); |
| 132 | 118 |
| 133 ScopedVector<PasswordForm> forms; | 119 ScopedVector<PasswordForm> forms; |
| 134 EXPECT_TRUE(login_db_->GetLogins(PasswordStore::FormDigest(form), &forms)); | 120 EXPECT_TRUE(login_db_->GetLogins(PasswordStore::FormDigest(form), &forms)); |
| 135 | 121 |
| 136 ASSERT_EQ(1U, forms.size()); | 122 ASSERT_EQ(1U, forms.size()); |
| 137 EXPECT_STREQ("secret", UTF16ToUTF8(forms[0]->password_value).c_str()); | 123 EXPECT_STREQ("secret", UTF16ToUTF8(forms[0]->password_value).c_str()); |
| 138 ASSERT_EQ(1U, GetKeychainSize()); | 124 ASSERT_EQ(1U, GetKeychainSize()); |
| 139 } | 125 } |
| 140 | 126 |
| 141 TEST_F(LoginDatabaseIOSTest, RemoveLogin) { | 127 TEST_F(LoginDatabaseIOSTest, RemoveLogin) { |
| 142 #if TARGET_IPHONE_SIMULATOR | |
| 143 // TODO(crbug.com/619982): Broken by iOS10. | |
| 144 if (base::ios::IsRunningOnIOS10OrLater()) { | |
| 145 return; | |
| 146 } | |
| 147 #endif | |
| 148 | |
| 149 PasswordForm form; | 128 PasswordForm form; |
| 150 form.signon_realm = "www.example.com"; | 129 form.signon_realm = "www.example.com"; |
| 151 form.action = GURL("www.example.com/action"); | 130 form.action = GURL("www.example.com/action"); |
| 152 form.password_element = base::ASCIIToUTF16("pwd"); | 131 form.password_element = base::ASCIIToUTF16("pwd"); |
| 153 form.password_value = base::ASCIIToUTF16("example"); | 132 form.password_value = base::ASCIIToUTF16("example"); |
| 154 | 133 |
| 155 ignore_result(login_db_->AddLogin(form)); | 134 ignore_result(login_db_->AddLogin(form)); |
| 156 | 135 |
| 157 ignore_result(login_db_->RemoveLogin(form)); | 136 ignore_result(login_db_->RemoveLogin(form)); |
| 158 | 137 |
| 159 ScopedVector<PasswordForm> forms; | 138 ScopedVector<PasswordForm> forms; |
| 160 EXPECT_TRUE(login_db_->GetLogins(PasswordStore::FormDigest(form), &forms)); | 139 EXPECT_TRUE(login_db_->GetLogins(PasswordStore::FormDigest(form), &forms)); |
| 161 | 140 |
| 162 ASSERT_EQ(0U, forms.size()); | 141 ASSERT_EQ(0U, forms.size()); |
| 163 ASSERT_EQ(0U, GetKeychainSize()); | 142 ASSERT_EQ(0U, GetKeychainSize()); |
| 164 } | 143 } |
| 165 | 144 |
| 166 TEST_F(LoginDatabaseIOSTest, RemoveLoginsCreatedBetween) { | 145 TEST_F(LoginDatabaseIOSTest, RemoveLoginsCreatedBetween) { |
| 167 #if TARGET_IPHONE_SIMULATOR | |
| 168 // TODO(crbug.com/619982): Broken by iOS10. | |
| 169 if (base::ios::IsRunningOnIOS10OrLater()) { | |
| 170 return; | |
| 171 } | |
| 172 #endif | |
| 173 | |
| 174 PasswordForm forms[3]; | 146 PasswordForm forms[3]; |
| 175 forms[0].origin = GURL("http://0.com"); | 147 forms[0].origin = GURL("http://0.com"); |
| 176 forms[0].signon_realm = "http://www.example.com"; | 148 forms[0].signon_realm = "http://www.example.com"; |
| 177 forms[0].username_element = base::ASCIIToUTF16("login0"); | 149 forms[0].username_element = base::ASCIIToUTF16("login0"); |
| 178 forms[0].date_created = base::Time::FromDoubleT(100); | 150 forms[0].date_created = base::Time::FromDoubleT(100); |
| 179 forms[0].password_value = base::ASCIIToUTF16("pass0"); | 151 forms[0].password_value = base::ASCIIToUTF16("pass0"); |
| 180 | 152 |
| 181 forms[1].origin = GURL("http://1.com"); | 153 forms[1].origin = GURL("http://1.com"); |
| 182 forms[1].signon_realm = "http://www.example.com"; | 154 forms[1].signon_realm = "http://www.example.com"; |
| 183 forms[1].username_element = base::ASCIIToUTF16("login1"); | 155 forms[1].username_element = base::ASCIIToUTF16("login1"); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 205 ASSERT_EQ(2U, logins.size()); | 177 ASSERT_EQ(2U, logins.size()); |
| 206 ASSERT_EQ(2U, GetKeychainSize()); | 178 ASSERT_EQ(2U, GetKeychainSize()); |
| 207 | 179 |
| 208 EXPECT_STREQ("login0", UTF16ToUTF8(logins[0]->username_element).c_str()); | 180 EXPECT_STREQ("login0", UTF16ToUTF8(logins[0]->username_element).c_str()); |
| 209 EXPECT_STREQ("pass0", UTF16ToUTF8(logins[0]->password_value).c_str()); | 181 EXPECT_STREQ("pass0", UTF16ToUTF8(logins[0]->password_value).c_str()); |
| 210 EXPECT_STREQ("login2", UTF16ToUTF8(logins[1]->username_element).c_str()); | 182 EXPECT_STREQ("login2", UTF16ToUTF8(logins[1]->username_element).c_str()); |
| 211 EXPECT_STREQ("pass2", UTF16ToUTF8(logins[1]->password_value).c_str()); | 183 EXPECT_STREQ("pass2", UTF16ToUTF8(logins[1]->password_value).c_str()); |
| 212 } | 184 } |
| 213 | 185 |
| 214 } // namespace password_manager | 186 } // namespace password_manager |
| OLD | NEW |