Commit 53d84ae8 authored by tnagel@chromium.org's avatar tnagel@chromium.org

Encapsulate data-format constants in EnterpriseInstallAttributes.

Also add mentioning that some constants have been copied to Chromium OS.

BUG=none

Review URL: https://codereview.chromium.org/397543005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283772 0039d316-1c4b-4281-b951-d872f2087c98
parent d4c56f65
......@@ -13,7 +13,6 @@
#include "base/stl_util.h"
#include "chrome/browser/chromeos/policy/device_policy_builder.h"
#include "chrome/browser/chromeos/policy/enterprise_install_attributes.h"
#include "chrome/browser/chromeos/policy/proto/install_attributes.pb.h"
#include "chrome/common/chrome_paths.h"
#include "chromeos/chromeos_paths.h"
#include "chromeos/dbus/fake_dbus_thread_manager.h"
......@@ -35,22 +34,14 @@ DevicePolicyCrosTestHelper::~DevicePolicyCrosTestHelper() {}
void DevicePolicyCrosTestHelper::MarkAsEnterpriseOwned() {
OverridePaths();
cryptohome::SerializedInstallAttributes install_attrs_proto;
cryptohome::SerializedInstallAttributes::Attribute* attribute = NULL;
attribute = install_attrs_proto.add_attributes();
attribute->set_name(EnterpriseInstallAttributes::kAttrEnterpriseOwned);
attribute->set_value("true");
attribute = install_attrs_proto.add_attributes();
attribute->set_name(EnterpriseInstallAttributes::kAttrEnterpriseUser);
attribute->set_value(device_policy_.policy_data().username());
const std::string install_attrs_blob(
EnterpriseInstallAttributes::
GetEnterpriseOwnedInstallAttributesBlobForTesting(
device_policy_.policy_data().username()));
base::FilePath install_attrs_file;
ASSERT_TRUE(
PathService::Get(chromeos::FILE_INSTALL_ATTRIBUTES, &install_attrs_file));
const std::string install_attrs_blob(
install_attrs_proto.SerializeAsString());
ASSERT_EQ(static_cast<int>(install_attrs_blob.size()),
base::WriteFile(install_attrs_file,
install_attrs_blob.c_str(),
......
......@@ -22,40 +22,6 @@ namespace cryptohome_util = chromeos::cryptohome_util;
namespace {
// Translates DeviceMode constants to strings used in the lockbox.
std::string GetDeviceModeString(DeviceMode mode) {
switch (mode) {
case DEVICE_MODE_CONSUMER:
return EnterpriseInstallAttributes::kConsumerDeviceMode;
case DEVICE_MODE_ENTERPRISE:
return EnterpriseInstallAttributes::kEnterpriseDeviceMode;
case DEVICE_MODE_RETAIL_KIOSK:
return EnterpriseInstallAttributes::kRetailKioskDeviceMode;
case DEVICE_MODE_CONSUMER_KIOSK_AUTOLAUNCH:
return EnterpriseInstallAttributes::kConsumerKioskDeviceMode;
case DEVICE_MODE_PENDING:
case DEVICE_MODE_NOT_SET:
break;
}
NOTREACHED() << "Invalid device mode: " << mode;
return EnterpriseInstallAttributes::kUnknownDeviceMode;
}
// Translates strings used in the lockbox to DeviceMode values.
DeviceMode GetDeviceModeFromString(
const std::string& mode) {
if (mode == EnterpriseInstallAttributes::kConsumerDeviceMode)
return DEVICE_MODE_CONSUMER;
else if (mode == EnterpriseInstallAttributes::kEnterpriseDeviceMode)
return DEVICE_MODE_ENTERPRISE;
else if (mode == EnterpriseInstallAttributes::kRetailKioskDeviceMode)
return DEVICE_MODE_RETAIL_KIOSK;
else if (mode == EnterpriseInstallAttributes::kConsumerKioskDeviceMode)
return DEVICE_MODE_CONSUMER_KIOSK_AUTOLAUNCH;
NOTREACHED() << "Unknown device mode string: " << mode;
return DEVICE_MODE_NOT_SET;
}
bool ReadMapKey(const std::map<std::string, std::string>& map,
const std::string& key,
std::string* value) {
......@@ -69,25 +35,23 @@ bool ReadMapKey(const std::map<std::string, std::string>& map,
} // namespace
const char EnterpriseInstallAttributes::kConsumerDeviceMode[] = "consumer";
const char EnterpriseInstallAttributes::kEnterpriseDeviceMode[] = "enterprise";
const char EnterpriseInstallAttributes::kRetailKioskDeviceMode[] = "kiosk";
const char EnterpriseInstallAttributes::kConsumerKioskDeviceMode[] =
"consumer_kiosk";
const char EnterpriseInstallAttributes::kUnknownDeviceMode[] = "unknown";
// static
std::string
EnterpriseInstallAttributes::GetEnterpriseOwnedInstallAttributesBlobForTesting(
const std::string& user_name) {
cryptohome::SerializedInstallAttributes install_attrs_proto;
cryptohome::SerializedInstallAttributes::Attribute* attribute = NULL;
const char EnterpriseInstallAttributes::kAttrEnterpriseDeviceId[] =
"enterprise.device_id";
const char EnterpriseInstallAttributes::kAttrEnterpriseDomain[] =
"enterprise.domain";
const char EnterpriseInstallAttributes::kAttrEnterpriseMode[] =
"enterprise.mode";
const char EnterpriseInstallAttributes::kAttrEnterpriseOwned[] =
"enterprise.owned";
const char EnterpriseInstallAttributes::kAttrEnterpriseUser[] =
"enterprise.user";
const char EnterpriseInstallAttributes::kAttrConsumerKioskEnabled[] =
"consumer.app_kiosk_enabled";
attribute = install_attrs_proto.add_attributes();
attribute->set_name(EnterpriseInstallAttributes::kAttrEnterpriseOwned);
attribute->set_value("true");
attribute = install_attrs_proto.add_attributes();
attribute->set_name(EnterpriseInstallAttributes::kAttrEnterpriseUser);
attribute->set_value(user_name);
return install_attrs_proto.SerializeAsString();
}
EnterpriseInstallAttributes::EnterpriseInstallAttributes(
chromeos::CryptohomeClient* cryptohome_client)
......@@ -333,6 +297,61 @@ DeviceMode EnterpriseInstallAttributes::GetMode() {
return registration_mode_;
}
// Note that some of these constants have been copied to
// login_manager/device_policy_service.cc. Please make sure that all changes to
// the constants are reflected there as well.
const char EnterpriseInstallAttributes::kConsumerDeviceMode[] = "consumer";
const char EnterpriseInstallAttributes::kEnterpriseDeviceMode[] = "enterprise";
const char EnterpriseInstallAttributes::kRetailKioskDeviceMode[] = "kiosk";
const char EnterpriseInstallAttributes::kConsumerKioskDeviceMode[] =
"consumer_kiosk";
const char EnterpriseInstallAttributes::kUnknownDeviceMode[] = "unknown";
const char EnterpriseInstallAttributes::kAttrEnterpriseDeviceId[] =
"enterprise.device_id";
const char EnterpriseInstallAttributes::kAttrEnterpriseDomain[] =
"enterprise.domain";
const char EnterpriseInstallAttributes::kAttrEnterpriseMode[] =
"enterprise.mode";
const char EnterpriseInstallAttributes::kAttrEnterpriseOwned[] =
"enterprise.owned";
const char EnterpriseInstallAttributes::kAttrEnterpriseUser[] =
"enterprise.user";
const char EnterpriseInstallAttributes::kAttrConsumerKioskEnabled[] =
"consumer.app_kiosk_enabled";
std::string EnterpriseInstallAttributes::GetDeviceModeString(DeviceMode mode) {
switch (mode) {
case DEVICE_MODE_CONSUMER:
return EnterpriseInstallAttributes::kConsumerDeviceMode;
case DEVICE_MODE_ENTERPRISE:
return EnterpriseInstallAttributes::kEnterpriseDeviceMode;
case DEVICE_MODE_RETAIL_KIOSK:
return EnterpriseInstallAttributes::kRetailKioskDeviceMode;
case DEVICE_MODE_CONSUMER_KIOSK_AUTOLAUNCH:
return EnterpriseInstallAttributes::kConsumerKioskDeviceMode;
case DEVICE_MODE_PENDING:
case DEVICE_MODE_NOT_SET:
break;
}
NOTREACHED() << "Invalid device mode: " << mode;
return EnterpriseInstallAttributes::kUnknownDeviceMode;
}
DeviceMode EnterpriseInstallAttributes::GetDeviceModeFromString(
const std::string& mode) {
if (mode == EnterpriseInstallAttributes::kConsumerDeviceMode)
return DEVICE_MODE_CONSUMER;
else if (mode == EnterpriseInstallAttributes::kEnterpriseDeviceMode)
return DEVICE_MODE_ENTERPRISE;
else if (mode == EnterpriseInstallAttributes::kRetailKioskDeviceMode)
return DEVICE_MODE_RETAIL_KIOSK;
else if (mode == EnterpriseInstallAttributes::kConsumerKioskDeviceMode)
return DEVICE_MODE_CONSUMER_KIOSK_AUTOLAUNCH;
NOTREACHED() << "Unknown device mode string: " << mode;
return DEVICE_MODE_NOT_SET;
}
void EnterpriseInstallAttributes::DecodeInstallAttributes(
const std::map<std::string, std::string>& attr_map) {
std::string enterprise_owned;
......
......@@ -12,6 +12,7 @@
#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/files/file_path.h"
#include "base/gtest_prod_util.h"
#include "base/memory/weak_ptr.h"
#include "chromeos/dbus/cryptohome_client.h"
#include "chromeos/dbus/dbus_method_call_status.h"
......@@ -35,20 +36,9 @@ class EnterpriseInstallAttributes {
// A callback to handle responses of methods returning a LockResult value.
typedef base::Callback<void(LockResult lock_result)> LockResultCallback;
// Constants for the possible device modes that can be stored in the lockbox.
static const char kConsumerDeviceMode[];
static const char kEnterpriseDeviceMode[];
static const char kRetailKioskDeviceMode[];
static const char kConsumerKioskDeviceMode[];
static const char kUnknownDeviceMode[];
// Field names in the lockbox.
static const char kAttrEnterpriseDeviceId[];
static const char kAttrEnterpriseDomain[];
static const char kAttrEnterpriseMode[];
static const char kAttrEnterpriseOwned[];
static const char kAttrEnterpriseUser[];
static const char kAttrConsumerKioskEnabled[];
// Return serialized InstallAttributes of an enterprise-owned configuration.
static std::string GetEnterpriseOwnedInstallAttributesBlobForTesting(
const std::string& user_name);
explicit EnterpriseInstallAttributes(
chromeos::CryptohomeClient* cryptohome_client);
......@@ -106,6 +96,36 @@ class EnterpriseInstallAttributes {
DeviceMode registration_mode_;
private:
FRIEND_TEST_ALL_PREFIXES(EnterpriseInstallAttributesTest,
DeviceLockedFromOlderVersion);
FRIEND_TEST_ALL_PREFIXES(EnterpriseInstallAttributesTest,
ReadCacheFile);
FRIEND_TEST_ALL_PREFIXES(EnterpriseInstallAttributesTest,
ReadCacheFileForConsumerKiosk);
FRIEND_TEST_ALL_PREFIXES(EnterpriseInstallAttributesTest,
VerifyFakeInstallAttributesCache);
// Constants for the possible device modes that can be stored in the lockbox.
static const char kConsumerDeviceMode[];
static const char kEnterpriseDeviceMode[];
static const char kRetailKioskDeviceMode[];
static const char kConsumerKioskDeviceMode[];
static const char kUnknownDeviceMode[];
// Field names in the lockbox.
static const char kAttrEnterpriseDeviceId[];
static const char kAttrEnterpriseDomain[];
static const char kAttrEnterpriseMode[];
static const char kAttrEnterpriseOwned[];
static const char kAttrEnterpriseUser[];
static const char kAttrConsumerKioskEnabled[];
// Translates DeviceMode constants to strings used in the lockbox.
std::string GetDeviceModeString(DeviceMode mode);
// Translates strings used in the lockbox to DeviceMode values.
DeviceMode GetDeviceModeFromString(const std::string& mode);
// Decodes the install attributes provided in |attr_map|.
void DecodeInstallAttributes(
const std::map<std::string, std::string>& attr_map);
......
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