OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 | 5 |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 TEST_F(CryptohomeAuthenticatorTest, DriveGuestLogin) { | 531 TEST_F(CryptohomeAuthenticatorTest, DriveGuestLogin) { |
532 ExpectGuestLoginSuccess(); | 532 ExpectGuestLoginSuccess(); |
533 FailOnLoginFailure(); | 533 FailOnLoginFailure(); |
534 | 534 |
535 // Set up mock async method caller to respond as though a tmpfs mount | 535 // Set up mock async method caller to respond as though a tmpfs mount |
536 // attempt has occurred and succeeded. | 536 // attempt has occurred and succeeded. |
537 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); | 537 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); |
538 EXPECT_CALL(*mock_caller_, AsyncMountGuest(_)).Times(1).RetiresOnSaturation(); | 538 EXPECT_CALL(*mock_caller_, AsyncMountGuest(_)).Times(1).RetiresOnSaturation(); |
539 | 539 |
540 auth_->LoginOffTheRecord(); | 540 auth_->LoginOffTheRecord(); |
541 base::MessageLoop::current()->Run(); | 541 base::RunLoop().Run(); |
542 } | 542 } |
543 | 543 |
544 TEST_F(CryptohomeAuthenticatorTest, DriveGuestLoginButFail) { | 544 TEST_F(CryptohomeAuthenticatorTest, DriveGuestLoginButFail) { |
545 FailOnGuestLoginSuccess(); | 545 FailOnGuestLoginSuccess(); |
546 ExpectLoginFailure(AuthFailure(AuthFailure::COULD_NOT_MOUNT_TMPFS)); | 546 ExpectLoginFailure(AuthFailure(AuthFailure::COULD_NOT_MOUNT_TMPFS)); |
547 | 547 |
548 // Set up mock async method caller to respond as though a tmpfs mount | 548 // Set up mock async method caller to respond as though a tmpfs mount |
549 // attempt has occurred and failed. | 549 // attempt has occurred and failed. |
550 mock_caller_->SetUp(false, cryptohome::MOUNT_ERROR_NONE); | 550 mock_caller_->SetUp(false, cryptohome::MOUNT_ERROR_NONE); |
551 EXPECT_CALL(*mock_caller_, AsyncMountGuest(_)).Times(1).RetiresOnSaturation(); | 551 EXPECT_CALL(*mock_caller_, AsyncMountGuest(_)).Times(1).RetiresOnSaturation(); |
552 | 552 |
553 auth_->LoginOffTheRecord(); | 553 auth_->LoginOffTheRecord(); |
554 base::MessageLoop::current()->Run(); | 554 base::RunLoop().Run(); |
555 } | 555 } |
556 | 556 |
557 TEST_F(CryptohomeAuthenticatorTest, DriveDataResync) { | 557 TEST_F(CryptohomeAuthenticatorTest, DriveDataResync) { |
558 UserContext expected_user_context(user_context_with_transformed_key_); | 558 UserContext expected_user_context(user_context_with_transformed_key_); |
559 expected_user_context.SetUserIDHash( | 559 expected_user_context.SetUserIDHash( |
560 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername); | 560 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername); |
561 ExpectLoginSuccess(expected_user_context); | 561 ExpectLoginSuccess(expected_user_context); |
562 FailOnLoginFailure(); | 562 FailOnLoginFailure(); |
563 | 563 |
564 // Set up mock async method caller to respond successfully to a cryptohome | 564 // Set up mock async method caller to respond successfully to a cryptohome |
565 // remove attempt. | 565 // remove attempt. |
566 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); | 566 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); |
567 EXPECT_CALL( | 567 EXPECT_CALL( |
568 *mock_caller_, | 568 *mock_caller_, |
569 AsyncRemove(cryptohome::Identification(user_context_.GetAccountId()), _)) | 569 AsyncRemove(cryptohome::Identification(user_context_.GetAccountId()), _)) |
570 .Times(1) | 570 .Times(1) |
571 .RetiresOnSaturation(); | 571 .RetiresOnSaturation(); |
572 | 572 |
573 // Set up mock homedir methods to respond successfully to a cryptohome create | 573 // Set up mock homedir methods to respond successfully to a cryptohome create |
574 // attempt. | 574 // attempt. |
575 ExpectGetKeyDataExCall(std::unique_ptr<int64_t>(), | 575 ExpectGetKeyDataExCall(std::unique_ptr<int64_t>(), |
576 std::unique_ptr<std::string>()); | 576 std::unique_ptr<std::string>()); |
577 ExpectMountExCall(true /* expect_create_attempt */); | 577 ExpectMountExCall(true /* expect_create_attempt */); |
578 | 578 |
579 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone()); | 579 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone()); |
580 SetAttemptState(auth_.get(), state_.release()); | 580 SetAttemptState(auth_.get(), state_.release()); |
581 | 581 |
582 auth_->ResyncEncryptedData(); | 582 auth_->ResyncEncryptedData(); |
583 base::MessageLoop::current()->Run(); | 583 base::RunLoop().Run(); |
584 } | 584 } |
585 | 585 |
586 TEST_F(CryptohomeAuthenticatorTest, DriveResyncFail) { | 586 TEST_F(CryptohomeAuthenticatorTest, DriveResyncFail) { |
587 FailOnLoginSuccess(); | 587 FailOnLoginSuccess(); |
588 ExpectLoginFailure(AuthFailure(AuthFailure::DATA_REMOVAL_FAILED)); | 588 ExpectLoginFailure(AuthFailure(AuthFailure::DATA_REMOVAL_FAILED)); |
589 | 589 |
590 // Set up mock async method caller to fail a cryptohome remove attempt. | 590 // Set up mock async method caller to fail a cryptohome remove attempt. |
591 mock_caller_->SetUp(false, cryptohome::MOUNT_ERROR_NONE); | 591 mock_caller_->SetUp(false, cryptohome::MOUNT_ERROR_NONE); |
592 EXPECT_CALL( | 592 EXPECT_CALL( |
593 *mock_caller_, | 593 *mock_caller_, |
594 AsyncRemove(cryptohome::Identification(user_context_.GetAccountId()), _)) | 594 AsyncRemove(cryptohome::Identification(user_context_.GetAccountId()), _)) |
595 .Times(1) | 595 .Times(1) |
596 .RetiresOnSaturation(); | 596 .RetiresOnSaturation(); |
597 | 597 |
598 SetAttemptState(auth_.get(), state_.release()); | 598 SetAttemptState(auth_.get(), state_.release()); |
599 | 599 |
600 auth_->ResyncEncryptedData(); | 600 auth_->ResyncEncryptedData(); |
601 base::MessageLoop::current()->Run(); | 601 base::RunLoop().Run(); |
602 } | 602 } |
603 | 603 |
604 TEST_F(CryptohomeAuthenticatorTest, DriveRequestOldPassword) { | 604 TEST_F(CryptohomeAuthenticatorTest, DriveRequestOldPassword) { |
605 FailOnLoginSuccess(); | 605 FailOnLoginSuccess(); |
606 ExpectPasswordChange(); | 606 ExpectPasswordChange(); |
607 | 607 |
608 state_->PresetCryptohomeStatus(false, cryptohome::MOUNT_ERROR_KEY_FAILURE); | 608 state_->PresetCryptohomeStatus(false, cryptohome::MOUNT_ERROR_KEY_FAILURE); |
609 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone()); | 609 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone()); |
610 SetAttemptState(auth_.get(), state_.release()); | 610 SetAttemptState(auth_.get(), state_.release()); |
611 | 611 |
(...skipping 19 matching lines...) Expand all Loading... |
631 // Set up mock homedir methods to respond successfully to a cryptohome mount | 631 // Set up mock homedir methods to respond successfully to a cryptohome mount |
632 // attempt. | 632 // attempt. |
633 ExpectGetKeyDataExCall(std::unique_ptr<int64_t>(), | 633 ExpectGetKeyDataExCall(std::unique_ptr<int64_t>(), |
634 std::unique_ptr<std::string>()); | 634 std::unique_ptr<std::string>()); |
635 ExpectMountExCall(false /* expect_create_attempt */); | 635 ExpectMountExCall(false /* expect_create_attempt */); |
636 | 636 |
637 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone()); | 637 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone()); |
638 SetAttemptState(auth_.get(), state_.release()); | 638 SetAttemptState(auth_.get(), state_.release()); |
639 | 639 |
640 auth_->RecoverEncryptedData(std::string()); | 640 auth_->RecoverEncryptedData(std::string()); |
641 base::MessageLoop::current()->Run(); | 641 base::RunLoop().Run(); |
642 } | 642 } |
643 | 643 |
644 TEST_F(CryptohomeAuthenticatorTest, DriveDataRecoverButFail) { | 644 TEST_F(CryptohomeAuthenticatorTest, DriveDataRecoverButFail) { |
645 FailOnLoginSuccess(); | 645 FailOnLoginSuccess(); |
646 ExpectPasswordChange(); | 646 ExpectPasswordChange(); |
647 | 647 |
648 // Set up mock async method caller to fail a key migration attempt, | 648 // Set up mock async method caller to fail a key migration attempt, |
649 // asserting that the wrong password was used. | 649 // asserting that the wrong password was used. |
650 mock_caller_->SetUp(false, cryptohome::MOUNT_ERROR_KEY_FAILURE); | 650 mock_caller_->SetUp(false, cryptohome::MOUNT_ERROR_KEY_FAILURE); |
651 EXPECT_CALL( | 651 EXPECT_CALL( |
652 *mock_caller_, | 652 *mock_caller_, |
653 AsyncMigrateKey(cryptohome::Identification(user_context_.GetAccountId()), | 653 AsyncMigrateKey(cryptohome::Identification(user_context_.GetAccountId()), |
654 _, transformed_key_.GetSecret(), _)) | 654 _, transformed_key_.GetSecret(), _)) |
655 .Times(1) | 655 .Times(1) |
656 .RetiresOnSaturation(); | 656 .RetiresOnSaturation(); |
657 | 657 |
658 SetAttemptState(auth_.get(), state_.release()); | 658 SetAttemptState(auth_.get(), state_.release()); |
659 | 659 |
660 auth_->RecoverEncryptedData(std::string()); | 660 auth_->RecoverEncryptedData(std::string()); |
661 base::MessageLoop::current()->Run(); | 661 base::RunLoop().Run(); |
662 } | 662 } |
663 | 663 |
664 TEST_F(CryptohomeAuthenticatorTest, ResolveNoMountToFailedMount) { | 664 TEST_F(CryptohomeAuthenticatorTest, ResolveNoMountToFailedMount) { |
665 // Set up state as though a cryptohome mount attempt has occurred | 665 // Set up state as though a cryptohome mount attempt has occurred |
666 // and been rejected because the user doesn't exist. | 666 // and been rejected because the user doesn't exist. |
667 state_->PresetCryptohomeStatus(false, | 667 state_->PresetCryptohomeStatus(false, |
668 cryptohome::MOUNT_ERROR_USER_DOES_NOT_EXIST); | 668 cryptohome::MOUNT_ERROR_USER_DOES_NOT_EXIST); |
669 | 669 |
670 // When there is no online attempt and online results, NO_MOUNT will be | 670 // When there is no online attempt and online results, NO_MOUNT will be |
671 // resolved to FAILED_MOUNT. | 671 // resolved to FAILED_MOUNT. |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
742 // key-check attempt. | 742 // key-check attempt. |
743 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); | 743 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); |
744 EXPECT_CALL( | 744 EXPECT_CALL( |
745 *mock_caller_, | 745 *mock_caller_, |
746 AsyncCheckKey(cryptohome::Identification(user_context_.GetAccountId()), _, | 746 AsyncCheckKey(cryptohome::Identification(user_context_.GetAccountId()), _, |
747 _)) | 747 _)) |
748 .Times(1) | 748 .Times(1) |
749 .RetiresOnSaturation(); | 749 .RetiresOnSaturation(); |
750 | 750 |
751 auth_->AuthenticateToUnlock(user_context_); | 751 auth_->AuthenticateToUnlock(user_context_); |
752 base::MessageLoop::current()->Run(); | 752 base::RunLoop().Run(); |
753 } | 753 } |
754 | 754 |
755 TEST_F(CryptohomeAuthenticatorTest, DriveLoginWithPreHashedPassword) { | 755 TEST_F(CryptohomeAuthenticatorTest, DriveLoginWithPreHashedPassword) { |
756 CreateTransformedKey(Key::KEY_TYPE_SALTED_SHA256, kSalt); | 756 CreateTransformedKey(Key::KEY_TYPE_SALTED_SHA256, kSalt); |
757 | 757 |
758 UserContext expected_user_context(user_context_with_transformed_key_); | 758 UserContext expected_user_context(user_context_with_transformed_key_); |
759 expected_user_context.SetUserIDHash( | 759 expected_user_context.SetUserIDHash( |
760 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername); | 760 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername); |
761 ExpectLoginSuccess(expected_user_context); | 761 ExpectLoginSuccess(expected_user_context); |
762 FailOnLoginFailure(); | 762 FailOnLoginFailure(); |
(...skipping 20 matching lines...) Expand all Loading... |
783 // pre-hashed key was used to create the cryptohome but without the required | 783 // pre-hashed key was used to create the cryptohome but without the required |
784 // salt. | 784 // salt. |
785 ExpectGetKeyDataExCall(base::MakeUnique<int64_t>(Key::KEY_TYPE_SALTED_SHA256), | 785 ExpectGetKeyDataExCall(base::MakeUnique<int64_t>(Key::KEY_TYPE_SALTED_SHA256), |
786 std::unique_ptr<std::string>()); | 786 std::unique_ptr<std::string>()); |
787 | 787 |
788 auth_->AuthenticateToLogin(NULL, user_context_); | 788 auth_->AuthenticateToLogin(NULL, user_context_); |
789 base::RunLoop().Run(); | 789 base::RunLoop().Run(); |
790 } | 790 } |
791 | 791 |
792 } // namespace chromeos | 792 } // namespace chromeos |
OLD | NEW |