| 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 <vector> |
| 8 |
| 9 #include "base/basictypes.h" |
| 10 #include "base/compiler_specific.h" |
| 11 #include "base/file_path.h" |
| 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/threading/sequenced_worker_pool.h" |
| 7 #include "chrome/browser/chromeos/cros/cryptohome_library.h" | 14 #include "chrome/browser/chromeos/cros/cryptohome_library.h" |
| 8 #include "chrome/browser/chromeos/settings/mock_signed_settings_helper.h" | 15 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" |
| 16 #include "chrome/browser/chromeos/settings/mock_owner_key_util.h" |
| 9 #include "chrome/browser/policy/cloud_policy_data_store.h" | 17 #include "chrome/browser/policy/cloud_policy_data_store.h" |
| 10 #include "chrome/browser/policy/enterprise_install_attributes.h" | 18 #include "chrome/browser/policy/enterprise_install_attributes.h" |
| 19 #include "chrome/browser/policy/policy_builder.h" |
| 11 #include "chrome/browser/policy/proto/chrome_device_policy.pb.h" | 20 #include "chrome/browser/policy/proto/chrome_device_policy.pb.h" |
| 21 #include "chrome/browser/policy/proto/device_management_backend.pb.h" |
| 12 #include "content/public/test/test_browser_thread.h" | 22 #include "content/public/test/test_browser_thread.h" |
| 13 #include "policy/policy_constants.h" | 23 #include "policy/policy_constants.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 26 |
| 27 using ::testing::Mock; |
| 28 |
| 17 namespace em = enterprise_management; | 29 namespace em = enterprise_management; |
| 18 | 30 |
| 19 namespace policy { | 31 namespace policy { |
| 20 | 32 |
| 21 namespace { | 33 namespace { |
| 22 | 34 |
| 23 // Test registration user name. | |
| 24 const char kTestUser[] = "test@example.com"; | |
| 25 | |
| 26 using ::chromeos::SignedSettings; | |
| 27 using ::testing::InSequence; | |
| 28 using ::testing::Mock; | |
| 29 using ::testing::SaveArg; | |
| 30 using ::testing::_; | |
| 31 | |
| 32 class MockCloudPolicyCacheObserver : public CloudPolicyCacheBase::Observer { | 35 class MockCloudPolicyCacheObserver : public CloudPolicyCacheBase::Observer { |
| 33 public: | 36 public: |
| 37 virtual ~MockCloudPolicyCacheObserver() {} |
| 38 |
| 34 MOCK_METHOD1(OnCacheGoingAway, void(CloudPolicyCacheBase*)); | 39 MOCK_METHOD1(OnCacheGoingAway, void(CloudPolicyCacheBase*)); |
| 35 MOCK_METHOD1(OnCacheUpdate, void(CloudPolicyCacheBase*)); | 40 MOCK_METHOD1(OnCacheUpdate, void(CloudPolicyCacheBase*)); |
| 36 }; | 41 }; |
| 37 | 42 |
| 38 void CreatePolicy(em::PolicyFetchResponse* policy, | |
| 39 const std::string& user, | |
| 40 em::ChromeDeviceSettingsProto& settings) { | |
| 41 // This method omits a few fields which currently aren't needed by tests: | |
| 42 // timestamp, machine_name, public key info. | |
| 43 em::PolicyData signed_response; | |
| 44 signed_response.set_username(user); | |
| 45 signed_response.set_request_token("dmtoken"); | |
| 46 signed_response.set_device_id("deviceid"); | |
| 47 EXPECT_TRUE( | |
| 48 settings.SerializeToString(signed_response.mutable_policy_value())); | |
| 49 std::string serialized_signed_response; | |
| 50 EXPECT_TRUE(signed_response.SerializeToString(&serialized_signed_response)); | |
| 51 policy->set_policy_data(serialized_signed_response); | |
| 52 } | |
| 53 | |
| 54 void CreateRefreshRatePolicy(em::PolicyFetchResponse* policy, | |
| 55 const std::string& user, | |
| 56 int refresh_rate) { | |
| 57 em::ChromeDeviceSettingsProto settings; | |
| 58 settings.mutable_device_policy_refresh_rate()-> | |
| 59 set_device_policy_refresh_rate(refresh_rate); | |
| 60 CreatePolicy(policy, user, settings); | |
| 61 } | |
| 62 | |
| 63 void CreateProxyPolicy(em::PolicyFetchResponse* policy, | |
| 64 const std::string& user, | |
| 65 const std::string& proxy_mode, | |
| 66 const std::string& proxy_server, | |
| 67 const std::string& proxy_pac_url, | |
| 68 const std::string& proxy_bypass_list) { | |
| 69 em::ChromeDeviceSettingsProto settings; | |
| 70 em::DeviceProxySettingsProto* proxy_settings = | |
| 71 settings.mutable_device_proxy_settings(); | |
| 72 proxy_settings->set_proxy_mode(proxy_mode); | |
| 73 proxy_settings->set_proxy_server(proxy_server); | |
| 74 proxy_settings->set_proxy_pac_url(proxy_pac_url); | |
| 75 proxy_settings->set_proxy_bypass_list(proxy_bypass_list); | |
| 76 CreatePolicy(policy, user, settings); | |
| 77 } | |
| 78 | |
| 79 } // namespace | 43 } // namespace |
| 80 | 44 |
| 81 class DevicePolicyCacheTest : public testing::Test { | 45 class DevicePolicyCacheTest : public testing::Test { |
| 82 protected: | 46 protected: |
| 83 DevicePolicyCacheTest() | 47 DevicePolicyCacheTest() |
| 84 : cryptohome_(chromeos::CryptohomeLibrary::GetImpl(true)), | 48 : cryptohome_(chromeos::CryptohomeLibrary::GetImpl(true)), |
| 49 owner_key_util_(new chromeos::MockOwnerKeyUtil()), |
| 85 install_attributes_(cryptohome_.get()), | 50 install_attributes_(cryptohome_.get()), |
| 86 message_loop_(MessageLoop::TYPE_UI), | 51 message_loop_(MessageLoop::TYPE_UI), |
| 87 ui_thread_(content::BrowserThread::UI, &message_loop_), | 52 ui_thread_(content::BrowserThread::UI, &message_loop_), |
| 88 file_thread_(content::BrowserThread::FILE, &message_loop_) {} | 53 file_thread_(content::BrowserThread::FILE, &message_loop_) {} |
| 89 | 54 |
| 90 virtual void SetUp() { | 55 virtual void SetUp() OVERRIDE { |
| 91 data_store_.reset(CloudPolicyDataStore::CreateForUserPolicies()); | 56 policy_.payload().mutable_device_policy_refresh_rate()-> |
| 57 set_device_policy_refresh_rate(120); |
| 58 policy_.Build(); |
| 59 device_settings_test_helper_.set_policy_blob(policy_.GetBlob()); |
| 60 |
| 61 owner_key_util_->SetPublicKeyFromPrivateKey(policy_.signing_key()); |
| 62 |
| 63 device_settings_service_.Initialize(&device_settings_test_helper_, |
| 64 owner_key_util_); |
| 65 |
| 66 data_store_.reset(CloudPolicyDataStore::CreateForDevicePolicies()); |
| 92 cache_.reset(new DevicePolicyCache(data_store_.get(), | 67 cache_.reset(new DevicePolicyCache(data_store_.get(), |
| 93 &install_attributes_, | 68 &install_attributes_, |
| 94 &signed_settings_helper_)); | 69 &device_settings_service_)); |
| 95 cache_->AddObserver(&observer_); | 70 cache_->AddObserver(&observer_); |
| 96 } | 71 } |
| 97 | 72 |
| 98 virtual void TearDown() { | 73 virtual void TearDown() OVERRIDE { |
| 74 device_settings_test_helper_.Flush(); |
| 75 device_settings_service_.Shutdown(); |
| 76 |
| 99 cache_->RemoveObserver(&observer_); | 77 cache_->RemoveObserver(&observer_); |
| 100 cache_.reset(); | 78 cache_.reset(); |
| 101 } | 79 } |
| 102 | 80 |
| 103 void MakeEnterpriseDevice(const char* registration_user) { | 81 void Startup() { |
| 82 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get())); |
| 83 device_settings_service_.Load(); |
| 84 device_settings_test_helper_.Flush(); |
| 85 cache_->Load(); |
| 86 Mock::VerifyAndClearExpectations(&observer_); |
| 87 } |
| 88 |
| 89 void MakeEnterpriseDevice() { |
| 104 ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS, | 90 ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS, |
| 105 install_attributes_.LockDevice( | 91 install_attributes_.LockDevice( |
| 106 registration_user, | 92 policy_.policy_data().username(), |
| 107 DEVICE_MODE_ENTERPRISE, | 93 DEVICE_MODE_ENTERPRISE, |
| 108 std::string())); | 94 std::string())); |
| 109 } | 95 } |
| 110 | 96 |
| 111 const Value* GetPolicy(const char* policy_name) { | 97 const Value* GetPolicy(const char* policy_name) { |
| 112 return cache_->policy()->GetValue(policy_name); | 98 return cache_->policy()->GetValue(policy_name); |
| 113 } | 99 } |
| 114 | 100 |
| 115 MockCloudPolicyCacheObserver observer_; | 101 MockCloudPolicyCacheObserver observer_; |
| 102 |
| 116 scoped_ptr<chromeos::CryptohomeLibrary> cryptohome_; | 103 scoped_ptr<chromeos::CryptohomeLibrary> cryptohome_; |
| 104 scoped_refptr<chromeos::MockOwnerKeyUtil> owner_key_util_; |
| 105 chromeos::DeviceSettingsTestHelper device_settings_test_helper_; |
| 106 chromeos::DeviceSettingsService device_settings_service_; |
| 117 EnterpriseInstallAttributes install_attributes_; | 107 EnterpriseInstallAttributes install_attributes_; |
| 108 |
| 118 scoped_ptr<CloudPolicyDataStore> data_store_; | 109 scoped_ptr<CloudPolicyDataStore> data_store_; |
| 119 chromeos::MockSignedSettingsHelper signed_settings_helper_; | |
| 120 scoped_ptr<DevicePolicyCache> cache_; | 110 scoped_ptr<DevicePolicyCache> cache_; |
| 111 DevicePolicyBuilder policy_; |
| 121 | 112 |
| 122 MessageLoop message_loop_; | 113 MessageLoop message_loop_; |
| 123 content::TestBrowserThread ui_thread_; | 114 content::TestBrowserThread ui_thread_; |
| 124 content::TestBrowserThread file_thread_; | 115 content::TestBrowserThread file_thread_; |
| 125 | 116 |
| 126 private: | 117 private: |
| 127 DISALLOW_COPY_AND_ASSIGN(DevicePolicyCacheTest); | 118 DISALLOW_COPY_AND_ASSIGN(DevicePolicyCacheTest); |
| 128 }; | 119 }; |
| 129 | 120 |
| 130 TEST_F(DevicePolicyCacheTest, Startup) { | 121 TEST_F(DevicePolicyCacheTest, ColdStartup) { |
| 131 em::PolicyFetchResponse policy; | 122 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get())).Times(0); |
| 132 CreateRefreshRatePolicy(&policy, kTestUser, 120); | 123 cache_->Load(); |
| 133 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce( | 124 Mock::VerifyAndClearExpectations(&observer_); |
| 134 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS, | 125 |
| 135 policy)); | |
| 136 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get())); | 126 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get())); |
| 137 cache_->Load(); | 127 device_settings_service_.Load(); |
| 138 Mock::VerifyAndClearExpectations(&signed_settings_helper_); | 128 device_settings_test_helper_.Flush(); |
| 129 Mock::VerifyAndClearExpectations(&observer_); |
| 130 |
| 131 base::FundamentalValue expected(120); |
| 132 EXPECT_TRUE(Value::Equals(&expected, |
| 133 GetPolicy(key::kDevicePolicyRefreshRate))); |
| 134 } |
| 135 |
| 136 TEST_F(DevicePolicyCacheTest, WarmStartup) { |
| 137 Startup(); |
| 138 |
| 139 base::FundamentalValue expected(120); | 139 base::FundamentalValue expected(120); |
| 140 EXPECT_TRUE(Value::Equals(&expected, | 140 EXPECT_TRUE(Value::Equals(&expected, |
| 141 GetPolicy(key::kDevicePolicyRefreshRate))); | 141 GetPolicy(key::kDevicePolicyRefreshRate))); |
| 142 } | 142 } |
| 143 | 143 |
| 144 TEST_F(DevicePolicyCacheTest, SetPolicy) { | 144 TEST_F(DevicePolicyCacheTest, SetPolicy) { |
| 145 InSequence s; | 145 MakeEnterpriseDevice(); |
| 146 Startup(); |
| 146 | 147 |
| 147 MakeEnterpriseDevice(kTestUser); | |
| 148 | |
| 149 // Startup. | |
| 150 em::PolicyFetchResponse policy; | |
| 151 CreateRefreshRatePolicy(&policy, kTestUser, 120); | |
| 152 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce( | |
| 153 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS, | |
| 154 policy)); | |
| 155 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get())); | |
| 156 cache_->Load(); | |
| 157 Mock::VerifyAndClearExpectations(&signed_settings_helper_); | |
| 158 Mock::VerifyAndClearExpectations(&observer_); | |
| 159 base::FundamentalValue expected(120); | 148 base::FundamentalValue expected(120); |
| 160 EXPECT_TRUE(Value::Equals(&expected, | 149 EXPECT_TRUE(Value::Equals(&expected, |
| 161 GetPolicy(key::kDevicePolicyRefreshRate))); | 150 GetPolicy(key::kDevicePolicyRefreshRate))); |
| 162 | 151 |
| 163 // Set new policy information. | 152 // Set new policy information. |
| 164 chromeos::SignedSettingsHelper::StorePolicyCallback store_callback; | 153 policy_.payload().mutable_device_policy_refresh_rate()-> |
| 165 em::PolicyFetchResponse new_policy; | 154 set_device_policy_refresh_rate(300); |
| 166 CreateRefreshRatePolicy(&new_policy, kTestUser, 300); | 155 policy_.Build(); |
| 167 EXPECT_CALL(signed_settings_helper_, StartStorePolicyOp(_, _)).WillOnce( | |
| 168 SaveArg<1>(&store_callback)); | |
| 169 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get())).Times(0); | 156 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get())).Times(0); |
| 170 EXPECT_TRUE(cache_->SetPolicy(new_policy)); | 157 EXPECT_TRUE(cache_->SetPolicy(policy_.policy())); |
| 171 cache_->SetFetchingDone(); | 158 cache_->SetFetchingDone(); |
| 172 Mock::VerifyAndClearExpectations(&signed_settings_helper_); | |
| 173 Mock::VerifyAndClearExpectations(&observer_); | 159 Mock::VerifyAndClearExpectations(&observer_); |
| 174 ASSERT_FALSE(store_callback.is_null()); | |
| 175 | 160 |
| 176 chromeos::SignedSettingsHelper::RetrievePolicyCallback retrieve_callback; | |
| 177 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce( | |
| 178 SaveArg<0>(&retrieve_callback)); | |
| 179 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get())).Times(0); | 161 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get())).Times(0); |
| 180 store_callback.Run(chromeos::SignedSettings::SUCCESS); | 162 device_settings_test_helper_.FlushStore(); |
| 181 Mock::VerifyAndClearExpectations(&signed_settings_helper_); | |
| 182 Mock::VerifyAndClearExpectations(&observer_); | 163 Mock::VerifyAndClearExpectations(&observer_); |
| 183 ASSERT_FALSE(retrieve_callback.is_null()); | |
| 184 | 164 |
| 185 // Cache update notification should only fire in the retrieve callback. | 165 // Cache update notification should only fire in the retrieve callback. |
| 186 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get())); | 166 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get())); |
| 187 retrieve_callback.Run(chromeos::SignedSettings::SUCCESS, new_policy); | 167 device_settings_test_helper_.Flush(); |
| 168 Mock::VerifyAndClearExpectations(&observer_); |
| 169 |
| 188 base::FundamentalValue updated_expected(300); | 170 base::FundamentalValue updated_expected(300); |
| 189 EXPECT_TRUE(Value::Equals(&updated_expected, | 171 EXPECT_TRUE(Value::Equals(&updated_expected, |
| 190 GetPolicy(key::kDevicePolicyRefreshRate))); | 172 GetPolicy(key::kDevicePolicyRefreshRate))); |
| 191 Mock::VerifyAndClearExpectations(&observer_); | |
| 192 | 173 |
| 193 cache_->RemoveObserver(&observer_); | 174 cache_->RemoveObserver(&observer_); |
| 194 } | 175 } |
| 195 | 176 |
| 196 TEST_F(DevicePolicyCacheTest, SetPolicyOtherUserSameDomain) { | 177 TEST_F(DevicePolicyCacheTest, SetPolicyOtherUserSameDomain) { |
| 197 InSequence s; | 178 MakeEnterpriseDevice(); |
| 198 | 179 Startup(); |
| 199 MakeEnterpriseDevice(kTestUser); | |
| 200 | |
| 201 // Startup. | |
| 202 em::PolicyFetchResponse policy; | |
| 203 CreateRefreshRatePolicy(&policy, kTestUser, 120); | |
| 204 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce( | |
| 205 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS, | |
| 206 policy)); | |
| 207 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get())); | |
| 208 cache_->Load(); | |
| 209 Mock::VerifyAndClearExpectations(&signed_settings_helper_); | |
| 210 | 180 |
| 211 // Set new policy information. This should succeed as the domain is the same. | 181 // Set new policy information. This should succeed as the domain is the same. |
| 212 chromeos::SignedSettingsHelper::StorePolicyCallback store_callback; | 182 policy_.policy_data().set_username("another_user@example.com"); |
| 213 em::PolicyFetchResponse new_policy; | 183 policy_.Build(); |
| 214 CreateRefreshRatePolicy(&new_policy, "another_user@example.com", 300); | 184 |
| 215 EXPECT_CALL(signed_settings_helper_, StartStorePolicyOp(_, _)).WillOnce( | 185 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get())); |
| 216 SaveArg<1>(&store_callback)); | 186 EXPECT_TRUE(cache_->SetPolicy(policy_.policy())); |
| 217 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get())).Times(1); | 187 device_settings_test_helper_.Flush(); |
| 218 EXPECT_TRUE(cache_->SetPolicy(new_policy)); | |
| 219 cache_->SetFetchingDone(); | |
| 220 store_callback.Run(chromeos::SignedSettings::OPERATION_FAILED); | |
| 221 Mock::VerifyAndClearExpectations(&signed_settings_helper_); | |
| 222 Mock::VerifyAndClearExpectations(&observer_); | 188 Mock::VerifyAndClearExpectations(&observer_); |
| 189 EXPECT_EQ(policy_.GetBlob(), device_settings_test_helper_.policy_blob()); |
| 223 } | 190 } |
| 224 | 191 |
| 225 TEST_F(DevicePolicyCacheTest, SetPolicyOtherUserOtherDomain) { | 192 TEST_F(DevicePolicyCacheTest, SetPolicyOtherUserOtherDomain) { |
| 226 InSequence s; | 193 MakeEnterpriseDevice(); |
| 227 | 194 Startup(); |
| 228 MakeEnterpriseDevice(kTestUser); | |
| 229 | |
| 230 // Startup. | |
| 231 em::PolicyFetchResponse policy; | |
| 232 CreateRefreshRatePolicy(&policy, kTestUser, 120); | |
| 233 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce( | |
| 234 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS, | |
| 235 policy)); | |
| 236 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get())); | |
| 237 cache_->Load(); | |
| 238 Mock::VerifyAndClearExpectations(&signed_settings_helper_); | |
| 239 | 195 |
| 240 // Set new policy information. This should fail because the user is from | 196 // Set new policy information. This should fail because the user is from |
| 241 // different domain. | 197 // different domain. |
| 242 em::PolicyFetchResponse new_policy; | 198 policy_.policy_data().set_username("foreign_user@hackers.com"); |
| 243 CreateRefreshRatePolicy(&new_policy, "foreign_user@hackers.com", 300); | 199 policy_.Build(); |
| 244 EXPECT_CALL(signed_settings_helper_, StartStorePolicyOp(_, _)).Times(0); | 200 EXPECT_NE(policy_.GetBlob(), device_settings_test_helper_.policy_blob()); |
| 245 EXPECT_FALSE(cache_->SetPolicy(new_policy)); | |
| 246 Mock::VerifyAndClearExpectations(&signed_settings_helper_); | |
| 247 | 201 |
| 248 base::FundamentalValue expected(120); | 202 EXPECT_FALSE(cache_->SetPolicy(policy_.policy())); |
| 249 EXPECT_TRUE(Value::Equals(&expected, | 203 device_settings_test_helper_.Flush(); |
| 250 GetPolicy(key::kDevicePolicyRefreshRate))); | 204 EXPECT_NE(policy_.GetBlob(), device_settings_test_helper_.policy_blob()); |
| 251 } | 205 } |
| 252 | 206 |
| 253 TEST_F(DevicePolicyCacheTest, SetPolicyNonEnterpriseDevice) { | 207 TEST_F(DevicePolicyCacheTest, SetPolicyNonEnterpriseDevice) { |
| 254 InSequence s; | 208 Startup(); |
| 255 | |
| 256 // Startup. | |
| 257 em::PolicyFetchResponse policy; | |
| 258 CreateRefreshRatePolicy(&policy, kTestUser, 120); | |
| 259 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce( | |
| 260 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS, | |
| 261 policy)); | |
| 262 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get())); | |
| 263 cache_->Load(); | |
| 264 Mock::VerifyAndClearExpectations(&signed_settings_helper_); | |
| 265 | 209 |
| 266 // Set new policy information. This should fail due to invalid user. | 210 // Set new policy information. This should fail due to invalid user. |
| 267 em::PolicyFetchResponse new_policy; | 211 device_settings_test_helper_.set_policy_blob(std::string()); |
| 268 CreateRefreshRatePolicy(&new_policy, kTestUser, 120); | |
| 269 EXPECT_CALL(signed_settings_helper_, StartStorePolicyOp(_, _)).Times(0); | |
| 270 EXPECT_FALSE(cache_->SetPolicy(new_policy)); | |
| 271 Mock::VerifyAndClearExpectations(&signed_settings_helper_); | |
| 272 | 212 |
| 273 base::FundamentalValue expected(120); | 213 EXPECT_FALSE(cache_->SetPolicy(policy_.policy())); |
| 274 EXPECT_TRUE(Value::Equals(&expected, | 214 device_settings_test_helper_.Flush(); |
| 275 GetPolicy(key::kDevicePolicyRefreshRate))); | 215 EXPECT_TRUE(device_settings_test_helper_.policy_blob().empty()); |
| 276 } | 216 } |
| 277 | 217 |
| 278 TEST_F(DevicePolicyCacheTest, SetProxyPolicy) { | 218 TEST_F(DevicePolicyCacheTest, SetProxyPolicy) { |
| 279 MakeEnterpriseDevice(kTestUser); | 219 MakeEnterpriseDevice(); |
| 280 | 220 |
| 281 // Startup. | 221 em::DeviceProxySettingsProto proxy_settings; |
| 282 em::PolicyFetchResponse policy; | 222 proxy_settings.set_proxy_mode("direct"); |
| 283 CreateProxyPolicy(&policy, kTestUser, "direct", "http://proxy:8080", | 223 proxy_settings.set_proxy_server("http://proxy:8080"); |
| 284 "http://proxy:8080/pac.js", "127.0.0.1,example.com"); | 224 proxy_settings.set_proxy_pac_url("http://proxy:8080/pac.js"); |
| 285 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce( | 225 proxy_settings.set_proxy_bypass_list("127.0.0.1,example.com"); |
| 286 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS, | 226 policy_.payload().mutable_device_proxy_settings()->CopyFrom(proxy_settings); |
| 287 policy)); | 227 policy_.Build(); |
| 288 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get())); | 228 device_settings_test_helper_.set_policy_blob(policy_.GetBlob()); |
| 289 cache_->Load(); | 229 Startup(); |
| 290 Mock::VerifyAndClearExpectations(&signed_settings_helper_); | 230 |
| 291 DictionaryValue expected; | 231 DictionaryValue expected; |
| 292 expected.SetString(key::kProxyMode, "direct"); | 232 expected.SetString(key::kProxyMode, proxy_settings.proxy_mode()); |
| 293 expected.SetString(key::kProxyServer, "http://proxy:8080"); | 233 expected.SetString(key::kProxyServer, proxy_settings.proxy_server()); |
| 294 expected.SetString(key::kProxyPacUrl, "http://proxy:8080/pac.js"); | 234 expected.SetString(key::kProxyPacUrl, proxy_settings.proxy_pac_url()); |
| 295 expected.SetString(key::kProxyBypassList, "127.0.0.1,example.com"); | 235 expected.SetString(key::kProxyBypassList, proxy_settings.proxy_bypass_list()); |
| 296 EXPECT_TRUE(Value::Equals(&expected, | 236 EXPECT_TRUE(Value::Equals(&expected, GetPolicy(key::kProxySettings))); |
| 297 GetPolicy(key::kProxySettings))); | |
| 298 } | 237 } |
| 299 | 238 |
| 300 TEST_F(DevicePolicyCacheTest, SetDeviceNetworkConfigurationPolicy) { | 239 TEST_F(DevicePolicyCacheTest, SetDeviceNetworkConfigurationPolicy) { |
| 301 MakeEnterpriseDevice(kTestUser); | 240 MakeEnterpriseDevice(); |
| 302 | 241 |
| 303 // Startup. | |
| 304 std::string fake_config("{ 'NetworkConfigurations': [] }"); | 242 std::string fake_config("{ 'NetworkConfigurations': [] }"); |
| 305 em::PolicyFetchResponse policy; | 243 policy_.payload().mutable_open_network_configuration()-> |
| 306 em::ChromeDeviceSettingsProto settings; | 244 set_open_network_configuration(fake_config); |
| 307 settings.mutable_open_network_configuration()->set_open_network_configuration( | 245 policy_.Build(); |
| 308 fake_config); | 246 device_settings_test_helper_.set_policy_blob(policy_.GetBlob()); |
| 309 CreatePolicy(&policy, kTestUser, settings); | 247 Startup(); |
| 310 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce( | 248 |
| 311 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS, | |
| 312 policy)); | |
| 313 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get())); | |
| 314 cache_->Load(); | |
| 315 Mock::VerifyAndClearExpectations(&signed_settings_helper_); | |
| 316 StringValue expected_config(fake_config); | 249 StringValue expected_config(fake_config); |
| 317 EXPECT_TRUE( | 250 EXPECT_TRUE( |
| 318 Value::Equals(&expected_config, | 251 Value::Equals(&expected_config, |
| 319 GetPolicy(key::kDeviceOpenNetworkConfiguration))); | 252 GetPolicy(key::kDeviceOpenNetworkConfiguration))); |
| 320 } | 253 } |
| 321 | 254 |
| 322 } // namespace policy | 255 } // namespace policy |
| OLD | NEW |