| 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/policy/device_policy_cache.h" | 5 #include "chrome/browser/policy/device_policy_cache.h" |
| 6 | 6 |
| 7 #include "chrome/browser/chromeos/cros/cryptohome_library.h" | 7 #include "chrome/browser/chromeos/cros/cryptohome_library.h" |
| 8 #include "chrome/browser/chromeos/login/mock_signed_settings_helper.h" | 8 #include "chrome/browser/chromeos/login/mock_signed_settings_helper.h" |
| 9 #include "chrome/browser/policy/cloud_policy_data_store.h" | 9 #include "chrome/browser/policy/cloud_policy_data_store.h" |
| 10 #include "chrome/browser/policy/enterprise_install_attributes.h" | 10 #include "chrome/browser/policy/enterprise_install_attributes.h" |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get())); | 185 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get())); |
| 186 retrieve_callback.Run(chromeos::SignedSettings::SUCCESS, new_policy); | 186 retrieve_callback.Run(chromeos::SignedSettings::SUCCESS, new_policy); |
| 187 base::FundamentalValue updated_expected(300); | 187 base::FundamentalValue updated_expected(300); |
| 188 EXPECT_TRUE(Value::Equals(&updated_expected, | 188 EXPECT_TRUE(Value::Equals(&updated_expected, |
| 189 GetPolicy(key::kDevicePolicyRefreshRate))); | 189 GetPolicy(key::kDevicePolicyRefreshRate))); |
| 190 Mock::VerifyAndClearExpectations(&observer_); | 190 Mock::VerifyAndClearExpectations(&observer_); |
| 191 | 191 |
| 192 cache_->RemoveObserver(&observer_); | 192 cache_->RemoveObserver(&observer_); |
| 193 } | 193 } |
| 194 | 194 |
| 195 TEST_F(DevicePolicyCacheTest, SetPolicyWrongUser) { | 195 TEST_F(DevicePolicyCacheTest, SetPolicyOtherUserSameDomain) { |
| 196 InSequence s; | 196 InSequence s; |
| 197 | 197 |
| 198 MakeEnterpriseDevice(kTestUser); | 198 MakeEnterpriseDevice(kTestUser); |
| 199 | 199 |
| 200 // Startup. | 200 // Startup. |
| 201 em::PolicyFetchResponse policy; | 201 em::PolicyFetchResponse policy; |
| 202 CreateRefreshRatePolicy(&policy, kTestUser, 120); | 202 CreateRefreshRatePolicy(&policy, kTestUser, 120); |
| 203 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce( | 203 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce( |
| 204 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS, | 204 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS, |
| 205 policy)); | 205 policy)); |
| 206 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get())); | 206 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get())); |
| 207 cache_->Load(); | 207 cache_->Load(); |
| 208 Mock::VerifyAndClearExpectations(&signed_settings_helper_); | 208 Mock::VerifyAndClearExpectations(&signed_settings_helper_); |
| 209 | 209 |
| 210 // Set new policy information. This should fail due to invalid user. | 210 // Set new policy information. This should succeed as the domain is the same. |
| 211 em::PolicyFetchResponse new_policy; | 211 em::PolicyFetchResponse new_policy; |
| 212 CreateRefreshRatePolicy(&new_policy, "foreign_user@example.com", 300); | 212 CreateRefreshRatePolicy(&new_policy, "another_user@example.com", 300); |
| 213 EXPECT_CALL(signed_settings_helper_, StartStorePolicyOp(_, _)).Times(1); |
| 214 EXPECT_TRUE(cache_->SetPolicy(new_policy)); |
| 215 Mock::VerifyAndClearExpectations(&signed_settings_helper_); |
| 216 |
| 217 base::FundamentalValue expected(120); |
| 218 EXPECT_TRUE(Value::Equals(&expected, |
| 219 GetPolicy(key::kDevicePolicyRefreshRate))); |
| 220 } |
| 221 |
| 222 TEST_F(DevicePolicyCacheTest, SetPolicyOtherUserOtherDomain) { |
| 223 InSequence s; |
| 224 |
| 225 MakeEnterpriseDevice(kTestUser); |
| 226 |
| 227 // Startup. |
| 228 em::PolicyFetchResponse policy; |
| 229 CreateRefreshRatePolicy(&policy, kTestUser, 120); |
| 230 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce( |
| 231 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS, |
| 232 policy)); |
| 233 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get())); |
| 234 cache_->Load(); |
| 235 Mock::VerifyAndClearExpectations(&signed_settings_helper_); |
| 236 |
| 237 // Set new policy information. This should fail because the user is from |
| 238 // different domain. |
| 239 em::PolicyFetchResponse new_policy; |
| 240 CreateRefreshRatePolicy(&new_policy, "foreign_user@hackers.com", 300); |
| 213 EXPECT_CALL(signed_settings_helper_, StartStorePolicyOp(_, _)).Times(0); | 241 EXPECT_CALL(signed_settings_helper_, StartStorePolicyOp(_, _)).Times(0); |
| 214 EXPECT_FALSE(cache_->SetPolicy(new_policy)); | 242 EXPECT_FALSE(cache_->SetPolicy(new_policy)); |
| 215 Mock::VerifyAndClearExpectations(&signed_settings_helper_); | 243 Mock::VerifyAndClearExpectations(&signed_settings_helper_); |
| 216 | 244 |
| 217 base::FundamentalValue expected(120); | 245 base::FundamentalValue expected(120); |
| 218 EXPECT_TRUE(Value::Equals(&expected, | 246 EXPECT_TRUE(Value::Equals(&expected, |
| 219 GetPolicy(key::kDevicePolicyRefreshRate))); | 247 GetPolicy(key::kDevicePolicyRefreshRate))); |
| 220 } | 248 } |
| 221 | 249 |
| 222 TEST_F(DevicePolicyCacheTest, SetPolicyNonEnterpriseDevice) { | 250 TEST_F(DevicePolicyCacheTest, SetPolicyNonEnterpriseDevice) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get())); | 310 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get())); |
| 283 cache_->Load(); | 311 cache_->Load(); |
| 284 Mock::VerifyAndClearExpectations(&signed_settings_helper_); | 312 Mock::VerifyAndClearExpectations(&signed_settings_helper_); |
| 285 StringValue expected_config(fake_config); | 313 StringValue expected_config(fake_config); |
| 286 EXPECT_TRUE( | 314 EXPECT_TRUE( |
| 287 Value::Equals(&expected_config, | 315 Value::Equals(&expected_config, |
| 288 GetPolicy(key::kDeviceOpenNetworkConfiguration))); | 316 GetPolicy(key::kDeviceOpenNetworkConfiguration))); |
| 289 } | 317 } |
| 290 | 318 |
| 291 } // namespace policy | 319 } // namespace policy |
| OLD | NEW |