OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 }; | 111 }; |
112 | 112 |
113 TEST_F(DevicePolicyCacheTest, Startup) { | 113 TEST_F(DevicePolicyCacheTest, Startup) { |
114 em::PolicyFetchResponse policy; | 114 em::PolicyFetchResponse policy; |
115 CreateRefreshRatePolicy(&policy, kTestUser, 120); | 115 CreateRefreshRatePolicy(&policy, kTestUser, 120); |
116 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce( | 116 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce( |
117 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS, | 117 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS, |
118 policy)); | 118 policy)); |
119 cache_->Load(); | 119 cache_->Load(); |
120 testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_); | 120 testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_); |
121 FundamentalValue expected(120); | 121 base::FundamentalValue expected(120); |
122 EXPECT_TRUE(Value::Equals(&expected, | 122 EXPECT_TRUE(Value::Equals(&expected, |
123 GetMandatoryPolicy( | 123 GetMandatoryPolicy( |
124 kPolicyDevicePolicyRefreshRate))); | 124 kPolicyDevicePolicyRefreshRate))); |
125 } | 125 } |
126 | 126 |
127 TEST_F(DevicePolicyCacheTest, SetPolicy) { | 127 TEST_F(DevicePolicyCacheTest, SetPolicy) { |
128 InSequence s; | 128 InSequence s; |
129 | 129 |
130 MakeEnterpriseDevice(kTestUser); | 130 MakeEnterpriseDevice(kTestUser); |
131 | 131 |
132 // Startup. | 132 // Startup. |
133 em::PolicyFetchResponse policy; | 133 em::PolicyFetchResponse policy; |
134 CreateRefreshRatePolicy(&policy, kTestUser, 120); | 134 CreateRefreshRatePolicy(&policy, kTestUser, 120); |
135 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce( | 135 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce( |
136 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS, | 136 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS, |
137 policy)); | 137 policy)); |
138 cache_->Load(); | 138 cache_->Load(); |
139 testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_); | 139 testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_); |
140 FundamentalValue expected(120); | 140 base::FundamentalValue expected(120); |
141 EXPECT_TRUE(Value::Equals(&expected, | 141 EXPECT_TRUE(Value::Equals(&expected, |
142 GetMandatoryPolicy( | 142 GetMandatoryPolicy( |
143 kPolicyDevicePolicyRefreshRate))); | 143 kPolicyDevicePolicyRefreshRate))); |
144 | 144 |
145 // Set new policy information. | 145 // Set new policy information. |
146 em::PolicyFetchResponse new_policy; | 146 em::PolicyFetchResponse new_policy; |
147 CreateRefreshRatePolicy(&new_policy, kTestUser, 300); | 147 CreateRefreshRatePolicy(&new_policy, kTestUser, 300); |
148 EXPECT_CALL(signed_settings_helper_, StartStorePolicyOp(_, _)).WillOnce( | 148 EXPECT_CALL(signed_settings_helper_, StartStorePolicyOp(_, _)).WillOnce( |
149 MockSignedSettingsHelperStorePolicy(chromeos::SignedSettings::SUCCESS)); | 149 MockSignedSettingsHelperStorePolicy(chromeos::SignedSettings::SUCCESS)); |
150 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce( | 150 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce( |
151 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS, | 151 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS, |
152 new_policy)); | 152 new_policy)); |
153 EXPECT_CALL(signed_settings_helper_, CancelCallback(_)); | 153 EXPECT_CALL(signed_settings_helper_, CancelCallback(_)); |
154 cache_->SetPolicy(new_policy); | 154 cache_->SetPolicy(new_policy); |
155 testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_); | 155 testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_); |
156 FundamentalValue updated_expected(300); | 156 base::FundamentalValue updated_expected(300); |
157 EXPECT_TRUE(Value::Equals(&updated_expected, | 157 EXPECT_TRUE(Value::Equals(&updated_expected, |
158 GetMandatoryPolicy( | 158 GetMandatoryPolicy( |
159 kPolicyDevicePolicyRefreshRate))); | 159 kPolicyDevicePolicyRefreshRate))); |
160 } | 160 } |
161 | 161 |
162 TEST_F(DevicePolicyCacheTest, SetPolicyWrongUser) { | 162 TEST_F(DevicePolicyCacheTest, SetPolicyWrongUser) { |
163 InSequence s; | 163 InSequence s; |
164 | 164 |
165 MakeEnterpriseDevice(kTestUser); | 165 MakeEnterpriseDevice(kTestUser); |
166 | 166 |
167 // Startup. | 167 // Startup. |
168 em::PolicyFetchResponse policy; | 168 em::PolicyFetchResponse policy; |
169 CreateRefreshRatePolicy(&policy, kTestUser, 120); | 169 CreateRefreshRatePolicy(&policy, kTestUser, 120); |
170 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce( | 170 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce( |
171 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS, | 171 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS, |
172 policy)); | 172 policy)); |
173 cache_->Load(); | 173 cache_->Load(); |
174 testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_); | 174 testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_); |
175 | 175 |
176 // Set new policy information. This should fail due to invalid user. | 176 // Set new policy information. This should fail due to invalid user. |
177 em::PolicyFetchResponse new_policy; | 177 em::PolicyFetchResponse new_policy; |
178 CreateRefreshRatePolicy(&new_policy, "foreign_user@example.com", 300); | 178 CreateRefreshRatePolicy(&new_policy, "foreign_user@example.com", 300); |
179 EXPECT_CALL(signed_settings_helper_, StartStorePolicyOp(_, _)).Times(0); | 179 EXPECT_CALL(signed_settings_helper_, StartStorePolicyOp(_, _)).Times(0); |
180 cache_->SetPolicy(new_policy); | 180 cache_->SetPolicy(new_policy); |
181 testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_); | 181 testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_); |
182 | 182 |
183 FundamentalValue expected(120); | 183 base::FundamentalValue expected(120); |
184 EXPECT_TRUE(Value::Equals(&expected, | 184 EXPECT_TRUE(Value::Equals(&expected, |
185 GetMandatoryPolicy( | 185 GetMandatoryPolicy( |
186 kPolicyDevicePolicyRefreshRate))); | 186 kPolicyDevicePolicyRefreshRate))); |
187 } | 187 } |
188 | 188 |
189 TEST_F(DevicePolicyCacheTest, SetPolicyNonEnterpriseDevice) { | 189 TEST_F(DevicePolicyCacheTest, SetPolicyNonEnterpriseDevice) { |
190 InSequence s; | 190 InSequence s; |
191 | 191 |
192 // Startup. | 192 // Startup. |
193 em::PolicyFetchResponse policy; | 193 em::PolicyFetchResponse policy; |
194 CreateRefreshRatePolicy(&policy, kTestUser, 120); | 194 CreateRefreshRatePolicy(&policy, kTestUser, 120); |
195 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce( | 195 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce( |
196 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS, | 196 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS, |
197 policy)); | 197 policy)); |
198 cache_->Load(); | 198 cache_->Load(); |
199 testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_); | 199 testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_); |
200 | 200 |
201 // Set new policy information. This should fail due to invalid user. | 201 // Set new policy information. This should fail due to invalid user. |
202 em::PolicyFetchResponse new_policy; | 202 em::PolicyFetchResponse new_policy; |
203 CreateRefreshRatePolicy(&new_policy, kTestUser, 120); | 203 CreateRefreshRatePolicy(&new_policy, kTestUser, 120); |
204 EXPECT_CALL(signed_settings_helper_, StartStorePolicyOp(_, _)).Times(0); | 204 EXPECT_CALL(signed_settings_helper_, StartStorePolicyOp(_, _)).Times(0); |
205 cache_->SetPolicy(new_policy); | 205 cache_->SetPolicy(new_policy); |
206 testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_); | 206 testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_); |
207 | 207 |
208 FundamentalValue expected(120); | 208 base::FundamentalValue expected(120); |
209 EXPECT_TRUE(Value::Equals(&expected, | 209 EXPECT_TRUE(Value::Equals(&expected, |
210 GetMandatoryPolicy( | 210 GetMandatoryPolicy( |
211 kPolicyDevicePolicyRefreshRate))); | 211 kPolicyDevicePolicyRefreshRate))); |
212 } | 212 } |
213 | 213 |
214 TEST_F(DevicePolicyCacheTest, SetProxyPolicy) { | 214 TEST_F(DevicePolicyCacheTest, SetProxyPolicy) { |
215 InSequence s; | 215 InSequence s; |
216 | 216 |
217 MakeEnterpriseDevice(kTestUser); | 217 MakeEnterpriseDevice(kTestUser); |
218 | 218 |
(...skipping 14 matching lines...) Expand all Loading... |
233 GetRecommendedPolicy(kPolicyProxyMode))); | 233 GetRecommendedPolicy(kPolicyProxyMode))); |
234 EXPECT_TRUE(Value::Equals(&expected_proxy_server, | 234 EXPECT_TRUE(Value::Equals(&expected_proxy_server, |
235 GetRecommendedPolicy(kPolicyProxyServer))); | 235 GetRecommendedPolicy(kPolicyProxyServer))); |
236 EXPECT_TRUE(Value::Equals(&expected_proxy_pac_url, | 236 EXPECT_TRUE(Value::Equals(&expected_proxy_pac_url, |
237 GetRecommendedPolicy(kPolicyProxyPacUrl))); | 237 GetRecommendedPolicy(kPolicyProxyPacUrl))); |
238 EXPECT_TRUE(Value::Equals(&expected_proxy_bypass_list, | 238 EXPECT_TRUE(Value::Equals(&expected_proxy_bypass_list, |
239 GetRecommendedPolicy(kPolicyProxyBypassList))); | 239 GetRecommendedPolicy(kPolicyProxyBypassList))); |
240 } | 240 } |
241 | 241 |
242 } // namespace policy | 242 } // namespace policy |
OLD | NEW |