Commit 5a1d77cc authored by Roman Sorokin's avatar Roman Sorokin Committed by Commit Bot

DeviceStateMixin: Write owner key file

TBR=xiyuan@chromium.org
CQ-DEPEND=CL:1570024

Bug: 952855
Change-Id: I783e41a3c810764d8118dda3643f2a1964186966
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1572405Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarRoman Sorokin [CET] <rsorokin@chromium.org>
Reviewed-by: default avatarToni Baržić <tbarzic@chromium.org>
Commit-Queue: Roman Sorokin [CET] <rsorokin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#652613}
parent b4973253
...@@ -130,7 +130,7 @@ base::FilePath GetKerberosCredentialsCachePath() { ...@@ -130,7 +130,7 @@ base::FilePath GetKerberosCredentialsCachePath() {
class ExistingUserControllerTest : public policy::DevicePolicyCrosBrowserTest { class ExistingUserControllerTest : public policy::DevicePolicyCrosBrowserTest {
protected: protected:
ExistingUserControllerTest() {} ExistingUserControllerTest() = default;
ExistingUserController* existing_user_controller() { ExistingUserController* existing_user_controller() {
return ExistingUserController::current_controller(); return ExistingUserController::current_controller();
...@@ -141,8 +141,6 @@ class ExistingUserControllerTest : public policy::DevicePolicyCrosBrowserTest { ...@@ -141,8 +141,6 @@ class ExistingUserControllerTest : public policy::DevicePolicyCrosBrowserTest {
} }
void SetUpInProcessBrowserTestFixture() override { void SetUpInProcessBrowserTestFixture() override {
SetUpSessionManager();
DevicePolicyCrosBrowserTest::SetUpInProcessBrowserTestFixture(); DevicePolicyCrosBrowserTest::SetUpInProcessBrowserTestFixture();
mock_login_display_host_ = std::make_unique<MockLoginDisplayHost>(); mock_login_display_host_ = std::make_unique<MockLoginDisplayHost>();
...@@ -150,8 +148,6 @@ class ExistingUserControllerTest : public policy::DevicePolicyCrosBrowserTest { ...@@ -150,8 +148,6 @@ class ExistingUserControllerTest : public policy::DevicePolicyCrosBrowserTest {
SetUpLoginDisplay(); SetUpLoginDisplay();
} }
virtual void SetUpSessionManager() {}
virtual void SetUpLoginDisplay() { virtual void SetUpLoginDisplay() {
EXPECT_CALL(*mock_login_display_host_, GetLoginDisplay()) EXPECT_CALL(*mock_login_display_host_, GetLoginDisplay())
.Times(AnyNumber()) .Times(AnyNumber())
...@@ -164,11 +160,13 @@ class ExistingUserControllerTest : public policy::DevicePolicyCrosBrowserTest { ...@@ -164,11 +160,13 @@ class ExistingUserControllerTest : public policy::DevicePolicyCrosBrowserTest {
} }
void SetUpCommandLine(base::CommandLine* command_line) override { void SetUpCommandLine(base::CommandLine* command_line) override {
policy::DevicePolicyCrosBrowserTest::SetUpCommandLine(command_line);
command_line->AppendSwitch(switches::kLoginManager); command_line->AppendSwitch(switches::kLoginManager);
command_line->AppendSwitch(switches::kForceLoginManagerInTests); command_line->AppendSwitch(switches::kForceLoginManagerInTests);
} }
void SetUpOnMainThread() override { void SetUpOnMainThread() override {
policy::DevicePolicyCrosBrowserTest::SetUpOnMainThread();
existing_user_controller_ = std::make_unique<ExistingUserController>(); existing_user_controller_ = std::make_unique<ExistingUserController>();
EXPECT_CALL(*mock_login_display_host_, GetExistingUserController()) EXPECT_CALL(*mock_login_display_host_, GetExistingUserController())
.Times(AnyNumber()) .Times(AnyNumber())
...@@ -278,28 +276,17 @@ IN_PROC_BROWSER_TEST_F(ExistingUserControllerTest, DISABLED_ExistingUserLogin) { ...@@ -278,28 +276,17 @@ IN_PROC_BROWSER_TEST_F(ExistingUserControllerTest, DISABLED_ExistingUserLogin) {
// started. // started.
class ExistingUserControllerUntrustedTest : public ExistingUserControllerTest { class ExistingUserControllerUntrustedTest : public ExistingUserControllerTest {
public: public:
ExistingUserControllerUntrustedTest(); ExistingUserControllerUntrustedTest() = default;
void SetUpInProcessBrowserTestFixture() override;
void SetUpSessionManager() override; void SetUpInProcessBrowserTestFixture() override {
ExistingUserControllerTest::SetUpInProcessBrowserTestFixture();
ExpectLoginFailure();
}
private: private:
DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerUntrustedTest); DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerUntrustedTest);
}; };
ExistingUserControllerUntrustedTest::ExistingUserControllerUntrustedTest() {}
void ExistingUserControllerUntrustedTest::SetUpInProcessBrowserTestFixture() {
ExistingUserControllerTest::SetUpInProcessBrowserTestFixture();
ExpectLoginFailure();
}
void ExistingUserControllerUntrustedTest::SetUpSessionManager() {
InstallOwnerKey();
}
IN_PROC_BROWSER_TEST_F(ExistingUserControllerUntrustedTest, IN_PROC_BROWSER_TEST_F(ExistingUserControllerUntrustedTest,
ExistingUserLoginForbidden) { ExistingUserLoginForbidden) {
UserContext user_context(user_manager::UserType::USER_TYPE_REGULAR, UserContext user_context(user_manager::UserType::USER_TYPE_REGULAR,
...@@ -385,9 +372,8 @@ class ExistingUserControllerPublicSessionTest ...@@ -385,9 +372,8 @@ class ExistingUserControllerPublicSessionTest
} }
} }
void SetUpSessionManager() override { void SetUpInProcessBrowserTestFixture() override {
InstallOwnerKey(); ExistingUserControllerTest::SetUpInProcessBrowserTestFixture();
// Setup the device policy. // Setup the device policy.
em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
em::DeviceLocalAccountInfoProto* account = em::DeviceLocalAccountInfoProto* account =
...@@ -1034,9 +1020,10 @@ class ExistingUserControllerSavePasswordHashTest ...@@ -1034,9 +1020,10 @@ class ExistingUserControllerSavePasswordHashTest
: public ExistingUserControllerTest { : public ExistingUserControllerTest {
public: public:
ExistingUserControllerSavePasswordHashTest() = default; ExistingUserControllerSavePasswordHashTest() = default;
~ExistingUserControllerSavePasswordHashTest() override = default;
void SetUpSessionManager() override { void SetUpInProcessBrowserTestFixture() override {
InstallOwnerKey(); ExistingUserControllerTest::SetUpInProcessBrowserTestFixture();
RefreshDevicePolicy(); RefreshDevicePolicy();
} }
}; };
......
...@@ -4,11 +4,13 @@ ...@@ -4,11 +4,13 @@
#include "chrome/browser/chromeos/login/test/device_state_mixin.h" #include "chrome/browser/chromeos/login/test/device_state_mixin.h"
#include "base/numerics/safe_conversions.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_paths.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chromeos/constants/chromeos_paths.h" #include "chromeos/constants/chromeos_paths.h"
#include "components/policy/core/common/cloud/policy_builder.h"
#include "components/policy/proto/install_attributes.pb.h" #include "components/policy/proto/install_attributes.pb.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
...@@ -66,6 +68,7 @@ void DeviceStateMixin::SetDeviceState() { ...@@ -66,6 +68,7 @@ void DeviceStateMixin::SetDeviceState() {
is_setup_ = true; is_setup_ = true;
WriteInstallAttrFile(); WriteInstallAttrFile();
WriteOwnerKey();
} }
void DeviceStateMixin::WriteInstallAttrFile() { void DeviceStateMixin::WriteInstallAttrFile() {
...@@ -102,8 +105,31 @@ void DeviceStateMixin::WriteInstallAttrFile() { ...@@ -102,8 +105,31 @@ void DeviceStateMixin::WriteInstallAttrFile() {
std::string blob; std::string blob;
CHECK(BuildInstallAttributes(device_mode, domain, realm, kFakeDeviceId) CHECK(BuildInstallAttributes(device_mode, domain, realm, kFakeDeviceId)
.SerializeToString(&blob)); .SerializeToString(&blob));
CHECK_EQ(static_cast<int>(blob.size()), CHECK_EQ(base::checked_cast<int>(blob.length()),
base::WriteFile(install_attrs_file, blob.data(), blob.size())); base::WriteFile(install_attrs_file, blob.data(), blob.length()));
}
void DeviceStateMixin::WriteOwnerKey() {
switch (state_) {
case DeviceStateMixin::State::BEFORE_OOBE:
case DeviceStateMixin::State::OOBE_COMPLETED_UNOWNED:
case DeviceStateMixin::State::OOBE_COMPLETED_ACTIVE_DIRECTORY_ENROLLED:
return;
case DeviceStateMixin::State::OOBE_COMPLETED_CLOUD_ENROLLED:
case DeviceStateMixin::State::OOBE_COMPLETED_CONSUMER_OWNED:
case DeviceStateMixin::State::OOBE_COMPLETED_DEMO_MODE:
base::FilePath user_data_dir;
base::FilePath owner_key_file;
CHECK(base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir));
owner_key_file = user_data_dir.Append("stub_owner.key");
const std::string owner_key_bits =
policy::PolicyBuilder::GetPublicTestKeyAsString();
CHECK(!owner_key_bits.empty());
CHECK_EQ(base::checked_cast<int>(owner_key_bits.length()),
base::WriteFile(owner_key_file, owner_key_bits.data(),
owner_key_bits.length()));
break;
}
} }
DeviceStateMixin::~DeviceStateMixin() = default; DeviceStateMixin::~DeviceStateMixin() = default;
......
...@@ -38,6 +38,7 @@ class DeviceStateMixin : public InProcessBrowserTestMixin { ...@@ -38,6 +38,7 @@ class DeviceStateMixin : public InProcessBrowserTestMixin {
private: private:
void SetDeviceState(); void SetDeviceState();
void WriteInstallAttrFile(); void WriteInstallAttrFile();
void WriteOwnerKey();
State state_; State state_;
std::string domain_; std::string domain_;
......
...@@ -542,8 +542,6 @@ class WebviewClientCertsLoginTest : public WebviewLoginTest { ...@@ -542,8 +542,6 @@ class WebviewClientCertsLoginTest : public WebviewLoginTest {
} }
void SetUpInProcessBrowserTestFixture() override { void SetUpInProcessBrowserTestFixture() override {
device_policy_test_helper_.InstallOwnerKey();
// Override FakeSessionManagerClient. This will be shut down by the browser. // Override FakeSessionManagerClient. This will be shut down by the browser.
chromeos::SessionManagerClient::InitializeFakeInMemory(); chromeos::SessionManagerClient::InitializeFakeInMemory();
FakeSessionManagerClient::Get()->set_device_policy( FakeSessionManagerClient::Get()->set_device_policy(
...@@ -899,8 +897,6 @@ class WebviewProxyAuthLoginTest : public WebviewLoginTest { ...@@ -899,8 +897,6 @@ class WebviewProxyAuthLoginTest : public WebviewLoginTest {
void SetUpInProcessBrowserTestFixture() override { void SetUpInProcessBrowserTestFixture() override {
WebviewLoginTest::SetUpInProcessBrowserTestFixture(); WebviewLoginTest::SetUpInProcessBrowserTestFixture();
device_policy_test_helper_.InstallOwnerKey();
FakeSessionManagerClient::Get()->set_device_policy( FakeSessionManagerClient::Get()->set_device_policy(
device_policy_builder()->GetBlob()); device_policy_builder()->GetBlob());
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h" #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h"
#include "chrome/browser/chromeos/policy/device_policy_builder.h" #include "chrome/browser/chromeos/policy/device_policy_builder.h"
#include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h"
#include "chrome/common/chrome_paths.h"
#include "chromeos/constants/chromeos_switches.h" #include "chromeos/constants/chromeos_switches.h"
#include "chromeos/cryptohome/cryptohome_parameters.h" #include "chromeos/cryptohome/cryptohome_parameters.h"
#include "chromeos/dbus/auth_policy/fake_auth_policy_client.h" #include "chromeos/dbus/auth_policy/fake_auth_policy_client.h"
...@@ -48,6 +49,10 @@ namespace { ...@@ -48,6 +49,10 @@ namespace {
// Creates policy key file for the user specified in |user_policy|. // Creates policy key file for the user specified in |user_policy|.
void SetUserKeys(const policy::UserPolicyBuilder& user_policy) { void SetUserKeys(const policy::UserPolicyBuilder& user_policy) {
base::FilePath user_data_dir;
if (base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir))
chromeos::dbus_paths::RegisterStubPathOverrides(user_data_dir);
const AccountId account_id = const AccountId account_id =
AccountId::FromUserEmail(user_policy.policy_data().username()); AccountId::FromUserEmail(user_policy.policy_data().username());
base::FilePath user_keys_dir; base::FilePath user_keys_dir;
...@@ -123,7 +128,6 @@ void AffiliationTestHelper::SetDeviceAffiliationIDs( ...@@ -123,7 +128,6 @@ void AffiliationTestHelper::SetDeviceAffiliationIDs(
if (management_type_ != ManagementType::kActiveDirectory) { if (management_type_ != ManagementType::kActiveDirectory) {
// Create keys and sign policy. Note that Active Directory policy is // Create keys and sign policy. Note that Active Directory policy is
// unsigned. // unsigned.
test_helper->InstallOwnerKey();
device_policy->SetDefaultSigningKey(); device_policy->SetDefaultSigningKey();
} }
device_policy->Build(); device_policy->Build();
......
...@@ -71,15 +71,6 @@ void DevicePolicyCrosBrowserTest::SetUp() { ...@@ -71,15 +71,6 @@ void DevicePolicyCrosBrowserTest::SetUp() {
chromeos::MixinBasedInProcessBrowserTest::SetUp(); chromeos::MixinBasedInProcessBrowserTest::SetUp();
} }
void DevicePolicyCrosBrowserTest::SetUpInProcessBrowserTestFixture() {
InstallOwnerKey();
chromeos::MixinBasedInProcessBrowserTest::SetUpInProcessBrowserTestFixture();
}
void DevicePolicyCrosBrowserTest::InstallOwnerKey() {
test_helper_.InstallOwnerKey();
}
void DevicePolicyCrosBrowserTest::RefreshDevicePolicy() { void DevicePolicyCrosBrowserTest::RefreshDevicePolicy() {
// Reset the key to its original state. // Reset the key to its original state.
device_policy()->SetDefaultSigningKey(); device_policy()->SetDefaultSigningKey();
......
...@@ -48,10 +48,6 @@ class DevicePolicyCrosBrowserTest ...@@ -48,10 +48,6 @@ class DevicePolicyCrosBrowserTest
// MixinBasedInProcessBrowserTest: // MixinBasedInProcessBrowserTest:
void SetUp() override; void SetUp() override;
void SetUpInProcessBrowserTestFixture() override;
// Writes the owner key to disk. To be called before installing a policy.
void InstallOwnerKey();
// Reinstalls |device_policy_| as the policy (to be used when it was // Reinstalls |device_policy_| as the policy (to be used when it was
// recently changed). // recently changed).
......
...@@ -392,7 +392,6 @@ class DisplayResolutionBootTest ...@@ -392,7 +392,6 @@ class DisplayResolutionBootTest
void SetUpInProcessBrowserTestFixture() override { void SetUpInProcessBrowserTestFixture() override {
// Override FakeSessionManagerClient. This will be shut down by the browser. // Override FakeSessionManagerClient. This will be shut down by the browser.
chromeos::SessionManagerClient::InitializeFakeInMemory(); chromeos::SessionManagerClient::InitializeFakeInMemory();
test_helper_.InstallOwnerKey();
ash::DisplayConfigurationController::DisableAnimatorForTest(); ash::DisplayConfigurationController::DisableAnimatorForTest();
chromeos::MixinBasedInProcessBrowserTest:: chromeos::MixinBasedInProcessBrowserTest::
SetUpInProcessBrowserTestFixture(); SetUpInProcessBrowserTestFixture();
......
...@@ -265,7 +265,6 @@ class DisplayRotationBootTest ...@@ -265,7 +265,6 @@ class DisplayRotationBootTest
void SetUpInProcessBrowserTestFixture() override { void SetUpInProcessBrowserTestFixture() override {
// Override FakeSessionManagerClient. This will be shut down by the browser. // Override FakeSessionManagerClient. This will be shut down by the browser.
chromeos::SessionManagerClient::InitializeFakeInMemory(); chromeos::SessionManagerClient::InitializeFakeInMemory();
test_helper_.InstallOwnerKey();
ash::DisplayConfigurationController::DisableAnimatorForTest(); ash::DisplayConfigurationController::DisableAnimatorForTest();
chromeos::MixinBasedInProcessBrowserTest:: chromeos::MixinBasedInProcessBrowserTest::
SetUpInProcessBrowserTestFixture(); SetUpInProcessBrowserTestFixture();
......
...@@ -131,8 +131,6 @@ void DeviceDisablingTest::SetUpInProcessBrowserTestFixture() { ...@@ -131,8 +131,6 @@ void DeviceDisablingTest::SetUpInProcessBrowserTestFixture() {
chromeos::SessionManagerClient::InitializeFakeInMemory(); chromeos::SessionManagerClient::InitializeFakeInMemory();
OobeBaseTest::SetUpInProcessBrowserTestFixture(); OobeBaseTest::SetUpInProcessBrowserTestFixture();
test_helper_.InstallOwnerKey();
} }
void DeviceDisablingTest::SetUpOnMainThread() { void DeviceDisablingTest::SetUpOnMainThread() {
......
...@@ -147,6 +147,7 @@ class EnterpriseDeviceAttributesTest ...@@ -147,6 +147,7 @@ class EnterpriseDeviceAttributesTest
device_affiliation_ids.insert(kAffiliationID); device_affiliation_ids.insert(kAffiliationID);
ASSERT_NO_FATAL_FAILURE(affiliation_helper.SetDeviceAffiliationIDs( ASSERT_NO_FATAL_FAILURE(affiliation_helper.SetDeviceAffiliationIDs(
&test_helper_, device_affiliation_ids)); &test_helper_, device_affiliation_ids));
test_helper_.InstallOwnerKey();
std::set<std::string> user_affiliation_ids; std::set<std::string> user_affiliation_ids;
if (GetParam().affiliated) { if (GetParam().affiliated) {
......
...@@ -104,6 +104,7 @@ void PlatformKeysTestBase::SetUpInProcessBrowserTestFixture() { ...@@ -104,6 +104,7 @@ void PlatformKeysTestBase::SetUpInProcessBrowserTestFixture() {
device_affiliation_ids.insert(kAffiliationID); device_affiliation_ids.insert(kAffiliationID);
ASSERT_NO_FATAL_FAILURE(affiliation_helper.SetDeviceAffiliationIDs( ASSERT_NO_FATAL_FAILURE(affiliation_helper.SetDeviceAffiliationIDs(
&device_policy_test_helper_, device_affiliation_ids)); &device_policy_test_helper_, device_affiliation_ids));
device_policy_test_helper_.InstallOwnerKey();
install_attributes_.Get()->SetCloudManaged( install_attributes_.Get()->SetCloudManaged(
policy::PolicyBuilder::kFakeDomain, policy::PolicyBuilder::kFakeDomain,
policy::PolicyBuilder::kFakeDeviceId); policy::PolicyBuilder::kFakeDeviceId);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment