Commit 60670640 authored by Roman Sorokin's avatar Roman Sorokin Committed by Commit Bot

DeviceStateMixin: Use file install attributes instead of StubInstallAttributes

Also added SetUpUserDataDirectory into InProcessBrowserTestMixin

Bug: 952855
Change-Id: I844ea3ed718cea27b74fe36df974defcacbdd958
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1570024Reviewed-by: default avatarToni Baržić <tbarzic@chromium.org>
Reviewed-by: default avatarRoman Sorokin [CET] <rsorokin@chromium.org>
Commit-Queue: Roman Sorokin [CET] <rsorokin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#652257}
parent 0f9e5ca8
......@@ -8,6 +8,7 @@
#include "chrome/browser/chromeos/login/enrollment/auto_enrollment_check_screen.h"
#include "chrome/browser/chromeos/login/enrollment/enrollment_screen.h"
#include "chrome/browser/chromeos/login/startup_utils.h"
#include "chrome/browser/chromeos/login/test/device_state_mixin.h"
#include "chrome/browser/chromeos/login/test/enrollment_ui_mixin.h"
#include "chrome/browser/chromeos/login/test/fake_gaia_mixin.h"
#include "chrome/browser/chromeos/login/test/js_checker.h"
......@@ -25,6 +26,7 @@
#include "chromeos/cryptohome/async_method_caller.h"
#include "chromeos/dbus/cryptohome/fake_cryptohome_client.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/tpm/install_attributes.h"
#include "components/policy/core/common/policy_switches.h"
#include "components/strings/grit/components_strings.h"
......@@ -90,6 +92,7 @@ class EnrollmentLocalPolicyServerBase : public OobeBaseTest {
OobeScreenWaiter(OobeScreen::SCREEN_OOBE_ENROLLMENT).Wait();
ASSERT_FALSE(StartupUtils::IsDeviceRegistered());
ASSERT_FALSE(InstallAttributes::Get()->IsEnterpriseManaged());
enrollment_screen()->OnLoginDone(FakeGaiaMixin::kFakeUserEmail,
FakeGaiaMixin::kFakeAuthCode);
}
......@@ -97,6 +100,8 @@ class EnrollmentLocalPolicyServerBase : public OobeBaseTest {
LocalPolicyTestServerMixin policy_server_{&mixin_host_};
test::EnrollmentUIMixin enrollment_ui_{&mixin_host_};
FakeGaiaMixin fake_gaia_{&mixin_host_, embedded_test_server()};
DeviceStateMixin device_state_{&mixin_host_,
DeviceStateMixin::State::BEFORE_OOBE};
private:
DISALLOW_COPY_AND_ASSIGN(EnrollmentLocalPolicyServerBase);
......@@ -134,6 +139,7 @@ IN_PROC_BROWSER_TEST_F(EnrollmentLocalPolicyServerBase, ManualEnrollment) {
enrollment_ui_.WaitForStep(test::ui::kEnrollmentStepSuccess);
EXPECT_TRUE(StartupUtils::IsDeviceRegistered());
EXPECT_TRUE(InstallAttributes::Get()->IsCloudManaged());
}
// Simple manual enrollment with device attributes prompt.
......@@ -148,6 +154,7 @@ IN_PROC_BROWSER_TEST_F(EnrollmentLocalPolicyServerBase,
test::values::kLocation);
enrollment_ui_.WaitForStep(test::ui::kEnrollmentStepSuccess);
EXPECT_TRUE(StartupUtils::IsDeviceRegistered());
EXPECT_TRUE(InstallAttributes::Get()->IsCloudManaged());
}
// Simple manual enrollment with only license type available.
......@@ -162,6 +169,7 @@ IN_PROC_BROWSER_TEST_F(EnrollmentLocalPolicyServerBase,
enrollment_ui_.WaitForStep(test::ui::kEnrollmentStepSuccess);
EXPECT_TRUE(StartupUtils::IsDeviceRegistered());
EXPECT_TRUE(InstallAttributes::Get()->IsCloudManaged());
}
// Simple manual enrollment with license selection.
......@@ -179,6 +187,7 @@ IN_PROC_BROWSER_TEST_F(EnrollmentLocalPolicyServerBase,
enrollment_ui_.WaitForStep(test::ui::kEnrollmentStepSuccess);
EXPECT_TRUE(StartupUtils::IsDeviceRegistered());
EXPECT_TRUE(InstallAttributes::Get()->IsCloudManaged());
}
// Negative scenarios: see different HTTP error codes in
......@@ -196,6 +205,7 @@ IN_PROC_BROWSER_TEST_F(EnrollmentLocalPolicyServerBase,
IDS_ENTERPRISE_ENROLLMENT_MISSING_LICENSES_ERROR, /* can retry */ true);
enrollment_ui_.RetryAfterError();
EXPECT_FALSE(StartupUtils::IsDeviceRegistered());
EXPECT_FALSE(InstallAttributes::Get()->IsEnterpriseManaged());
}
// Error during enrollment : 403 - management not allowed.
......@@ -210,6 +220,7 @@ IN_PROC_BROWSER_TEST_F(EnrollmentLocalPolicyServerBase,
IDS_ENTERPRISE_ENROLLMENT_AUTH_ACCOUNT_ERROR, /* can retry */ true);
enrollment_ui_.RetryAfterError();
EXPECT_FALSE(StartupUtils::IsDeviceRegistered());
EXPECT_FALSE(InstallAttributes::Get()->IsEnterpriseManaged());
}
// Error during enrollment : 405 - invalid device serial.
......@@ -226,6 +237,7 @@ IN_PROC_BROWSER_TEST_F(EnrollmentLocalPolicyServerBase,
/* can retry */ true);
enrollment_ui_.RetryAfterError();
EXPECT_FALSE(StartupUtils::IsDeviceRegistered());
EXPECT_FALSE(InstallAttributes::Get()->IsEnterpriseManaged());
}
// Error during enrollment : 406 - domain mismatch
......@@ -240,6 +252,7 @@ IN_PROC_BROWSER_TEST_F(EnrollmentLocalPolicyServerBase,
IDS_ENTERPRISE_ENROLLMENT_DOMAIN_MISMATCH_ERROR, /* can retry */ true);
enrollment_ui_.RetryAfterError();
EXPECT_FALSE(StartupUtils::IsDeviceRegistered());
EXPECT_FALSE(InstallAttributes::Get()->IsEnterpriseManaged());
}
// Error during enrollment : 409 - Device ID is already in use
......@@ -255,6 +268,7 @@ IN_PROC_BROWSER_TEST_F(EnrollmentLocalPolicyServerBase,
IDS_POLICY_DM_STATUS_SERVICE_DEVICE_ID_CONFLICT, /* can retry */ true);
enrollment_ui_.RetryAfterError();
EXPECT_FALSE(StartupUtils::IsDeviceRegistered());
EXPECT_FALSE(InstallAttributes::Get()->IsEnterpriseManaged());
}
// Error during enrollment : 412 - Activation is pending
......@@ -269,6 +283,7 @@ IN_PROC_BROWSER_TEST_F(EnrollmentLocalPolicyServerBase,
IDS_POLICY_DM_STATUS_SERVICE_ACTIVATION_PENDING, /* can retry */ true);
enrollment_ui_.RetryAfterError();
EXPECT_FALSE(StartupUtils::IsDeviceRegistered());
EXPECT_FALSE(InstallAttributes::Get()->IsEnterpriseManaged());
}
// Error during enrollment : 417 - Consumer account with packaged license.
......@@ -284,6 +299,7 @@ IN_PROC_BROWSER_TEST_F(EnrollmentLocalPolicyServerBase,
/* can retry */ true);
enrollment_ui_.RetryAfterError();
EXPECT_FALSE(StartupUtils::IsDeviceRegistered());
EXPECT_FALSE(InstallAttributes::Get()->IsEnterpriseManaged());
}
// Error during enrollment : 500 - Consumer account with packaged license.
......@@ -298,6 +314,7 @@ IN_PROC_BROWSER_TEST_F(EnrollmentLocalPolicyServerBase,
/* can retry */ true);
enrollment_ui_.RetryAfterError();
EXPECT_FALSE(StartupUtils::IsDeviceRegistered());
EXPECT_FALSE(InstallAttributes::Get()->IsEnterpriseManaged());
}
// Error during enrollment : Strange HTTP response from server.
......@@ -312,6 +329,7 @@ IN_PROC_BROWSER_TEST_F(EnrollmentLocalPolicyServerBase,
/* can retry */ true);
enrollment_ui_.RetryAfterError();
EXPECT_FALSE(StartupUtils::IsDeviceRegistered());
EXPECT_FALSE(InstallAttributes::Get()->IsEnterpriseManaged());
}
// Error during enrollment : Can not update device attributes
......@@ -328,6 +346,7 @@ IN_PROC_BROWSER_TEST_F(EnrollmentLocalPolicyServerBase,
enrollment_ui_.WaitForStep(test::ui::kEnrollmentStepDeviceAttributesError);
EXPECT_TRUE(StartupUtils::IsDeviceRegistered());
EXPECT_TRUE(InstallAttributes::Get()->IsCloudManaged());
enrollment_ui_.LeaveDeviceAttributeErrorScreen();
OobeScreenWaiter(OobeScreen::SCREEN_GAIA_SIGNIN).Wait();
}
......@@ -343,6 +362,7 @@ IN_PROC_BROWSER_TEST_F(EnrollmentLocalPolicyServerBase,
enrollment_ui_.ExpectErrorMessage(IDS_POLICY_DM_STATUS_TEMPORARY_UNAVAILABLE,
/* can retry */ true);
EXPECT_FALSE(StartupUtils::IsDeviceRegistered());
EXPECT_FALSE(InstallAttributes::Get()->IsEnterpriseManaged());
enrollment_ui_.RetryAfterError();
}
......@@ -358,6 +378,7 @@ IN_PROC_BROWSER_TEST_F(EnrollmentLocalPolicyServerBase,
IDS_POLICY_DM_STATUS_SERVICE_POLICY_NOT_FOUND,
/* can retry */ true);
EXPECT_FALSE(StartupUtils::IsDeviceRegistered());
EXPECT_FALSE(InstallAttributes::Get()->IsEnterpriseManaged());
enrollment_ui_.RetryAfterError();
}
......@@ -372,6 +393,7 @@ IN_PROC_BROWSER_TEST_F(EnrollmentLocalPolicyServerBase,
enrollment_ui_.ExpectErrorMessage(IDS_POLICY_DM_STATUS_SERVICE_DEPROVISIONED,
/* can retry */ true);
EXPECT_FALSE(StartupUtils::IsDeviceRegistered());
EXPECT_FALSE(InstallAttributes::Get()->IsEnterpriseManaged());
enrollment_ui_.RetryAfterError();
}
......@@ -443,6 +465,7 @@ IN_PROC_BROWSER_TEST_F(AutoEnrollmentLocalPolicyServer, Attestation) {
host()->StartWizard(OobeScreen::SCREEN_AUTO_ENROLLMENT_CHECK);
enrollment_ui_.WaitForStep(test::ui::kEnrollmentStepSuccess);
EXPECT_TRUE(StartupUtils::IsDeviceRegistered());
EXPECT_TRUE(InstallAttributes::Get()->IsCloudManaged());
}
} // namespace chromeos
......@@ -25,6 +25,10 @@ void InProcessBrowserTestMixin::SetUpCommandLine(
void InProcessBrowserTestMixin::SetUpDefaultCommandLine(
base::CommandLine* command_line) {}
bool InProcessBrowserTestMixin::SetUpUserDataDirectory() {
return true;
}
void InProcessBrowserTestMixin::SetUpInProcessBrowserTestFixture() {}
void InProcessBrowserTestMixin::CreatedBrowserMainParts(
......@@ -59,6 +63,14 @@ void InProcessBrowserTestMixinHost::SetUpDefaultCommandLine(
mixin->SetUpDefaultCommandLine(command_line);
}
bool InProcessBrowserTestMixinHost::SetUpUserDataDirectory() {
for (InProcessBrowserTestMixin* mixin : mixins_) {
if (!mixin->SetUpUserDataDirectory())
return false;
}
return true;
}
void InProcessBrowserTestMixinHost::SetUpInProcessBrowserTestFixture() {
for (InProcessBrowserTestMixin* mixin : mixins_)
mixin->SetUpInProcessBrowserTestFixture();
......@@ -111,6 +123,11 @@ void MixinBasedInProcessBrowserTest::SetUpDefaultCommandLine(
InProcessBrowserTest::SetUpDefaultCommandLine(command_line);
}
bool MixinBasedInProcessBrowserTest::SetUpUserDataDirectory() {
return mixin_host_.SetUpUserDataDirectory() &&
InProcessBrowserTest::SetUpUserDataDirectory();
}
void MixinBasedInProcessBrowserTest::SetUpInProcessBrowserTestFixture() {
mixin_host_.SetUpInProcessBrowserTestFixture();
InProcessBrowserTest::SetUpInProcessBrowserTestFixture();
......
......@@ -71,6 +71,7 @@ class InProcessBrowserTestMixin {
// SetUp
// SetUpCommandLine
// SetUpDefaultCommandLine
// SetUpUserDataDirectory
// SetUpInProcessBrowserTestFixture
// CreatedBrowserMainParts
// SetUpOnMainThread
......@@ -83,6 +84,7 @@ class InProcessBrowserTestMixin {
virtual void SetUp();
virtual void SetUpCommandLine(base::CommandLine* command_line);
virtual void SetUpDefaultCommandLine(base::CommandLine* command_line);
virtual bool SetUpUserDataDirectory();
virtual void SetUpInProcessBrowserTestFixture();
virtual void CreatedBrowserMainParts(
content::BrowserMainParts* browser_main_parts);
......@@ -104,6 +106,7 @@ class InProcessBrowserTestMixinHost final {
void SetUp();
void SetUpCommandLine(base::CommandLine* command_line);
void SetUpDefaultCommandLine(base::CommandLine* command_line);
bool SetUpUserDataDirectory();
void SetUpInProcessBrowserTestFixture();
void CreatedBrowserMainParts(content::BrowserMainParts* browser_main_parts);
void SetUpOnMainThread();
......@@ -132,6 +135,7 @@ class MixinBasedInProcessBrowserTest : public InProcessBrowserTest {
void SetUp() override;
void SetUpCommandLine(base::CommandLine* command_line) override;
void SetUpDefaultCommandLine(base::CommandLine* command_line) override;
bool SetUpUserDataDirectory() override;
void SetUpInProcessBrowserTestFixture() override;
void CreatedBrowserMainParts(
content::BrowserMainParts* browser_main_parts) override;
......
......@@ -1402,7 +1402,10 @@ IN_PROC_BROWSER_TEST_F(SAMLPolicyTest, SAMLInterstitialNext) {
// forcing the WebUI login, thus allowing views-based login.
class SAMLPolicyViewsBasedLoginTest : public SAMLPolicyTest {
public:
SAMLPolicyViewsBasedLoginTest() = default;
SAMLPolicyViewsBasedLoginTest() : SAMLPolicyTest() {
device_state_.SetState(
chromeos::DeviceStateMixin::State::OOBE_COMPLETED_CONSUMER_OWNED);
}
~SAMLPolicyViewsBasedLoginTest() override = default;
protected:
......@@ -1416,13 +1419,6 @@ class SAMLPolicyViewsBasedLoginTest : public SAMLPolicyTest {
DISALLOW_COPY_AND_ASSIGN(SAMLPolicyViewsBasedLoginTest);
};
IN_PROC_BROWSER_TEST_F(SAMLPolicyViewsBasedLoginTest,
PRE_TestLoginMediaPermission) {
// Mark OOBE completed to go directly to the sign-in screen - this is
// currently needed to trigger the views-based login UI.
StartupUtils::MarkOobeCompleted();
}
// Ensure that the permission status of getUserMedia requests from SAML login
// pages is controlled by the kLoginVideoCaptureAllowedUrls pref rather than the
// underlying user content setting.
......
......@@ -4,8 +4,12 @@
#include "chrome/browser/chromeos/login/test/device_state_mixin.h"
#include "base/path_service.h"
#include "chrome/browser/browser_process.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/pref_names.h"
#include "chromeos/constants/chromeos_paths.h"
#include "components/policy/proto/install_attributes.pb.h"
#include "components/prefs/pref_service.h"
namespace chromeos {
......@@ -15,14 +19,40 @@ namespace {
constexpr char kFakeDomain[] = "example.com";
constexpr char kFakeDeviceId[] = "device_id";
cryptohome::SerializedInstallAttributes BuildInstallAttributes(
const std::string& mode,
const std::string& domain,
const std::string& realm,
const std::string& device_id) {
std::map<std::string, std::string> install_attrs_;
install_attrs_["enterprise.mode"] = mode;
install_attrs_["enterprise.domain"] = domain;
install_attrs_["enterprise.realm"] = realm;
install_attrs_["enterprise.device_id"] = device_id;
install_attrs_["enterprise.owned"] = "true";
cryptohome::SerializedInstallAttributes install_attrs;
for (const auto& it : install_attrs_) {
cryptohome::SerializedInstallAttributes::Attribute* attr_entry =
install_attrs.add_attributes();
const std::string& name = it.first;
const std::string& value = it.second;
attr_entry->set_name(name);
attr_entry->mutable_value()->assign(value.data(),
value.data() + value.size());
}
return install_attrs;
}
} // namespace
DeviceStateMixin::DeviceStateMixin(InProcessBrowserTestMixinHost* host,
State initial_state)
: InProcessBrowserTestMixin(host), state_(initial_state) {}
void DeviceStateMixin::SetUpInProcessBrowserTestFixture() {
bool DeviceStateMixin::SetUpUserDataDirectory() {
SetDeviceState();
return true;
}
void DeviceStateMixin::SetState(State state) {
......@@ -34,27 +64,46 @@ void DeviceStateMixin::SetDeviceState() {
DCHECK(!is_setup_);
DCHECK(domain_.empty() || state_ == State::OOBE_COMPLETED_CLOUD_ENROLLED);
is_setup_ = true;
WriteInstallAttrFile();
}
void DeviceStateMixin::WriteInstallAttrFile() {
base::FilePath user_data_dir;
CHECK(base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir));
base::FilePath install_attrs_file =
user_data_dir.Append("stub_install_attributes.pb");
if (base::PathExists(install_attrs_file)) {
return;
}
std::string device_mode, domain, realm, device_id;
switch (state_) {
case State::BEFORE_OOBE:
case State::OOBE_COMPLETED_UNOWNED:
install_attributes_.Get()->Clear();
return;
case State::OOBE_COMPLETED_CLOUD_ENROLLED: {
const std::string domain = !domain_.empty() ? domain_ : kFakeDomain;
install_attributes_.Get()->SetCloudManaged(domain, kFakeDeviceId);
return;
}
case State::OOBE_COMPLETED_ACTIVE_DIRECTORY_ENROLLED:
install_attributes_.Get()->SetActiveDirectoryManaged(kFakeDomain,
kFakeDeviceId);
return;
case State::OOBE_COMPLETED_CONSUMER_OWNED:
install_attributes_.Get()->SetConsumerOwned();
return;
case State::OOBE_COMPLETED_DEMO_MODE:
install_attributes_.Get()->SetDemoMode(kFakeDeviceId);
case DeviceStateMixin::State::BEFORE_OOBE:
case DeviceStateMixin::State::OOBE_COMPLETED_UNOWNED:
return;
case DeviceStateMixin::State::OOBE_COMPLETED_CLOUD_ENROLLED:
device_mode = "enterprise";
domain = !domain_.empty() ? domain_ : kFakeDomain;
break;
case DeviceStateMixin::State::OOBE_COMPLETED_ACTIVE_DIRECTORY_ENROLLED:
device_mode = "enterprise_ad";
realm = kFakeDomain;
break;
case DeviceStateMixin::State::OOBE_COMPLETED_CONSUMER_OWNED:
device_mode = "consumer";
break;
case DeviceStateMixin::State::OOBE_COMPLETED_DEMO_MODE:
device_mode = "demo_mode";
domain = "cros-demo-mode.com";
break;
}
std::string blob;
CHECK(BuildInstallAttributes(device_mode, domain, realm, kFakeDeviceId)
.SerializeToString(&blob));
CHECK_EQ(static_cast<int>(blob.size()),
base::WriteFile(install_attrs_file, blob.data(), blob.size()));
}
DeviceStateMixin::~DeviceStateMixin() = default;
......
......@@ -12,7 +12,6 @@
#include "base/values.h"
#include "chrome/browser/chromeos/login/demo_mode/demo_session.h"
#include "chrome/browser/chromeos/login/mixin_based_in_process_browser_test.h"
#include "chromeos/tpm/stub_install_attributes.h"
namespace chromeos {
......@@ -31,16 +30,17 @@ class DeviceStateMixin : public InProcessBrowserTestMixin {
~DeviceStateMixin() override;
// InProcessBrowserTestMixin:
void SetUpInProcessBrowserTestFixture() override;
bool SetUpUserDataDirectory() override;
void SetState(State state);
void set_domain(const std::string& domain) { domain_ = domain; }
private:
void SetDeviceState();
void WriteInstallAttrFile();
State state_;
std::string domain_;
ScopedStubInstallAttributes install_attributes_;
bool is_setup_ = false;
......
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