Chromium Code Reviews

Side by Side Diff: chrome/browser/chromeos/login/google_authenticator_unittest.cc

Issue 3436031: [Chrome OS] Refactor Canonicalize() method into base class to prepare for new Authenticator subclass (Closed)
Patch Set: aaaaand fix one more header Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/chromeos/login/google_authenticator.h"
6
5 #include <string> 7 #include <string>
6 #include <vector> 8 #include <vector>
7 9
8 #include "base/file_path.h" 10 #include "base/file_path.h"
9 #include "base/file_util.h" 11 #include "base/file_util.h"
10 #include "base/message_loop.h" 12 #include "base/message_loop.h"
11 #include "base/path_service.h" 13 #include "base/path_service.h"
12 #include "base/scoped_ptr.h" 14 #include "base/scoped_ptr.h"
13 #include "base/string_util.h" 15 #include "base/string_util.h"
14 #include "base/stringprintf.h" 16 #include "base/stringprintf.h"
15 #include "chrome/browser/chrome_thread.h" 17 #include "chrome/browser/chrome_thread.h"
16 #include "chrome/browser/chromeos/cros/mock_cryptohome_library.h" 18 #include "chrome/browser/chromeos/cros/mock_cryptohome_library.h"
17 #include "chrome/browser/chromeos/cros/mock_library_loader.h" 19 #include "chrome/browser/chromeos/cros/mock_library_loader.h"
18 #include "chrome/browser/chromeos/login/client_login_response_handler.h" 20 #include "chrome/browser/chromeos/login/client_login_response_handler.h"
19 #include "chrome/browser/chromeos/login/google_authenticator.h"
20 #include "chrome/browser/chromeos/login/issue_response_handler.h" 21 #include "chrome/browser/chromeos/login/issue_response_handler.h"
21 #include "chrome/browser/chromeos/login/mock_auth_response_handler.h" 22 #include "chrome/browser/chromeos/login/mock_auth_response_handler.h"
22 #include "chrome/browser/chromeos/login/mock_url_fetchers.h" 23 #include "chrome/browser/chromeos/login/mock_url_fetchers.h"
23 #include "chrome/common/chrome_paths.h" 24 #include "chrome/common/chrome_paths.h"
24 #include "chrome/common/net/gaia/gaia_authenticator2_unittest.h" 25 #include "chrome/common/net/gaia/gaia_authenticator2_unittest.h"
25 #include "chrome/common/net/url_fetcher.h" 26 #include "chrome/common/net/url_fetcher.h"
26 #include "chrome/test/testing_profile.h" 27 #include "chrome/test/testing_profile.h"
27 #include "googleurl/src/gurl.h" 28 #include "googleurl/src/gurl.h"
28 #include "net/base/net_errors.h" 29 #include "net/base/net_errors.h"
29 #include "net/url_request/url_request_status.h" 30 #include "net/url_request/url_request_status.h"
(...skipping 134 matching lines...)
164 165
165 ON_CALL(*mock_library_, GetSystemSalt()) 166 ON_CALL(*mock_library_, GetSystemSalt())
166 .WillByDefault(Return(salt_v)); 167 .WillByDefault(Return(salt_v));
167 EXPECT_CALL(*mock_library_, GetSystemSalt()) 168 EXPECT_CALL(*mock_library_, GetSystemSalt())
168 .Times(1) 169 .Times(1)
169 .RetiresOnSaturation(); 170 .RetiresOnSaturation();
170 171
171 EXPECT_EQ("0a010000000000a0", auth->SaltAsAscii()); 172 EXPECT_EQ("0a010000000000a0", auth->SaltAsAscii());
172 } 173 }
173 174
174 TEST_F(GoogleAuthenticatorTest, EmailAddressNoOp) {
175 const char lower_case[] = "user@what.com";
176 EXPECT_EQ(lower_case, GoogleAuthenticator::Canonicalize(lower_case));
177 }
178
179 TEST_F(GoogleAuthenticatorTest, EmailAddressIgnoreCaps) {
180 EXPECT_EQ(GoogleAuthenticator::Canonicalize("user@what.com"),
181 GoogleAuthenticator::Canonicalize("UsEr@what.com"));
182 }
183
184 TEST_F(GoogleAuthenticatorTest, EmailAddressIgnoreDomainCaps) {
185 EXPECT_EQ(GoogleAuthenticator::Canonicalize("user@what.com"),
186 GoogleAuthenticator::Canonicalize("UsEr@what.COM"));
187 }
188
189 TEST_F(GoogleAuthenticatorTest, EmailAddressIgnoreOneUsernameDot) {
190 EXPECT_EQ(GoogleAuthenticator::Canonicalize("us.er@what.com"),
191 GoogleAuthenticator::Canonicalize("UsEr@what.com"));
192 }
193
194 TEST_F(GoogleAuthenticatorTest, EmailAddressIgnoreManyUsernameDots) {
195 EXPECT_EQ(GoogleAuthenticator::Canonicalize("u.ser@what.com"),
196 GoogleAuthenticator::Canonicalize("Us.E.r@what.com"));
197 }
198
199 TEST_F(GoogleAuthenticatorTest, EmailAddressIgnoreConsecutiveUsernameDots) {
200 EXPECT_EQ(GoogleAuthenticator::Canonicalize("use.r@what.com"),
201 GoogleAuthenticator::Canonicalize("Us....E.r@what.com"));
202 }
203
204 TEST_F(GoogleAuthenticatorTest, EmailAddressDifferentOnesRejected) {
205 EXPECT_NE(GoogleAuthenticator::Canonicalize("who@what.com"),
206 GoogleAuthenticator::Canonicalize("Us....E.r@what.com"));
207 }
208
209 TEST_F(GoogleAuthenticatorTest, EmailAddressIgnorePlusSuffix) {
210 EXPECT_EQ(GoogleAuthenticator::Canonicalize("user+cc@what.com"),
211 GoogleAuthenticator::Canonicalize("user@what.com"));
212 }
213
214 TEST_F(GoogleAuthenticatorTest, EmailAddressIgnoreMultiPlusSuffix) {
215 EXPECT_EQ(GoogleAuthenticator::Canonicalize("user+cc+bcc@what.com"),
216 GoogleAuthenticator::Canonicalize("user@what.com"));
217 }
218
219 TEST_F(GoogleAuthenticatorTest, ReadLocalaccount) { 175 TEST_F(GoogleAuthenticatorTest, ReadLocalaccount) {
220 FilePath tmp_file_path = FakeLocalaccountFile(bytes_as_ascii_); 176 FilePath tmp_file_path = FakeLocalaccountFile(bytes_as_ascii_);
221 177
222 scoped_refptr<GoogleAuthenticator> auth(new GoogleAuthenticator(NULL)); 178 scoped_refptr<GoogleAuthenticator> auth(new GoogleAuthenticator(NULL));
223 ReadLocalaccountFile(auth.get(), tmp_file_path.BaseName().value()); 179 ReadLocalaccountFile(auth.get(), tmp_file_path.BaseName().value());
224 EXPECT_EQ(auth->localaccount_, bytes_as_ascii_); 180 EXPECT_EQ(auth->localaccount_, bytes_as_ascii_);
225 Delete(tmp_file_path, false); 181 Delete(tmp_file_path, false);
226 } 182 }
227 183
228 TEST_F(GoogleAuthenticatorTest, ReadLocalaccountTrailingWS) { 184 TEST_F(GoogleAuthenticatorTest, ReadLocalaccountTrailingWS) {
(...skipping 511 matching lines...)
740 // Post a task to cancel the login attempt. 696 // Post a task to cancel the login attempt.
741 CancelLogin(auth.get()); 697 CancelLogin(auth.get());
742 698
743 URLFetcher::set_factory(NULL); 699 URLFetcher::set_factory(NULL);
744 700
745 // Run the UI thread until we exit it gracefully. 701 // Run the UI thread until we exit it gracefully.
746 message_loop.Run(); 702 message_loop.Run();
747 } 703 }
748 704
749 } // namespace chromeos 705 } // namespace chromeos
OLDNEW

Powered by Google App Engine