OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/proximity_auth/unlock_manager_impl.h" | 5 #include "components/proximity_auth/unlock_manager_impl.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 } | 633 } |
634 | 634 |
635 TEST_F(ProximityAuthUnlockManagerImplTest, | 635 TEST_F(ProximityAuthUnlockManagerImplTest, |
636 OnAuthAttempted_NoRemoteDeviceLifeCycle) { | 636 OnAuthAttempted_NoRemoteDeviceLifeCycle) { |
637 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); | 637 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); |
638 SimulateUserPresentState(); | 638 SimulateUserPresentState(); |
639 | 639 |
640 unlock_manager_->SetRemoteDeviceLifeCycle(nullptr); | 640 unlock_manager_->SetRemoteDeviceLifeCycle(nullptr); |
641 | 641 |
642 EXPECT_CALL(proximity_auth_client_, FinalizeUnlock(false)); | 642 EXPECT_CALL(proximity_auth_client_, FinalizeUnlock(false)); |
643 unlock_manager_->OnAuthAttempted(ScreenlockBridge::LockHandler::USER_CLICK); | 643 unlock_manager_->OnAuthAttempted(mojom::AuthType::USER_CLICK); |
644 } | 644 } |
645 | 645 |
646 TEST_F(ProximityAuthUnlockManagerImplTest, OnAuthAttempted_UnlockNotAllowed) { | 646 TEST_F(ProximityAuthUnlockManagerImplTest, OnAuthAttempted_UnlockNotAllowed) { |
647 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); | 647 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); |
648 SimulateUserPresentState(); | 648 SimulateUserPresentState(); |
649 | 649 |
650 ON_CALL(*proximity_monitor(), IsUnlockAllowed()).WillByDefault(Return(false)); | 650 ON_CALL(*proximity_monitor(), IsUnlockAllowed()).WillByDefault(Return(false)); |
651 | 651 |
652 EXPECT_CALL(proximity_auth_client_, FinalizeUnlock(false)); | 652 EXPECT_CALL(proximity_auth_client_, FinalizeUnlock(false)); |
653 unlock_manager_->OnAuthAttempted(ScreenlockBridge::LockHandler::USER_CLICK); | 653 unlock_manager_->OnAuthAttempted(mojom::AuthType::USER_CLICK); |
654 } | 654 } |
655 | 655 |
656 TEST_F(ProximityAuthUnlockManagerImplTest, OnAuthAttempted_NotUserClick) { | 656 TEST_F(ProximityAuthUnlockManagerImplTest, OnAuthAttempted_NotUserClick) { |
657 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); | 657 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); |
658 SimulateUserPresentState(); | 658 SimulateUserPresentState(); |
659 | 659 |
660 EXPECT_CALL(proximity_auth_client_, FinalizeUnlock(_)).Times(0); | 660 EXPECT_CALL(proximity_auth_client_, FinalizeUnlock(_)).Times(0); |
661 unlock_manager_->OnAuthAttempted( | 661 unlock_manager_->OnAuthAttempted(mojom::AuthType::EXPAND_THEN_USER_CLICK); |
662 ScreenlockBridge::LockHandler::EXPAND_THEN_USER_CLICK); | |
663 } | 662 } |
664 | 663 |
665 TEST_F(ProximityAuthUnlockManagerImplTest, OnAuthAttempted_DuplicateCall) { | 664 TEST_F(ProximityAuthUnlockManagerImplTest, OnAuthAttempted_DuplicateCall) { |
666 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); | 665 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); |
667 SimulateUserPresentState(); | 666 SimulateUserPresentState(); |
668 | 667 |
669 EXPECT_CALL(messenger_, RequestUnlock()); | 668 EXPECT_CALL(messenger_, RequestUnlock()); |
670 unlock_manager_->OnAuthAttempted(ScreenlockBridge::LockHandler::USER_CLICK); | 669 unlock_manager_->OnAuthAttempted(mojom::AuthType::USER_CLICK); |
671 | 670 |
672 EXPECT_CALL(messenger_, RequestUnlock()).Times(0); | 671 EXPECT_CALL(messenger_, RequestUnlock()).Times(0); |
673 unlock_manager_->OnAuthAttempted(ScreenlockBridge::LockHandler::USER_CLICK); | 672 unlock_manager_->OnAuthAttempted(mojom::AuthType::USER_CLICK); |
674 } | 673 } |
675 | 674 |
676 TEST_F(ProximityAuthUnlockManagerImplTest, OnAuthAttempted_TimesOut) { | 675 TEST_F(ProximityAuthUnlockManagerImplTest, OnAuthAttempted_TimesOut) { |
677 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); | 676 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); |
678 SimulateUserPresentState(); | 677 SimulateUserPresentState(); |
679 | 678 |
680 unlock_manager_->OnAuthAttempted(ScreenlockBridge::LockHandler::USER_CLICK); | 679 unlock_manager_->OnAuthAttempted(mojom::AuthType::USER_CLICK); |
681 | 680 |
682 // Simulate the timeout period elapsing. | 681 // Simulate the timeout period elapsing. |
683 EXPECT_CALL(proximity_auth_client_, FinalizeUnlock(false)); | 682 EXPECT_CALL(proximity_auth_client_, FinalizeUnlock(false)); |
684 RunPendingTasks(); | 683 RunPendingTasks(); |
685 } | 684 } |
686 | 685 |
687 TEST_F(ProximityAuthUnlockManagerImplTest, | 686 TEST_F(ProximityAuthUnlockManagerImplTest, |
688 OnAuthAttempted_DoesntTimeOutFollowingResponse) { | 687 OnAuthAttempted_DoesntTimeOutFollowingResponse) { |
689 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); | 688 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); |
690 SimulateUserPresentState(); | 689 SimulateUserPresentState(); |
691 | 690 |
692 unlock_manager_->OnAuthAttempted(ScreenlockBridge::LockHandler::USER_CLICK); | 691 unlock_manager_->OnAuthAttempted(mojom::AuthType::USER_CLICK); |
693 | 692 |
694 EXPECT_CALL(proximity_auth_client_, FinalizeUnlock(_)); | 693 EXPECT_CALL(proximity_auth_client_, FinalizeUnlock(_)); |
695 unlock_manager_->OnUnlockResponse(false); | 694 unlock_manager_->OnUnlockResponse(false); |
696 | 695 |
697 // Simulate the timeout period elapsing. | 696 // Simulate the timeout period elapsing. |
698 EXPECT_CALL(proximity_auth_client_, FinalizeUnlock(_)).Times(0); | 697 EXPECT_CALL(proximity_auth_client_, FinalizeUnlock(_)).Times(0); |
699 RunPendingTasks(); | 698 RunPendingTasks(); |
700 } | 699 } |
701 | 700 |
702 TEST_F(ProximityAuthUnlockManagerImplTest, | 701 TEST_F(ProximityAuthUnlockManagerImplTest, |
703 OnAuthAttempted_Unlock_SupportsSignIn_UnlockRequestFails) { | 702 OnAuthAttempted_Unlock_SupportsSignIn_UnlockRequestFails) { |
704 ON_CALL(messenger_, SupportsSignIn()).WillByDefault(Return(true)); | 703 ON_CALL(messenger_, SupportsSignIn()).WillByDefault(Return(true)); |
705 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); | 704 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); |
706 SimulateUserPresentState(); | 705 SimulateUserPresentState(); |
707 | 706 |
708 EXPECT_CALL(messenger_, RequestUnlock()); | 707 EXPECT_CALL(messenger_, RequestUnlock()); |
709 unlock_manager_->OnAuthAttempted(ScreenlockBridge::LockHandler::USER_CLICK); | 708 unlock_manager_->OnAuthAttempted(mojom::AuthType::USER_CLICK); |
710 | 709 |
711 EXPECT_CALL(proximity_auth_client_, FinalizeUnlock(false)); | 710 EXPECT_CALL(proximity_auth_client_, FinalizeUnlock(false)); |
712 unlock_manager_->OnUnlockResponse(false); | 711 unlock_manager_->OnUnlockResponse(false); |
713 } | 712 } |
714 | 713 |
715 TEST_F(ProximityAuthUnlockManagerImplTest, | 714 TEST_F(ProximityAuthUnlockManagerImplTest, |
716 OnAuthAttempted_Unlock_WithSignIn_RequestSucceeds_EventSendFails) { | 715 OnAuthAttempted_Unlock_WithSignIn_RequestSucceeds_EventSendFails) { |
717 ON_CALL(messenger_, SupportsSignIn()).WillByDefault(Return(true)); | 716 ON_CALL(messenger_, SupportsSignIn()).WillByDefault(Return(true)); |
718 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); | 717 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); |
719 SimulateUserPresentState(); | 718 SimulateUserPresentState(); |
720 | 719 |
721 EXPECT_CALL(messenger_, RequestUnlock()); | 720 EXPECT_CALL(messenger_, RequestUnlock()); |
722 unlock_manager_->OnAuthAttempted(ScreenlockBridge::LockHandler::USER_CLICK); | 721 unlock_manager_->OnAuthAttempted(mojom::AuthType::USER_CLICK); |
723 | 722 |
724 EXPECT_CALL(messenger_, DispatchUnlockEvent()); | 723 EXPECT_CALL(messenger_, DispatchUnlockEvent()); |
725 unlock_manager_->OnUnlockResponse(true); | 724 unlock_manager_->OnUnlockResponse(true); |
726 | 725 |
727 EXPECT_CALL(proximity_auth_client_, FinalizeUnlock(false)); | 726 EXPECT_CALL(proximity_auth_client_, FinalizeUnlock(false)); |
728 unlock_manager_->OnUnlockEventSent(false); | 727 unlock_manager_->OnUnlockEventSent(false); |
729 } | 728 } |
730 | 729 |
731 TEST_F(ProximityAuthUnlockManagerImplTest, | 730 TEST_F(ProximityAuthUnlockManagerImplTest, |
732 OnAuthAttempted_Unlock_WithSignIn_RequestSucceeds_EventSendSucceeds) { | 731 OnAuthAttempted_Unlock_WithSignIn_RequestSucceeds_EventSendSucceeds) { |
733 ON_CALL(messenger_, SupportsSignIn()).WillByDefault(Return(true)); | 732 ON_CALL(messenger_, SupportsSignIn()).WillByDefault(Return(true)); |
734 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); | 733 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); |
735 SimulateUserPresentState(); | 734 SimulateUserPresentState(); |
736 | 735 |
737 EXPECT_CALL(messenger_, RequestUnlock()); | 736 EXPECT_CALL(messenger_, RequestUnlock()); |
738 unlock_manager_->OnAuthAttempted(ScreenlockBridge::LockHandler::USER_CLICK); | 737 unlock_manager_->OnAuthAttempted(mojom::AuthType::USER_CLICK); |
739 | 738 |
740 EXPECT_CALL(messenger_, DispatchUnlockEvent()); | 739 EXPECT_CALL(messenger_, DispatchUnlockEvent()); |
741 unlock_manager_->OnUnlockResponse(true); | 740 unlock_manager_->OnUnlockResponse(true); |
742 | 741 |
743 EXPECT_CALL(proximity_auth_client_, FinalizeUnlock(true)); | 742 EXPECT_CALL(proximity_auth_client_, FinalizeUnlock(true)); |
744 unlock_manager_->OnUnlockEventSent(true); | 743 unlock_manager_->OnUnlockEventSent(true); |
745 } | 744 } |
746 | 745 |
747 TEST_F(ProximityAuthUnlockManagerImplTest, | 746 TEST_F(ProximityAuthUnlockManagerImplTest, |
748 OnAuthAttempted_Unlock_DoesntSupportSignIn_UnlockEventSendFails) { | 747 OnAuthAttempted_Unlock_DoesntSupportSignIn_UnlockEventSendFails) { |
749 ON_CALL(messenger_, SupportsSignIn()).WillByDefault(Return(false)); | 748 ON_CALL(messenger_, SupportsSignIn()).WillByDefault(Return(false)); |
750 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); | 749 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); |
751 SimulateUserPresentState(); | 750 SimulateUserPresentState(); |
752 | 751 |
753 EXPECT_CALL(messenger_, DispatchUnlockEvent()); | 752 EXPECT_CALL(messenger_, DispatchUnlockEvent()); |
754 unlock_manager_->OnAuthAttempted(ScreenlockBridge::LockHandler::USER_CLICK); | 753 unlock_manager_->OnAuthAttempted(mojom::AuthType::USER_CLICK); |
755 | 754 |
756 EXPECT_CALL(proximity_auth_client_, FinalizeUnlock(false)); | 755 EXPECT_CALL(proximity_auth_client_, FinalizeUnlock(false)); |
757 unlock_manager_->OnUnlockEventSent(false); | 756 unlock_manager_->OnUnlockEventSent(false); |
758 } | 757 } |
759 | 758 |
760 TEST_F(ProximityAuthUnlockManagerImplTest, | 759 TEST_F(ProximityAuthUnlockManagerImplTest, |
761 OnAuthAttempted_Unlock_SupportsSignIn_UnlockEventSendSucceeds) { | 760 OnAuthAttempted_Unlock_SupportsSignIn_UnlockEventSendSucceeds) { |
762 ON_CALL(messenger_, SupportsSignIn()).WillByDefault(Return(false)); | 761 ON_CALL(messenger_, SupportsSignIn()).WillByDefault(Return(false)); |
763 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); | 762 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); |
764 SimulateUserPresentState(); | 763 SimulateUserPresentState(); |
765 | 764 |
766 EXPECT_CALL(messenger_, DispatchUnlockEvent()); | 765 EXPECT_CALL(messenger_, DispatchUnlockEvent()); |
767 unlock_manager_->OnAuthAttempted(ScreenlockBridge::LockHandler::USER_CLICK); | 766 unlock_manager_->OnAuthAttempted(mojom::AuthType::USER_CLICK); |
768 | 767 |
769 EXPECT_CALL(proximity_auth_client_, FinalizeUnlock(true)); | 768 EXPECT_CALL(proximity_auth_client_, FinalizeUnlock(true)); |
770 unlock_manager_->OnUnlockEventSent(true); | 769 unlock_manager_->OnUnlockEventSent(true); |
771 } | 770 } |
772 | 771 |
773 TEST_F(ProximityAuthUnlockManagerImplTest, OnAuthAttempted_SignIn_Success) { | 772 TEST_F(ProximityAuthUnlockManagerImplTest, OnAuthAttempted_SignIn_Success) { |
774 ON_CALL(messenger_, SupportsSignIn()).WillByDefault(Return(true)); | 773 ON_CALL(messenger_, SupportsSignIn()).WillByDefault(Return(true)); |
775 CreateUnlockManager(ProximityAuthSystem::SIGN_IN); | 774 CreateUnlockManager(ProximityAuthSystem::SIGN_IN); |
776 SimulateUserPresentState(); | 775 SimulateUserPresentState(); |
777 | 776 |
778 std::string channel_binding_data = secure_context_.GetChannelBindingData(); | 777 std::string channel_binding_data = secure_context_.GetChannelBindingData(); |
779 EXPECT_CALL(proximity_auth_client_, | 778 EXPECT_CALL(proximity_auth_client_, |
780 GetChallengeForUserAndDevice(remote_device_.user_id, | 779 GetChallengeForUserAndDevice(remote_device_.user_id, |
781 remote_device_.public_key, | 780 remote_device_.public_key, |
782 channel_binding_data, _)) | 781 channel_binding_data, _)) |
783 .WillOnce(Invoke( | 782 .WillOnce(Invoke( |
784 [](const std::string& user_id, const std::string& public_key, | 783 [](const std::string& user_id, const std::string& public_key, |
785 const std::string& channel_binding_data, | 784 const std::string& channel_binding_data, |
786 base::Callback<void(const std::string& challenge)> callback) { | 785 base::Callback<void(const std::string& challenge)> callback) { |
787 callback.Run(kChallenge); | 786 callback.Run(kChallenge); |
788 })); | 787 })); |
789 | 788 |
790 EXPECT_CALL(messenger_, RequestDecryption(kChallenge)); | 789 EXPECT_CALL(messenger_, RequestDecryption(kChallenge)); |
791 unlock_manager_->OnAuthAttempted(ScreenlockBridge::LockHandler::USER_CLICK); | 790 unlock_manager_->OnAuthAttempted(mojom::AuthType::USER_CLICK); |
792 | 791 |
793 EXPECT_CALL(messenger_, DispatchUnlockEvent()); | 792 EXPECT_CALL(messenger_, DispatchUnlockEvent()); |
794 unlock_manager_->OnDecryptResponse(kSignInSecret); | 793 unlock_manager_->OnDecryptResponse(kSignInSecret); |
795 | 794 |
796 EXPECT_CALL(proximity_auth_client_, FinalizeSignin(kSignInSecret)); | 795 EXPECT_CALL(proximity_auth_client_, FinalizeSignin(kSignInSecret)); |
797 unlock_manager_->OnUnlockEventSent(true); | 796 unlock_manager_->OnUnlockEventSent(true); |
798 } | 797 } |
799 | 798 |
800 TEST_F(ProximityAuthUnlockManagerImplTest, | 799 TEST_F(ProximityAuthUnlockManagerImplTest, |
801 OnAuthAttempted_SignIn_UnlockEventSendFails) { | 800 OnAuthAttempted_SignIn_UnlockEventSendFails) { |
802 ON_CALL(messenger_, SupportsSignIn()).WillByDefault(Return(true)); | 801 ON_CALL(messenger_, SupportsSignIn()).WillByDefault(Return(true)); |
803 CreateUnlockManager(ProximityAuthSystem::SIGN_IN); | 802 CreateUnlockManager(ProximityAuthSystem::SIGN_IN); |
804 SimulateUserPresentState(); | 803 SimulateUserPresentState(); |
805 | 804 |
806 std::string channel_binding_data = secure_context_.GetChannelBindingData(); | 805 std::string channel_binding_data = secure_context_.GetChannelBindingData(); |
807 EXPECT_CALL(proximity_auth_client_, | 806 EXPECT_CALL(proximity_auth_client_, |
808 GetChallengeForUserAndDevice(remote_device_.user_id, | 807 GetChallengeForUserAndDevice(remote_device_.user_id, |
809 remote_device_.public_key, | 808 remote_device_.public_key, |
810 channel_binding_data, _)) | 809 channel_binding_data, _)) |
811 .WillOnce(Invoke( | 810 .WillOnce(Invoke( |
812 [](const std::string& user_id, const std::string& public_key, | 811 [](const std::string& user_id, const std::string& public_key, |
813 const std::string& channel_binding_data, | 812 const std::string& channel_binding_data, |
814 base::Callback<void(const std::string& challenge)> callback) { | 813 base::Callback<void(const std::string& challenge)> callback) { |
815 callback.Run(kChallenge); | 814 callback.Run(kChallenge); |
816 })); | 815 })); |
817 | 816 |
818 EXPECT_CALL(messenger_, RequestDecryption(kChallenge)); | 817 EXPECT_CALL(messenger_, RequestDecryption(kChallenge)); |
819 unlock_manager_->OnAuthAttempted(ScreenlockBridge::LockHandler::USER_CLICK); | 818 unlock_manager_->OnAuthAttempted(mojom::AuthType::USER_CLICK); |
820 | 819 |
821 EXPECT_CALL(messenger_, DispatchUnlockEvent()); | 820 EXPECT_CALL(messenger_, DispatchUnlockEvent()); |
822 unlock_manager_->OnDecryptResponse(kSignInSecret); | 821 unlock_manager_->OnDecryptResponse(kSignInSecret); |
823 | 822 |
824 EXPECT_CALL(proximity_auth_client_, FinalizeSignin(std::string())); | 823 EXPECT_CALL(proximity_auth_client_, FinalizeSignin(std::string())); |
825 unlock_manager_->OnUnlockEventSent(false); | 824 unlock_manager_->OnUnlockEventSent(false); |
826 } | 825 } |
827 | 826 |
828 TEST_F(ProximityAuthUnlockManagerImplTest, | 827 TEST_F(ProximityAuthUnlockManagerImplTest, |
829 OnAuthAttempted_SignIn_DecryptRequestFails) { | 828 OnAuthAttempted_SignIn_DecryptRequestFails) { |
830 ON_CALL(messenger_, SupportsSignIn()).WillByDefault(Return(true)); | 829 ON_CALL(messenger_, SupportsSignIn()).WillByDefault(Return(true)); |
831 CreateUnlockManager(ProximityAuthSystem::SIGN_IN); | 830 CreateUnlockManager(ProximityAuthSystem::SIGN_IN); |
832 SimulateUserPresentState(); | 831 SimulateUserPresentState(); |
833 | 832 |
834 std::string channel_binding_data = secure_context_.GetChannelBindingData(); | 833 std::string channel_binding_data = secure_context_.GetChannelBindingData(); |
835 EXPECT_CALL(proximity_auth_client_, | 834 EXPECT_CALL(proximity_auth_client_, |
836 GetChallengeForUserAndDevice(remote_device_.user_id, | 835 GetChallengeForUserAndDevice(remote_device_.user_id, |
837 remote_device_.public_key, | 836 remote_device_.public_key, |
838 channel_binding_data, _)) | 837 channel_binding_data, _)) |
839 .WillOnce(Invoke( | 838 .WillOnce(Invoke( |
840 [](const std::string& user_id, const std::string& public_key, | 839 [](const std::string& user_id, const std::string& public_key, |
841 const std::string& channel_binding_data, | 840 const std::string& channel_binding_data, |
842 base::Callback<void(const std::string& challenge)> callback) { | 841 base::Callback<void(const std::string& challenge)> callback) { |
843 callback.Run(kChallenge); | 842 callback.Run(kChallenge); |
844 })); | 843 })); |
845 | 844 |
846 EXPECT_CALL(messenger_, RequestDecryption(kChallenge)); | 845 EXPECT_CALL(messenger_, RequestDecryption(kChallenge)); |
847 unlock_manager_->OnAuthAttempted(ScreenlockBridge::LockHandler::USER_CLICK); | 846 unlock_manager_->OnAuthAttempted(mojom::AuthType::USER_CLICK); |
848 | 847 |
849 EXPECT_CALL(proximity_auth_client_, FinalizeSignin(std::string())); | 848 EXPECT_CALL(proximity_auth_client_, FinalizeSignin(std::string())); |
850 unlock_manager_->OnDecryptResponse(std::string()); | 849 unlock_manager_->OnDecryptResponse(std::string()); |
851 } | 850 } |
852 | 851 |
853 } // namespace proximity_auth | 852 } // namespace proximity_auth |
OLD | NEW |