Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(363)

Unified Diff: components/policy/core/common/cloud/cloud_policy_validator_unittest.cc

Issue 2150603002: Added policy device id validation similar to the existing DM token validation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added policy device id validation similar to the existing DM token validation. BUG: 360708 Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/policy/core/common/cloud/cloud_policy_validator.cc ('k') | components/policy_strings.grdp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/policy/core/common/cloud/cloud_policy_validator_unittest.cc
diff --git a/components/policy/core/common/cloud/cloud_policy_validator_unittest.cc b/components/policy/core/common/cloud/cloud_policy_validator_unittest.cc
index 7cce23c833da03c2c024c782718bd8f9269321dc..d45cf4134b0f203241df19896dc10d589817b17d 100644
--- a/components/policy/core/common/cloud/cloud_policy_validator_unittest.cc
+++ b/components/policy/core/common/cloud/cloud_policy_validator_unittest.cc
@@ -49,6 +49,7 @@ class CloudPolicyValidatorTest : public testing::Test {
ignore_missing_dm_token_(CloudPolicyValidatorBase::DM_TOKEN_REQUIRED),
allow_key_rotation_(true),
existing_dm_token_(PolicyBuilder::kFakeToken),
+ existing_device_id_(PolicyBuilder::kFakeDeviceId),
owning_domain_(PolicyBuilder::kFakeDomain),
cached_key_signature_(PolicyBuilder::GetTestSigningKeySignature()) {
policy_.SetDefaultNewSigningKey();
@@ -97,6 +98,7 @@ class CloudPolicyValidatorTest : public testing::Test {
if (!owning_domain_.empty())
validator->ValidateDomain(owning_domain_);
validator->ValidateDMToken(existing_dm_token_, ignore_missing_dm_token_);
+ validator->ValidateDeviceId(existing_device_id_);
validator->ValidatePolicyType(dm_protocol::kChromeUserPolicyType);
validator->ValidatePayload();
validator->ValidateCachedKey(public_key,
@@ -130,6 +132,7 @@ class CloudPolicyValidatorTest : public testing::Test {
std::string signing_key_;
bool allow_key_rotation_;
std::string existing_dm_token_;
+ std::string existing_device_id_;
std::string owning_domain_;
std::string cached_key_signature_;
@@ -242,6 +245,24 @@ TEST_F(CloudPolicyValidatorTest, ErrorInvalidRequestToken) {
Validate(CheckStatus(CloudPolicyValidatorBase::VALIDATION_WRONG_TOKEN));
}
+TEST_F(CloudPolicyValidatorTest, ErrorNoDeviceId) {
+ policy_.policy_data().clear_device_id();
+ Validate(CheckStatus(CloudPolicyValidatorBase::VALIDATION_WRONG_DEVICE_ID));
+}
+
+TEST_F(CloudPolicyValidatorTest, ErrorNoDeviceIdNoDeviceIdPassed) {
+ // Mimic the first fetch of policy (no existing device id) - should still
+ // complain about not having any device id.
+ existing_device_id_.clear();
+ policy_.policy_data().clear_device_id();
+ Validate(CheckStatus(CloudPolicyValidatorBase::VALIDATION_WRONG_DEVICE_ID));
+}
+
+TEST_F(CloudPolicyValidatorTest, ErrorInvalidDeviceId) {
+ policy_.policy_data().set_device_id("invalid");
+ Validate(CheckStatus(CloudPolicyValidatorBase::VALIDATION_WRONG_DEVICE_ID));
+}
+
TEST_F(CloudPolicyValidatorTest, ErrorNoPolicyValue) {
policy_.clear_payload();
Validate(
« no previous file with comments | « components/policy/core/common/cloud/cloud_policy_validator.cc ('k') | components/policy_strings.grdp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698