Commit 896c66cf authored by Aga Wronska's avatar Aga Wronska Committed by Commit Bot

Clear requisition string if demo mode setup fails.

Change-Id: I9f0b101c57bcba075149a876e9d74e6fca721788
Reviewed-on: https://chromium-review.googlesource.com/1235374Reviewed-by: default avatarSergey Poromov <poromov@chromium.org>
Reviewed-by: default avatarMichael Giuffrida <michaelpg@chromium.org>
Commit-Queue: Aga Wronska <agawronska@chromium.org>
Cr-Commit-Position: refs/heads/master@{#594883}
parent ed3f1cda
...@@ -136,6 +136,14 @@ void DemoSetupController::RegisterLocalStatePrefs( ...@@ -136,6 +136,14 @@ void DemoSetupController::RegisterLocalStatePrefs(
static_cast<int>(DemoSession::DemoModeConfig::kNone)); static_cast<int>(DemoSession::DemoModeConfig::kNone));
} }
// static
void DemoSetupController::ClearDemoRequisition(
policy::DeviceCloudPolicyManagerChromeOS* policy_manager) {
if (policy_manager->GetDeviceRequisition() == kDemoRequisition) {
policy_manager->SetDeviceRequisition(std::string());
}
}
// static // static
bool DemoSetupController::IsDemoModeAllowed() { bool DemoSetupController::IsDemoModeAllowed() {
// Demo mode is only allowed on devices that support ARC++. // Demo mode is only allowed on devices that support ARC++.
...@@ -230,10 +238,12 @@ void DemoSetupController::OnDemoResourcesCrOSComponentLoaded( ...@@ -230,10 +238,12 @@ void DemoSetupController::OnDemoResourcesCrOSComponentLoaded(
return; return;
} }
policy::BrowserPolicyConnectorChromeOS* connector = policy::DeviceCloudPolicyManagerChromeOS* policy_manager =
g_browser_process->platform_part()->browser_policy_connector_chromeos(); g_browser_process->platform_part()
connector->GetDeviceCloudPolicyManager()->SetDeviceRequisition( ->browser_policy_connector_chromeos()
kDemoRequisition); ->GetDeviceCloudPolicyManager();
DCHECK(policy_manager->GetDeviceRequisition().empty());
policy_manager->SetDeviceRequisition(kDemoRequisition);
policy::EnrollmentConfig config; policy::EnrollmentConfig config;
config.mode = policy::EnrollmentConfig::MODE_ATTESTATION; config.mode = policy::EnrollmentConfig::MODE_ATTESTATION;
config.management_domain = DemoSetupController::kDemoModeDomain; config.management_domain = DemoSetupController::kDemoModeDomain;
...@@ -422,6 +432,7 @@ void DemoSetupController::Reset() { ...@@ -422,6 +432,7 @@ void DemoSetupController::Reset() {
DCHECK_NE(demo_config_, DemoSession::DemoModeConfig::kNone); DCHECK_NE(demo_config_, DemoSession::DemoModeConfig::kNone);
DCHECK_NE(demo_config_ == DemoSession::DemoModeConfig::kOffline, DCHECK_NE(demo_config_ == DemoSession::DemoModeConfig::kOffline,
policy_dir_.empty()); policy_dir_.empty());
// |demo_config_| is not reset here, because it is needed for retrying setup. // |demo_config_| is not reset here, because it is needed for retrying setup.
enrollment_helper_.reset(); enrollment_helper_.reset();
policy_dir_.clear(); policy_dir_.clear();
...@@ -429,6 +440,11 @@ void DemoSetupController::Reset() { ...@@ -429,6 +440,11 @@ void DemoSetupController::Reset() {
device_local_account_policy_store_->RemoveObserver(this); device_local_account_policy_store_->RemoveObserver(this);
device_local_account_policy_store_ = nullptr; device_local_account_policy_store_ = nullptr;
} }
policy::DeviceCloudPolicyManagerChromeOS* policy_manager =
g_browser_process->platform_part()
->browser_policy_connector_chromeos()
->GetDeviceCloudPolicyManager();
ClearDemoRequisition(policy_manager);
} }
void DemoSetupController::OnStoreLoaded(policy::CloudPolicyStore* store) { void DemoSetupController::OnStoreLoaded(policy::CloudPolicyStore* store) {
......
...@@ -18,6 +18,10 @@ ...@@ -18,6 +18,10 @@
class PrefRegistrySimple; class PrefRegistrySimple;
namespace policy {
class DeviceCloudPolicyManagerChromeOS;
}
namespace chromeos { namespace chromeos {
// Controlls enrollment flow for setting up Demo Mode. // Controlls enrollment flow for setting up Demo Mode.
...@@ -44,6 +48,11 @@ class DemoSetupController ...@@ -44,6 +48,11 @@ class DemoSetupController
static void RegisterLocalStatePrefs(PrefRegistrySimple* registry); static void RegisterLocalStatePrefs(PrefRegistrySimple* registry);
// Clears demo device enrollment requisition on the given |policy_manager| if
// it is set.
static void ClearDemoRequisition(
policy::DeviceCloudPolicyManagerChromeOS* policy_manager);
// Utility method that returns whether demo mode is allowed on the device. // Utility method that returns whether demo mode is allowed on the device.
static bool IsDemoModeAllowed(); static bool IsDemoModeAllowed();
......
...@@ -13,8 +13,11 @@ ...@@ -13,8 +13,11 @@
#include "base/optional.h" #include "base/optional.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/test/scoped_task_environment.h" #include "base/test/scoped_task_environment.h"
#include "chrome/browser/browser_process_platform_part.h"
#include "chrome/browser/chromeos/login/demo_mode/demo_session.h" #include "chrome/browser/chromeos/login/demo_mode/demo_session.h"
#include "chrome/browser/chromeos/login/demo_mode/demo_setup_test_utils.h" #include "chrome/browser/chromeos/login/demo_mode/demo_setup_test_utils.h"
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
#include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h"
#include "chrome/browser/chromeos/settings/device_settings_service.h" #include "chrome/browser/chromeos/settings/device_settings_service.h"
#include "chrome/browser/chromeos/settings/stub_install_attributes.h" #include "chrome/browser/chromeos/settings/stub_install_attributes.h"
#include "chrome/browser/component_updater/cros_component_installer_chromeos.h" #include "chrome/browser/component_updater/cros_component_installer_chromeos.h"
...@@ -95,6 +98,11 @@ class DemoSetupControllerTest : public testing::Test { ...@@ -95,6 +98,11 @@ class DemoSetupControllerTest : public testing::Test {
SystemSaltGetter::Initialize(); SystemSaltGetter::Initialize();
DBusThreadManager::Initialize(); DBusThreadManager::Initialize();
DeviceSettingsService::Initialize(); DeviceSettingsService::Initialize();
TestingBrowserProcess::GetGlobal()
->platform_part()
->browser_policy_connector_chromeos()
->GetDeviceCloudPolicyManager()
->Initialize(TestingBrowserProcess::GetGlobal()->local_state());
helper_ = std::make_unique<DemoSetupControllerTestHelper>(); helper_ = std::make_unique<DemoSetupControllerTestHelper>();
tested_controller_ = std::make_unique<DemoSetupController>(); tested_controller_ = std::make_unique<DemoSetupController>();
} }
...@@ -105,6 +113,14 @@ class DemoSetupControllerTest : public testing::Test { ...@@ -105,6 +113,14 @@ class DemoSetupControllerTest : public testing::Test {
DeviceSettingsService::Shutdown(); DeviceSettingsService::Shutdown();
} }
static std::string GetDeviceRequisition() {
return TestingBrowserProcess::GetGlobal()
->platform_part()
->browser_policy_connector_chromeos()
->GetDeviceCloudPolicyManager()
->GetDeviceRequisition();
}
std::unique_ptr<DemoSetupControllerTestHelper> helper_; std::unique_ptr<DemoSetupControllerTestHelper> helper_;
std::unique_ptr<DemoSetupController> tested_controller_; std::unique_ptr<DemoSetupController> tested_controller_;
...@@ -139,6 +155,7 @@ TEST_F(DemoSetupControllerTest, OfflineSuccess) { ...@@ -139,6 +155,7 @@ TEST_F(DemoSetupControllerTest, OfflineSuccess) {
base::Unretained(helper_.get()))); base::Unretained(helper_.get())));
EXPECT_TRUE(helper_->WaitResult(true)); EXPECT_TRUE(helper_->WaitResult(true));
EXPECT_EQ("", GetDeviceRequisition());
} }
TEST_F(DemoSetupControllerTest, OfflineDeviceLocalAccountPolicyLoadFailure) { TEST_F(DemoSetupControllerTest, OfflineDeviceLocalAccountPolicyLoadFailure) {
...@@ -161,6 +178,7 @@ TEST_F(DemoSetupControllerTest, OfflineDeviceLocalAccountPolicyLoadFailure) { ...@@ -161,6 +178,7 @@ TEST_F(DemoSetupControllerTest, OfflineDeviceLocalAccountPolicyLoadFailure) {
EXPECT_TRUE(helper_->WaitResult(false)); EXPECT_TRUE(helper_->WaitResult(false));
EXPECT_FALSE(helper_->IsErrorFatal()); EXPECT_FALSE(helper_->IsErrorFatal());
EXPECT_EQ("", GetDeviceRequisition());
} }
TEST_F(DemoSetupControllerTest, OfflineDeviceLocalAccountPolicyStoreFailed) { TEST_F(DemoSetupControllerTest, OfflineDeviceLocalAccountPolicyStoreFailed) {
...@@ -186,6 +204,7 @@ TEST_F(DemoSetupControllerTest, OfflineDeviceLocalAccountPolicyStoreFailed) { ...@@ -186,6 +204,7 @@ TEST_F(DemoSetupControllerTest, OfflineDeviceLocalAccountPolicyStoreFailed) {
EXPECT_TRUE(helper_->WaitResult(false)); EXPECT_TRUE(helper_->WaitResult(false));
EXPECT_TRUE(helper_->IsErrorFatal()); EXPECT_TRUE(helper_->IsErrorFatal());
EXPECT_EQ("", GetDeviceRequisition());
} }
TEST_F(DemoSetupControllerTest, OfflineInvalidDeviceLocalAccountPolicyBlob) { TEST_F(DemoSetupControllerTest, OfflineInvalidDeviceLocalAccountPolicyBlob) {
...@@ -206,6 +225,7 @@ TEST_F(DemoSetupControllerTest, OfflineInvalidDeviceLocalAccountPolicyBlob) { ...@@ -206,6 +225,7 @@ TEST_F(DemoSetupControllerTest, OfflineInvalidDeviceLocalAccountPolicyBlob) {
EXPECT_TRUE(helper_->WaitResult(false)); EXPECT_TRUE(helper_->WaitResult(false));
EXPECT_TRUE(helper_->IsErrorFatal()); EXPECT_TRUE(helper_->IsErrorFatal());
EXPECT_EQ("", GetDeviceRequisition());
} }
TEST_F(DemoSetupControllerTest, OfflineError) { TEST_F(DemoSetupControllerTest, OfflineError) {
...@@ -229,6 +249,7 @@ TEST_F(DemoSetupControllerTest, OfflineError) { ...@@ -229,6 +249,7 @@ TEST_F(DemoSetupControllerTest, OfflineError) {
EXPECT_TRUE(helper_->WaitResult(false)); EXPECT_TRUE(helper_->WaitResult(false));
EXPECT_FALSE(helper_->IsErrorFatal()); EXPECT_FALSE(helper_->IsErrorFatal());
EXPECT_EQ("", GetDeviceRequisition());
} }
TEST_F(DemoSetupControllerTest, OnlineSuccess) { TEST_F(DemoSetupControllerTest, OnlineSuccess) {
...@@ -243,6 +264,7 @@ TEST_F(DemoSetupControllerTest, OnlineSuccess) { ...@@ -243,6 +264,7 @@ TEST_F(DemoSetupControllerTest, OnlineSuccess) {
base::Unretained(helper_.get()))); base::Unretained(helper_.get())));
EXPECT_TRUE(helper_->WaitResult(true)); EXPECT_TRUE(helper_->WaitResult(true));
EXPECT_EQ("", GetDeviceRequisition());
} }
TEST_F(DemoSetupControllerTest, OnlineError) { TEST_F(DemoSetupControllerTest, OnlineError) {
...@@ -258,6 +280,7 @@ TEST_F(DemoSetupControllerTest, OnlineError) { ...@@ -258,6 +280,7 @@ TEST_F(DemoSetupControllerTest, OnlineError) {
EXPECT_TRUE(helper_->WaitResult(false)); EXPECT_TRUE(helper_->WaitResult(false));
EXPECT_FALSE(helper_->IsErrorFatal()); EXPECT_FALSE(helper_->IsErrorFatal());
EXPECT_EQ("", GetDeviceRequisition());
} }
TEST_F(DemoSetupControllerTest, OnlineComponentError) { TEST_F(DemoSetupControllerTest, OnlineComponentError) {
...@@ -276,6 +299,7 @@ TEST_F(DemoSetupControllerTest, OnlineComponentError) { ...@@ -276,6 +299,7 @@ TEST_F(DemoSetupControllerTest, OnlineComponentError) {
EXPECT_TRUE(helper_->WaitResult(false)); EXPECT_TRUE(helper_->WaitResult(false));
EXPECT_FALSE(helper_->IsErrorFatal()); EXPECT_FALSE(helper_->IsErrorFatal());
EXPECT_EQ("", GetDeviceRequisition());
} }
TEST_F(DemoSetupControllerTest, EnrollTwice) { TEST_F(DemoSetupControllerTest, EnrollTwice) {
...@@ -291,6 +315,7 @@ TEST_F(DemoSetupControllerTest, EnrollTwice) { ...@@ -291,6 +315,7 @@ TEST_F(DemoSetupControllerTest, EnrollTwice) {
EXPECT_TRUE(helper_->WaitResult(false)); EXPECT_TRUE(helper_->WaitResult(false));
EXPECT_FALSE(helper_->IsErrorFatal()); EXPECT_FALSE(helper_->IsErrorFatal());
EXPECT_EQ("", GetDeviceRequisition());
helper_->Reset(); helper_->Reset();
...@@ -305,6 +330,7 @@ TEST_F(DemoSetupControllerTest, EnrollTwice) { ...@@ -305,6 +330,7 @@ TEST_F(DemoSetupControllerTest, EnrollTwice) {
base::Unretained(helper_.get()))); base::Unretained(helper_.get())));
EXPECT_TRUE(helper_->WaitResult(true)); EXPECT_TRUE(helper_->WaitResult(true));
EXPECT_EQ("", GetDeviceRequisition());
} }
} // namespace chromeos } // namespace chromeos
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/attestation/attestation_policy_observer.h" #include "chrome/browser/chromeos/attestation/attestation_policy_observer.h"
#include "chrome/browser/chromeos/attestation/enrollment_policy_observer.h" #include "chrome/browser/chromeos/attestation/enrollment_policy_observer.h"
#include "chrome/browser/chromeos/login/demo_mode/demo_setup_controller.h"
#include "chrome/browser/chromeos/login/enrollment/auto_enrollment_controller.h" #include "chrome/browser/chromeos/login/enrollment/auto_enrollment_controller.h"
#include "chrome/browser/chromeos/login/startup_utils.h" #include "chrome/browser/chromeos/login/startup_utils.h"
#include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h" #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h"
...@@ -332,6 +333,9 @@ void DeviceCloudPolicyManagerChromeOS::InitializeRequisition() { ...@@ -332,6 +333,9 @@ void DeviceCloudPolicyManagerChromeOS::InitializeRequisition() {
if (chromeos::StartupUtils::IsOobeCompleted()) if (chromeos::StartupUtils::IsOobeCompleted())
return; return;
// Demo requisition may have been set in a prior enrollment attempt that was
// interrupted.
chromeos::DemoSetupController::ClearDemoRequisition(this);
const PrefService::Preference* pref = local_state_->FindPreference( const PrefService::Preference* pref = local_state_->FindPreference(
prefs::kDeviceEnrollmentRequisition); prefs::kDeviceEnrollmentRequisition);
if (pref->IsDefaultValue()) { if (pref->IsDefaultValue()) {
......
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