| 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 |
| 218 TEST_F(DevicePolicyCacheTest, SetPolicyOtherUserOtherDomain) { |
| 219 InSequence s; |
| 220 |
| 221 MakeEnterpriseDevice(kTestUser); |
| 222 |
| 223 // Startup. |
| 224 em::PolicyFetchResponse policy; |
| 225 CreateRefreshRatePolicy(&policy, kTestUser, 120); |
| 226 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce( |
| 227 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS, |
| 228 policy)); |
| 229 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get())); |
| 230 cache_->Load(); |
| 231 Mock::VerifyAndClearExpectations(&signed_settings_helper_); |
| 232 |
| 233 // Set new policy information. This should fail because the user is from |
| 234 // different domain. |
| 235 em::PolicyFetchResponse new_policy; |
| 236 CreateRefreshRatePolicy(&new_policy, "foreign_user@hackers.com", 300); |
| 213 EXPECT_CALL(signed_settings_helper_, StartStorePolicyOp(_, _)).Times(0); | 237 EXPECT_CALL(signed_settings_helper_, StartStorePolicyOp(_, _)).Times(0); |
| 214 EXPECT_FALSE(cache_->SetPolicy(new_policy)); | 238 EXPECT_FALSE(cache_->SetPolicy(new_policy)); |
| 215 Mock::VerifyAndClearExpectations(&signed_settings_helper_); | 239 Mock::VerifyAndClearExpectations(&signed_settings_helper_); |
| 216 | 240 |
| 217 base::FundamentalValue expected(120); | 241 base::FundamentalValue expected(120); |
| 218 EXPECT_TRUE(Value::Equals(&expected, | 242 EXPECT_TRUE(Value::Equals(&expected, |
| 219 GetPolicy(key::kDevicePolicyRefreshRate))); | 243 GetPolicy(key::kDevicePolicyRefreshRate))); |
| 220 } | 244 } |
| 221 | 245 |
| 222 TEST_F(DevicePolicyCacheTest, SetPolicyNonEnterpriseDevice) { | 246 TEST_F(DevicePolicyCacheTest, SetPolicyNonEnterpriseDevice) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get())); | 306 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get())); |
| 283 cache_->Load(); | 307 cache_->Load(); |
| 284 Mock::VerifyAndClearExpectations(&signed_settings_helper_); | 308 Mock::VerifyAndClearExpectations(&signed_settings_helper_); |
| 285 StringValue expected_config(fake_config); | 309 StringValue expected_config(fake_config); |
| 286 EXPECT_TRUE( | 310 EXPECT_TRUE( |
| 287 Value::Equals(&expected_config, | 311 Value::Equals(&expected_config, |
| 288 GetPolicy(key::kDeviceOpenNetworkConfiguration))); | 312 GetPolicy(key::kDeviceOpenNetworkConfiguration))); |
| 289 } | 313 } |
| 290 | 314 |
| 291 } // namespace policy | 315 } // namespace policy |
| OLD | NEW |