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

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: Rearrange device settings list. 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/fake_owner_settings_service.h"
20 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" 21 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h"
21 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h" 22 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h"
22 #include "chrome/browser/chromeos/profiles/profile_helper.h" 23 #include "chrome/browser/chromeos/profiles/profile_helper.h"
23 #include "chrome/browser/chromeos/settings/cros_settings.h" 24 #include "chrome/browser/chromeos/settings/cros_settings.h"
24 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" 25 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h"
25 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" 26 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h"
26 #include "chrome/test/base/testing_browser_process.h" 27 #include "chrome/test/base/testing_browser_process.h"
27 #include "chrome/test/base/testing_profile.h" 28 #include "chrome/test/base/testing_profile.h"
28 #include "chrome/test/base/testing_profile_manager.h" 29 #include "chrome/test/base/testing_profile_manager.h"
29 #include "chromeos/chromeos_switches.h" 30 #include "chromeos/chromeos_switches.h"
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 user_context_.SetUserIDHash("me_nowhere_com_hash"); 143 user_context_.SetUserIDHash("me_nowhere_com_hash");
143 const user_manager::User* user = 144 const user_manager::User* user =
144 user_manager_->AddUser(user_context_.GetUserID()); 145 user_manager_->AddUser(user_context_.GetUserID());
145 profile_.set_profile_name(user_context_.GetUserID()); 146 profile_.set_profile_name(user_context_.GetUserID());
146 147
147 ProfileHelper::Get()->SetUserToProfileMappingForTesting(user, &profile_); 148 ProfileHelper::Get()->SetUserToProfileMappingForTesting(user, &profile_);
148 149
149 CreateTransformedKey(Key::KEY_TYPE_SALTED_SHA256_TOP_HALF, 150 CreateTransformedKey(Key::KEY_TYPE_SALTED_SHA256_TOP_HALF,
150 SystemSaltGetter::ConvertRawSaltToHexString( 151 SystemSaltGetter::ConvertRawSaltToHexString(
151 FakeCryptohomeClient::GetStubSystemSalt())); 152 FakeCryptohomeClient::GetStubSystemSalt()));
153
154 owner_settings_service_.reset(
155 new chromeos::FakeOwnerSettingsService(&profile_, owner_key_util_));
152 } 156 }
153 157
154 ~CryptohomeAuthenticatorTest() override {} 158 ~CryptohomeAuthenticatorTest() override {}
155 159
156 void SetUp() override { 160 void SetUp() override {
157 base::CommandLine::ForCurrentProcess()->AppendSwitch( 161 base::CommandLine::ForCurrentProcess()->AppendSwitch(
158 switches::kLoginManager); 162 switches::kLoginManager);
159 163
160 mock_caller_ = new cryptohome::MockAsyncMethodCaller; 164 mock_caller_ = new cryptohome::MockAsyncMethodCaller;
161 cryptohome::AsyncMethodCaller::InitializeForTesting(mock_caller_); 165 cryptohome::AsyncMethodCaller::InitializeForTesting(mock_caller_);
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 cryptohome::MockAsyncMethodCaller* mock_caller_; 335 cryptohome::MockAsyncMethodCaller* mock_caller_;
332 cryptohome::MockHomedirMethods* mock_homedir_methods_; 336 cryptohome::MockHomedirMethods* mock_homedir_methods_;
333 337
334 MockAuthStatusConsumer consumer_; 338 MockAuthStatusConsumer consumer_;
335 339
336 scoped_refptr<CryptohomeAuthenticator> auth_; 340 scoped_refptr<CryptohomeAuthenticator> auth_;
337 scoped_ptr<TestAttemptState> state_; 341 scoped_ptr<TestAttemptState> state_;
338 FakeCryptohomeClient* fake_cryptohome_client_; 342 FakeCryptohomeClient* fake_cryptohome_client_;
339 343
340 scoped_refptr<ownership::MockOwnerKeyUtil> owner_key_util_; 344 scoped_refptr<ownership::MockOwnerKeyUtil> owner_key_util_;
345 scoped_ptr<chromeos::FakeOwnerSettingsService> owner_settings_service_;
341 346
342 private: 347 private:
343 void InvokeGetDataExCallback( 348 void InvokeGetDataExCallback(
344 const cryptohome::HomedirMethods::GetKeyDataCallback& callback) { 349 const cryptohome::HomedirMethods::GetKeyDataCallback& callback) {
345 callback.Run(true /* success */, 350 callback.Run(true /* success */,
346 cryptohome::MOUNT_ERROR_NONE, 351 cryptohome::MOUNT_ERROR_NONE,
347 key_definitions_); 352 key_definitions_);
348 } 353 }
349 }; 354 };
350 355
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 FailOnLoginSuccess(); // Set failing on success as the default... 434 FailOnLoginSuccess(); // Set failing on success as the default...
430 AuthFailure failure = AuthFailure(AuthFailure::OWNER_REQUIRED); 435 AuthFailure failure = AuthFailure(AuthFailure::OWNER_REQUIRED);
431 ExpectLoginFailure(failure); 436 ExpectLoginFailure(failure);
432 437
433 // Set up state as though a cryptohome mount attempt has occurred 438 // 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. 439 // and succeeded but we are in safe mode and the current user is not owner.
435 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); 440 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
436 SetOwnerState(false, false); 441 SetOwnerState(false, false);
437 // Remove the real DeviceSettingsProvider and replace it with a stub. 442 // Remove the real DeviceSettingsProvider and replace it with a stub.
438 CrosSettingsProvider* device_settings_provider = 443 CrosSettingsProvider* device_settings_provider =
439 CrosSettings::Get()->GetProvider(chromeos::kReportDeviceVersionInfo); 444 CrosSettings::Get()->GetProvider(kPolicyMissingMitigationMode);
440 EXPECT_TRUE(device_settings_provider != NULL); 445 EXPECT_TRUE(device_settings_provider != NULL);
441 EXPECT_TRUE( 446 EXPECT_TRUE(
442 CrosSettings::Get()->RemoveSettingsProvider(device_settings_provider)); 447 CrosSettings::Get()->RemoveSettingsProvider(device_settings_provider));
443 StubCrosSettingsProvider stub_settings_provider; 448 StubCrosSettingsProvider stub_settings_provider;
444 CrosSettings::Get()->AddSettingsProvider(&stub_settings_provider); 449 CrosSettings::Get()->AddSettingsProvider(&stub_settings_provider);
445 CrosSettings::Get()->SetBoolean(kPolicyMissingMitigationMode, true); 450 owner_settings_service_->SetBoolean(kPolicyMissingMitigationMode, true);
446 451
447 // Initialize login state for this test to verify the login state is changed 452 // Initialize login state for this test to verify the login state is changed
448 // to SAFE_MODE. 453 // to SAFE_MODE.
449 LoginState::Initialize(); 454 LoginState::Initialize();
450 455
451 EXPECT_EQ(CryptohomeAuthenticator::CONTINUE, 456 EXPECT_EQ(CryptohomeAuthenticator::CONTINUE,
452 SetAndResolveState(auth_.get(), state_.release())); 457 SetAndResolveState(auth_.get(), state_.release()));
453 EXPECT_TRUE(LoginState::Get()->IsInSafeMode()); 458 EXPECT_TRUE(LoginState::Get()->IsInSafeMode());
454 459
455 // Flush all the pending operations. The operations should induce an owner 460 // Flush all the pending operations. The operations should induce an owner
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 ASSERT_TRUE(profile_manager_->SetUp()); 493 ASSERT_TRUE(profile_manager_->SetUp());
489 494
490 ExpectLoginSuccess(user_context_); 495 ExpectLoginSuccess(user_context_);
491 496
492 // Set up state as though a cryptohome mount attempt has occurred 497 // 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. 498 // and succeeded but we are in safe mode and the current user is not owner.
494 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); 499 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
495 SetOwnerState(false, false); 500 SetOwnerState(false, false);
496 // Remove the real DeviceSettingsProvider and replace it with a stub. 501 // Remove the real DeviceSettingsProvider and replace it with a stub.
497 CrosSettingsProvider* device_settings_provider = 502 CrosSettingsProvider* device_settings_provider =
498 CrosSettings::Get()->GetProvider(chromeos::kReportDeviceVersionInfo); 503 CrosSettings::Get()->GetProvider(kPolicyMissingMitigationMode);
499 EXPECT_TRUE(device_settings_provider != NULL); 504 EXPECT_TRUE(device_settings_provider != NULL);
500 EXPECT_TRUE( 505 EXPECT_TRUE(
501 CrosSettings::Get()->RemoveSettingsProvider(device_settings_provider)); 506 CrosSettings::Get()->RemoveSettingsProvider(device_settings_provider));
502 StubCrosSettingsProvider stub_settings_provider; 507 StubCrosSettingsProvider stub_settings_provider;
503 CrosSettings::Get()->AddSettingsProvider(&stub_settings_provider); 508 CrosSettings::Get()->AddSettingsProvider(&stub_settings_provider);
504 CrosSettings::Get()->SetBoolean(kPolicyMissingMitigationMode, true); 509 owner_settings_service_->SetBoolean(kPolicyMissingMitigationMode, true);
505 510
506 // Initialize login state for this test to verify the login state is changed 511 // Initialize login state for this test to verify the login state is changed
507 // to SAFE_MODE. 512 // to SAFE_MODE.
508 LoginState::Initialize(); 513 LoginState::Initialize();
509 514
510 EXPECT_EQ(CryptohomeAuthenticator::CONTINUE, 515 EXPECT_EQ(CryptohomeAuthenticator::CONTINUE,
511 SetAndResolveState(auth_.get(), state_.release())); 516 SetAndResolveState(auth_.get(), state_.release()));
512 EXPECT_TRUE(LoginState::Get()->IsInSafeMode()); 517 EXPECT_TRUE(LoginState::Get()->IsInSafeMode());
513 518
514 // Flush all the pending operations. The operations should induce an owner 519 // Flush all the pending operations. The operations should induce an owner
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 // salt. 795 // salt.
791 ExpectGetKeyDataExCall( 796 ExpectGetKeyDataExCall(
792 make_scoped_ptr(new int64(Key::KEY_TYPE_SALTED_SHA256)), 797 make_scoped_ptr(new int64(Key::KEY_TYPE_SALTED_SHA256)),
793 scoped_ptr<std::string>()); 798 scoped_ptr<std::string>());
794 799
795 auth_->AuthenticateToLogin(NULL, user_context_); 800 auth_->AuthenticateToLogin(NULL, user_context_);
796 base::RunLoop().Run(); 801 base::RunLoop().Run();
797 } 802 }
798 803
799 } // namespace chromeos 804 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698