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

Side by Side Diff: chrome/browser/chromeos/settings/session_manager_operation_unittest.cc

Issue 116273002: Added support for signed policy blobs on desktop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup from self-review + cros clang fix. Created 6 years, 11 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/settings/session_manager_operation.h" 5 #include "chrome/browser/chromeos/settings/session_manager_operation.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 policy_response.Pass(), message_loop_.message_loop_proxy()); 256 policy_response.Pass(), message_loop_.message_loop_proxy());
257 validator->ValidateUsername(policy_.policy_data().username()); 257 validator->ValidateUsername(policy_.policy_data().username());
258 validator->ValidateTimestamp( 258 validator->ValidateTimestamp(
259 before, 259 before,
260 after, 260 after,
261 policy::CloudPolicyValidatorBase::TIMESTAMP_REQUIRED); 261 policy::CloudPolicyValidatorBase::TIMESTAMP_REQUIRED);
262 validator->ValidatePolicyType(policy::dm_protocol::kChromeDevicePolicyType); 262 validator->ValidatePolicyType(policy::dm_protocol::kChromeDevicePolicyType);
263 validator->ValidatePayload(); 263 validator->ValidatePayload();
264 std::vector<uint8> public_key; 264 std::vector<uint8> public_key;
265 policy_.GetSigningKey()->ExportPublicKey(&public_key); 265 policy_.GetSigningKey()->ExportPublicKey(&public_key);
266 validator->ValidateSignature(public_key, false); 266 // Convert from bytes to string format (which is what ValidateSignature()
267 // takes).
268 std::string public_key_as_string = std::string(
269 reinterpret_cast<const char*>(vector_as_array(&public_key)),
270 public_key.size());
271
Mattias Nissler (ping if slow) 2014/01/27 13:52:13 nit: remove newline?
Andrew T Wilson (Slow) 2014/01/30 17:10:31 Done.
272 validator->ValidateSignature(
273 public_key_as_string,
274 policy::GetPolicyVerificationKey(),
275 policy::PolicyBuilder::CreateTestSigningKeySignature(),
276 false);
267 validator->StartValidation( 277 validator->StartValidation(
268 base::Bind(&SessionManagerOperationTest::CheckSuccessfulValidation, 278 base::Bind(&SessionManagerOperationTest::CheckSuccessfulValidation,
269 base::Unretained(this))); 279 base::Unretained(this)));
270 280
271 message_loop_.RunUntilIdle(); 281 message_loop_.RunUntilIdle();
272 EXPECT_TRUE(validated_); 282 EXPECT_TRUE(validated_);
273 283
274 // Check that the loaded policy_data contains the expected values. 284 // Check that the loaded policy_data contains the expected values.
275 EXPECT_EQ(policy::dm_protocol::kChromeDevicePolicyType, 285 EXPECT_EQ(policy::dm_protocol::kChromeDevicePolicyType,
276 op.policy_data()->policy_type()); 286 op.policy_data()->policy_type());
277 EXPECT_LE((before - base::Time::UnixEpoch()).InMilliseconds(), 287 EXPECT_LE((before - base::Time::UnixEpoch()).InMilliseconds(),
278 op.policy_data()->timestamp()); 288 op.policy_data()->timestamp());
279 EXPECT_GE((after - base::Time::UnixEpoch()).InMilliseconds(), 289 EXPECT_GE((after - base::Time::UnixEpoch()).InMilliseconds(),
280 op.policy_data()->timestamp()); 290 op.policy_data()->timestamp());
281 EXPECT_FALSE(op.policy_data()->has_request_token()); 291 EXPECT_FALSE(op.policy_data()->has_request_token());
282 EXPECT_EQ(policy_.policy_data().username(), op.policy_data()->username()); 292 EXPECT_EQ(policy_.policy_data().username(), op.policy_data()->username());
283 293
284 // Loaded device settings should match what the operation received. 294 // Loaded device settings should match what the operation received.
285 ASSERT_TRUE(op.device_settings().get()); 295 ASSERT_TRUE(op.device_settings().get());
286 EXPECT_EQ(policy_.payload().SerializeAsString(), 296 EXPECT_EQ(policy_.payload().SerializeAsString(),
287 op.device_settings()->SerializeAsString()); 297 op.device_settings()->SerializeAsString());
288 } 298 }
289 299
290 } // namespace chromeos 300 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698