1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
|
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_POLICY_TEST_SUPPORT_POLICY_STORAGE_H_
#define COMPONENTS_POLICY_TEST_SUPPORT_POLICY_STORAGE_H_
#include <stdint.h>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "base/containers/flat_map.h"
#include "base/containers/flat_set.h"
#include "base/time/time.h"
#include "components/policy/proto/device_management_backend.pb.h"
#include "components/policy/test_support/signature_provider.h"
namespace policy {
class SignatureProvider;
// Stores preferences about policies to be applied to registered browsers.
class PolicyStorage {
public:
PolicyStorage();
PolicyStorage(PolicyStorage&& policy_storage);
PolicyStorage& operator=(PolicyStorage&& policy_storage);
virtual ~PolicyStorage();
// Returns the serialized proto associated with |policy_type| and optional
// |entity_id|. Returns empty string if there is no such association.
std::string GetPolicyPayload(
const std::string& policy_type,
const std::string& entity_id = std::string()) const;
std::vector<std::string> GetEntityIdsForType(const std::string& policy_type);
// Associates the serialized proto stored in |policy_payload| with
// |policy_type| and optional |entity_id|.
void SetPolicyPayload(const std::string& policy_type,
const std::string& policy_payload);
void SetPolicyPayload(const std::string& policy_type,
const std::string& entity_id,
const std::string& policy_payload);
// Returns the raw payload to be served by an external endpoint and associated
// with |policy_type| and optional |entity_id|. Returns empty string if there
// is no such association.
std::string GetExternalPolicyPayload(const std::string& policy_type,
const std::string& entity_id);
// Associates the |raw_payload| to be served via an external endpoint with
// |policy_type| and optional |entity_id|.
void SetExternalPolicyPayload(const std::string& policy_type,
const std::string& entity_id,
const std::string& raw_payload);
SignatureProvider* signature_provider() const {
return signature_provider_.get();
}
void set_signature_provider(
std::unique_ptr<SignatureProvider> signature_provider) {
signature_provider_ = std::move(signature_provider);
}
const std::string& robot_api_auth_code() const {
return robot_api_auth_code_;
}
void set_robot_api_auth_code(const std::string& robot_api_auth_code) {
robot_api_auth_code_ = robot_api_auth_code;
}
bool has_kiosk_license() const { return has_kiosk_license_; }
void set_has_kiosk_license(bool has_kiosk_license) {
has_kiosk_license_ = has_kiosk_license;
}
bool has_enterprise_license() const { return has_enterprise_license_; }
void set_has_enterprise_license(bool has_enterprise_license) {
has_enterprise_license_ = has_enterprise_license;
}
const std::string& service_account_identity() const {
return service_account_identity_;
}
void set_service_account_identity(
const std::string& service_account_identity) {
service_account_identity_ = service_account_identity;
}
const base::flat_set<std::string>& managed_users() const {
return managed_users_;
}
void add_managed_user(const std::string& managed_user) {
managed_users_.insert(managed_user);
}
const std::vector<std::string>& device_affiliation_ids() const {
return device_affiliation_ids_;
}
void add_device_affiliation_id(const std::string& device_affiliation_id) {
device_affiliation_ids_.emplace_back(device_affiliation_id);
}
const std::vector<std::string>& user_affiliation_ids() const {
return user_affiliation_ids_;
}
void add_user_affiliation_id(const std::string& user_affiliation_id) {
user_affiliation_ids_.emplace_back(user_affiliation_id);
}
const std::string& directory_api_id() const { return directory_api_id_; }
void set_directory_api_id(const std::string& directory_api_id) {
directory_api_id_ = directory_api_id;
}
std::string policy_user() const { return policy_user_; }
void set_policy_user(const std::string& policy_user) {
policy_user_ = policy_user;
}
const std::string& policy_invalidation_topic() const {
return policy_invalidation_topic_;
}
void set_policy_invalidation_topic(
const std::string& policy_invalidation_topic) {
policy_invalidation_topic_ = policy_invalidation_topic;
}
const std::optional<enterprise_management::PolicyData::MarketSegment>
market_segment() const {
return market_segment_;
}
void set_market_segment(
enterprise_management::PolicyData::MarketSegment segment) {
market_segment_ = segment;
}
const std::optional<enterprise_management::PolicyData::MetricsLogSegment>
metrics_log_segment() const {
return metrics_log_segment_;
}
void set_metrics_log_segment(
enterprise_management::PolicyData::MetricsLogSegment segment) {
metrics_log_segment_ = segment;
}
const std::optional<
enterprise_management::PolicyData::K12AgeClassificationMetricsLogSegment>
k12_age_classification_metrics_log_segment() const {
return k12_age_classification_metrics_log_segment_;
}
void set_k12_age_classification_metrics_log_segment(
enterprise_management::PolicyData::K12AgeClassificationMetricsLogSegment
segment) {
k12_age_classification_metrics_log_segment_ = segment;
}
base::Time timestamp() const { return timestamp_; }
void set_timestamp(const base::Time& timestamp) { timestamp_ = timestamp; }
bool allow_set_device_attributes() { return allow_set_device_attributes_; }
void set_allow_set_device_attributes(bool allow_set_device_attributes) {
allow_set_device_attributes_ = allow_set_device_attributes;
}
struct DeviceState {
std::string management_domain;
enterprise_management::DeviceStateRetrievalResponse::RestoreMode
restore_mode;
};
const DeviceState& device_state() { return device_state_; }
void set_device_state(const DeviceState& device_state) {
device_state_ = device_state;
}
struct PsmEntry {
int psm_execution_result;
int64_t psm_determination_timestamp;
};
void SetPsmEntry(const std::string& brand_serial_id,
const PsmEntry& psm_entry);
const PsmEntry* GetPsmEntry(const std::string& brand_serial_id) const;
struct InitialEnrollmentState {
enterprise_management::DeviceInitialEnrollmentStateResponse::
InitialEnrollmentMode initial_enrollment_mode;
std::string management_domain;
};
void SetInitialEnrollmentState(
const std::string& brand_serial_id,
const InitialEnrollmentState& initial_enrollment_state);
const InitialEnrollmentState* GetInitialEnrollmentState(
const std::string& brand_serial_id) const;
// Returns truncated hashes (the first 8 bytes only) for brand serial IDs
// whose initial enrollment state is registered on the server. Only hashes,
// which, when divied by |modulus|, result in the specified |remainder|, are
// returned.
std::vector<std::string> GetMatchingSerialHashes(uint64_t modulus,
uint64_t remainder) const;
void set_error_detail(
enterprise_management::DeviceManagementErrorDetail error_detail) {
error_detail_ = error_detail;
}
enterprise_management::DeviceManagementErrorDetail error_detail() const {
return error_detail_;
}
bool enrollment_required() const { return enrollment_required_; }
void set_enrollment_required(bool enrollment_required) {
enrollment_required_ = enrollment_required;
}
private:
// Maps policy keys to a serialized proto representing the policies to be
// applied for the type (e.g. CloudPolicySettings, ChromeDeviceSettingsProto).
base::flat_map<std::string, std::string> policy_payloads_;
// Maps policy keys to a raw policy data served via an external endpoint.
base::flat_map<std::string, std::string> external_policy_payloads_;
std::unique_ptr<SignatureProvider> signature_provider_;
std::string robot_api_auth_code_;
std::string service_account_identity_;
base::flat_set<std::string> managed_users_;
std::vector<std::string> device_affiliation_ids_;
std::vector<std::string> user_affiliation_ids_;
std::string directory_api_id_;
std::string policy_user_;
std::string policy_invalidation_topic_;
std::optional<enterprise_management::PolicyData::MarketSegment>
market_segment_;
std::optional<enterprise_management::PolicyData::MetricsLogSegment>
metrics_log_segment_;
std::optional<
enterprise_management::PolicyData::K12AgeClassificationMetricsLogSegment>
k12_age_classification_metrics_log_segment_;
base::Time timestamp_;
bool allow_set_device_attributes_ = true;
DeviceState device_state_;
bool has_kiosk_license_ = true;
bool has_enterprise_license_ = true;
bool enrollment_required_ = false;
// Maps brand serial ID to PsmEntry.
base::flat_map<std::string, PsmEntry> psm_entries_;
// Maps brand serial ID to InitialEnrollmentState.
base::flat_map<std::string, InitialEnrollmentState>
initial_enrollment_states_;
// Determines whether the DMToken should be invalidated or deleted during
// browser unenrollment.
enterprise_management::DeviceManagementErrorDetail error_detail_ =
enterprise_management::CBCM_DELETION_POLICY_PREFERENCE_INVALIDATE_TOKEN;
};
} // namespace policy
#endif // COMPONENTS_POLICY_TEST_SUPPORT_POLICY_STORAGE_H_
|