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 "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 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 | 240 |
241 // Mocks, destroyed by CrosLibrary class. | 241 // Mocks, destroyed by CrosLibrary class. |
242 MockCryptohomeLibrary* mock_library_; | 242 MockCryptohomeLibrary* mock_library_; |
243 MockLibraryLoader* loader_; | 243 MockLibraryLoader* loader_; |
244 | 244 |
245 MockConsumer consumer_; | 245 MockConsumer consumer_; |
246 scoped_refptr<ParallelAuthenticator> auth_; | 246 scoped_refptr<ParallelAuthenticator> auth_; |
247 scoped_ptr<TestAttemptState> state_; | 247 scoped_ptr<TestAttemptState> state_; |
248 }; | 248 }; |
249 | 249 |
250 TEST_F(ParallelAuthenticatorTest, SaltToAscii) { | |
251 unsigned char fake_salt[8] = { 0 }; | |
252 fake_salt[0] = 10; | |
253 fake_salt[1] = 1; | |
254 fake_salt[7] = 10 << 4; | |
255 std::vector<unsigned char> salt_v(fake_salt, fake_salt + sizeof(fake_salt)); | |
256 | |
257 ON_CALL(*mock_library_, GetSystemSalt()) | |
258 .WillByDefault(Return(salt_v)); | |
259 EXPECT_CALL(*mock_library_, GetSystemSalt()) | |
260 .Times(1) | |
261 .RetiresOnSaturation(); | |
262 | |
263 EXPECT_EQ("0a010000000000a0", auth_->SaltAsAscii()); | |
264 } | |
265 | |
266 TEST_F(ParallelAuthenticatorTest, ReadLocalaccount) { | 250 TEST_F(ParallelAuthenticatorTest, ReadLocalaccount) { |
267 FilePath tmp_file_path = FakeLocalaccountFile(username_); | 251 FilePath tmp_file_path = FakeLocalaccountFile(username_); |
268 | 252 |
269 ReadLocalaccountFile(auth_.get(), tmp_file_path.BaseName().value()); | 253 ReadLocalaccountFile(auth_.get(), tmp_file_path.BaseName().value()); |
270 EXPECT_EQ(auth_->localaccount_, username_); | 254 EXPECT_EQ(auth_->localaccount_, username_); |
271 Delete(tmp_file_path, false); | 255 Delete(tmp_file_path, false); |
272 } | 256 } |
273 | 257 |
274 TEST_F(ParallelAuthenticatorTest, ReadLocalaccountTrailingWS) { | 258 TEST_F(ParallelAuthenticatorTest, ReadLocalaccountTrailingWS) { |
275 FilePath tmp_file_path = | 259 FilePath tmp_file_path = |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 FailOnLoginFailure(); | 441 FailOnLoginFailure(); |
458 | 442 |
459 // Set up mock cryptohome library to respond successfully to a key migration. | 443 // Set up mock cryptohome library to respond successfully to a key migration. |
460 mock_library_->SetUp(true, 0); | 444 mock_library_->SetUp(true, 0); |
461 EXPECT_CALL(*mock_library_, AsyncMigrateKey(username_, _, hash_ascii_, _)) | 445 EXPECT_CALL(*mock_library_, AsyncMigrateKey(username_, _, hash_ascii_, _)) |
462 .Times(1) | 446 .Times(1) |
463 .RetiresOnSaturation(); | 447 .RetiresOnSaturation(); |
464 EXPECT_CALL(*mock_library_, AsyncMount(username_, hash_ascii_, false, _)) | 448 EXPECT_CALL(*mock_library_, AsyncMount(username_, hash_ascii_, false, _)) |
465 .Times(1) | 449 .Times(1) |
466 .RetiresOnSaturation(); | 450 .RetiresOnSaturation(); |
467 EXPECT_CALL(*mock_library_, GetSystemSalt()) | 451 EXPECT_CALL(*mock_library_, HashPassword(_)) |
468 .WillOnce(Return(CryptohomeBlob(2, 0))) | 452 .WillOnce(Return(std::string())) |
469 .RetiresOnSaturation(); | 453 .RetiresOnSaturation(); |
470 | 454 |
471 state_->PresetOnlineLoginStatus(result_, LoginFailure::None()); | 455 state_->PresetOnlineLoginStatus(result_, LoginFailure::None()); |
472 SetAttemptState(auth_, state_.release()); | 456 SetAttemptState(auth_, state_.release()); |
473 | 457 |
474 auth_->RecoverEncryptedData(std::string(), result_); | 458 auth_->RecoverEncryptedData(std::string(), result_); |
475 message_loop_.Run(); | 459 message_loop_.Run(); |
476 } | 460 } |
477 | 461 |
478 TEST_F(ParallelAuthenticatorTest, DriveDataRecoverButFail) { | 462 TEST_F(ParallelAuthenticatorTest, DriveDataRecoverButFail) { |
479 FailOnLoginSuccess(); | 463 FailOnLoginSuccess(); |
480 ExpectPasswordChange(); | 464 ExpectPasswordChange(); |
481 | 465 |
482 // Set up mock cryptohome library to fail a key migration attempt, | 466 // Set up mock cryptohome library to fail a key migration attempt, |
483 // asserting that the wrong password was used. | 467 // asserting that the wrong password was used. |
484 mock_library_->SetUp(false, chromeos::kCryptohomeMountErrorKeyFailure); | 468 mock_library_->SetUp(false, chromeos::kCryptohomeMountErrorKeyFailure); |
485 EXPECT_CALL(*mock_library_, AsyncMigrateKey(username_, _, hash_ascii_, _)) | 469 EXPECT_CALL(*mock_library_, AsyncMigrateKey(username_, _, hash_ascii_, _)) |
486 .Times(1) | 470 .Times(1) |
487 .RetiresOnSaturation(); | 471 .RetiresOnSaturation(); |
488 EXPECT_CALL(*mock_library_, GetSystemSalt()) | 472 EXPECT_CALL(*mock_library_, HashPassword(_)) |
489 .WillOnce(Return(CryptohomeBlob(2, 0))) | 473 .WillOnce(Return(std::string())) |
490 .RetiresOnSaturation(); | 474 .RetiresOnSaturation(); |
491 | 475 |
492 SetAttemptState(auth_, state_.release()); | 476 SetAttemptState(auth_, state_.release()); |
493 | 477 |
494 auth_->RecoverEncryptedData(std::string(), result_); | 478 auth_->RecoverEncryptedData(std::string(), result_); |
495 message_loop_.Run(); | 479 message_loop_.Run(); |
496 } | 480 } |
497 | 481 |
498 TEST_F(ParallelAuthenticatorTest, ResolveNoMount) { | 482 TEST_F(ParallelAuthenticatorTest, ResolveNoMount) { |
499 // Set a fake online attempt so that we return intermediate cryptohome state. | 483 // Set a fake online attempt so that we return intermediate cryptohome state. |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 FailOnLoginFailure(); | 593 FailOnLoginFailure(); |
610 | 594 |
611 // Set up mock cryptohome library to respond successfully to a key migration. | 595 // Set up mock cryptohome library to respond successfully to a key migration. |
612 mock_library_->SetUp(true, 0); | 596 mock_library_->SetUp(true, 0); |
613 EXPECT_CALL(*mock_library_, AsyncMigrateKey(username_, | 597 EXPECT_CALL(*mock_library_, AsyncMigrateKey(username_, |
614 state_->ascii_hash, | 598 state_->ascii_hash, |
615 _, | 599 _, |
616 _)) | 600 _)) |
617 .Times(1) | 601 .Times(1) |
618 .RetiresOnSaturation(); | 602 .RetiresOnSaturation(); |
619 EXPECT_CALL(*mock_library_, GetSystemSalt()) | 603 EXPECT_CALL(*mock_library_, HashPassword(_)) |
620 .WillOnce(Return(CryptohomeBlob(2, 0))) | 604 .WillOnce(Return(std::string())) |
621 .RetiresOnSaturation(); | 605 .RetiresOnSaturation(); |
622 | 606 |
623 // Set up state as though a cryptohome mount attempt has occurred and | 607 // Set up state as though a cryptohome mount attempt has occurred and |
624 // succeeded; also, an online request that never made it. | 608 // succeeded; also, an online request that never made it. |
625 state_->PresetCryptohomeStatus(true, 0); | 609 state_->PresetCryptohomeStatus(true, 0); |
626 // state_ is released further down. | 610 // state_ is released further down. |
627 SetAttemptState(auth_, state_.get()); | 611 SetAttemptState(auth_, state_.get()); |
628 RunResolve(auth_.get(), &message_loop_); | 612 RunResolve(auth_.get(), &message_loop_); |
629 | 613 |
630 // Offline login has completed, so now we "complete" the online request. | 614 // Offline login has completed, so now we "complete" the online request. |
(...skipping 15 matching lines...) Expand all Loading... |
646 username_, | 630 username_, |
647 std::string(), | 631 std::string(), |
648 std::string(), | 632 std::string(), |
649 std::string()); | 633 std::string()); |
650 message_loop_.Run(); | 634 message_loop_.Run(); |
651 } | 635 } |
652 | 636 |
653 TEST_F(ParallelAuthenticatorTest, DriveOfflineLoginGetCaptchad) { | 637 TEST_F(ParallelAuthenticatorTest, DriveOfflineLoginGetCaptchad) { |
654 ExpectLoginSuccess(username_, password_, result_, true); | 638 ExpectLoginSuccess(username_, password_, result_, true); |
655 FailOnLoginFailure(); | 639 FailOnLoginFailure(); |
656 EXPECT_CALL(*mock_library_, GetSystemSalt()) | 640 EXPECT_CALL(*mock_library_, HashPassword(_)) |
657 .WillOnce(Return(CryptohomeBlob(2, 0))) | 641 .WillOnce(Return(std::string())) |
658 .RetiresOnSaturation(); | 642 .RetiresOnSaturation(); |
659 | 643 |
660 // Set up state as though a cryptohome mount attempt has occurred and | 644 // Set up state as though a cryptohome mount attempt has occurred and |
661 // succeeded; also, an online request that never made it. | 645 // succeeded; also, an online request that never made it. |
662 state_->PresetCryptohomeStatus(true, 0); | 646 state_->PresetCryptohomeStatus(true, 0); |
663 // state_ is released further down. | 647 // state_ is released further down. |
664 SetAttemptState(auth_, state_.get()); | 648 SetAttemptState(auth_, state_.get()); |
665 RunResolve(auth_.get(), &message_loop_); | 649 RunResolve(auth_.get(), &message_loop_); |
666 | 650 |
667 // Offline login has completed, so now we "complete" the online request. | 651 // Offline login has completed, so now we "complete" the online request. |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
759 TEST_F(ParallelAuthenticatorTest, DriveUnlock) { | 743 TEST_F(ParallelAuthenticatorTest, DriveUnlock) { |
760 ExpectLoginSuccess(username_, std::string(), result_, false); | 744 ExpectLoginSuccess(username_, std::string(), result_, false); |
761 FailOnLoginFailure(); | 745 FailOnLoginFailure(); |
762 | 746 |
763 // Set up mock cryptohome library to respond successfully to a cryptohome | 747 // Set up mock cryptohome library to respond successfully to a cryptohome |
764 // key-check attempt. | 748 // key-check attempt. |
765 mock_library_->SetUp(true, 0); | 749 mock_library_->SetUp(true, 0); |
766 EXPECT_CALL(*mock_library_, AsyncCheckKey(username_, _, _)) | 750 EXPECT_CALL(*mock_library_, AsyncCheckKey(username_, _, _)) |
767 .Times(1) | 751 .Times(1) |
768 .RetiresOnSaturation(); | 752 .RetiresOnSaturation(); |
769 EXPECT_CALL(*mock_library_, GetSystemSalt()) | 753 EXPECT_CALL(*mock_library_, HashPassword(_)) |
770 .WillOnce(Return(CryptohomeBlob(2, 0))) | 754 .WillOnce(Return(std::string())) |
771 .RetiresOnSaturation(); | 755 .RetiresOnSaturation(); |
772 | 756 |
773 auth_->AuthenticateToUnlock(username_, ""); | 757 auth_->AuthenticateToUnlock(username_, ""); |
774 message_loop_.Run(); | 758 message_loop_.Run(); |
775 } | 759 } |
776 | 760 |
777 TEST_F(ParallelAuthenticatorTest, DriveLocalUnlock) { | 761 TEST_F(ParallelAuthenticatorTest, DriveLocalUnlock) { |
778 ExpectLoginSuccess(username_, std::string(), result_, false); | 762 ExpectLoginSuccess(username_, std::string(), result_, false); |
779 FailOnLoginFailure(); | 763 FailOnLoginFailure(); |
780 | 764 |
781 // Set up mock cryptohome library to fail a cryptohome key-check | 765 // Set up mock cryptohome library to fail a cryptohome key-check |
782 // attempt. | 766 // attempt. |
783 mock_library_->SetUp(false, 0); | 767 mock_library_->SetUp(false, 0); |
784 EXPECT_CALL(*mock_library_, AsyncCheckKey(username_, _, _)) | 768 EXPECT_CALL(*mock_library_, AsyncCheckKey(username_, _, _)) |
785 .Times(1) | 769 .Times(1) |
786 .RetiresOnSaturation(); | 770 .RetiresOnSaturation(); |
787 EXPECT_CALL(*mock_library_, GetSystemSalt()) | 771 EXPECT_CALL(*mock_library_, HashPassword(_)) |
788 .WillOnce(Return(CryptohomeBlob(2, 0))) | 772 .WillOnce(Return(std::string())) |
789 .RetiresOnSaturation(); | 773 .RetiresOnSaturation(); |
790 | 774 |
791 // Deal with getting the localaccount file | 775 // Deal with getting the localaccount file |
792 FilePath tmp_file_path = FakeLocalaccountFile(username_); | 776 FilePath tmp_file_path = FakeLocalaccountFile(username_); |
793 ReadLocalaccountFile(auth_.get(), tmp_file_path.BaseName().value()); | 777 ReadLocalaccountFile(auth_.get(), tmp_file_path.BaseName().value()); |
794 | 778 |
795 auth_->AuthenticateToUnlock(username_, ""); | 779 auth_->AuthenticateToUnlock(username_, ""); |
796 message_loop_.Run(); | 780 message_loop_.Run(); |
797 | 781 |
798 Delete(tmp_file_path, false); | 782 Delete(tmp_file_path, false); |
799 } | 783 } |
800 | 784 |
801 } // namespace chromeos | 785 } // namespace chromeos |
OLD | NEW |