OLD | NEW |
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 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 // When there is no online attempt and online results, POSSIBLE_PW_CHANGE | 270 // When there is no online attempt and online results, POSSIBLE_PW_CHANGE |
271 EXPECT_EQ(ParallelAuthenticator::FAILED_MOUNT, | 271 EXPECT_EQ(ParallelAuthenticator::FAILED_MOUNT, |
272 SetAndResolveState(auth_, state_.release())); | 272 SetAndResolveState(auth_, state_.release())); |
273 } | 273 } |
274 | 274 |
275 TEST_F(ParallelAuthenticatorTest, ResolveNeedOldPw) { | 275 TEST_F(ParallelAuthenticatorTest, ResolveNeedOldPw) { |
276 // Set up state as though a cryptohome mount attempt has occurred | 276 // Set up state as though a cryptohome mount attempt has occurred |
277 // and been rejected because of unmatched key; additionally, | 277 // and been rejected because of unmatched key; additionally, |
278 // an online auth attempt has completed successfully. | 278 // an online auth attempt has completed successfully. |
279 state_->PresetCryptohomeStatus(false, cryptohome::MOUNT_ERROR_KEY_FAILURE); | 279 state_->PresetCryptohomeStatus(false, cryptohome::MOUNT_ERROR_KEY_FAILURE); |
280 state_->PresetOnlineLoginStatus(LoginFailure::None()); | 280 state_->PresetOnlineLoginStatus(LoginFailure::LoginFailureNone()); |
281 | 281 |
282 EXPECT_EQ(ParallelAuthenticator::NEED_OLD_PW, | 282 EXPECT_EQ(ParallelAuthenticator::NEED_OLD_PW, |
283 SetAndResolveState(auth_, state_.release())); | 283 SetAndResolveState(auth_, state_.release())); |
284 } | 284 } |
285 | 285 |
286 TEST_F(ParallelAuthenticatorTest, ResolveOwnerNeededDirectFailedMount) { | 286 TEST_F(ParallelAuthenticatorTest, ResolveOwnerNeededDirectFailedMount) { |
287 // Set up state as though a cryptohome mount attempt has occurred | 287 // Set up state as though a cryptohome mount attempt has occurred |
288 // and succeeded but we are in safe mode and the current user is not owner. | 288 // and succeeded but we are in safe mode and the current user is not owner. |
289 // This is a high level test to verify the proper transitioning in this mode | 289 // This is a high level test to verify the proper transitioning in this mode |
290 // only. It is not testing that we properly verify that the user is an owner | 290 // only. It is not testing that we properly verify that the user is an owner |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 // |CREATE_IF_MISSING| flag to AsyncMount). | 447 // |CREATE_IF_MISSING| flag to AsyncMount). |
448 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); | 448 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); |
449 EXPECT_CALL(*mock_caller_, AsyncRemove(username_, _)) | 449 EXPECT_CALL(*mock_caller_, AsyncRemove(username_, _)) |
450 .Times(1) | 450 .Times(1) |
451 .RetiresOnSaturation(); | 451 .RetiresOnSaturation(); |
452 EXPECT_CALL(*mock_caller_, AsyncMount(username_, hash_ascii_, | 452 EXPECT_CALL(*mock_caller_, AsyncMount(username_, hash_ascii_, |
453 cryptohome::CREATE_IF_MISSING, _)) | 453 cryptohome::CREATE_IF_MISSING, _)) |
454 .Times(1) | 454 .Times(1) |
455 .RetiresOnSaturation(); | 455 .RetiresOnSaturation(); |
456 | 456 |
457 state_->PresetOnlineLoginStatus(LoginFailure::None()); | 457 state_->PresetOnlineLoginStatus(LoginFailure::LoginFailureNone()); |
458 SetAttemptState(auth_, state_.release()); | 458 SetAttemptState(auth_, state_.release()); |
459 | 459 |
460 auth_->ResyncEncryptedData(); | 460 auth_->ResyncEncryptedData(); |
461 message_loop_.Run(); | 461 message_loop_.Run(); |
462 } | 462 } |
463 | 463 |
464 TEST_F(ParallelAuthenticatorTest, DriveResyncFail) { | 464 TEST_F(ParallelAuthenticatorTest, DriveResyncFail) { |
465 FailOnLoginSuccess(); | 465 FailOnLoginSuccess(); |
466 ExpectLoginFailure(LoginFailure(LoginFailure::DATA_REMOVAL_FAILED)); | 466 ExpectLoginFailure(LoginFailure(LoginFailure::DATA_REMOVAL_FAILED)); |
467 | 467 |
468 // Set up mock cryptohome library to fail a cryptohome remove attempt. | 468 // Set up mock cryptohome library to fail a cryptohome remove attempt. |
469 mock_caller_->SetUp(false, cryptohome::MOUNT_ERROR_NONE); | 469 mock_caller_->SetUp(false, cryptohome::MOUNT_ERROR_NONE); |
470 EXPECT_CALL(*mock_caller_, AsyncRemove(username_, _)) | 470 EXPECT_CALL(*mock_caller_, AsyncRemove(username_, _)) |
471 .Times(1) | 471 .Times(1) |
472 .RetiresOnSaturation(); | 472 .RetiresOnSaturation(); |
473 | 473 |
474 SetAttemptState(auth_, state_.release()); | 474 SetAttemptState(auth_, state_.release()); |
475 | 475 |
476 auth_->ResyncEncryptedData(); | 476 auth_->ResyncEncryptedData(); |
477 message_loop_.Run(); | 477 message_loop_.Run(); |
478 } | 478 } |
479 | 479 |
480 TEST_F(ParallelAuthenticatorTest, DriveRequestOldPassword) { | 480 TEST_F(ParallelAuthenticatorTest, DriveRequestOldPassword) { |
481 FailOnLoginSuccess(); | 481 FailOnLoginSuccess(); |
482 ExpectPasswordChange(); | 482 ExpectPasswordChange(); |
483 | 483 |
484 state_->PresetCryptohomeStatus(false, cryptohome::MOUNT_ERROR_KEY_FAILURE); | 484 state_->PresetCryptohomeStatus(false, cryptohome::MOUNT_ERROR_KEY_FAILURE); |
485 state_->PresetOnlineLoginStatus(LoginFailure::None()); | 485 state_->PresetOnlineLoginStatus(LoginFailure::LoginFailureNone()); |
486 SetAttemptState(auth_, state_.release()); | 486 SetAttemptState(auth_, state_.release()); |
487 | 487 |
488 RunResolve(auth_.get()); | 488 RunResolve(auth_.get()); |
489 } | 489 } |
490 | 490 |
491 TEST_F(ParallelAuthenticatorTest, DriveDataRecover) { | 491 TEST_F(ParallelAuthenticatorTest, DriveDataRecover) { |
492 ExpectLoginSuccess(username_, password_, false); | 492 ExpectLoginSuccess(username_, password_, false); |
493 FailOnLoginFailure(); | 493 FailOnLoginFailure(); |
494 | 494 |
495 // Set up mock cryptohome library to respond successfully to a key migration. | 495 // Set up mock cryptohome library to respond successfully to a key migration. |
496 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); | 496 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); |
497 EXPECT_CALL(*mock_caller_, AsyncMigrateKey(username_, _, hash_ascii_, _)) | 497 EXPECT_CALL(*mock_caller_, AsyncMigrateKey(username_, _, hash_ascii_, _)) |
498 .Times(1) | 498 .Times(1) |
499 .RetiresOnSaturation(); | 499 .RetiresOnSaturation(); |
500 EXPECT_CALL(*mock_caller_, AsyncMount(username_, hash_ascii_, | 500 EXPECT_CALL(*mock_caller_, AsyncMount(username_, hash_ascii_, |
501 cryptohome::MOUNT_FLAGS_NONE, _)) | 501 cryptohome::MOUNT_FLAGS_NONE, _)) |
502 .Times(1) | 502 .Times(1) |
503 .RetiresOnSaturation(); | 503 .RetiresOnSaturation(); |
504 EXPECT_CALL(*mock_cryptohome_library_, GetSystemSalt()) | 504 EXPECT_CALL(*mock_cryptohome_library_, GetSystemSalt()) |
505 .WillOnce(Return(std::string())) | 505 .WillOnce(Return(std::string())) |
506 .RetiresOnSaturation(); | 506 .RetiresOnSaturation(); |
507 | 507 |
508 state_->PresetOnlineLoginStatus(LoginFailure::None()); | 508 state_->PresetOnlineLoginStatus(LoginFailure::LoginFailureNone()); |
509 SetAttemptState(auth_, state_.release()); | 509 SetAttemptState(auth_, state_.release()); |
510 | 510 |
511 auth_->RecoverEncryptedData(std::string()); | 511 auth_->RecoverEncryptedData(std::string()); |
512 message_loop_.Run(); | 512 message_loop_.Run(); |
513 } | 513 } |
514 | 514 |
515 TEST_F(ParallelAuthenticatorTest, DriveDataRecoverButFail) { | 515 TEST_F(ParallelAuthenticatorTest, DriveDataRecoverButFail) { |
516 FailOnLoginSuccess(); | 516 FailOnLoginSuccess(); |
517 ExpectPasswordChange(); | 517 ExpectPasswordChange(); |
518 | 518 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 EXPECT_EQ(ParallelAuthenticator::FAILED_MOUNT, | 556 EXPECT_EQ(ParallelAuthenticator::FAILED_MOUNT, |
557 SetAndResolveState(auth_, state_.release())); | 557 SetAndResolveState(auth_, state_.release())); |
558 } | 558 } |
559 | 559 |
560 TEST_F(ParallelAuthenticatorTest, ResolveCreateNew) { | 560 TEST_F(ParallelAuthenticatorTest, ResolveCreateNew) { |
561 // Set up state as though a cryptohome mount attempt has occurred | 561 // Set up state as though a cryptohome mount attempt has occurred |
562 // and been rejected because the user doesn't exist; additionally, | 562 // and been rejected because the user doesn't exist; additionally, |
563 // an online auth attempt has completed successfully. | 563 // an online auth attempt has completed successfully. |
564 state_->PresetCryptohomeStatus(false, | 564 state_->PresetCryptohomeStatus(false, |
565 cryptohome::MOUNT_ERROR_USER_DOES_NOT_EXIST); | 565 cryptohome::MOUNT_ERROR_USER_DOES_NOT_EXIST); |
566 state_->PresetOnlineLoginStatus(LoginFailure::None()); | 566 state_->PresetOnlineLoginStatus(LoginFailure::LoginFailureNone()); |
567 | 567 |
568 EXPECT_EQ(ParallelAuthenticator::CREATE_NEW, | 568 EXPECT_EQ(ParallelAuthenticator::CREATE_NEW, |
569 SetAndResolveState(auth_, state_.release())); | 569 SetAndResolveState(auth_, state_.release())); |
570 } | 570 } |
571 | 571 |
572 TEST_F(ParallelAuthenticatorTest, DriveCreateForNewUser) { | 572 TEST_F(ParallelAuthenticatorTest, DriveCreateForNewUser) { |
573 ExpectLoginSuccess(username_, password_, false); | 573 ExpectLoginSuccess(username_, password_, false); |
574 FailOnLoginFailure(); | 574 FailOnLoginFailure(); |
575 | 575 |
576 // Set up mock cryptohome library to respond successfully to a cryptohome | 576 // Set up mock cryptohome library to respond successfully to a cryptohome |
577 // create attempt (indicated by the |CREATE_IF_MISSING| flag to AsyncMount). | 577 // create attempt (indicated by the |CREATE_IF_MISSING| flag to AsyncMount). |
578 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); | 578 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); |
579 EXPECT_CALL(*mock_caller_, AsyncMount(username_, hash_ascii_, | 579 EXPECT_CALL(*mock_caller_, AsyncMount(username_, hash_ascii_, |
580 cryptohome::CREATE_IF_MISSING, _)) | 580 cryptohome::CREATE_IF_MISSING, _)) |
581 .Times(1) | 581 .Times(1) |
582 .RetiresOnSaturation(); | 582 .RetiresOnSaturation(); |
583 | 583 |
584 // Set up state as though a cryptohome mount attempt has occurred | 584 // Set up state as though a cryptohome mount attempt has occurred |
585 // and been rejected because the user doesn't exist; additionally, | 585 // and been rejected because the user doesn't exist; additionally, |
586 // an online auth attempt has completed successfully. | 586 // an online auth attempt has completed successfully. |
587 state_->PresetCryptohomeStatus(false, | 587 state_->PresetCryptohomeStatus(false, |
588 cryptohome::MOUNT_ERROR_USER_DOES_NOT_EXIST); | 588 cryptohome::MOUNT_ERROR_USER_DOES_NOT_EXIST); |
589 state_->PresetOnlineLoginStatus(LoginFailure::None()); | 589 state_->PresetOnlineLoginStatus(LoginFailure::LoginFailureNone()); |
590 SetAttemptState(auth_, state_.release()); | 590 SetAttemptState(auth_, state_.release()); |
591 | 591 |
592 RunResolve(auth_.get()); | 592 RunResolve(auth_.get()); |
593 } | 593 } |
594 | 594 |
595 TEST_F(ParallelAuthenticatorTest, DriveOfflineLogin) { | 595 TEST_F(ParallelAuthenticatorTest, DriveOfflineLogin) { |
596 ExpectLoginSuccess(username_, password_, false); | 596 ExpectLoginSuccess(username_, password_, false); |
597 FailOnLoginFailure(); | 597 FailOnLoginFailure(); |
598 | 598 |
599 // Set up state as though a cryptohome mount attempt has occurred and | 599 // Set up state as though a cryptohome mount attempt has occurred and |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 message_loop_.RunUntilIdle(); | 718 message_loop_.RunUntilIdle(); |
719 } | 719 } |
720 | 720 |
721 TEST_F(ParallelAuthenticatorTest, DriveOnlineLogin) { | 721 TEST_F(ParallelAuthenticatorTest, DriveOnlineLogin) { |
722 ExpectLoginSuccess(username_, password_, false); | 722 ExpectLoginSuccess(username_, password_, false); |
723 FailOnLoginFailure(); | 723 FailOnLoginFailure(); |
724 | 724 |
725 // Set up state as though a cryptohome mount attempt has occurred and | 725 // Set up state as though a cryptohome mount attempt has occurred and |
726 // succeeded. | 726 // succeeded. |
727 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); | 727 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); |
728 state_->PresetOnlineLoginStatus(LoginFailure::None()); | 728 state_->PresetOnlineLoginStatus(LoginFailure::LoginFailureNone()); |
729 SetAttemptState(auth_, state_.release()); | 729 SetAttemptState(auth_, state_.release()); |
730 | 730 |
731 RunResolve(auth_.get()); | 731 RunResolve(auth_.get()); |
732 } | 732 } |
733 | 733 |
734 // http://crbug.com/106538 | 734 // http://crbug.com/106538 |
735 TEST_F(ParallelAuthenticatorTest, DISABLED_DriveNeedNewPassword) { | 735 TEST_F(ParallelAuthenticatorTest, DISABLED_DriveNeedNewPassword) { |
736 FailOnLoginSuccess(); // Set failing on success as the default... | 736 FailOnLoginSuccess(); // Set failing on success as the default... |
737 // ...but expect ONE successful login first. | 737 // ...but expect ONE successful login first. |
738 ExpectLoginSuccess(username_, password_, true); | 738 ExpectLoginSuccess(username_, password_, true); |
(...skipping 23 matching lines...) Expand all Loading... |
762 .RetiresOnSaturation(); | 762 .RetiresOnSaturation(); |
763 EXPECT_CALL(*mock_cryptohome_library_, GetSystemSalt()) | 763 EXPECT_CALL(*mock_cryptohome_library_, GetSystemSalt()) |
764 .WillOnce(Return(std::string())) | 764 .WillOnce(Return(std::string())) |
765 .RetiresOnSaturation(); | 765 .RetiresOnSaturation(); |
766 | 766 |
767 auth_->AuthenticateToUnlock(username_, ""); | 767 auth_->AuthenticateToUnlock(username_, ""); |
768 message_loop_.Run(); | 768 message_loop_.Run(); |
769 } | 769 } |
770 | 770 |
771 } // namespace chromeos | 771 } // namespace chromeos |
OLD | NEW |