| 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()) | |
| 468 .WillOnce(Return(CryptohomeBlob(2, 0))) | |
| 469 .RetiresOnSaturation(); | |
| 470 | 451 |
| 471 state_->PresetOnlineLoginStatus(result_, LoginFailure::None()); | 452 state_->PresetOnlineLoginStatus(result_, LoginFailure::None()); |
| 472 SetAttemptState(auth_, state_.release()); | 453 SetAttemptState(auth_, state_.release()); |
| 473 | 454 |
| 474 auth_->RecoverEncryptedData(std::string(), result_); | 455 auth_->RecoverEncryptedData(std::string(), result_); |
| 475 message_loop_.Run(); | 456 message_loop_.Run(); |
| 476 } | 457 } |
| 477 | 458 |
| 478 TEST_F(ParallelAuthenticatorTest, DriveDataRecoverButFail) { | 459 TEST_F(ParallelAuthenticatorTest, DriveDataRecoverButFail) { |
| 479 FailOnLoginSuccess(); | 460 FailOnLoginSuccess(); |
| 480 ExpectPasswordChange(); | 461 ExpectPasswordChange(); |
| 481 | 462 |
| 482 // Set up mock cryptohome library to fail a key migration attempt, | 463 // Set up mock cryptohome library to fail a key migration attempt, |
| 483 // asserting that the wrong password was used. | 464 // asserting that the wrong password was used. |
| 484 mock_library_->SetUp(false, chromeos::kCryptohomeMountErrorKeyFailure); | 465 mock_library_->SetUp(false, chromeos::kCryptohomeMountErrorKeyFailure); |
| 485 EXPECT_CALL(*mock_library_, AsyncMigrateKey(username_, _, hash_ascii_, _)) | 466 EXPECT_CALL(*mock_library_, AsyncMigrateKey(username_, _, hash_ascii_, _)) |
| 486 .Times(1) | 467 .Times(1) |
| 487 .RetiresOnSaturation(); | 468 .RetiresOnSaturation(); |
| 488 EXPECT_CALL(*mock_library_, GetSystemSalt()) | |
| 489 .WillOnce(Return(CryptohomeBlob(2, 0))) | |
| 490 .RetiresOnSaturation(); | |
| 491 | 469 |
| 492 SetAttemptState(auth_, state_.release()); | 470 SetAttemptState(auth_, state_.release()); |
| 493 | 471 |
| 494 auth_->RecoverEncryptedData(std::string(), result_); | 472 auth_->RecoverEncryptedData(std::string(), result_); |
| 495 message_loop_.Run(); | 473 message_loop_.Run(); |
| 496 } | 474 } |
| 497 | 475 |
| 498 TEST_F(ParallelAuthenticatorTest, ResolveNoMount) { | 476 TEST_F(ParallelAuthenticatorTest, ResolveNoMount) { |
| 499 // Set a fake online attempt so that we return intermediate cryptohome state. | 477 // Set a fake online attempt so that we return intermediate cryptohome state. |
| 500 FakeOnlineAttempt(); | 478 FakeOnlineAttempt(); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 FailOnLoginFailure(); | 587 FailOnLoginFailure(); |
| 610 | 588 |
| 611 // Set up mock cryptohome library to respond successfully to a key migration. | 589 // Set up mock cryptohome library to respond successfully to a key migration. |
| 612 mock_library_->SetUp(true, 0); | 590 mock_library_->SetUp(true, 0); |
| 613 EXPECT_CALL(*mock_library_, AsyncMigrateKey(username_, | 591 EXPECT_CALL(*mock_library_, AsyncMigrateKey(username_, |
| 614 state_->ascii_hash, | 592 state_->ascii_hash, |
| 615 _, | 593 _, |
| 616 _)) | 594 _)) |
| 617 .Times(1) | 595 .Times(1) |
| 618 .RetiresOnSaturation(); | 596 .RetiresOnSaturation(); |
| 619 EXPECT_CALL(*mock_library_, GetSystemSalt()) | |
| 620 .WillOnce(Return(CryptohomeBlob(2, 0))) | |
| 621 .RetiresOnSaturation(); | |
| 622 | 597 |
| 623 // Set up state as though a cryptohome mount attempt has occurred and | 598 // Set up state as though a cryptohome mount attempt has occurred and |
| 624 // succeeded; also, an online request that never made it. | 599 // succeeded; also, an online request that never made it. |
| 625 state_->PresetCryptohomeStatus(true, 0); | 600 state_->PresetCryptohomeStatus(true, 0); |
| 626 // state_ is released further down. | 601 // state_ is released further down. |
| 627 SetAttemptState(auth_, state_.get()); | 602 SetAttemptState(auth_, state_.get()); |
| 628 RunResolve(auth_.get(), &message_loop_); | 603 RunResolve(auth_.get(), &message_loop_); |
| 629 | 604 |
| 630 // Offline login has completed, so now we "complete" the online request. | 605 // Offline login has completed, so now we "complete" the online request. |
| 631 GoogleServiceAuthError error( | 606 GoogleServiceAuthError error( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 646 username_, | 621 username_, |
| 647 std::string(), | 622 std::string(), |
| 648 std::string(), | 623 std::string(), |
| 649 std::string()); | 624 std::string()); |
| 650 message_loop_.Run(); | 625 message_loop_.Run(); |
| 651 } | 626 } |
| 652 | 627 |
| 653 TEST_F(ParallelAuthenticatorTest, DriveOfflineLoginGetCaptchad) { | 628 TEST_F(ParallelAuthenticatorTest, DriveOfflineLoginGetCaptchad) { |
| 654 ExpectLoginSuccess(username_, password_, result_, true); | 629 ExpectLoginSuccess(username_, password_, result_, true); |
| 655 FailOnLoginFailure(); | 630 FailOnLoginFailure(); |
| 656 EXPECT_CALL(*mock_library_, GetSystemSalt()) | |
| 657 .WillOnce(Return(CryptohomeBlob(2, 0))) | |
| 658 .RetiresOnSaturation(); | |
| 659 | 631 |
| 660 // Set up state as though a cryptohome mount attempt has occurred and | 632 // Set up state as though a cryptohome mount attempt has occurred and |
| 661 // succeeded; also, an online request that never made it. | 633 // succeeded; also, an online request that never made it. |
| 662 state_->PresetCryptohomeStatus(true, 0); | 634 state_->PresetCryptohomeStatus(true, 0); |
| 663 // state_ is released further down. | 635 // state_ is released further down. |
| 664 SetAttemptState(auth_, state_.get()); | 636 SetAttemptState(auth_, state_.get()); |
| 665 RunResolve(auth_.get(), &message_loop_); | 637 RunResolve(auth_.get(), &message_loop_); |
| 666 | 638 |
| 667 // Offline login has completed, so now we "complete" the online request. | 639 // Offline login has completed, so now we "complete" the online request. |
| 668 GoogleServiceAuthError error( | 640 GoogleServiceAuthError error( |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 TEST_F(ParallelAuthenticatorTest, DriveUnlock) { | 731 TEST_F(ParallelAuthenticatorTest, DriveUnlock) { |
| 760 ExpectLoginSuccess(username_, std::string(), result_, false); | 732 ExpectLoginSuccess(username_, std::string(), result_, false); |
| 761 FailOnLoginFailure(); | 733 FailOnLoginFailure(); |
| 762 | 734 |
| 763 // Set up mock cryptohome library to respond successfully to a cryptohome | 735 // Set up mock cryptohome library to respond successfully to a cryptohome |
| 764 // key-check attempt. | 736 // key-check attempt. |
| 765 mock_library_->SetUp(true, 0); | 737 mock_library_->SetUp(true, 0); |
| 766 EXPECT_CALL(*mock_library_, AsyncCheckKey(username_, _, _)) | 738 EXPECT_CALL(*mock_library_, AsyncCheckKey(username_, _, _)) |
| 767 .Times(1) | 739 .Times(1) |
| 768 .RetiresOnSaturation(); | 740 .RetiresOnSaturation(); |
| 769 EXPECT_CALL(*mock_library_, GetSystemSalt()) | |
| 770 .WillOnce(Return(CryptohomeBlob(2, 0))) | |
| 771 .RetiresOnSaturation(); | |
| 772 | 741 |
| 773 auth_->AuthenticateToUnlock(username_, ""); | 742 auth_->AuthenticateToUnlock(username_, ""); |
| 774 message_loop_.Run(); | 743 message_loop_.Run(); |
| 775 } | 744 } |
| 776 | 745 |
| 777 TEST_F(ParallelAuthenticatorTest, DriveLocalUnlock) { | 746 TEST_F(ParallelAuthenticatorTest, DriveLocalUnlock) { |
| 778 ExpectLoginSuccess(username_, std::string(), result_, false); | 747 ExpectLoginSuccess(username_, std::string(), result_, false); |
| 779 FailOnLoginFailure(); | 748 FailOnLoginFailure(); |
| 780 | 749 |
| 781 // Set up mock cryptohome library to fail a cryptohome key-check | 750 // Set up mock cryptohome library to fail a cryptohome key-check |
| 782 // attempt. | 751 // attempt. |
| 783 mock_library_->SetUp(false, 0); | 752 mock_library_->SetUp(false, 0); |
| 784 EXPECT_CALL(*mock_library_, AsyncCheckKey(username_, _, _)) | 753 EXPECT_CALL(*mock_library_, AsyncCheckKey(username_, _, _)) |
| 785 .Times(1) | 754 .Times(1) |
| 786 .RetiresOnSaturation(); | 755 .RetiresOnSaturation(); |
| 787 EXPECT_CALL(*mock_library_, GetSystemSalt()) | |
| 788 .WillOnce(Return(CryptohomeBlob(2, 0))) | |
| 789 .RetiresOnSaturation(); | |
| 790 | 756 |
| 791 // Deal with getting the localaccount file | 757 // Deal with getting the localaccount file |
| 792 FilePath tmp_file_path = FakeLocalaccountFile(username_); | 758 FilePath tmp_file_path = FakeLocalaccountFile(username_); |
| 793 ReadLocalaccountFile(auth_.get(), tmp_file_path.BaseName().value()); | 759 ReadLocalaccountFile(auth_.get(), tmp_file_path.BaseName().value()); |
| 794 | 760 |
| 795 auth_->AuthenticateToUnlock(username_, ""); | 761 auth_->AuthenticateToUnlock(username_, ""); |
| 796 message_loop_.Run(); | 762 message_loop_.Run(); |
| 797 | 763 |
| 798 Delete(tmp_file_path, false); | 764 Delete(tmp_file_path, false); |
| 799 } | 765 } |
| 800 | 766 |
| 801 } // namespace chromeos | 767 } // namespace chromeos |
| OLD | NEW |