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

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

Issue 18686006: [cros] Cleanup login auth stack: remove ClientLogin legacy code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments Created 7 years, 5 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
« no previous file with comments | « chrome/browser/chromeos/login/parallel_authenticator.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 virtual void SetUp() { 75 virtual void SetUp() {
76 mock_caller_ = new cryptohome::MockAsyncMethodCaller; 76 mock_caller_ = new cryptohome::MockAsyncMethodCaller;
77 cryptohome::AsyncMethodCaller::InitializeForTesting(mock_caller_); 77 cryptohome::AsyncMethodCaller::InitializeForTesting(mock_caller_);
78 78
79 mock_cryptohome_library_ .reset(new MockCryptohomeLibrary()); 79 mock_cryptohome_library_ .reset(new MockCryptohomeLibrary());
80 CryptohomeLibrary::SetForTest(mock_cryptohome_library_.get()); 80 CryptohomeLibrary::SetForTest(mock_cryptohome_library_.get());
81 81
82 io_thread_.Start(); 82 io_thread_.Start();
83 83
84 auth_ = new ParallelAuthenticator(&consumer_); 84 auth_ = new ParallelAuthenticator(&consumer_);
85 auth_->set_using_oauth(false);
86 state_.reset(new TestAttemptState(UserContext(username_, 85 state_.reset(new TestAttemptState(UserContext(username_,
87 password_, 86 password_,
88 std::string()), 87 std::string()),
89 hash_ascii_, 88 hash_ascii_,
90 "", 89 "",
91 "", 90 "",
92 User::USER_TYPE_REGULAR, 91 User::USER_TYPE_REGULAR,
93 false)); 92 false));
94 } 93 }
95 94
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 151
153 void ExpectLoginSuccess(const std::string& username, 152 void ExpectLoginSuccess(const std::string& username,
154 const std::string& password, 153 const std::string& password,
155 const std::string& username_hash_, 154 const std::string& username_hash_,
156 bool pending) { 155 bool pending) {
157 EXPECT_CALL(consumer_, OnLoginSuccess(UserContext(username, 156 EXPECT_CALL(consumer_, OnLoginSuccess(UserContext(username,
158 password, 157 password,
159 std::string(), 158 std::string(),
160 username_hash_), 159 username_hash_),
161 pending, 160 pending,
162 false)) 161 true /* using_oauth */))
163 .WillOnce(Invoke(MockConsumer::OnSuccessQuit)) 162 .WillOnce(Invoke(MockConsumer::OnSuccessQuit))
164 .RetiresOnSaturation(); 163 .RetiresOnSaturation();
165 } 164 }
166 165
167 void ExpectGuestLoginSuccess() { 166 void ExpectGuestLoginSuccess() {
168 EXPECT_CALL(consumer_, OnOffTheRecordLoginSuccess()) 167 EXPECT_CALL(consumer_, OnOffTheRecordLoginSuccess())
169 .WillOnce(Invoke(MockConsumer::OnGuestSuccessQuit)) 168 .WillOnce(Invoke(MockConsumer::OnGuestSuccessQuit))
170 .RetiresOnSaturation(); 169 .RetiresOnSaturation();
171 } 170 }
172 171
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 MockConsumer consumer_; 222 MockConsumer consumer_;
224 scoped_refptr<ParallelAuthenticator> auth_; 223 scoped_refptr<ParallelAuthenticator> auth_;
225 scoped_ptr<TestAttemptState> state_; 224 scoped_ptr<TestAttemptState> state_;
226 }; 225 };
227 226
228 TEST_F(ParallelAuthenticatorTest, OnLoginSuccess) { 227 TEST_F(ParallelAuthenticatorTest, OnLoginSuccess) {
229 EXPECT_CALL(consumer_, OnLoginSuccess(UserContext(username_, 228 EXPECT_CALL(consumer_, OnLoginSuccess(UserContext(username_,
230 password_, 229 password_,
231 std::string(), 230 std::string(),
232 username_hash_), 231 username_hash_),
233 false, false)) 232 false, true /* using oauth */))
234 .Times(1) 233 .Times(1)
235 .RetiresOnSaturation(); 234 .RetiresOnSaturation();
236 235
237 SetAttemptState(auth_.get(), state_.release()); 236 SetAttemptState(auth_.get(), state_.release());
238 auth_->OnLoginSuccess(false); 237 auth_->OnLoginSuccess(false);
239 } 238 }
240 239
241 TEST_F(ParallelAuthenticatorTest, OnPasswordChangeDetected) { 240 TEST_F(ParallelAuthenticatorTest, OnPasswordChangeDetected) {
242 EXPECT_CALL(consumer_, OnPasswordChangeDetected()) 241 EXPECT_CALL(consumer_, OnPasswordChangeDetected())
243 .Times(1) 242 .Times(1)
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 RunResolve(auth_.get()); 611 RunResolve(auth_.get());
613 } 612 }
614 613
615 TEST_F(ParallelAuthenticatorTest, DriveOfflineLogin) { 614 TEST_F(ParallelAuthenticatorTest, DriveOfflineLogin) {
616 ExpectLoginSuccess(username_, password_, username_hash_, false); 615 ExpectLoginSuccess(username_, password_, username_hash_, false);
617 FailOnLoginFailure(); 616 FailOnLoginFailure();
618 617
619 // Set up state as though a cryptohome mount attempt has occurred and 618 // Set up state as though a cryptohome mount attempt has occurred and
620 // succeeded. 619 // succeeded.
621 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); 620 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
622 GoogleServiceAuthError error =
623 GoogleServiceAuthError::FromConnectionError(net::ERR_CONNECTION_RESET);
624 state_->PresetOnlineLoginStatus(LoginFailure::FromNetworkAuthFailure(error));
625 SetAttemptState(auth_.get(), state_.release()); 621 SetAttemptState(auth_.get(), state_.release());
626 622
627 RunResolve(auth_.get()); 623 RunResolve(auth_.get());
628 } 624 }
629 625
630 TEST_F(ParallelAuthenticatorTest, DriveOfflineLoginDelayedOnline) {
631 ExpectLoginSuccess(username_, password_, username_hash_, true);
632 FailOnLoginFailure();
633
634 // Set up state as though a cryptohome mount attempt has occurred and
635 // succeeded.
636 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
637 // state_ is released further down.
638 SetAttemptState(auth_.get(), state_.get());
639 RunResolve(auth_.get());
640
641 // Offline login has completed, so now we "complete" the online request.
642 GoogleServiceAuthError error(
643 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
644 LoginFailure failure = LoginFailure::FromNetworkAuthFailure(error);
645 state_.release()->PresetOnlineLoginStatus(failure);
646 ExpectLoginFailure(failure);
647
648 RunResolve(auth_.get());
649 }
650
651 TEST_F(ParallelAuthenticatorTest, DriveOfflineLoginGetNewPassword) {
652 ExpectLoginSuccess(username_, password_, username_hash_, true);
653 FailOnLoginFailure();
654
655 // Set up mock cryptohome library to respond successfully to a key migration.
656 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE);
657 EXPECT_CALL(*mock_caller_, AsyncMigrateKey(username_,
658 state_->ascii_hash,
659 _,
660 _))
661 .Times(1)
662 .RetiresOnSaturation();
663 EXPECT_CALL(*mock_cryptohome_library_, GetSystemSalt())
664 .WillOnce(Return(std::string()))
665 .RetiresOnSaturation();
666
667 // Set up state as though a cryptohome mount attempt has occurred and
668 // succeeded; also, an online request that never made it.
669 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
670 // state_ is released further down.
671 SetAttemptState(auth_.get(), state_.get());
672 RunResolve(auth_.get());
673
674 // Offline login has completed, so now we "complete" the online request.
675 GoogleServiceAuthError error(
676 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
677 LoginFailure failure = LoginFailure::FromNetworkAuthFailure(error);
678 state_.release()->PresetOnlineLoginStatus(failure);
679 ExpectLoginFailure(failure);
680
681 RunResolve(auth_.get());
682
683 // After the request below completes, OnLoginSuccess gets called again.
684 ExpectLoginSuccess(username_, password_, username_hash_, false);
685
686 MockURLFetcherFactory<SuccessFetcher> factory;
687 TestingProfile profile;
688
689 auth_->RetryAuth(&profile,
690 UserContext(username_,
691 std::string(),
692 std::string()),
693 std::string(),
694 std::string());
695 message_loop_.Run();
696 message_loop_.RunUntilIdle();
697 }
698
699 TEST_F(ParallelAuthenticatorTest, DriveOfflineLoginGetCaptchad) {
700 ExpectLoginSuccess(username_, password_, username_hash_, true);
701 FailOnLoginFailure();
702 EXPECT_CALL(*mock_cryptohome_library_, GetSystemSalt())
703 .WillOnce(Return(std::string()))
704 .RetiresOnSaturation();
705
706 // Set up state as though a cryptohome mount attempt has occurred and
707 // succeeded; also, an online request that never made it.
708 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
709 // state_ is released further down.
710 SetAttemptState(auth_.get(), state_.get());
711 RunResolve(auth_.get());
712
713 // Offline login has completed, so now we "complete" the online request.
714 GoogleServiceAuthError error(
715 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
716 LoginFailure failure = LoginFailure::FromNetworkAuthFailure(error);
717 state_.release()->PresetOnlineLoginStatus(failure);
718 ExpectLoginFailure(failure);
719
720 RunResolve(auth_.get());
721
722 // After the request below completes, OnLoginSuccess gets called again.
723 failure = LoginFailure::FromNetworkAuthFailure(
724 GoogleServiceAuthError::FromClientLoginCaptchaChallenge(
725 CaptchaFetcher::GetCaptchaToken(),
726 GURL(CaptchaFetcher::GetCaptchaUrl()),
727 GURL(CaptchaFetcher::GetUnlockUrl())));
728 ExpectLoginFailure(failure);
729
730 MockURLFetcherFactory<CaptchaFetcher> factory;
731 TestingProfile profile;
732
733 auth_->RetryAuth(&profile,
734 UserContext(username_,
735 std::string(),
736 std::string()),
737 std::string(),
738 std::string());
739 message_loop_.Run();
740 message_loop_.RunUntilIdle();
741 }
742
743 TEST_F(ParallelAuthenticatorTest, DriveOnlineLogin) { 626 TEST_F(ParallelAuthenticatorTest, DriveOnlineLogin) {
744 ExpectLoginSuccess(username_, password_, username_hash_, false); 627 ExpectLoginSuccess(username_, password_, username_hash_, false);
745 FailOnLoginFailure(); 628 FailOnLoginFailure();
746 629
747 // Set up state as though a cryptohome mount attempt has occurred and 630 // Set up state as though a cryptohome mount attempt has occurred and
748 // succeeded. 631 // succeeded.
749 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); 632 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
750 state_->PresetOnlineLoginStatus(LoginFailure::LoginFailureNone()); 633 state_->PresetOnlineLoginStatus(LoginFailure::LoginFailureNone());
751 SetAttemptState(auth_.get(), state_.release()); 634 SetAttemptState(auth_.get(), state_.release());
752 635
753 RunResolve(auth_.get()); 636 RunResolve(auth_.get());
754 } 637 }
755 638
756 // http://crbug.com/106538
757 TEST_F(ParallelAuthenticatorTest, DISABLED_DriveNeedNewPassword) {
758 FailOnLoginSuccess(); // Set failing on success as the default...
759 // ...but expect ONE successful login first.
760 ExpectLoginSuccess(username_, password_, username_hash_, true);
761 GoogleServiceAuthError error(
762 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
763 LoginFailure failure = LoginFailure::FromNetworkAuthFailure(error);
764 ExpectLoginFailure(failure);
765
766 // Set up state as though a cryptohome mount attempt has occurred and
767 // succeeded.
768 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
769 state_->PresetOnlineLoginStatus(failure);
770 SetAttemptState(auth_.get(), state_.release());
771
772 RunResolve(auth_.get());
773 }
774
775 TEST_F(ParallelAuthenticatorTest, DriveUnlock) { 639 TEST_F(ParallelAuthenticatorTest, DriveUnlock) {
776 ExpectLoginSuccess(username_, std::string(), std::string(), false); 640 ExpectLoginSuccess(username_, std::string(), std::string(), false);
777 FailOnLoginFailure(); 641 FailOnLoginFailure();
778 642
779 // Set up mock cryptohome library to respond successfully to a cryptohome 643 // Set up mock cryptohome library to respond successfully to a cryptohome
780 // key-check attempt. 644 // key-check attempt.
781 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); 645 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE);
782 EXPECT_CALL(*mock_caller_, AsyncCheckKey(username_, _, _)) 646 EXPECT_CALL(*mock_caller_, AsyncCheckKey(username_, _, _))
783 .Times(1) 647 .Times(1)
784 .RetiresOnSaturation(); 648 .RetiresOnSaturation();
785 EXPECT_CALL(*mock_cryptohome_library_, GetSystemSalt()) 649 EXPECT_CALL(*mock_cryptohome_library_, GetSystemSalt())
786 .WillOnce(Return(std::string())) 650 .WillOnce(Return(std::string()))
787 .RetiresOnSaturation(); 651 .RetiresOnSaturation();
788 652
789 auth_->AuthenticateToUnlock(UserContext(username_, 653 auth_->AuthenticateToUnlock(UserContext(username_,
790 std::string(), 654 std::string(),
791 std::string())); 655 std::string()));
792 message_loop_.Run(); 656 message_loop_.Run();
793 } 657 }
794 658
795 } // namespace chromeos 659 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/parallel_authenticator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698