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

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

Issue 12704002: Support for auth code based authentication flow for both app and web UI driven flow. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase4 Created 7 years, 9 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 | Annotate | Revision Log
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/chromeos/login/parallel_authenticator.h" 5 #include "chrome/browser/chromeos/login/parallel_authenticator.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 test_api->SetCryptohomeLibrary(mock_cryptohome_library_, true); 82 test_api->SetCryptohomeLibrary(mock_cryptohome_library_, true);
83 83
84 mock_cert_library_ = new MockCertLibrary(); 84 mock_cert_library_ = new MockCertLibrary();
85 EXPECT_CALL(*mock_cert_library_, LoadKeyStore()).Times(AnyNumber()); 85 EXPECT_CALL(*mock_cert_library_, LoadKeyStore()).Times(AnyNumber());
86 test_api->SetCertLibrary(mock_cert_library_, true); 86 test_api->SetCertLibrary(mock_cert_library_, true);
87 87
88 io_thread_.Start(); 88 io_thread_.Start();
89 89
90 auth_ = new ParallelAuthenticator(&consumer_); 90 auth_ = new ParallelAuthenticator(&consumer_);
91 auth_->set_using_oauth(false); 91 auth_->set_using_oauth(false);
92 state_.reset(new TestAttemptState(username_, 92 state_.reset(new TestAttemptState(UserCredentials(username_,
93 password_, 93 password_,
94 std::string()),
94 hash_ascii_, 95 hash_ascii_,
95 "", 96 "",
96 "", 97 "",
97 User::USER_TYPE_REGULAR, 98 User::USER_TYPE_REGULAR,
98 false)); 99 false));
99 } 100 }
100 101
101 // Tears down the test fixture. 102 // Tears down the test fixture.
102 virtual void TearDown() { 103 virtual void TearDown() {
103 // Prevent bogus gMock leak check from firing. 104 // Prevent bogus gMock leak check from firing.
(...skipping 24 matching lines...) Expand all
128 // Allow test to fail and exit gracefully, even if 129 // Allow test to fail and exit gracefully, even if
129 // OnRetailModeLoginSuccess() wasn't supposed to happen. 130 // OnRetailModeLoginSuccess() wasn't supposed to happen.
130 void FailOnRetailModeLoginSuccess() { 131 void FailOnRetailModeLoginSuccess() {
131 ON_CALL(consumer_, OnRetailModeLoginSuccess()) 132 ON_CALL(consumer_, OnRetailModeLoginSuccess())
132 .WillByDefault(Invoke(MockConsumer::OnRetailModeSuccessQuitAndFail)); 133 .WillByDefault(Invoke(MockConsumer::OnRetailModeSuccessQuitAndFail));
133 } 134 }
134 135
135 // Allow test to fail and exit gracefully, even if OnLoginSuccess() 136 // Allow test to fail and exit gracefully, even if OnLoginSuccess()
136 // wasn't supposed to happen. 137 // wasn't supposed to happen.
137 void FailOnLoginSuccess() { 138 void FailOnLoginSuccess() {
138 ON_CALL(consumer_, OnLoginSuccess(_, _, _, _)) 139 ON_CALL(consumer_, OnLoginSuccess(_, _, _))
139 .WillByDefault(Invoke(MockConsumer::OnSuccessQuitAndFail)); 140 .WillByDefault(Invoke(MockConsumer::OnSuccessQuitAndFail));
140 } 141 }
141 142
142 // Allow test to fail and exit gracefully, even if 143 // Allow test to fail and exit gracefully, even if
143 // OnOffTheRecordLoginSuccess() wasn't supposed to happen. 144 // OnOffTheRecordLoginSuccess() wasn't supposed to happen.
144 void FailOnGuestLoginSuccess() { 145 void FailOnGuestLoginSuccess() {
145 ON_CALL(consumer_, OnOffTheRecordLoginSuccess()) 146 ON_CALL(consumer_, OnOffTheRecordLoginSuccess())
146 .WillByDefault(Invoke(MockConsumer::OnGuestSuccessQuitAndFail)); 147 .WillByDefault(Invoke(MockConsumer::OnGuestSuccessQuitAndFail));
147 } 148 }
148 149
149 void ExpectLoginFailure(const LoginFailure& failure) { 150 void ExpectLoginFailure(const LoginFailure& failure) {
150 EXPECT_CALL(consumer_, OnLoginFailure(failure)) 151 EXPECT_CALL(consumer_, OnLoginFailure(failure))
151 .WillOnce(Invoke(MockConsumer::OnFailQuit)) 152 .WillOnce(Invoke(MockConsumer::OnFailQuit))
152 .RetiresOnSaturation(); 153 .RetiresOnSaturation();
153 } 154 }
154 155
155 void ExpectRetailModeLoginSuccess() { 156 void ExpectRetailModeLoginSuccess() {
156 EXPECT_CALL(consumer_, OnRetailModeLoginSuccess()) 157 EXPECT_CALL(consumer_, OnRetailModeLoginSuccess())
157 .WillOnce(Invoke(MockConsumer::OnRetailModeSuccessQuit)) 158 .WillOnce(Invoke(MockConsumer::OnRetailModeSuccessQuit))
158 .RetiresOnSaturation(); 159 .RetiresOnSaturation();
159 } 160 }
160 161
161 void ExpectLoginSuccess(const std::string& username, 162 void ExpectLoginSuccess(const std::string& username,
162 const std::string& password, 163 const std::string& password,
163 bool pending) { 164 bool pending) {
164 EXPECT_CALL(consumer_, OnLoginSuccess(username, password, pending, 165 EXPECT_CALL(consumer_, OnLoginSuccess(UserCredentials(username,
166 password,
167 std::string()),
168 pending,
165 false)) 169 false))
166 .WillOnce(Invoke(MockConsumer::OnSuccessQuit)) 170 .WillOnce(Invoke(MockConsumer::OnSuccessQuit))
167 .RetiresOnSaturation(); 171 .RetiresOnSaturation();
168 } 172 }
169 173
170 void ExpectGuestLoginSuccess() { 174 void ExpectGuestLoginSuccess() {
171 EXPECT_CALL(consumer_, OnOffTheRecordLoginSuccess()) 175 EXPECT_CALL(consumer_, OnOffTheRecordLoginSuccess())
172 .WillOnce(Invoke(MockConsumer::OnGuestSuccessQuit)) 176 .WillOnce(Invoke(MockConsumer::OnGuestSuccessQuit))
173 .RetiresOnSaturation(); 177 .RetiresOnSaturation();
174 } 178 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 ScopedMockUserManagerEnabler mock_user_manager_; 226 ScopedMockUserManagerEnabler mock_user_manager_;
223 227
224 cryptohome::MockAsyncMethodCaller* mock_caller_; 228 cryptohome::MockAsyncMethodCaller* mock_caller_;
225 229
226 MockConsumer consumer_; 230 MockConsumer consumer_;
227 scoped_refptr<ParallelAuthenticator> auth_; 231 scoped_refptr<ParallelAuthenticator> auth_;
228 scoped_ptr<TestAttemptState> state_; 232 scoped_ptr<TestAttemptState> state_;
229 }; 233 };
230 234
231 TEST_F(ParallelAuthenticatorTest, OnLoginSuccess) { 235 TEST_F(ParallelAuthenticatorTest, OnLoginSuccess) {
232 EXPECT_CALL(consumer_, OnLoginSuccess(username_, password_, false, false)) 236 EXPECT_CALL(consumer_, OnLoginSuccess(UserCredentials(username_,
237 password_,
238 std::string()),
239 false, false))
233 .Times(1) 240 .Times(1)
234 .RetiresOnSaturation(); 241 .RetiresOnSaturation();
235 242
236 SetAttemptState(auth_, state_.release()); 243 SetAttemptState(auth_, state_.release());
237 auth_->OnLoginSuccess(false); 244 auth_->OnLoginSuccess(false);
238 } 245 }
239 246
240 TEST_F(ParallelAuthenticatorTest, OnPasswordChangeDetected) { 247 TEST_F(ParallelAuthenticatorTest, OnPasswordChangeDetected) {
241 EXPECT_CALL(consumer_, OnPasswordChangeDetected()) 248 EXPECT_CALL(consumer_, OnPasswordChangeDetected())
242 .Times(1) 249 .Times(1)
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 } 304 }
298 305
299 TEST_F(ParallelAuthenticatorTest, ResolveOwnerNeededMount) { 306 TEST_F(ParallelAuthenticatorTest, ResolveOwnerNeededMount) {
300 // Set up state as though a cryptohome mount attempt has occurred 307 // Set up state as though a cryptohome mount attempt has occurred
301 // and succeeded but we are in safe mode and the current user is not owner. 308 // and succeeded but we are in safe mode and the current user is not owner.
302 // This test will check that the "safe-mode" policy is not set and will let 309 // This test will check that the "safe-mode" policy is not set and will let
303 // the mount finish successfully. 310 // the mount finish successfully.
304 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); 311 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
305 SetOwnerState(false, false); 312 SetOwnerState(false, false);
306 // and test that the mount has succeeded. 313 // and test that the mount has succeeded.
307 state_.reset(new TestAttemptState(username_, 314 state_.reset(new TestAttemptState(UserCredentials(username_,
308 password_, 315 password_,
316 std::string()),
309 hash_ascii_, 317 hash_ascii_,
310 "", 318 "",
311 "", 319 "",
312 User::USER_TYPE_REGULAR, 320 User::USER_TYPE_REGULAR,
313 false)); 321 false));
314 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); 322 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
315 EXPECT_EQ(ParallelAuthenticator::OFFLINE_LOGIN, 323 EXPECT_EQ(ParallelAuthenticator::OFFLINE_LOGIN,
316 SetAndResolveState(auth_, state_.release())); 324 SetAndResolveState(auth_, state_.release()));
317 } 325 }
318 326
(...skipping 23 matching lines...) Expand all
342 EXPECT_TRUE( 350 EXPECT_TRUE(
343 CrosSettings::Get()->RemoveSettingsProvider(device_settings_provider)); 351 CrosSettings::Get()->RemoveSettingsProvider(device_settings_provider));
344 CrosSettings::Get()->AddSettingsProvider(&stub_settings_provider); 352 CrosSettings::Get()->AddSettingsProvider(&stub_settings_provider);
345 CrosSettings::Get()->SetBoolean(kPolicyMissingMitigationMode, true); 353 CrosSettings::Get()->SetBoolean(kPolicyMissingMitigationMode, true);
346 354
347 EXPECT_EQ(ParallelAuthenticator::CONTINUE, 355 EXPECT_EQ(ParallelAuthenticator::CONTINUE,
348 SetAndResolveState(auth_, state_.release())); 356 SetAndResolveState(auth_, state_.release()));
349 // Let the owner verification run. 357 // Let the owner verification run.
350 device_settings_test_helper_.Flush(); 358 device_settings_test_helper_.Flush();
351 // and test that the mount has succeeded. 359 // and test that the mount has succeeded.
352 state_.reset(new TestAttemptState(username_, 360 state_.reset(new TestAttemptState(UserCredentials(username_,
353 password_, 361 password_,
362 std::string()),
354 hash_ascii_, 363 hash_ascii_,
355 "", 364 "",
356 "", 365 "",
357 User::USER_TYPE_REGULAR, 366 User::USER_TYPE_REGULAR,
358 false)); 367 false));
359 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); 368 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
360 EXPECT_EQ(ParallelAuthenticator::OWNER_REQUIRED, 369 EXPECT_EQ(ParallelAuthenticator::OWNER_REQUIRED,
361 SetAndResolveState(auth_, state_.release())); 370 SetAndResolveState(auth_, state_.release()));
362 371
363 EXPECT_TRUE( 372 EXPECT_TRUE(
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 669
661 RunResolve(auth_.get()); 670 RunResolve(auth_.get());
662 671
663 // After the request below completes, OnLoginSuccess gets called again. 672 // After the request below completes, OnLoginSuccess gets called again.
664 ExpectLoginSuccess(username_, password_, false); 673 ExpectLoginSuccess(username_, password_, false);
665 674
666 MockURLFetcherFactory<SuccessFetcher> factory; 675 MockURLFetcherFactory<SuccessFetcher> factory;
667 TestingProfile profile; 676 TestingProfile profile;
668 677
669 auth_->RetryAuth(&profile, 678 auth_->RetryAuth(&profile,
670 username_, 679 UserCredentials(username_,
671 std::string(), 680 std::string(),
681 std::string()),
672 std::string(), 682 std::string(),
673 std::string()); 683 std::string());
674 message_loop_.Run(); 684 message_loop_.Run();
675 message_loop_.RunUntilIdle(); 685 message_loop_.RunUntilIdle();
676 } 686 }
677 687
678 TEST_F(ParallelAuthenticatorTest, DriveOfflineLoginGetCaptchad) { 688 TEST_F(ParallelAuthenticatorTest, DriveOfflineLoginGetCaptchad) {
679 ExpectLoginSuccess(username_, password_, true); 689 ExpectLoginSuccess(username_, password_, true);
680 FailOnLoginFailure(); 690 FailOnLoginFailure();
681 EXPECT_CALL(*mock_cryptohome_library_, GetSystemSalt()) 691 EXPECT_CALL(*mock_cryptohome_library_, GetSystemSalt())
(...skipping 21 matching lines...) Expand all
703 GoogleServiceAuthError::FromClientLoginCaptchaChallenge( 713 GoogleServiceAuthError::FromClientLoginCaptchaChallenge(
704 CaptchaFetcher::GetCaptchaToken(), 714 CaptchaFetcher::GetCaptchaToken(),
705 GURL(CaptchaFetcher::GetCaptchaUrl()), 715 GURL(CaptchaFetcher::GetCaptchaUrl()),
706 GURL(CaptchaFetcher::GetUnlockUrl()))); 716 GURL(CaptchaFetcher::GetUnlockUrl())));
707 ExpectLoginFailure(failure); 717 ExpectLoginFailure(failure);
708 718
709 MockURLFetcherFactory<CaptchaFetcher> factory; 719 MockURLFetcherFactory<CaptchaFetcher> factory;
710 TestingProfile profile; 720 TestingProfile profile;
711 721
712 auth_->RetryAuth(&profile, 722 auth_->RetryAuth(&profile,
713 username_, 723 UserCredentials(username_,
714 std::string(), 724 std::string(),
725 std::string()),
715 std::string(), 726 std::string(),
716 std::string()); 727 std::string());
717 message_loop_.Run(); 728 message_loop_.Run();
718 message_loop_.RunUntilIdle(); 729 message_loop_.RunUntilIdle();
719 } 730 }
720 731
721 TEST_F(ParallelAuthenticatorTest, DriveOnlineLogin) { 732 TEST_F(ParallelAuthenticatorTest, DriveOnlineLogin) {
722 ExpectLoginSuccess(username_, password_, false); 733 ExpectLoginSuccess(username_, password_, false);
723 FailOnLoginFailure(); 734 FailOnLoginFailure();
724 735
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 // Set up mock cryptohome library to respond successfully to a cryptohome 768 // Set up mock cryptohome library to respond successfully to a cryptohome
758 // key-check attempt. 769 // key-check attempt.
759 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); 770 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE);
760 EXPECT_CALL(*mock_caller_, AsyncCheckKey(username_, _, _)) 771 EXPECT_CALL(*mock_caller_, AsyncCheckKey(username_, _, _))
761 .Times(1) 772 .Times(1)
762 .RetiresOnSaturation(); 773 .RetiresOnSaturation();
763 EXPECT_CALL(*mock_cryptohome_library_, GetSystemSalt()) 774 EXPECT_CALL(*mock_cryptohome_library_, GetSystemSalt())
764 .WillOnce(Return(std::string())) 775 .WillOnce(Return(std::string()))
765 .RetiresOnSaturation(); 776 .RetiresOnSaturation();
766 777
767 auth_->AuthenticateToUnlock(username_, ""); 778 auth_->AuthenticateToUnlock(UserCredentials(username_,
779 std::string(),
780 std::string()));
768 message_loop_.Run(); 781 message_loop_.Run();
769 } 782 }
770 783
771 } // namespace chromeos 784 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/parallel_authenticator.cc ('k') | chrome/browser/chromeos/login/screen_locker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698