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/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 fail due to invalid user. |
|
Mattias Nissler (ping if slow)
2012/06/04 10:17:52
comment is outdated.
pastarmovj
2012/06/08 09:54:32
Done.
| |
| 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 due to invalid user. | |
| 238 em::PolicyFetchResponse new_policy; | |
| 239 CreateRefreshRatePolicy(&new_policy, "foreign_user@hackers.com", 300); | |
| 213 EXPECT_CALL(signed_settings_helper_, StartStorePolicyOp(_, _)).Times(0); | 240 EXPECT_CALL(signed_settings_helper_, StartStorePolicyOp(_, _)).Times(0); |
| 214 EXPECT_FALSE(cache_->SetPolicy(new_policy)); | 241 EXPECT_FALSE(cache_->SetPolicy(new_policy)); |
| 215 Mock::VerifyAndClearExpectations(&signed_settings_helper_); | 242 Mock::VerifyAndClearExpectations(&signed_settings_helper_); |
| 216 | 243 |
| 217 base::FundamentalValue expected(120); | 244 base::FundamentalValue expected(120); |
| 218 EXPECT_TRUE(Value::Equals(&expected, | 245 EXPECT_TRUE(Value::Equals(&expected, |
| 219 GetPolicy(key::kDevicePolicyRefreshRate))); | 246 GetPolicy(key::kDevicePolicyRefreshRate))); |
| 220 } | 247 } |
| 221 | 248 |
| 222 TEST_F(DevicePolicyCacheTest, SetPolicyNonEnterpriseDevice) { | 249 TEST_F(DevicePolicyCacheTest, SetPolicyNonEnterpriseDevice) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 282 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get())); | 309 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get())); |
| 283 cache_->Load(); | 310 cache_->Load(); |
| 284 Mock::VerifyAndClearExpectations(&signed_settings_helper_); | 311 Mock::VerifyAndClearExpectations(&signed_settings_helper_); |
| 285 StringValue expected_config(fake_config); | 312 StringValue expected_config(fake_config); |
| 286 EXPECT_TRUE( | 313 EXPECT_TRUE( |
| 287 Value::Equals(&expected_config, | 314 Value::Equals(&expected_config, |
| 288 GetPolicy(key::kDeviceOpenNetworkConfiguration))); | 315 GetPolicy(key::kDeviceOpenNetworkConfiguration))); |
| 289 } | 316 } |
| 290 | 317 |
| 291 } // namespace policy | 318 } // namespace policy |
| OLD | NEW |