Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_store_chromeos.h" | 5 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.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" |
| 11 #include "base/bind.h" | |
| 12 #include "base/bind_helpers.h" | |
| 11 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 12 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/message_loop/message_loop_proxy.h" | 15 #include "base/message_loop/message_loop_proxy.h" |
| 14 #include "base/run_loop.h" | 16 #include "base/run_loop.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" |
| 17 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" | 19 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" |
| 18 #include "chrome/test/base/scoped_testing_local_state.h" | 20 #include "chrome/test/base/scoped_testing_local_state.h" |
| 19 #include "chrome/test/base/testing_browser_process.h" | 21 #include "chrome/test/base/testing_browser_process.h" |
| 20 #include "chromeos/cryptohome/cryptohome_util.h" | 22 #include "chromeos/cryptohome/cryptohome_util.h" |
| 21 #include "chromeos/dbus/dbus_thread_manager.h" | 23 #include "chromeos/dbus/dbus_thread_manager.h" |
| 22 #include "chromeos/dbus/fake_cryptohome_client.h" | 24 #include "chromeos/dbus/fake_cryptohome_client.h" |
| 25 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | |
| 23 #include "content/public/test/test_utils.h" | 26 #include "content/public/test/test_utils.h" |
| 24 #include "policy/policy_constants.h" | 27 #include "policy/policy_constants.h" |
| 28 #include "policy/proto/device_management_backend.pb.h" | |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
| 26 | 30 |
| 31 namespace em = enterprise_management; | |
| 32 | |
| 27 namespace policy { | 33 namespace policy { |
| 28 | 34 |
| 29 namespace { | 35 namespace { |
| 30 | 36 |
| 31 void CopyLockResult(base::RunLoop* loop, | 37 void CopyLockResult(base::RunLoop* loop, |
| 32 EnterpriseInstallAttributes::LockResult* out, | 38 EnterpriseInstallAttributes::LockResult* out, |
| 33 EnterpriseInstallAttributes::LockResult result) { | 39 EnterpriseInstallAttributes::LockResult result) { |
| 34 *out = result; | 40 *out = result; |
| 35 loop->Quit(); | 41 loop->Quit(); |
| 36 } | 42 } |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 61 EnterpriseInstallAttributes::LockResult result; | 67 EnterpriseInstallAttributes::LockResult result; |
| 62 install_attributes_->LockDevice( | 68 install_attributes_->LockDevice( |
| 63 PolicyBuilder::kFakeUsername, | 69 PolicyBuilder::kFakeUsername, |
| 64 DEVICE_MODE_ENTERPRISE, | 70 DEVICE_MODE_ENTERPRISE, |
| 65 PolicyBuilder::kFakeDeviceId, | 71 PolicyBuilder::kFakeDeviceId, |
| 66 base::Bind(&CopyLockResult, &loop, &result)); | 72 base::Bind(&CopyLockResult, &loop, &result)); |
| 67 loop.Run(); | 73 loop.Run(); |
| 68 ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS, result); | 74 ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS, result); |
| 69 } | 75 } |
| 70 | 76 |
| 77 void SetManagementModeAndLoad(em::PolicyData::ManagementMode mode) { | |
| 78 device_policy_.policy_data().set_management_mode(mode); | |
| 79 device_policy_.Build(); | |
| 80 scoped_ptr<em::PolicyFetchResponse> policy(new em::PolicyFetchResponse); | |
| 81 policy->MergeFrom(device_policy_.policy()); | |
| 82 device_settings_service_.Store(policy.Pass(), base::Bind(&base::DoNothing)); | |
|
Mattias Nissler (ping if slow)
2014/12/05 12:28:37
If the intention here is to test a load (and the f
davidyu
2014/12/05 13:54:10
Done.
| |
| 83 FlushDeviceSettings(); | |
| 84 EXPECT_EQ(chromeos::DeviceSettingsService::STORE_SUCCESS, | |
| 85 device_settings_service_.status()); | |
| 86 } | |
| 87 | |
| 71 void ExpectFailure(CloudPolicyStore::Status expected_status) { | 88 void ExpectFailure(CloudPolicyStore::Status expected_status) { |
| 72 EXPECT_EQ(expected_status, store_->status()); | 89 EXPECT_EQ(expected_status, store_->status()); |
| 73 EXPECT_TRUE(store_->is_initialized()); | 90 EXPECT_TRUE(store_->is_initialized()); |
| 74 EXPECT_FALSE(store_->has_policy()); | 91 EXPECT_FALSE(store_->has_policy()); |
| 75 EXPECT_FALSE(store_->is_managed()); | 92 EXPECT_FALSE(store_->is_managed()); |
| 76 } | 93 } |
| 77 | 94 |
| 95 void ExpectSuccessWithManagementMode(ManagementMode mode) { | |
| 96 EXPECT_EQ(CloudPolicyStore::STATUS_OK, store_->status()); | |
| 97 EXPECT_TRUE(store_->is_initialized()); | |
| 98 EXPECT_TRUE(store_->has_policy()); | |
| 99 EXPECT_TRUE(store_->is_managed()); | |
| 100 EXPECT_TRUE(store_->policy()); | |
| 101 EXPECT_TRUE(store_->policy_map().empty()); | |
| 102 if (store_->policy()) | |
| 103 EXPECT_EQ(mode, GetManagementMode(*store_->policy())); | |
| 104 } | |
| 105 | |
| 78 void ExpectSuccess() { | 106 void ExpectSuccess() { |
| 79 EXPECT_EQ(CloudPolicyStore::STATUS_OK, store_->status()); | 107 EXPECT_EQ(CloudPolicyStore::STATUS_OK, store_->status()); |
| 80 EXPECT_TRUE(store_->is_initialized()); | 108 EXPECT_TRUE(store_->is_initialized()); |
| 81 EXPECT_TRUE(store_->has_policy()); | 109 EXPECT_TRUE(store_->has_policy()); |
| 82 EXPECT_TRUE(store_->is_managed()); | 110 EXPECT_TRUE(store_->is_managed()); |
| 83 EXPECT_TRUE(store_->policy()); | 111 EXPECT_TRUE(store_->policy()); |
| 84 base::FundamentalValue expected(false); | 112 base::FundamentalValue expected(false); |
| 85 EXPECT_TRUE( | 113 EXPECT_TRUE( |
| 86 base::Value::Equals(&expected, | 114 base::Value::Equals(&expected, |
| 87 store_->policy_map().GetValue( | 115 store_->policy_map().GetValue( |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 FlushDeviceSettings(); | 174 FlushDeviceSettings(); |
| 147 ExpectFailure(CloudPolicyStore::STATUS_BAD_STATE); | 175 ExpectFailure(CloudPolicyStore::STATUS_BAD_STATE); |
| 148 } | 176 } |
| 149 | 177 |
| 150 TEST_F(DeviceCloudPolicyStoreChromeOSTest, LoadSuccess) { | 178 TEST_F(DeviceCloudPolicyStoreChromeOSTest, LoadSuccess) { |
| 151 store_->Load(); | 179 store_->Load(); |
| 152 FlushDeviceSettings(); | 180 FlushDeviceSettings(); |
| 153 ExpectSuccess(); | 181 ExpectSuccess(); |
| 154 } | 182 } |
| 155 | 183 |
| 184 TEST_F(DeviceCloudPolicyStoreChromeOSTest, UpdateFromServiceOnConsumerDevices) { | |
| 185 ResetToNonEnterprise(); | |
| 186 | |
| 187 SetManagementModeAndLoad(em::PolicyData::CONSUMER_MANAGED); | |
| 188 ExpectSuccessWithManagementMode(MANAGEMENT_MODE_CONSUMER_MANAGED); | |
| 189 | |
| 190 // Unenroll from consumer management. | |
| 191 SetManagementModeAndLoad(em::PolicyData::LOCAL_OWNER); | |
| 192 ExpectSuccessWithManagementMode(MANAGEMENT_MODE_LOCAL_OWNER); | |
| 193 } | |
| 194 | |
| 156 TEST_F(DeviceCloudPolicyStoreChromeOSTest, StoreSuccess) { | 195 TEST_F(DeviceCloudPolicyStoreChromeOSTest, StoreSuccess) { |
| 157 PrepareExistingPolicy(); | 196 PrepareExistingPolicy(); |
| 158 store_->Store(device_policy_.policy()); | 197 store_->Store(device_policy_.policy()); |
| 159 FlushDeviceSettings(); | 198 FlushDeviceSettings(); |
| 160 ExpectSuccess(); | 199 ExpectSuccess(); |
| 161 } | 200 } |
| 162 | 201 |
| 163 TEST_F(DeviceCloudPolicyStoreChromeOSTest, StoreNoSignature) { | 202 TEST_F(DeviceCloudPolicyStoreChromeOSTest, StoreNoSignature) { |
| 164 PrepareExistingPolicy(); | 203 PrepareExistingPolicy(); |
| 165 device_policy_.policy().clear_policy_data_signature(); | 204 device_policy_.policy().clear_policy_data_signature(); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 272 | 311 |
| 273 TEST_F(DeviceCloudPolicyStoreChromeOSTest, InstallInitialPolicyNotEnterprise) { | 312 TEST_F(DeviceCloudPolicyStoreChromeOSTest, InstallInitialPolicyNotEnterprise) { |
| 274 PrepareNewSigningKey(); | 313 PrepareNewSigningKey(); |
| 275 ResetToNonEnterprise(); | 314 ResetToNonEnterprise(); |
| 276 store_->InstallInitialPolicy(device_policy_.policy()); | 315 store_->InstallInitialPolicy(device_policy_.policy()); |
| 277 FlushDeviceSettings(); | 316 FlushDeviceSettings(); |
| 278 ExpectFailure(CloudPolicyStore::STATUS_BAD_STATE); | 317 ExpectFailure(CloudPolicyStore::STATUS_BAD_STATE); |
| 279 } | 318 } |
| 280 | 319 |
| 281 } // namespace policy | 320 } // namespace policy |
| OLD | NEW |