Commit 6b35ac7c authored by Irem Uğuz's avatar Irem Uğuz Committed by Commit Bot

Cert Provisioning: Add name field to CertProfile

This cl adds name field to CertProfile and updates the tests and serializer accordingly. Certificate name field will be necessary to show it on the UI for the associated bug.

Bug: 1137523
Change-Id: Iefbe3f167a1e65ada7cfda7af858355a1e27c134
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2543146
Commit-Queue: Irem Uğuz <iremuguz@google.com>
Reviewed-by: default avatarPavol Marko <pmarko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#830544}
parent 2065e802
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "chrome/browser/chromeos/cert_provisioning/cert_provisioning_common.h" #include "chrome/browser/chromeos/cert_provisioning/cert_provisioning_common.h"
#include <string>
#include "base/callback_helpers.h" #include "base/callback_helpers.h"
#include "base/notreached.h" #include "base/notreached.h"
#include "base/optional.h" #include "base/optional.h"
...@@ -90,19 +92,27 @@ bool IsFinalState(CertProvisioningWorkerState state) { ...@@ -90,19 +92,27 @@ bool IsFinalState(CertProvisioningWorkerState state) {
//===================== CertProfile ============================================ //===================== CertProfile ============================================
CertProfile::CertProfile(CertProfileId profile_id, CertProfile::CertProfile(CertProfileId profile_id,
std::string name,
std::string policy_version, std::string policy_version,
bool is_va_enabled, bool is_va_enabled,
base::TimeDelta renewal_period) base::TimeDelta renewal_period)
: profile_id(profile_id), : profile_id(profile_id),
policy_version(policy_version), name(std::move(name)),
policy_version(std::move(policy_version)),
is_va_enabled(is_va_enabled), is_va_enabled(is_va_enabled),
renewal_period(renewal_period) {} renewal_period(renewal_period) {}
CertProfile::CertProfile(const CertProfile& other) = default;
CertProfile::CertProfile() = default;
CertProfile::~CertProfile() = default;
base::Optional<CertProfile> CertProfile::MakeFromValue( base::Optional<CertProfile> CertProfile::MakeFromValue(
const base::Value& value) { const base::Value& value) {
static_assert(kVersion == 4, "This function should be updated"); static_assert(kVersion == 5, "This function should be updated");
const std::string* id = value.FindStringKey(kCertProfileIdKey); const std::string* id = value.FindStringKey(kCertProfileIdKey);
const std::string* name = value.FindStringKey(kCertProfileNameKey);
const std::string* policy_version = const std::string* policy_version =
value.FindStringKey(kCertProfilePolicyVersionKey); value.FindStringKey(kCertProfilePolicyVersionKey);
base::Optional<bool> is_va_enabled = base::Optional<bool> is_va_enabled =
...@@ -116,6 +126,7 @@ base::Optional<CertProfile> CertProfile::MakeFromValue( ...@@ -116,6 +126,7 @@ base::Optional<CertProfile> CertProfile::MakeFromValue(
CertProfile result; CertProfile result;
result.profile_id = *id; result.profile_id = *id;
result.name = name ? *name : std::string();
result.policy_version = *policy_version; result.policy_version = *policy_version;
result.is_va_enabled = is_va_enabled.value_or(true); result.is_va_enabled = is_va_enabled.value_or(true);
result.renewal_period = result.renewal_period =
...@@ -125,8 +136,8 @@ base::Optional<CertProfile> CertProfile::MakeFromValue( ...@@ -125,8 +136,8 @@ base::Optional<CertProfile> CertProfile::MakeFromValue(
} }
bool CertProfile::operator==(const CertProfile& other) const { bool CertProfile::operator==(const CertProfile& other) const {
static_assert(kVersion == 4, "This function should be updated"); static_assert(kVersion == 5, "This function should be updated");
return ((profile_id == other.profile_id) && return ((profile_id == other.profile_id) && (name == other.name) &&
(policy_version == other.policy_version) && (policy_version == other.policy_version) &&
(is_va_enabled == other.is_va_enabled) && (is_va_enabled == other.is_va_enabled) &&
(renewal_period == other.renewal_period)); (renewal_period == other.renewal_period));
...@@ -138,8 +149,8 @@ bool CertProfile::operator!=(const CertProfile& other) const { ...@@ -138,8 +149,8 @@ bool CertProfile::operator!=(const CertProfile& other) const {
bool CertProfileComparator::operator()(const CertProfile& a, bool CertProfileComparator::operator()(const CertProfile& a,
const CertProfile& b) const { const CertProfile& b) const {
static_assert(CertProfile::kVersion == 4, "This function should be updated"); static_assert(CertProfile::kVersion == 5, "This function should be updated");
return ((a.profile_id < b.profile_id) || return ((a.profile_id < b.profile_id) || (a.name < b.name) ||
(a.policy_version < b.policy_version) || (a.policy_version < b.policy_version) ||
(a.is_va_enabled < b.is_va_enabled) || (a.is_va_enabled < b.is_va_enabled) ||
(a.renewal_period < b.renewal_period)); (a.renewal_period < b.renewal_period));
......
...@@ -75,6 +75,7 @@ using CertProfileId = std::string; ...@@ -75,6 +75,7 @@ using CertProfileId = std::string;
// with definitions of RequiredClientCertificateForDevice and // with definitions of RequiredClientCertificateForDevice and
// RequiredClientCertificateForUser policies in policy_templates.json file. // RequiredClientCertificateForUser policies in policy_templates.json file.
const char kCertProfileIdKey[] = "cert_profile_id"; const char kCertProfileIdKey[] = "cert_profile_id";
const char kCertProfileNameKey[] = "name";
const char kCertProfileRenewalPeroidSec[] = "renewal_period_seconds"; const char kCertProfileRenewalPeroidSec[] = "renewal_period_seconds";
const char kCertProfilePolicyVersionKey[] = "policy_version"; const char kCertProfilePolicyVersionKey[] = "policy_version";
const char kCertProfileIsVaEnabledKey[] = "enable_remote_attestation_check"; const char kCertProfileIsVaEnabledKey[] = "enable_remote_attestation_check";
...@@ -82,14 +83,19 @@ const char kCertProfileIsVaEnabledKey[] = "enable_remote_attestation_check"; ...@@ -82,14 +83,19 @@ const char kCertProfileIsVaEnabledKey[] = "enable_remote_attestation_check";
struct CertProfile { struct CertProfile {
static base::Optional<CertProfile> MakeFromValue(const base::Value& value); static base::Optional<CertProfile> MakeFromValue(const base::Value& value);
CertProfile() = default; CertProfile();
// For tests. // For tests.
CertProfile(CertProfileId profile_id, CertProfile(CertProfileId profile_id,
std::string name,
std::string policy_version, std::string policy_version,
bool is_va_enabled, bool is_va_enabled,
base::TimeDelta renewal_period); base::TimeDelta renewal_period);
CertProfile(const CertProfile& other);
~CertProfile();
CertProfileId profile_id; CertProfileId profile_id;
// Human-readable name (UTF-8).
std::string name;
std::string policy_version; std::string policy_version;
bool is_va_enabled = true; bool is_va_enabled = true;
// Default renewal period 0 means that a certificate will be renewed only // Default renewal period 0 means that a certificate will be renewed only
...@@ -99,7 +105,7 @@ struct CertProfile { ...@@ -99,7 +105,7 @@ struct CertProfile {
// IMPORTANT: // IMPORTANT:
// Increment this when you add/change any member in CertProfile (and update // Increment this when you add/change any member in CertProfile (and update
// all functions that fail to compile because of it). // all functions that fail to compile because of it).
static constexpr int kVersion = 4; static constexpr int kVersion = 5;
bool operator==(const CertProfile& other) const; bool operator==(const CertProfile& other) const;
bool operator!=(const CertProfile& other) const; bool operator!=(const CertProfile& other) const;
......
...@@ -44,6 +44,7 @@ namespace { ...@@ -44,6 +44,7 @@ namespace {
constexpr char kWifiServiceGuid[] = "wifi_guid"; constexpr char kWifiServiceGuid[] = "wifi_guid";
constexpr char kCertProfileId[] = "cert_profile_id_1"; constexpr char kCertProfileId[] = "cert_profile_id_1";
constexpr char kCertProfileName[] = "Certificate Profile 1";
constexpr char kCertProfileVersion[] = "cert_profile_version_1"; constexpr char kCertProfileVersion[] = "cert_profile_version_1";
constexpr TimeDelta kCertProfileRenewalPeriod = TimeDelta::FromSeconds(0); constexpr TimeDelta kCertProfileRenewalPeriod = TimeDelta::FromSeconds(0);
...@@ -209,7 +210,8 @@ TEST_F(CertProvisioningSchedulerTest, Success) { ...@@ -209,7 +210,8 @@ TEST_F(CertProvisioningSchedulerTest, Success) {
VerifyDeleteKeysByPrefixCalledOnce(kCertScope); VerifyDeleteKeysByPrefixCalledOnce(kCertScope);
// One worker will be created on prefs update. // One worker will be created on prefs update.
CertProfile cert_profile(kCertProfileId, kCertProfileVersion, CertProfile cert_profile(kCertProfileId, kCertProfileName,
kCertProfileVersion,
/*is_va_enabled=*/true, kCertProfileRenewalPeriod); /*is_va_enabled=*/true, kCertProfileRenewalPeriod);
MockCertProvisioningWorker* worker = MockCertProvisioningWorker* worker =
mock_factory_.ExpectCreateReturnMock(kCertScope, cert_profile); mock_factory_.ExpectCreateReturnMock(kCertScope, cert_profile);
...@@ -263,7 +265,8 @@ TEST_F(CertProvisioningSchedulerTest, WorkerFailed) { ...@@ -263,7 +265,8 @@ TEST_F(CertProvisioningSchedulerTest, WorkerFailed) {
VerifyDeleteKeysByPrefixCalledOnce(kCertScope); VerifyDeleteKeysByPrefixCalledOnce(kCertScope);
// One worker will be created on prefs update. // One worker will be created on prefs update.
CertProfile cert_profile(kCertProfileId, kCertProfileVersion, CertProfile cert_profile(kCertProfileId, kCertProfileName,
kCertProfileVersion,
/*is_va_enabled=*/true, kCertProfileRenewalPeriod); /*is_va_enabled=*/true, kCertProfileRenewalPeriod);
MockCertProvisioningWorker* worker = MockCertProvisioningWorker* worker =
mock_factory_.ExpectCreateReturnMock(kCertScope, cert_profile); mock_factory_.ExpectCreateReturnMock(kCertScope, cert_profile);
...@@ -302,7 +305,8 @@ TEST_F(CertProvisioningSchedulerTest, WorkerFailed) { ...@@ -302,7 +305,8 @@ TEST_F(CertProvisioningSchedulerTest, WorkerFailed) {
TEST_F(CertProvisioningSchedulerTest, InitialAndDailyUpdates) { TEST_F(CertProvisioningSchedulerTest, InitialAndDailyUpdates) {
const CertScope kCertScope = CertScope::kUser; const CertScope kCertScope = CertScope::kUser;
CertProfile cert_profile(kCertProfileId, kCertProfileVersion, CertProfile cert_profile(kCertProfileId, kCertProfileName,
kCertProfileVersion,
/*is_va_enabled=*/true, kCertProfileRenewalPeriod); /*is_va_enabled=*/true, kCertProfileRenewalPeriod);
// Add 1 certificate profile to the policy (the values are the same as // Add 1 certificate profile to the policy (the values are the same as
...@@ -378,16 +382,22 @@ TEST_F(CertProvisioningSchedulerTest, MultipleWorkers) { ...@@ -378,16 +382,22 @@ TEST_F(CertProvisioningSchedulerTest, MultipleWorkers) {
// New workers will be created on prefs update. // New workers will be created on prefs update.
const char kCertProfileId0[] = "cert_profile_id_0"; const char kCertProfileId0[] = "cert_profile_id_0";
const char kCertProfileName0[] = "Certificate Profile 0";
const char kCertProfileVersion0[] = "cert_profile_version_0"; const char kCertProfileVersion0[] = "cert_profile_version_0";
CertProfile cert_profile0(kCertProfileId0, kCertProfileVersion0, CertProfile cert_profile0(kCertProfileId0, kCertProfileName0,
kCertProfileVersion0,
/*is_va_enabled=*/true, kCertProfileRenewalPeriod); /*is_va_enabled=*/true, kCertProfileRenewalPeriod);
const char kCertProfileId1[] = "cert_profile_id_1"; const char kCertProfileId1[] = "cert_profile_id_1";
const char kCertProfileName1[] = "Certificate Profile 1";
const char kCertProfileVersion1[] = "cert_profile_version_1"; const char kCertProfileVersion1[] = "cert_profile_version_1";
CertProfile cert_profile1(kCertProfileId1, kCertProfileVersion1, CertProfile cert_profile1(kCertProfileId1, kCertProfileName1,
kCertProfileVersion1,
/*is_va_enabled=*/true, kCertProfileRenewalPeriod); /*is_va_enabled=*/true, kCertProfileRenewalPeriod);
const char kCertProfileId2[] = "cert_profile_id_2"; const char kCertProfileId2[] = "cert_profile_id_2";
const char kCertProfileName2[] = "Certificate Profile 2";
const char kCertProfileVersion2[] = "cert_profile_version_2"; const char kCertProfileVersion2[] = "cert_profile_version_2";
CertProfile cert_profile2(kCertProfileId2, kCertProfileVersion2, CertProfile cert_profile2(kCertProfileId2, kCertProfileName2,
kCertProfileVersion2,
/*is_va_enabled=*/true, kCertProfileRenewalPeriod); /*is_va_enabled=*/true, kCertProfileRenewalPeriod);
MockCertProvisioningWorker* worker0 = MockCertProvisioningWorker* worker0 =
mock_factory_.ExpectCreateReturnMock(kCertScope, cert_profile0); mock_factory_.ExpectCreateReturnMock(kCertScope, cert_profile0);
...@@ -483,7 +493,8 @@ TEST_F(CertProvisioningSchedulerTest, RemoveCertWithoutPolicy) { ...@@ -483,7 +493,8 @@ TEST_F(CertProvisioningSchedulerTest, RemoveCertWithoutPolicy) {
TEST_F(CertProvisioningSchedulerTest, DeserializeWorkers) { TEST_F(CertProvisioningSchedulerTest, DeserializeWorkers) {
const CertScope kCertScope = CertScope::kUser; const CertScope kCertScope = CertScope::kUser;
CertProfile cert_profile(kCertProfileId, kCertProfileVersion, CertProfile cert_profile(kCertProfileId, kCertProfileName,
kCertProfileVersion,
/*is_va_enabled=*/true, kCertProfileRenewalPeriod); /*is_va_enabled=*/true, kCertProfileRenewalPeriod);
// Add 1 certificate profile to the policy (the values are the same as // Add 1 certificate profile to the policy (the values are the same as
...@@ -548,9 +559,9 @@ TEST_F(CertProvisioningSchedulerTest, InconsistentDataErrorHandling) { ...@@ -548,9 +559,9 @@ TEST_F(CertProvisioningSchedulerTest, InconsistentDataErrorHandling) {
// From CertProvisioningScheduler::CleanVaKeysIfIdle. // From CertProvisioningScheduler::CleanVaKeysIfIdle.
VerifyDeleteKeysByPrefixCalledOnce(kCertScope); VerifyDeleteKeysByPrefixCalledOnce(kCertScope);
CertProfile cert_profile_v1(kCertProfileId, kCertProfileVersion1, CertProfile cert_profile_v1(
/*is_va_enabled=*/true, kCertProfileId, kCertProfileName, kCertProfileVersion1,
kCertProfileRenewalPeriod); /*is_va_enabled=*/true, kCertProfileRenewalPeriod);
MockCertProvisioningWorker* worker = MockCertProvisioningWorker* worker =
mock_factory_.ExpectCreateReturnMock(kCertScope, cert_profile_v1); mock_factory_.ExpectCreateReturnMock(kCertScope, cert_profile_v1);
...@@ -597,9 +608,9 @@ TEST_F(CertProvisioningSchedulerTest, InconsistentDataErrorHandling) { ...@@ -597,9 +608,9 @@ TEST_F(CertProvisioningSchedulerTest, InconsistentDataErrorHandling) {
EXPECT_TRUE(scheduler.GetFailedCertProfileIds().empty()); EXPECT_TRUE(scheduler.GetFailedCertProfileIds().empty());
// Add a new worker to the factory. // Add a new worker to the factory.
CertProfile cert_profile_v2(kCertProfileId, kCertProfileVersion2, CertProfile cert_profile_v2(
/*is_va_enabled=*/true, kCertProfileId, kCertProfileName, kCertProfileVersion2,
kCertProfileRenewalPeriod); /*is_va_enabled=*/true, kCertProfileRenewalPeriod);
worker = mock_factory_.ExpectCreateReturnMock(kCertScope, cert_profile_v2); worker = mock_factory_.ExpectCreateReturnMock(kCertScope, cert_profile_v2);
worker->SetExpectations(/*do_step_times=*/AtLeast(1), /*is_waiting=*/false, worker->SetExpectations(/*do_step_times=*/AtLeast(1), /*is_waiting=*/false,
cert_profile_v2); cert_profile_v2);
...@@ -644,7 +655,8 @@ TEST_F(CertProvisioningSchedulerTest, RetryAfterNoInternetConnection) { ...@@ -644,7 +655,8 @@ TEST_F(CertProvisioningSchedulerTest, RetryAfterNoInternetConnection) {
const CertScope kCertScope = CertScope::kDevice; const CertScope kCertScope = CertScope::kDevice;
SetWifiNetworkState(shill::kStateIdle); SetWifiNetworkState(shill::kStateIdle);
CertProfile cert_profile(kCertProfileId, kCertProfileVersion, CertProfile cert_profile(kCertProfileId, kCertProfileName,
kCertProfileVersion,
/*is_va_enabled=*/true, kCertProfileRenewalPeriod); /*is_va_enabled=*/true, kCertProfileRenewalPeriod);
// Add 1 certificate profile to the policy (the values are the same as // Add 1 certificate profile to the policy (the values are the same as
// in |cert_profile|). // in |cert_profile|).
...@@ -681,7 +693,8 @@ TEST_F(CertProvisioningSchedulerTest, RetryAfterNoInternetConnection) { ...@@ -681,7 +693,8 @@ TEST_F(CertProvisioningSchedulerTest, RetryAfterNoInternetConnection) {
TEST_F(CertProvisioningSchedulerTest, DeleteWorkerWithoutPolicy) { TEST_F(CertProvisioningSchedulerTest, DeleteWorkerWithoutPolicy) {
const CertScope kCertScope = CertScope::kDevice; const CertScope kCertScope = CertScope::kDevice;
CertProfile cert_profile(kCertProfileId, kCertProfileVersion, CertProfile cert_profile(kCertProfileId, kCertProfileName,
kCertProfileVersion,
/*is_va_enabled=*/true, kCertProfileRenewalPeriod); /*is_va_enabled=*/true, kCertProfileRenewalPeriod);
// Add 1 certificate profile to the policy (the values are the same as // Add 1 certificate profile to the policy (the values are the same as
// in |cert_profile|). // in |cert_profile|).
...@@ -748,7 +761,8 @@ TEST_F(CertProvisioningSchedulerTest, DeleteVaKeysOnIdle) { ...@@ -748,7 +761,8 @@ TEST_F(CertProvisioningSchedulerTest, DeleteVaKeysOnIdle) {
->ClearDeleteKeysHistory(); ->ClearDeleteKeysHistory();
{ {
CertProfile cert_profile(kCertProfileId, kCertProfileVersion, CertProfile cert_profile(kCertProfileId, kCertProfileName,
kCertProfileVersion,
/*is_va_enabled=*/true, kCertProfileRenewalPeriod); /*is_va_enabled=*/true, kCertProfileRenewalPeriod);
// Add 1 serialized worker for the profile (the values are the same as // Add 1 serialized worker for the profile (the values are the same as
...@@ -799,7 +813,8 @@ TEST_F(CertProvisioningSchedulerTest, UpdateOneCert) { ...@@ -799,7 +813,8 @@ TEST_F(CertProvisioningSchedulerTest, UpdateOneCert) {
network_state_test_helper_.network_state_handler(), network_state_test_helper_.network_state_handler(),
MakeFakeInvalidationFactory()); MakeFakeInvalidationFactory());
CertProfile cert_profile(kCertProfileId, kCertProfileVersion, CertProfile cert_profile(kCertProfileId, kCertProfileName,
kCertProfileVersion,
/*is_va_enabled=*/true, kCertProfileRenewalPeriod); /*is_va_enabled=*/true, kCertProfileRenewalPeriod);
FastForwardBy(TimeDelta::FromSeconds(1)); FastForwardBy(TimeDelta::FromSeconds(1));
...@@ -886,7 +901,8 @@ TEST_F(CertProvisioningSchedulerTest, CertRenewal) { ...@@ -886,7 +901,8 @@ TEST_F(CertProvisioningSchedulerTest, CertRenewal) {
// 1 day == 86400 seconds. // 1 day == 86400 seconds.
const TimeDelta kRenewalPeriod = TimeDelta::FromDays(1); const TimeDelta kRenewalPeriod = TimeDelta::FromDays(1);
CertProfile cert_profile(kCertProfileId, kCertProfileVersion, CertProfile cert_profile(kCertProfileId, kCertProfileName,
kCertProfileVersion,
/*is_va_enabled=*/true, kRenewalPeriod); /*is_va_enabled=*/true, kRenewalPeriod);
const Time t1 = Time::Now() - TimeDelta::FromDays(1); const Time t1 = Time::Now() - TimeDelta::FromDays(1);
...@@ -959,7 +975,8 @@ TEST_F(CertProvisioningSchedulerTest, PlatformKeysServiceShutDown) { ...@@ -959,7 +975,8 @@ TEST_F(CertProvisioningSchedulerTest, PlatformKeysServiceShutDown) {
// Same as in the policy. // Same as in the policy.
const char kCertProfileId[] = "cert_profile_id_1"; const char kCertProfileId[] = "cert_profile_id_1";
const char kCertProfileVersion[] = "cert_profile_version_1"; const char kCertProfileVersion[] = "cert_profile_version_1";
CertProfile cert_profile{kCertProfileId, kCertProfileVersion, CertProfile cert_profile{kCertProfileId, kCertProfileName,
kCertProfileVersion,
/*is_va_enabled=*/true, kCertProfileRenewalPeriod}; /*is_va_enabled=*/true, kCertProfileRenewalPeriod};
MockCertProvisioningWorker* worker = MockCertProvisioningWorker* worker =
...@@ -1006,12 +1023,16 @@ TEST_F(CertProvisioningSchedulerTest, StateChangeNotifications) { ...@@ -1006,12 +1023,16 @@ TEST_F(CertProvisioningSchedulerTest, StateChangeNotifications) {
// Two new workers will be created on prefs update. // Two new workers will be created on prefs update.
// Expect a state change notification for this. // Expect a state change notification for this.
const char kCertProfileId0[] = "cert_profile_id_0"; const char kCertProfileId0[] = "cert_profile_id_0";
const char kCertProfileName0[] = "Certificate Profile 0";
const char kCertProfileVersion0[] = "cert_profile_version_0"; const char kCertProfileVersion0[] = "cert_profile_version_0";
CertProfile cert_profile0(kCertProfileId0, kCertProfileVersion0, CertProfile cert_profile0(kCertProfileId0, kCertProfileName0,
kCertProfileVersion0,
/*is_va_enabled=*/true, kCertProfileRenewalPeriod); /*is_va_enabled=*/true, kCertProfileRenewalPeriod);
const char kCertProfileId1[] = "cert_profile_id_1"; const char kCertProfileId1[] = "cert_profile_id_1";
const char kCertProfileName1[] = "Certificate Profile 1";
const char kCertProfileVersion1[] = "cert_profile_version_1"; const char kCertProfileVersion1[] = "cert_profile_version_1";
CertProfile cert_profile1(kCertProfileId1, kCertProfileVersion1, CertProfile cert_profile1(kCertProfileId1, kCertProfileName1,
kCertProfileVersion1,
/*is_va_enabled=*/true, kCertProfileRenewalPeriod); /*is_va_enabled=*/true, kCertProfileRenewalPeriod);
MockCertProvisioningWorker* worker0 = MockCertProvisioningWorker* worker0 =
......
...@@ -24,6 +24,7 @@ constexpr char kKeyNamePublicKey[] = "public_key"; ...@@ -24,6 +24,7 @@ constexpr char kKeyNamePublicKey[] = "public_key";
constexpr char kKeyNameInvalidationTopic[] = "invalidation_topic"; constexpr char kKeyNameInvalidationTopic[] = "invalidation_topic";
constexpr char kKeyNameCertProfileId[] = "profile_id"; constexpr char kKeyNameCertProfileId[] = "profile_id";
constexpr char kKeyNameCertProfileName[] = "name";
constexpr char kKeyNameCertProfileVersion[] = "policy_version"; constexpr char kKeyNameCertProfileVersion[] = "policy_version";
constexpr char kKeyNameCertProfileVaEnabled[] = "va_enabled"; constexpr char kKeyNameCertProfileVaEnabled[] = "va_enabled";
constexpr char kKeyNameCertProfileRenewalPeriod[] = "renewal_period"; constexpr char kKeyNameCertProfileRenewalPeriod[] = "renewal_period";
...@@ -82,10 +83,11 @@ bool DeserializeRenewalPeriod(const base::Value& parent_value, ...@@ -82,10 +83,11 @@ bool DeserializeRenewalPeriod(const base::Value& parent_value,
} }
base::Value SerializeCertProfile(const CertProfile& profile) { base::Value SerializeCertProfile(const CertProfile& profile) {
static_assert(CertProfile::kVersion == 4, "This function should be updated"); static_assert(CertProfile::kVersion == 5, "This function should be updated");
base::Value result(base::Value::Type::DICTIONARY); base::Value result(base::Value::Type::DICTIONARY);
result.SetStringKey(kKeyNameCertProfileId, profile.profile_id); result.SetStringKey(kKeyNameCertProfileId, profile.profile_id);
result.SetStringKey(kKeyNameCertProfileName, profile.name);
result.SetStringKey(kKeyNameCertProfileVersion, profile.policy_version); result.SetStringKey(kKeyNameCertProfileVersion, profile.policy_version);
result.SetBoolKey(kKeyNameCertProfileVaEnabled, profile.is_va_enabled); result.SetBoolKey(kKeyNameCertProfileVaEnabled, profile.is_va_enabled);
...@@ -100,7 +102,7 @@ base::Value SerializeCertProfile(const CertProfile& profile) { ...@@ -100,7 +102,7 @@ base::Value SerializeCertProfile(const CertProfile& profile) {
bool DeserializeCertProfile(const base::Value& parent_value, bool DeserializeCertProfile(const base::Value& parent_value,
const char* value_name, const char* value_name,
CertProfile* dst) { CertProfile* dst) {
static_assert(CertProfile::kVersion == 4, "This function should be updated"); static_assert(CertProfile::kVersion == 5, "This function should be updated");
const base::Value* serialized_profile = const base::Value* serialized_profile =
parent_value.FindKeyOfType(value_name, base::Value::Type::DICTIONARY); parent_value.FindKeyOfType(value_name, base::Value::Type::DICTIONARY);
...@@ -113,6 +115,9 @@ bool DeserializeCertProfile(const base::Value& parent_value, ...@@ -113,6 +115,9 @@ bool DeserializeCertProfile(const base::Value& parent_value,
is_ok = is_ok && is_ok = is_ok &&
DeserializeStringValue(*serialized_profile, kKeyNameCertProfileId, DeserializeStringValue(*serialized_profile, kKeyNameCertProfileId,
&(dst->profile_id)); &(dst->profile_id));
is_ok =
is_ok && DeserializeStringValue(*serialized_profile,
kKeyNameCertProfileName, &(dst->name));
is_ok = is_ok && DeserializeStringValue(*serialized_profile, is_ok = is_ok && DeserializeStringValue(*serialized_profile,
kKeyNameCertProfileVersion, kKeyNameCertProfileVersion,
&(dst->policy_version)); &(dst->policy_version));
......
...@@ -90,6 +90,7 @@ constexpr char kPublicKeyBase64[] = ...@@ -90,6 +90,7 @@ constexpr char kPublicKeyBase64[] =
"TLaN7pwQx68PK5pd/lv58B7jjxCIAai0BX1rV6bl/Am3EukhTSuIcQiTr5c1G4E6bKwIDAQAB"; "TLaN7pwQx68PK5pd/lv58B7jjxCIAai0BX1rV6bl/Am3EukhTSuIcQiTr5c1G4E6bKwIDAQAB";
constexpr char kCertProfileId[] = "cert_profile_1"; constexpr char kCertProfileId[] = "cert_profile_1";
constexpr char kCertProfileName[] = "Certificate Profile 1";
constexpr char kCertProfileVersion[] = "cert_profile_version_1"; constexpr char kCertProfileVersion[] = "cert_profile_version_1";
constexpr base::TimeDelta kCertProfileRenewalPeriod = constexpr base::TimeDelta kCertProfileRenewalPeriod =
base::TimeDelta::FromSeconds(0); base::TimeDelta::FromSeconds(0);
...@@ -468,7 +469,8 @@ class CertProvisioningWorkerTest : public ::testing::Test { ...@@ -468,7 +469,8 @@ class CertProvisioningWorkerTest : public ::testing::Test {
TEST_F(CertProvisioningWorkerTest, Success) { TEST_F(CertProvisioningWorkerTest, Success) {
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
CertProfile cert_profile(kCertProfileId, kCertProfileVersion, CertProfile cert_profile(kCertProfileId, kCertProfileName,
kCertProfileVersion,
/*is_va_enabled=*/true, kCertProfileRenewalPeriod); /*is_va_enabled=*/true, kCertProfileRenewalPeriod);
MockTpmChallengeKeySubtle* mock_tpm_challenge_key = PrepareTpmChallengeKey(); MockTpmChallengeKeySubtle* mock_tpm_challenge_key = PrepareTpmChallengeKey();
...@@ -559,7 +561,8 @@ TEST_F(CertProvisioningWorkerTest, Success) { ...@@ -559,7 +561,8 @@ TEST_F(CertProvisioningWorkerTest, Success) {
// Checks that the worker makes all necessary requests to other modules during // Checks that the worker makes all necessary requests to other modules during
// success scenario when VA challenge is not received. // success scenario when VA challenge is not received.
TEST_F(CertProvisioningWorkerTest, NoVaSuccess) { TEST_F(CertProvisioningWorkerTest, NoVaSuccess) {
CertProfile cert_profile(kCertProfileId, kCertProfileVersion, CertProfile cert_profile(kCertProfileId, kCertProfileName,
kCertProfileVersion,
/*is_va_enabled=*/false, kCertProfileRenewalPeriod); /*is_va_enabled=*/false, kCertProfileRenewalPeriod);
CertProvisioningWorkerImpl worker( CertProvisioningWorkerImpl worker(
...@@ -619,7 +622,8 @@ TEST_F(CertProvisioningWorkerTest, NoVaSuccess) { ...@@ -619,7 +622,8 @@ TEST_F(CertProvisioningWorkerTest, NoVaSuccess) {
// Checks that when the server returns try_again_later field, the worker will // Checks that when the server returns try_again_later field, the worker will
// retry a request when it asked to continue the provisioning. // retry a request when it asked to continue the provisioning.
TEST_F(CertProvisioningWorkerTest, TryLaterManualRetry) { TEST_F(CertProvisioningWorkerTest, TryLaterManualRetry) {
CertProfile cert_profile(kCertProfileId, kCertProfileVersion, CertProfile cert_profile(kCertProfileId, kCertProfileName,
kCertProfileVersion,
/*is_va_enabled=*/true, kCertProfileRenewalPeriod); /*is_va_enabled=*/true, kCertProfileRenewalPeriod);
MockTpmChallengeKeySubtle* mock_tpm_challenge_key = PrepareTpmChallengeKey(); MockTpmChallengeKeySubtle* mock_tpm_challenge_key = PrepareTpmChallengeKey();
...@@ -730,7 +734,8 @@ TEST_F(CertProvisioningWorkerTest, TryLaterManualRetry) { ...@@ -730,7 +734,8 @@ TEST_F(CertProvisioningWorkerTest, TryLaterManualRetry) {
// Checks that when the server returns try_again_later field, the worker will // Checks that when the server returns try_again_later field, the worker will
// automatically retry a request after some time. // automatically retry a request after some time.
TEST_F(CertProvisioningWorkerTest, TryLaterWait) { TEST_F(CertProvisioningWorkerTest, TryLaterWait) {
CertProfile cert_profile(kCertProfileId, kCertProfileVersion, CertProfile cert_profile(kCertProfileId, kCertProfileName,
kCertProfileVersion,
/*is_va_enabled=*/true, kCertProfileRenewalPeriod); /*is_va_enabled=*/true, kCertProfileRenewalPeriod);
MockTpmChallengeKeySubtle* mock_tpm_challenge_key = PrepareTpmChallengeKey(); MockTpmChallengeKeySubtle* mock_tpm_challenge_key = PrepareTpmChallengeKey();
...@@ -849,7 +854,8 @@ TEST_F(CertProvisioningWorkerTest, TryLaterWait) { ...@@ -849,7 +854,8 @@ TEST_F(CertProvisioningWorkerTest, TryLaterWait) {
// Checks that when the server returns try_again_later field, the worker will // Checks that when the server returns try_again_later field, the worker will
// retry when the invalidation is triggered. // retry when the invalidation is triggered.
TEST_F(CertProvisioningWorkerTest, InvalidationRespected) { TEST_F(CertProvisioningWorkerTest, InvalidationRespected) {
CertProfile cert_profile(kCertProfileId, kCertProfileVersion, CertProfile cert_profile(kCertProfileId, kCertProfileName,
kCertProfileVersion,
/*is_va_enabled=*/true, kCertProfileRenewalPeriod); /*is_va_enabled=*/true, kCertProfileRenewalPeriod);
MockTpmChallengeKeySubtle* mock_tpm_challenge_key = PrepareTpmChallengeKey(); MockTpmChallengeKeySubtle* mock_tpm_challenge_key = PrepareTpmChallengeKey();
...@@ -972,7 +978,8 @@ TEST_F(CertProvisioningWorkerTest, InvalidationRespected) { ...@@ -972,7 +978,8 @@ TEST_F(CertProvisioningWorkerTest, InvalidationRespected) {
// error state and stop the provisioning. // error state and stop the provisioning.
TEST_F(CertProvisioningWorkerTest, StatusErrorHandling) { TEST_F(CertProvisioningWorkerTest, StatusErrorHandling) {
const CertScope kCertScope = CertScope::kUser; const CertScope kCertScope = CertScope::kUser;
CertProfile cert_profile(kCertProfileId, kCertProfileVersion, CertProfile cert_profile(kCertProfileId, kCertProfileName,
kCertProfileVersion,
/*is_va_enabled=*/true, kCertProfileRenewalPeriod); /*is_va_enabled=*/true, kCertProfileRenewalPeriod);
MockTpmChallengeKeySubtle* mock_tpm_challenge_key = PrepareTpmChallengeKey(); MockTpmChallengeKeySubtle* mock_tpm_challenge_key = PrepareTpmChallengeKey();
...@@ -1015,7 +1022,8 @@ TEST_F(CertProvisioningWorkerTest, ResponseErrorHandling) { ...@@ -1015,7 +1022,8 @@ TEST_F(CertProvisioningWorkerTest, ResponseErrorHandling) {
const CertScope kCertScope = CertScope::kUser; const CertScope kCertScope = CertScope::kUser;
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
CertProfile cert_profile(kCertProfileId, kCertProfileVersion, CertProfile cert_profile(kCertProfileId, kCertProfileName,
kCertProfileVersion,
/*is_va_enabled=*/true, kCertProfileRenewalPeriod); /*is_va_enabled=*/true, kCertProfileRenewalPeriod);
MockTpmChallengeKeySubtle* mock_tpm_challenge_key = PrepareTpmChallengeKey(); MockTpmChallengeKeySubtle* mock_tpm_challenge_key = PrepareTpmChallengeKey();
...@@ -1059,7 +1067,8 @@ TEST_F(CertProvisioningWorkerTest, ResponseErrorHandling) { ...@@ -1059,7 +1067,8 @@ TEST_F(CertProvisioningWorkerTest, ResponseErrorHandling) {
TEST_F(CertProvisioningWorkerTest, InconsistentDataErrorHandling) { TEST_F(CertProvisioningWorkerTest, InconsistentDataErrorHandling) {
const CertScope kCertScope = CertScope::kUser; const CertScope kCertScope = CertScope::kUser;
CertProfile cert_profile(kCertProfileId, kCertProfileVersion, CertProfile cert_profile(kCertProfileId, kCertProfileName,
kCertProfileVersion,
/*is_va_enabled=*/true, kCertProfileRenewalPeriod); /*is_va_enabled=*/true, kCertProfileRenewalPeriod);
MockTpmChallengeKeySubtle* mock_tpm_challenge_key = PrepareTpmChallengeKey(); MockTpmChallengeKeySubtle* mock_tpm_challenge_key = PrepareTpmChallengeKey();
...@@ -1098,7 +1107,8 @@ TEST_F(CertProvisioningWorkerTest, InconsistentDataErrorHandling) { ...@@ -1098,7 +1107,8 @@ TEST_F(CertProvisioningWorkerTest, InconsistentDataErrorHandling) {
// Checks that when the server returns TEMPORARY_UNAVAILABLE status code, the // Checks that when the server returns TEMPORARY_UNAVAILABLE status code, the
// worker will automatically retry a request using exponential backoff strategy. // worker will automatically retry a request using exponential backoff strategy.
TEST_F(CertProvisioningWorkerTest, BackoffStrategy) { TEST_F(CertProvisioningWorkerTest, BackoffStrategy) {
CertProfile cert_profile(kCertProfileId, kCertProfileVersion, CertProfile cert_profile(kCertProfileId, kCertProfileName,
kCertProfileVersion,
/*is_va_enabled=*/true, kCertProfileRenewalPeriod); /*is_va_enabled=*/true, kCertProfileRenewalPeriod);
MockTpmChallengeKeySubtle* mock_tpm_challenge_key = PrepareTpmChallengeKey(); MockTpmChallengeKeySubtle* mock_tpm_challenge_key = PrepareTpmChallengeKey();
...@@ -1165,7 +1175,8 @@ TEST_F(CertProvisioningWorkerTest, BackoffStrategy) { ...@@ -1165,7 +1175,8 @@ TEST_F(CertProvisioningWorkerTest, BackoffStrategy) {
TEST_F(CertProvisioningWorkerTest, RemoveRegisteredKey) { TEST_F(CertProvisioningWorkerTest, RemoveRegisteredKey) {
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
CertProfile cert_profile(kCertProfileId, kCertProfileVersion, CertProfile cert_profile(kCertProfileId, kCertProfileName,
kCertProfileVersion,
/*is_va_enabled=*/true, kCertProfileRenewalPeriod); /*is_va_enabled=*/true, kCertProfileRenewalPeriod);
MockTpmChallengeKeySubtle* mock_tpm_challenge_key = PrepareTpmChallengeKey(); MockTpmChallengeKeySubtle* mock_tpm_challenge_key = PrepareTpmChallengeKey();
MockCertProvisioningInvalidator* mock_invalidator = nullptr; MockCertProvisioningInvalidator* mock_invalidator = nullptr;
...@@ -1262,7 +1273,8 @@ class PrefServiceObserver { ...@@ -1262,7 +1273,8 @@ class PrefServiceObserver {
TEST_F(CertProvisioningWorkerTest, SerializationSuccess) { TEST_F(CertProvisioningWorkerTest, SerializationSuccess) {
const base::TimeDelta kRenewalPeriod = base::TimeDelta::FromSeconds(1200300); const base::TimeDelta kRenewalPeriod = base::TimeDelta::FromSeconds(1200300);
CertProfile cert_profile(kCertProfileId, kCertProfileVersion, CertProfile cert_profile(kCertProfileId, kCertProfileName,
kCertProfileVersion,
/*is_va_enabled=*/true, kRenewalPeriod); /*is_va_enabled=*/true, kRenewalPeriod);
const CertScope kCertScope = CertScope::kUser; const CertScope kCertScope = CertScope::kUser;
...@@ -1300,6 +1312,7 @@ TEST_F(CertProvisioningWorkerTest, SerializationSuccess) { ...@@ -1300,6 +1312,7 @@ TEST_F(CertProvisioningWorkerTest, SerializationSuccess) {
"cert_profile_1": { "cert_profile_1": {
"cert_profile": { "cert_profile": {
"policy_version": "cert_profile_version_1", "policy_version": "cert_profile_version_1",
"name": "Certificate Profile 1",
"profile_id": "cert_profile_1", "profile_id": "cert_profile_1",
"va_enabled": true, "va_enabled": true,
"renewal_period": 1200300 "renewal_period": 1200300
...@@ -1382,6 +1395,7 @@ TEST_F(CertProvisioningWorkerTest, SerializationSuccess) { ...@@ -1382,6 +1395,7 @@ TEST_F(CertProvisioningWorkerTest, SerializationSuccess) {
"cert_profile_1": { "cert_profile_1": {
"cert_profile": { "cert_profile": {
"policy_version": "cert_profile_version_1", "policy_version": "cert_profile_version_1",
"name": "Certificate Profile 1",
"profile_id": "cert_profile_1", "profile_id": "cert_profile_1",
"va_enabled": true, "va_enabled": true,
"renewal_period": 1200300 "renewal_period": 1200300
...@@ -1449,7 +1463,8 @@ TEST_F(CertProvisioningWorkerTest, SerializationSuccess) { ...@@ -1449,7 +1463,8 @@ TEST_F(CertProvisioningWorkerTest, SerializationSuccess) {
TEST_F(CertProvisioningWorkerTest, SerializationOnFailure) { TEST_F(CertProvisioningWorkerTest, SerializationOnFailure) {
const CertScope kCertScope = CertScope::kUser; const CertScope kCertScope = CertScope::kUser;
CertProfile cert_profile(kCertProfileId, kCertProfileVersion, CertProfile cert_profile(kCertProfileId, kCertProfileName,
kCertProfileVersion,
/*is_va_enabled=*/true, kCertProfileRenewalPeriod); /*is_va_enabled=*/true, kCertProfileRenewalPeriod);
MockTpmChallengeKeySubtle* mock_tpm_challenge_key = PrepareTpmChallengeKey(); MockTpmChallengeKeySubtle* mock_tpm_challenge_key = PrepareTpmChallengeKey();
...@@ -1480,6 +1495,7 @@ TEST_F(CertProvisioningWorkerTest, SerializationOnFailure) { ...@@ -1480,6 +1495,7 @@ TEST_F(CertProvisioningWorkerTest, SerializationOnFailure) {
"cert_profile_1": { "cert_profile_1": {
"cert_profile": { "cert_profile": {
"policy_version": "cert_profile_version_1", "policy_version": "cert_profile_version_1",
"name": "Certificate Profile 1",
"profile_id": "cert_profile_1", "profile_id": "cert_profile_1",
"va_enabled": true "va_enabled": true
}, },
...@@ -1510,7 +1526,8 @@ TEST_F(CertProvisioningWorkerTest, SerializationOnFailure) { ...@@ -1510,7 +1526,8 @@ TEST_F(CertProvisioningWorkerTest, SerializationOnFailure) {
TEST_F(CertProvisioningWorkerTest, InformationalGetters) { TEST_F(CertProvisioningWorkerTest, InformationalGetters) {
const CertScope kCertScope = CertScope::kUser; const CertScope kCertScope = CertScope::kUser;
CertProfile cert_profile(kCertProfileId, kCertProfileVersion, CertProfile cert_profile(kCertProfileId, kCertProfileName,
kCertProfileVersion,
/*is_va_enabled=*/true, kCertProfileRenewalPeriod); /*is_va_enabled=*/true, kCertProfileRenewalPeriod);
MockTpmChallengeKeySubtle* mock_tpm_challenge_key = PrepareTpmChallengeKey(); MockTpmChallengeKeySubtle* mock_tpm_challenge_key = PrepareTpmChallengeKey();
...@@ -1564,7 +1581,8 @@ TEST_F(CertProvisioningWorkerTest, CancelDeviceWorker) { ...@@ -1564,7 +1581,8 @@ TEST_F(CertProvisioningWorkerTest, CancelDeviceWorker) {
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
const CertScope kCertScope = CertScope::kDevice; const CertScope kCertScope = CertScope::kDevice;
CertProfile cert_profile(kCertProfileId, kCertProfileVersion, CertProfile cert_profile(kCertProfileId, kCertProfileName,
kCertProfileVersion,
/*is_va_enabled=*/true, kCertProfileRenewalPeriod); /*is_va_enabled=*/true, kCertProfileRenewalPeriod);
EXPECT_CALL(state_change_callback_observer_, StateChangeCallback) EXPECT_CALL(state_change_callback_observer_, StateChangeCallback)
...@@ -1597,6 +1615,7 @@ TEST_F(CertProvisioningWorkerTest, CancelDeviceWorker) { ...@@ -1597,6 +1615,7 @@ TEST_F(CertProvisioningWorkerTest, CancelDeviceWorker) {
"cert_profile_1": { "cert_profile_1": {
"cert_profile": { "cert_profile": {
"policy_version": "cert_profile_version_1", "policy_version": "cert_profile_version_1",
"name": "Certificate Profile 1",
"profile_id": "cert_profile_1", "profile_id": "cert_profile_1",
"va_enabled": true "va_enabled": true
}, },
......
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