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

Side by Side Diff: chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos_unittest.cc

Issue 212653004: Update server-backed state key generation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make state keys time-dependent. Created 6 years, 9 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/policy/device_cloud_policy_manager_chromeos.h" 5 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h"
6 6
7 #include <algorithm>
8
7 #include "base/basictypes.h" 9 #include "base/basictypes.h"
8 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
9 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
11 #include "base/prefs/pref_registry_simple.h" 13 #include "base/prefs/pref_registry_simple.h"
12 #include "base/prefs/testing_pref_service.h" 14 #include "base/prefs/testing_pref_service.h"
13 #include "base/run_loop.h" 15 #include "base/run_loop.h"
14 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h" 16 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h"
15 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" 17 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h"
16 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" 18 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 256
255 manager_->Connect(&local_state_, 257 manager_->Connect(&local_state_,
256 &device_management_service_, 258 &device_management_service_,
257 scoped_ptr<CloudPolicyClient::StatusProvider>()); 259 scoped_ptr<CloudPolicyClient::StatusProvider>());
258 EXPECT_TRUE(manager_->policies().Equals(bundle)); 260 EXPECT_TRUE(manager_->policies().Equals(bundle));
259 261
260 manager_->Shutdown(); 262 manager_->Shutdown();
261 EXPECT_TRUE(manager_->policies().Equals(bundle)); 263 EXPECT_TRUE(manager_->policies().Equals(bundle));
262 } 264 }
263 265
266 class DeviceCloudPolicyManagerChromeOSStateKeyTest : public testing::Test {
267 protected:
268 DeviceCloudPolicyManagerChromeOSStateKeyTest() {}
269
270 virtual void SetUp() OVERRIDE {
271 chromeos::system::StatisticsProvider::SetTestProvider(
272 &statistics_provider_);
Joao da Silva 2014/03/27 15:45:40 Remove this on TearDown?
Mattias Nissler (ping if slow) 2014/03/27 16:12:41 I debated it as it's not strictly needed (i.e. tes
Joao da Silva 2014/03/27 16:29:48 Note that this mock object will remain as the stat
Mattias Nissler (ping if slow) 2014/03/27 17:04:08 Uh, good point. Fixed. Globals suck.
273 EXPECT_CALL(statistics_provider_, GetMachineStatistic(_, _))
274 .WillRepeatedly(Invoke(this,
275 &DeviceCloudPolicyManagerChromeOSStateKeyTest::
276 GetMachineStatistic));
277 }
278
279 bool GetMachineStatistic(const std::string& name, std::string* result) {
280 *result = "fake-" + name;
281 return true;
282 }
283
284 private:
285 chromeos::system::MockStatisticsProvider statistics_provider_;
286
287 DISALLOW_COPY_AND_ASSIGN(DeviceCloudPolicyManagerChromeOSStateKeyTest);
288 };
289
290 TEST_F(DeviceCloudPolicyManagerChromeOSStateKeyTest, GetDeviceStateKeys) {
291 base::Time current = base::Time::UnixEpoch() + base::TimeDelta::FromDays(100);
292
293 // The correct number of state keys gets returned.
294 std::vector<std::string> state_keys;
295 EXPECT_TRUE(DeviceCloudPolicyManagerChromeOS::GetDeviceStateKeys(
296 current, &state_keys));
297 EXPECT_EQ(DeviceCloudPolicyManagerChromeOS::kDeviceStateKeyFutureQuanta,
298 static_cast<int>(state_keys.size()));
299
300 // All state keys are different.
301 std::set<std::string> state_key_set(state_keys.begin(), state_keys.end());
302 EXPECT_EQ(DeviceCloudPolicyManagerChromeOS::kDeviceStateKeyFutureQuanta,
303 static_cast<int>(state_key_set.size()));
304
305 // Incrementing time results in the state keys rolling forward.
306 int64 step =
307 GG_INT64_C(1)
308 << DeviceCloudPolicyManagerChromeOS::kDeviceStateKeyTimeQuantumPower;
309 current += 2 * base::TimeDelta::FromSeconds(step);
310
311 std::vector<std::string> new_state_keys;
312 EXPECT_TRUE(DeviceCloudPolicyManagerChromeOS::GetDeviceStateKeys(
313 current, &new_state_keys));
314 ASSERT_EQ(DeviceCloudPolicyManagerChromeOS::kDeviceStateKeyFutureQuanta,
315 static_cast<int>(new_state_keys.size()));
316 EXPECT_TRUE(std::equal(state_keys.begin() + 2, state_keys.end(),
317 new_state_keys.begin()));
318 }
Joao da Silva 2014/03/27 15:45:40 Suggestion: verify that a small time increase with
Mattias Nissler (ping if slow) 2014/03/27 16:12:41 Good idea, done.
319
264 class DeviceCloudPolicyManagerChromeOSEnrollmentTest 320 class DeviceCloudPolicyManagerChromeOSEnrollmentTest
265 : public DeviceCloudPolicyManagerChromeOSTest { 321 : public DeviceCloudPolicyManagerChromeOSTest {
266 public: 322 public:
267 void Done(EnrollmentStatus status) { 323 void Done(EnrollmentStatus status) {
268 status_ = status; 324 status_ = status;
269 done_ = true; 325 done_ = true;
270 } 326 }
271 327
272 protected: 328 protected:
273 DeviceCloudPolicyManagerChromeOSEnrollmentTest() 329 DeviceCloudPolicyManagerChromeOSEnrollmentTest()
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 631
576 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest, 632 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest,
577 RobotRefreshSaveFailed) { 633 RobotRefreshSaveFailed) {
578 // Without the system salt, the robot token can't be stored. 634 // Without the system salt, the robot token can't be stored.
579 RunTest(); 635 RunTest();
580 ExpectFailedEnrollment(EnrollmentStatus::STATUS_ROBOT_REFRESH_STORE_FAILED); 636 ExpectFailedEnrollment(EnrollmentStatus::STATUS_ROBOT_REFRESH_STORE_FAILED);
581 } 637 }
582 638
583 } // namespace 639 } // namespace
584 } // namespace policy 640 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698