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 |
85 base::string16 test_passwords[] = { | 92 base::string16 test_passwords[] = { |
86 base::ASCIIToUTF16("foo"), base::ASCIIToUTF16("bar"), | 93 base::ASCIIToUTF16("foo"), base::ASCIIToUTF16("bar"), |
87 base::WideToUTF16(L"\u043F\u0430\u0440\u043E\u043B\u044C"), | 94 base::WideToUTF16(L"\u043F\u0430\u0440\u043E\u043B\u044C"), |
88 base::string16(), | 95 base::string16(), |
89 }; | 96 }; |
90 | 97 |
91 for (unsigned int i = 0; i < arraysize(test_passwords); i++) { | 98 for (unsigned int i = 0; i < arraysize(test_passwords); i++) { |
92 std::string encrypted; | 99 std::string encrypted; |
93 EXPECT_EQ(LoginDatabase::ENCRYPTION_RESULT_SUCCESS, | 100 EXPECT_EQ(LoginDatabase::ENCRYPTION_RESULT_SUCCESS, |
94 login_db_->EncryptedString(test_passwords[i], &encrypted)); | 101 login_db_->EncryptedString(test_passwords[i], &encrypted)); |
95 base::string16 decrypted; | 102 base::string16 decrypted; |
96 EXPECT_EQ(LoginDatabase::ENCRYPTION_RESULT_SUCCESS, | 103 EXPECT_EQ(LoginDatabase::ENCRYPTION_RESULT_SUCCESS, |
97 login_db_->DecryptedString(encrypted, &decrypted)); | 104 login_db_->DecryptedString(encrypted, &decrypted)); |
98 EXPECT_STREQ(UTF16ToUTF8(test_passwords[i]).c_str(), | 105 EXPECT_STREQ(UTF16ToUTF8(test_passwords[i]).c_str(), |
99 UTF16ToUTF8(decrypted).c_str()); | 106 UTF16ToUTF8(decrypted).c_str()); |
100 } | 107 } |
101 } | 108 } |
102 | 109 |
103 TEST_F(LoginDatabaseIOSTest, UpdateLogin) { | 110 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 |
104 PasswordForm form; | 118 PasswordForm form; |
105 form.origin = GURL("http://0.com"); | 119 form.origin = GURL("http://0.com"); |
106 form.signon_realm = "http://www.example.com"; | 120 form.signon_realm = "http://www.example.com"; |
107 form.action = GURL("http://www.example.com/action"); | 121 form.action = GURL("http://www.example.com/action"); |
108 form.password_element = base::ASCIIToUTF16("pwd"); | 122 form.password_element = base::ASCIIToUTF16("pwd"); |
109 form.password_value = base::ASCIIToUTF16("example"); | 123 form.password_value = base::ASCIIToUTF16("example"); |
110 | 124 |
111 ignore_result(login_db_->AddLogin(form)); | 125 ignore_result(login_db_->AddLogin(form)); |
112 | 126 |
113 form.password_value = base::ASCIIToUTF16("secret"); | 127 form.password_value = base::ASCIIToUTF16("secret"); |
114 | 128 |
115 password_manager::PasswordStoreChangeList changes = | 129 password_manager::PasswordStoreChangeList changes = |
116 login_db_->UpdateLogin(form); | 130 login_db_->UpdateLogin(form); |
117 ASSERT_EQ(1u, changes.size()); | 131 ASSERT_EQ(1u, changes.size()); |
118 | 132 |
119 ScopedVector<PasswordForm> forms; | 133 ScopedVector<PasswordForm> forms; |
120 EXPECT_TRUE(login_db_->GetLogins(PasswordStore::FormDigest(form), &forms)); | 134 EXPECT_TRUE(login_db_->GetLogins(PasswordStore::FormDigest(form), &forms)); |
121 | 135 |
122 ASSERT_EQ(1U, forms.size()); | 136 ASSERT_EQ(1U, forms.size()); |
123 EXPECT_STREQ("secret", UTF16ToUTF8(forms[0]->password_value).c_str()); | 137 EXPECT_STREQ("secret", UTF16ToUTF8(forms[0]->password_value).c_str()); |
124 ASSERT_EQ(1U, GetKeychainSize()); | 138 ASSERT_EQ(1U, GetKeychainSize()); |
125 } | 139 } |
126 | 140 |
127 TEST_F(LoginDatabaseIOSTest, RemoveLogin) { | 141 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 |
128 PasswordForm form; | 149 PasswordForm form; |
129 form.signon_realm = "www.example.com"; | 150 form.signon_realm = "www.example.com"; |
130 form.action = GURL("www.example.com/action"); | 151 form.action = GURL("www.example.com/action"); |
131 form.password_element = base::ASCIIToUTF16("pwd"); | 152 form.password_element = base::ASCIIToUTF16("pwd"); |
132 form.password_value = base::ASCIIToUTF16("example"); | 153 form.password_value = base::ASCIIToUTF16("example"); |
133 | 154 |
134 ignore_result(login_db_->AddLogin(form)); | 155 ignore_result(login_db_->AddLogin(form)); |
135 | 156 |
136 ignore_result(login_db_->RemoveLogin(form)); | 157 ignore_result(login_db_->RemoveLogin(form)); |
137 | 158 |
138 ScopedVector<PasswordForm> forms; | 159 ScopedVector<PasswordForm> forms; |
139 EXPECT_TRUE(login_db_->GetLogins(PasswordStore::FormDigest(form), &forms)); | 160 EXPECT_TRUE(login_db_->GetLogins(PasswordStore::FormDigest(form), &forms)); |
140 | 161 |
141 ASSERT_EQ(0U, forms.size()); | 162 ASSERT_EQ(0U, forms.size()); |
142 ASSERT_EQ(0U, GetKeychainSize()); | 163 ASSERT_EQ(0U, GetKeychainSize()); |
143 } | 164 } |
144 | 165 |
145 TEST_F(LoginDatabaseIOSTest, RemoveLoginsCreatedBetween) { | 166 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 |
146 PasswordForm forms[3]; | 174 PasswordForm forms[3]; |
147 forms[0].origin = GURL("http://0.com"); | 175 forms[0].origin = GURL("http://0.com"); |
148 forms[0].signon_realm = "http://www.example.com"; | 176 forms[0].signon_realm = "http://www.example.com"; |
149 forms[0].username_element = base::ASCIIToUTF16("login0"); | 177 forms[0].username_element = base::ASCIIToUTF16("login0"); |
150 forms[0].date_created = base::Time::FromDoubleT(100); | 178 forms[0].date_created = base::Time::FromDoubleT(100); |
151 forms[0].password_value = base::ASCIIToUTF16("pass0"); | 179 forms[0].password_value = base::ASCIIToUTF16("pass0"); |
152 | 180 |
153 forms[1].origin = GURL("http://1.com"); | 181 forms[1].origin = GURL("http://1.com"); |
154 forms[1].signon_realm = "http://www.example.com"; | 182 forms[1].signon_realm = "http://www.example.com"; |
155 forms[1].username_element = base::ASCIIToUTF16("login1"); | 183 forms[1].username_element = base::ASCIIToUTF16("login1"); |
(...skipping 21 matching lines...) Expand all Loading... |
177 ASSERT_EQ(2U, logins.size()); | 205 ASSERT_EQ(2U, logins.size()); |
178 ASSERT_EQ(2U, GetKeychainSize()); | 206 ASSERT_EQ(2U, GetKeychainSize()); |
179 | 207 |
180 EXPECT_STREQ("login0", UTF16ToUTF8(logins[0]->username_element).c_str()); | 208 EXPECT_STREQ("login0", UTF16ToUTF8(logins[0]->username_element).c_str()); |
181 EXPECT_STREQ("pass0", UTF16ToUTF8(logins[0]->password_value).c_str()); | 209 EXPECT_STREQ("pass0", UTF16ToUTF8(logins[0]->password_value).c_str()); |
182 EXPECT_STREQ("login2", UTF16ToUTF8(logins[1]->username_element).c_str()); | 210 EXPECT_STREQ("login2", UTF16ToUTF8(logins[1]->username_element).c_str()); |
183 EXPECT_STREQ("pass2", UTF16ToUTF8(logins[1]->password_value).c_str()); | 211 EXPECT_STREQ("pass2", UTF16ToUTF8(logins[1]->password_value).c_str()); |
184 } | 212 } |
185 | 213 |
186 } // namespace password_manager | 214 } // namespace password_manager |
OLD | NEW |