Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(236)

Side by Side Diff: chrome/browser/chromeos/login/auth/cryptohome_authenticator_unittest.cc

Issue 1019283004: Switch to direct use of OwnerSettingsServiceChromeOS::Set() in tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "chrome/browser/chromeos/login/auth/chrome_cryptohome_authenticator.h" 5 #include "chrome/browser/chromeos/login/auth/chrome_cryptohome_authenticator.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/run_loop.h" 16 #include "base/run_loop.h"
17 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
18 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
19 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" 19 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
20 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" 20 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h"
21 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h" 21 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h"
22 #include "chrome/browser/chromeos/profiles/profile_helper.h" 22 #include "chrome/browser/chromeos/profiles/profile_helper.h"
23 #include "chrome/browser/chromeos/settings/cros_settings.h" 23 #include "chrome/browser/chromeos/settings/cros_settings.h"
24 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" 24 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h"
25 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" 25 #include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h"
26 #include "chrome/test/base/testing_browser_process.h" 26 #include "chrome/test/base/testing_browser_process.h"
27 #include "chrome/test/base/testing_profile.h" 27 #include "chrome/test/base/testing_profile.h"
28 #include "chrome/test/base/testing_profile_manager.h" 28 #include "chrome/test/base/testing_profile_manager.h"
29 #include "chromeos/chromeos_switches.h" 29 #include "chromeos/chromeos_switches.h"
30 #include "chromeos/cryptohome/cryptohome_parameters.h" 30 #include "chromeos/cryptohome/cryptohome_parameters.h"
31 #include "chromeos/cryptohome/homedir_methods.h" 31 #include "chromeos/cryptohome/homedir_methods.h"
32 #include "chromeos/cryptohome/mock_async_method_caller.h" 32 #include "chromeos/cryptohome/mock_async_method_caller.h"
33 #include "chromeos/cryptohome/mock_homedir_methods.h" 33 #include "chromeos/cryptohome/mock_homedir_methods.h"
34 #include "chromeos/cryptohome/system_salt_getter.h" 34 #include "chromeos/cryptohome/system_salt_getter.h"
35 #include "chromeos/dbus/cros_disks_client.h" 35 #include "chromeos/dbus/cros_disks_client.h"
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 ASSERT_TRUE(profile_manager_->SetUp()); 427 ASSERT_TRUE(profile_manager_->SetUp());
428 428
429 FailOnLoginSuccess(); // Set failing on success as the default... 429 FailOnLoginSuccess(); // Set failing on success as the default...
430 AuthFailure failure = AuthFailure(AuthFailure::OWNER_REQUIRED); 430 AuthFailure failure = AuthFailure(AuthFailure::OWNER_REQUIRED);
431 ExpectLoginFailure(failure); 431 ExpectLoginFailure(failure);
432 432
433 // Set up state as though a cryptohome mount attempt has occurred 433 // Set up state as though a cryptohome mount attempt has occurred
434 // and succeeded but we are in safe mode and the current user is not owner. 434 // and succeeded but we are in safe mode and the current user is not owner.
435 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); 435 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
436 SetOwnerState(false, false); 436 SetOwnerState(false, false);
437 // Remove the real DeviceSettingsProvider and replace it with a stub. 437 ScopedCrosSettingsTestHelper settings_helper(false);
438 CrosSettingsProvider* device_settings_provider = 438 settings_helper.ReplaceProvider(kPolicyMissingMitigationMode);
439 CrosSettings::Get()->GetProvider(chromeos::kReportDeviceVersionInfo); 439 settings_helper.SetBoolean(kPolicyMissingMitigationMode, true);
440 EXPECT_TRUE(device_settings_provider != NULL);
441 EXPECT_TRUE(
442 CrosSettings::Get()->RemoveSettingsProvider(device_settings_provider));
443 StubCrosSettingsProvider stub_settings_provider;
444 CrosSettings::Get()->AddSettingsProvider(&stub_settings_provider);
445 CrosSettings::Get()->SetBoolean(kPolicyMissingMitigationMode, true);
446 440
447 // Initialize login state for this test to verify the login state is changed 441 // Initialize login state for this test to verify the login state is changed
448 // to SAFE_MODE. 442 // to SAFE_MODE.
449 LoginState::Initialize(); 443 LoginState::Initialize();
450 444
451 EXPECT_EQ(CryptohomeAuthenticator::CONTINUE, 445 EXPECT_EQ(CryptohomeAuthenticator::CONTINUE,
452 SetAndResolveState(auth_.get(), state_.release())); 446 SetAndResolveState(auth_.get(), state_.release()));
453 EXPECT_TRUE(LoginState::Get()->IsInSafeMode()); 447 EXPECT_TRUE(LoginState::Get()->IsInSafeMode());
454 448
455 // Flush all the pending operations. The operations should induce an owner 449 // Flush all the pending operations. The operations should induce an owner
456 // verification. 450 // verification.
457 device_settings_test_helper_.Flush(); 451 device_settings_test_helper_.Flush();
458 452
459 state_.reset(new TestAttemptState(user_context_, false)); 453 state_.reset(new TestAttemptState(user_context_, false));
460 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); 454 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
461 455
462 // The owner key util should not have found the owner key, so login should 456 // The owner key util should not have found the owner key, so login should
463 // not be allowed. 457 // not be allowed.
464 EXPECT_EQ(CryptohomeAuthenticator::OWNER_REQUIRED, 458 EXPECT_EQ(CryptohomeAuthenticator::OWNER_REQUIRED,
465 SetAndResolveState(auth_.get(), state_.release())); 459 SetAndResolveState(auth_.get(), state_.release()));
466 EXPECT_TRUE(LoginState::Get()->IsInSafeMode()); 460 EXPECT_TRUE(LoginState::Get()->IsInSafeMode());
467 461
468 // Unset global objects used by this test. 462 // Unset global objects used by this test.
469 fake_cryptohome_client_->set_unmount_result(true); 463 fake_cryptohome_client_->set_unmount_result(true);
470 LoginState::Shutdown(); 464 LoginState::Shutdown();
471 EXPECT_TRUE(
472 CrosSettings::Get()->RemoveSettingsProvider(&stub_settings_provider));
473 CrosSettings::Get()->AddSettingsProvider(device_settings_provider);
474 } 465 }
475 466
476 // Test the case that login switches to SafeMode and the Owner logs in, which 467 // Test the case that login switches to SafeMode and the Owner logs in, which
477 // should lead to a successful login. 468 // should lead to a successful login.
478 TEST_F(CryptohomeAuthenticatorTest, ResolveOwnerNeededSuccess) { 469 TEST_F(CryptohomeAuthenticatorTest, ResolveOwnerNeededSuccess) {
479 crypto::ScopedTestNSSChromeOSUser test_user_db(user_context_.GetUserIDHash()); 470 crypto::ScopedTestNSSChromeOSUser test_user_db(user_context_.GetUserIDHash());
480 owner_key_util_->SetPublicKey(GetOwnerPublicKey()); 471 owner_key_util_->SetPublicKey(GetOwnerPublicKey());
481 472
482 crypto::ScopedPK11Slot user_slot( 473 crypto::ScopedPK11Slot user_slot(
483 crypto::GetPublicSlotForChromeOSUser(user_context_.GetUserIDHash())); 474 crypto::GetPublicSlotForChromeOSUser(user_context_.GetUserIDHash()));
484 CreateOwnerKeyInSlot(user_slot.get()); 475 CreateOwnerKeyInSlot(user_slot.get());
485 476
486 profile_manager_.reset( 477 profile_manager_.reset(
487 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); 478 new TestingProfileManager(TestingBrowserProcess::GetGlobal()));
488 ASSERT_TRUE(profile_manager_->SetUp()); 479 ASSERT_TRUE(profile_manager_->SetUp());
489 480
490 ExpectLoginSuccess(user_context_); 481 ExpectLoginSuccess(user_context_);
491 482
492 // Set up state as though a cryptohome mount attempt has occurred 483 // Set up state as though a cryptohome mount attempt has occurred
493 // and succeeded but we are in safe mode and the current user is not owner. 484 // and succeeded but we are in safe mode and the current user is not owner.
494 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); 485 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
495 SetOwnerState(false, false); 486 SetOwnerState(false, false);
496 // Remove the real DeviceSettingsProvider and replace it with a stub. 487 ScopedCrosSettingsTestHelper settings_helper(false);
497 CrosSettingsProvider* device_settings_provider = 488 settings_helper.ReplaceProvider(kPolicyMissingMitigationMode);
498 CrosSettings::Get()->GetProvider(chromeos::kReportDeviceVersionInfo); 489 settings_helper.SetBoolean(kPolicyMissingMitigationMode, true);
499 EXPECT_TRUE(device_settings_provider != NULL);
500 EXPECT_TRUE(
501 CrosSettings::Get()->RemoveSettingsProvider(device_settings_provider));
502 StubCrosSettingsProvider stub_settings_provider;
503 CrosSettings::Get()->AddSettingsProvider(&stub_settings_provider);
504 CrosSettings::Get()->SetBoolean(kPolicyMissingMitigationMode, true);
505 490
506 // Initialize login state for this test to verify the login state is changed 491 // Initialize login state for this test to verify the login state is changed
507 // to SAFE_MODE. 492 // to SAFE_MODE.
508 LoginState::Initialize(); 493 LoginState::Initialize();
509 494
510 EXPECT_EQ(CryptohomeAuthenticator::CONTINUE, 495 EXPECT_EQ(CryptohomeAuthenticator::CONTINUE,
511 SetAndResolveState(auth_.get(), state_.release())); 496 SetAndResolveState(auth_.get(), state_.release()));
512 EXPECT_TRUE(LoginState::Get()->IsInSafeMode()); 497 EXPECT_TRUE(LoginState::Get()->IsInSafeMode());
513 498
514 // Flush all the pending operations. The operations should induce an owner 499 // Flush all the pending operations. The operations should induce an owner
515 // verification. 500 // verification.
516 device_settings_test_helper_.Flush(); 501 device_settings_test_helper_.Flush();
517 502
518 state_.reset(new TestAttemptState(user_context_, false)); 503 state_.reset(new TestAttemptState(user_context_, false));
519 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); 504 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
520 505
521 // The owner key util should find the owner key, so login should succeed. 506 // The owner key util should find the owner key, so login should succeed.
522 EXPECT_EQ(CryptohomeAuthenticator::OFFLINE_LOGIN, 507 EXPECT_EQ(CryptohomeAuthenticator::OFFLINE_LOGIN,
523 SetAndResolveState(auth_.get(), state_.release())); 508 SetAndResolveState(auth_.get(), state_.release()));
524 EXPECT_TRUE(LoginState::Get()->IsInSafeMode()); 509 EXPECT_TRUE(LoginState::Get()->IsInSafeMode());
525 510
526 // Unset global objects used by this test. 511 // Unset global objects used by this test.
527 fake_cryptohome_client_->set_unmount_result(true); 512 fake_cryptohome_client_->set_unmount_result(true);
528 LoginState::Shutdown(); 513 LoginState::Shutdown();
529 EXPECT_TRUE(
530 CrosSettings::Get()->RemoveSettingsProvider(&stub_settings_provider));
531 CrosSettings::Get()->AddSettingsProvider(device_settings_provider);
532 } 514 }
533 515
534 TEST_F(CryptohomeAuthenticatorTest, DriveFailedMount) { 516 TEST_F(CryptohomeAuthenticatorTest, DriveFailedMount) {
535 FailOnLoginSuccess(); 517 FailOnLoginSuccess();
536 ExpectLoginFailure(AuthFailure(AuthFailure::COULD_NOT_MOUNT_CRYPTOHOME)); 518 ExpectLoginFailure(AuthFailure(AuthFailure::COULD_NOT_MOUNT_CRYPTOHOME));
537 519
538 // Set up state as though a cryptohome mount attempt has occurred 520 // Set up state as though a cryptohome mount attempt has occurred
539 // and failed. 521 // and failed.
540 state_->PresetCryptohomeStatus(false, cryptohome::MOUNT_ERROR_NONE); 522 state_->PresetCryptohomeStatus(false, cryptohome::MOUNT_ERROR_NONE);
541 SetAttemptState(auth_.get(), state_.release()); 523 SetAttemptState(auth_.get(), state_.release());
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 // salt. 772 // salt.
791 ExpectGetKeyDataExCall( 773 ExpectGetKeyDataExCall(
792 make_scoped_ptr(new int64(Key::KEY_TYPE_SALTED_SHA256)), 774 make_scoped_ptr(new int64(Key::KEY_TYPE_SALTED_SHA256)),
793 scoped_ptr<std::string>()); 775 scoped_ptr<std::string>());
794 776
795 auth_->AuthenticateToLogin(NULL, user_context_); 777 auth_->AuthenticateToLogin(NULL, user_context_);
796 base::RunLoop().Run(); 778 base::RunLoop().Run();
797 } 779 }
798 780
799 } // namespace chromeos 781 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698