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