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

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

Issue 2820063005: Remove the "not_after" validation of policy timestamps (Closed)
Patch Set: Fix test Created 3 years, 8 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
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 c3112952ebe1ee86a0c62f24d2bb896bddd3630f..a0cc84d37163ceb8d993a3d8e2df9c11a8aafef9 100644
--- a/components/policy/core/common/cloud/cloud_policy_validator_unittest.cc
+++ b/components/policy/core/common/cloud/cloud_policy_validator_unittest.cc
@@ -43,10 +43,10 @@ ACTION_P(CheckStatus, expected_status) {
class CloudPolicyValidatorTest : public testing::Test {
public:
CloudPolicyValidatorTest()
- : timestamp_(base::Time::UnixEpoch() +
- base::TimeDelta::FromMilliseconds(
- PolicyBuilder::kFakeTimestamp)),
- timestamp_option_(CloudPolicyValidatorBase::TIMESTAMP_FULLY_VALIDATED),
+ : timestamp_(
+ base::Time::UnixEpoch() +
+ base::TimeDelta::FromMilliseconds(PolicyBuilder::kFakeTimestamp)),
Thiemo Nagel 2017/04/19 11:43:09 Nit: Using FromJsTime(...::kFakeTimestamp) would a
emaxx 2017/04/19 20:48:45 Thanks for pointing at the already existing primit
Thiemo Nagel 2017/04/20 10:08:27 Imho that would be unnecessary overhead. The serv
+ timestamp_option_(CloudPolicyValidatorBase::TIMESTAMP_VALIDATED),
dm_token_option_(CloudPolicyValidatorBase::DM_TOKEN_REQUIRED),
device_id_option_(CloudPolicyValidatorBase::DEVICE_ID_REQUIRED),
allow_key_rotation_(true),
@@ -86,8 +86,7 @@ class CloudPolicyValidatorTest : public testing::Test {
UserCloudPolicyValidator* validator = UserCloudPolicyValidator::Create(
std::move(policy_response), base::ThreadTaskRunnerHandle::Get());
- validator->ValidateTimestamp(timestamp_, timestamp_,
- timestamp_option_);
+ validator->ValidateTimestamp(timestamp_, timestamp_option_);
validator->ValidateUsername(PolicyBuilder::kFakeUsername, true);
if (!owning_domain_.empty())
validator->ValidateDomain(owning_domain_);
@@ -176,6 +175,14 @@ TEST_F(CloudPolicyValidatorTest, SuccessfulRunValidationWithNoDeviceId) {
Validate(Invoke(this, &CloudPolicyValidatorTest::CheckSuccessfulValidation));
}
+TEST_F(CloudPolicyValidatorTest,
+ SuccessfulRunValidationWithTimestampFromTheFuture) {
+ base::Time timestamp(timestamp_ + base::TimeDelta::FromMinutes(5));
Thiemo Nagel 2017/04/19 11:43:09 Nit: Suggest to use FromHours(3) so that the test
emaxx 2017/04/19 20:48:45 Done.
+ policy_.policy_data().set_timestamp(
+ (timestamp - base::Time::UnixEpoch()).InMilliseconds());
Thiemo Nagel 2017/04/19 11:43:09 Nit: Using timestamp.ToJavaTime() would seem clean
emaxx 2017/04/19 20:48:45 Same as above: do you agree with deferring this fo
Thiemo Nagel 2017/04/20 10:08:27 Sure!
+ Validate(CheckStatus(CloudPolicyValidatorBase::VALIDATION_OK));
+}
+
TEST_F(CloudPolicyValidatorTest, UsernameCanonicalization) {
policy_.policy_data().set_username(
base::ToUpperASCII(PolicyBuilder::kFakeUsername));
@@ -210,22 +217,6 @@ TEST_F(CloudPolicyValidatorTest, ErrorOldTimestamp) {
Validate(CheckStatus(CloudPolicyValidatorBase::VALIDATION_BAD_TIMESTAMP));
}
-TEST_F(CloudPolicyValidatorTest, ErrorTimestampFromTheFuture) {
- base::Time timestamp(timestamp_ + base::TimeDelta::FromHours(3));
- policy_.policy_data().set_timestamp(
- (timestamp - base::Time::UnixEpoch()).InMilliseconds());
- Validate(CheckStatus(CloudPolicyValidatorBase::VALIDATION_BAD_TIMESTAMP));
-}
-
-TEST_F(CloudPolicyValidatorTest, IgnoreErrorTimestampFromTheFuture) {
- base::Time timestamp(timestamp_ + base::TimeDelta::FromMinutes(5));
- timestamp_option_ =
- CloudPolicyValidatorBase::TIMESTAMP_NOT_BEFORE;
- policy_.policy_data().set_timestamp(
- (timestamp - base::Time::UnixEpoch()).InMilliseconds());
- Validate(CheckStatus(CloudPolicyValidatorBase::VALIDATION_OK));
-}
-
TEST_F(CloudPolicyValidatorTest, ErrorNoDMToken) {
policy_.policy_data().clear_request_token();
Validate(CheckStatus(CloudPolicyValidatorBase::VALIDATION_BAD_DM_TOKEN));

Powered by Google App Engine
This is Rietveld 408576698