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

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

Issue 769703003: SetManagementSettings() is moved to OwnerSettingsServiceChromeOS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Failing test fixed. Created 6 years 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
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 <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 EXPECT_EQ(device_settings_test_helper_.policy_blob(), 216 EXPECT_EQ(device_settings_test_helper_.policy_blob(),
217 policy_.GetBlob()); 217 policy_.GetBlob());
218 ASSERT_TRUE(op.policy_data().get()); 218 ASSERT_TRUE(op.policy_data().get());
219 EXPECT_EQ(policy_.policy_data().SerializeAsString(), 219 EXPECT_EQ(policy_.policy_data().SerializeAsString(),
220 op.policy_data()->SerializeAsString()); 220 op.policy_data()->SerializeAsString());
221 ASSERT_TRUE(op.device_settings().get()); 221 ASSERT_TRUE(op.device_settings().get());
222 EXPECT_EQ(policy_.payload().SerializeAsString(), 222 EXPECT_EQ(policy_.payload().SerializeAsString(),
223 op.device_settings()->SerializeAsString()); 223 op.device_settings()->SerializeAsString());
224 } 224 }
225 225
226 TEST_F(SessionManagerOperationTest, SignAndStoreSettings) {
227 owner_key_util_->SetPrivateKey(policy_.GetSigningKey());
228 service_->OnTPMTokenReady(true /* is ready */);
229
230 scoped_ptr<em::PolicyData> policy(new em::PolicyData(policy_.policy_data()));
231 SignAndStoreSettingsOperation op(
232 base::Bind(&SessionManagerOperationTest::OnOperationCompleted,
233 base::Unretained(this)),
234 policy.Pass());
235 op.set_owner_settings_service(service_->as_weak_ptr());
236
237 EXPECT_CALL(*this,
238 OnOperationCompleted(
239 &op, DeviceSettingsService::STORE_SUCCESS));
240 op.Start(&device_settings_test_helper_, owner_key_util_, NULL);
241 device_settings_test_helper_.Flush();
242 Mock::VerifyAndClearExpectations(this);
243
244 // The blob should validate.
245 scoped_ptr<em::PolicyFetchResponse> policy_response(
246 new em::PolicyFetchResponse());
247 ASSERT_TRUE(
248 policy_response->ParseFromString(
249 device_settings_test_helper_.policy_blob()));
250 policy::DeviceCloudPolicyValidator* validator =
251 policy::DeviceCloudPolicyValidator::Create(
252 policy_response.Pass(), message_loop_.message_loop_proxy());
253 validator->ValidateUsername(policy_.policy_data().username(), true);
254 const base::Time expected_time = base::Time::UnixEpoch() +
255 base::TimeDelta::FromMilliseconds(policy::PolicyBuilder::kFakeTimestamp);
256 validator->ValidateTimestamp(
257 expected_time,
258 expected_time,
259 policy::CloudPolicyValidatorBase::TIMESTAMP_REQUIRED);
260 validator->ValidatePolicyType(policy::dm_protocol::kChromeDevicePolicyType);
261 validator->ValidatePayload();
262 std::vector<uint8> public_key;
263 policy_.GetSigningKey()->ExportPublicKey(&public_key);
264 // Convert from bytes to string format (which is what ValidateSignature()
265 // takes).
266 std::string public_key_as_string = std::string(
267 reinterpret_cast<const char*>(vector_as_array(&public_key)),
268 public_key.size());
269 validator->ValidateSignature(
270 public_key_as_string,
271 policy::GetPolicyVerificationKey(),
272 policy::PolicyBuilder::kFakeDomain,
273 false);
274 validator->StartValidation(
275 base::Bind(&SessionManagerOperationTest::CheckSuccessfulValidation,
276 base::Unretained(this)));
277
278 message_loop_.RunUntilIdle();
279 EXPECT_TRUE(validated_);
280
281 // Loaded device settings should match what the operation received.
282 ASSERT_TRUE(op.device_settings().get());
283 EXPECT_EQ(policy_.payload().SerializeAsString(),
284 op.device_settings()->SerializeAsString());
285 }
286
287 } // namespace chromeos 226 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698