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/chromeos/policy/user_cloud_policy_store_chromeos.h" | 5 #include "chrome/browser/chromeos/policy/user_cloud_policy_store_chromeos.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
14 #include "base/files/scoped_temp_dir.h" | 14 #include "base/files/scoped_temp_dir.h" |
15 #include "base/location.h" | 15 #include "base/location.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
18 #include "base/message_loop/message_loop.h" | 18 #include "base/message_loop/message_loop.h" |
| 19 #include "base/run_loop.h" |
19 #include "base/single_thread_task_runner.h" | 20 #include "base/single_thread_task_runner.h" |
20 #include "base/threading/sequenced_worker_pool.h" | 21 #include "base/threading/sequenced_worker_pool.h" |
21 #include "base/threading/thread_task_runner_handle.h" | 22 #include "base/threading/thread_task_runner_handle.h" |
22 #include "chromeos/dbus/mock_cryptohome_client.h" | 23 #include "chromeos/dbus/mock_cryptohome_client.h" |
23 #include "chromeos/dbus/mock_session_manager_client.h" | 24 #include "chromeos/dbus/mock_session_manager_client.h" |
24 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | 25 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
25 #include "components/policy/core/common/cloud/mock_cloud_policy_store.h" | 26 #include "components/policy/core/common/cloud/mock_cloud_policy_store.h" |
26 #include "components/policy/core/common/cloud/policy_builder.h" | 27 #include "components/policy/core/common/cloud/policy_builder.h" |
27 #include "components/policy/core/common/policy_types.h" | 28 #include "components/policy/core/common/policy_types.h" |
28 #include "components/policy/policy_constants.h" | 29 #include "components/policy/policy_constants.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 ASSERT_TRUE(policy_.GetSigningKey()->ExportPublicKey(&public_key)); | 80 ASSERT_TRUE(policy_.GetSigningKey()->ExportPublicKey(&public_key)); |
80 StoreUserPolicyKey(public_key); | 81 StoreUserPolicyKey(public_key); |
81 | 82 |
82 policy_.payload().mutable_homepagelocation()->set_value(kDefaultHomepage); | 83 policy_.payload().mutable_homepagelocation()->set_value(kDefaultHomepage); |
83 policy_.Build(); | 84 policy_.Build(); |
84 } | 85 } |
85 | 86 |
86 void TearDown() override { | 87 void TearDown() override { |
87 store_->RemoveObserver(&observer_); | 88 store_->RemoveObserver(&observer_); |
88 store_.reset(); | 89 store_.reset(); |
89 RunUntilIdle(); | 90 base::RunLoop().RunUntilIdle(); |
90 } | 91 } |
91 | 92 |
92 // Install an expectation on |observer_| for an error code. | 93 // Install an expectation on |observer_| for an error code. |
93 void ExpectError(CloudPolicyStore::Status error) { | 94 void ExpectError(CloudPolicyStore::Status error) { |
94 EXPECT_CALL(observer_, | 95 EXPECT_CALL(observer_, |
95 OnStoreError(AllOf(Eq(store_.get()), | 96 OnStoreError(AllOf(Eq(store_.get()), |
96 Property(&CloudPolicyStore::status, | 97 Property(&CloudPolicyStore::status, |
97 Eq(error))))); | 98 Eq(error))))); |
98 } | 99 } |
99 | 100 |
100 // Triggers a store_->Load() operation, handles the expected call to | 101 // Triggers a store_->Load() operation, handles the expected call to |
101 // |session_manager_client_| and sends |response|. | 102 // |session_manager_client_| and sends |response|. |
102 void PerformPolicyLoad(const std::string& response) { | 103 void PerformPolicyLoad(const std::string& response) { |
103 // Issue a load command. | 104 // Issue a load command. |
104 chromeos::SessionManagerClient::RetrievePolicyCallback retrieve_callback; | 105 chromeos::SessionManagerClient::RetrievePolicyCallback retrieve_callback; |
105 EXPECT_CALL(session_manager_client_, | 106 EXPECT_CALL(session_manager_client_, |
106 RetrievePolicyForUser(cryptohome_id_, _)) | 107 RetrievePolicyForUser(cryptohome_id_, _)) |
107 .WillOnce(SaveArg<1>(&retrieve_callback)); | 108 .WillOnce(SaveArg<1>(&retrieve_callback)); |
108 store_->Load(); | 109 store_->Load(); |
109 RunUntilIdle(); | 110 base::RunLoop().RunUntilIdle(); |
110 Mock::VerifyAndClearExpectations(&session_manager_client_); | 111 Mock::VerifyAndClearExpectations(&session_manager_client_); |
111 ASSERT_FALSE(retrieve_callback.is_null()); | 112 ASSERT_FALSE(retrieve_callback.is_null()); |
112 | 113 |
113 // Run the callback. | 114 // Run the callback. |
114 retrieve_callback.Run(response); | 115 retrieve_callback.Run(response); |
115 RunUntilIdle(); | 116 base::RunLoop().RunUntilIdle(); |
116 } | 117 } |
117 | 118 |
118 // Verifies that store_->policy_map() has the HomepageLocation entry with | 119 // Verifies that store_->policy_map() has the HomepageLocation entry with |
119 // the |expected_value|. | 120 // the |expected_value|. |
120 void VerifyPolicyMap(const char* expected_value) { | 121 void VerifyPolicyMap(const char* expected_value) { |
121 EXPECT_EQ(1U, store_->policy_map().size()); | 122 EXPECT_EQ(1U, store_->policy_map().size()); |
122 const PolicyMap::Entry* entry = | 123 const PolicyMap::Entry* entry = |
123 store_->policy_map().Get(key::kHomepageLocation); | 124 store_->policy_map().Get(key::kHomepageLocation); |
124 ASSERT_TRUE(entry); | 125 ASSERT_TRUE(entry); |
125 EXPECT_TRUE(base::StringValue(expected_value).Equals(entry->value.get())); | 126 EXPECT_TRUE(base::StringValue(expected_value).Equals(entry->value.get())); |
(...skipping 15 matching lines...) Expand all Loading... |
141 // If |new_value| is set then a new policy with that value is expected after | 142 // If |new_value| is set then a new policy with that value is expected after |
142 // storing the |policy_| blob. | 143 // storing the |policy_| blob. |
143 void PerformStorePolicy(const std::vector<uint8_t>* new_public_key, | 144 void PerformStorePolicy(const std::vector<uint8_t>* new_public_key, |
144 const char* previous_value, | 145 const char* previous_value, |
145 const char* new_value) { | 146 const char* new_value) { |
146 chromeos::SessionManagerClient::StorePolicyCallback store_callback; | 147 chromeos::SessionManagerClient::StorePolicyCallback store_callback; |
147 EXPECT_CALL(session_manager_client_, | 148 EXPECT_CALL(session_manager_client_, |
148 StorePolicyForUser(cryptohome_id_, policy_.GetBlob(), _)) | 149 StorePolicyForUser(cryptohome_id_, policy_.GetBlob(), _)) |
149 .WillOnce(SaveArg<2>(&store_callback)); | 150 .WillOnce(SaveArg<2>(&store_callback)); |
150 store_->Store(policy_.policy()); | 151 store_->Store(policy_.policy()); |
151 RunUntilIdle(); | 152 base::RunLoop().RunUntilIdle(); |
152 Mock::VerifyAndClearExpectations(&session_manager_client_); | 153 Mock::VerifyAndClearExpectations(&session_manager_client_); |
153 ASSERT_FALSE(store_callback.is_null()); | 154 ASSERT_FALSE(store_callback.is_null()); |
154 | 155 |
155 // The new policy shouldn't be present yet. | 156 // The new policy shouldn't be present yet. |
156 PolicyMap previous_policy; | 157 PolicyMap previous_policy; |
157 EXPECT_EQ(previous_value != NULL, store_->policy() != NULL); | 158 EXPECT_EQ(previous_value != NULL, store_->policy() != NULL); |
158 if (previous_value) { | 159 if (previous_value) { |
159 previous_policy.Set(key::kHomepageLocation, POLICY_LEVEL_MANDATORY, | 160 previous_policy.Set(key::kHomepageLocation, POLICY_LEVEL_MANDATORY, |
160 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, | 161 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
161 base::MakeUnique<base::StringValue>(previous_value), | 162 base::MakeUnique<base::StringValue>(previous_value), |
162 nullptr); | 163 nullptr); |
163 } | 164 } |
164 EXPECT_TRUE(previous_policy.Equals(store_->policy_map())); | 165 EXPECT_TRUE(previous_policy.Equals(store_->policy_map())); |
165 EXPECT_EQ(CloudPolicyStore::STATUS_OK, store_->status()); | 166 EXPECT_EQ(CloudPolicyStore::STATUS_OK, store_->status()); |
166 | 167 |
167 // Store the new public key so that the validation after the retrieve | 168 // Store the new public key so that the validation after the retrieve |
168 // operation completes can verify the signature. | 169 // operation completes can verify the signature. |
169 if (new_public_key) | 170 if (new_public_key) |
170 StoreUserPolicyKey(*new_public_key); | 171 StoreUserPolicyKey(*new_public_key); |
171 | 172 |
172 // Let the store operation complete. | 173 // Let the store operation complete. |
173 chromeos::SessionManagerClient::RetrievePolicyCallback retrieve_callback; | 174 chromeos::SessionManagerClient::RetrievePolicyCallback retrieve_callback; |
174 EXPECT_CALL(session_manager_client_, | 175 EXPECT_CALL(session_manager_client_, |
175 RetrievePolicyForUser(cryptohome_id_, _)) | 176 RetrievePolicyForUser(cryptohome_id_, _)) |
176 .WillOnce(SaveArg<1>(&retrieve_callback)); | 177 .WillOnce(SaveArg<1>(&retrieve_callback)); |
177 store_callback.Run(true); | 178 store_callback.Run(true); |
178 RunUntilIdle(); | 179 base::RunLoop().RunUntilIdle(); |
179 EXPECT_TRUE(previous_policy.Equals(store_->policy_map())); | 180 EXPECT_TRUE(previous_policy.Equals(store_->policy_map())); |
180 EXPECT_EQ(CloudPolicyStore::STATUS_OK, store_->status()); | 181 EXPECT_EQ(CloudPolicyStore::STATUS_OK, store_->status()); |
181 Mock::VerifyAndClearExpectations(&session_manager_client_); | 182 Mock::VerifyAndClearExpectations(&session_manager_client_); |
182 ASSERT_FALSE(retrieve_callback.is_null()); | 183 ASSERT_FALSE(retrieve_callback.is_null()); |
183 | 184 |
184 // Finish the retrieve callback. | 185 // Finish the retrieve callback. |
185 EXPECT_CALL(observer_, OnStoreLoaded(store_.get())); | 186 EXPECT_CALL(observer_, OnStoreLoaded(store_.get())); |
186 retrieve_callback.Run(policy_.GetBlob()); | 187 retrieve_callback.Run(policy_.GetBlob()); |
187 RunUntilIdle(); | 188 base::RunLoop().RunUntilIdle(); |
188 ASSERT_TRUE(store_->policy()); | 189 ASSERT_TRUE(store_->policy()); |
189 EXPECT_EQ(policy_.policy_data().SerializeAsString(), | 190 EXPECT_EQ(policy_.policy_data().SerializeAsString(), |
190 store_->policy()->SerializeAsString()); | 191 store_->policy()->SerializeAsString()); |
191 VerifyPolicyMap(new_value); | 192 VerifyPolicyMap(new_value); |
192 EXPECT_EQ(CloudPolicyStore::STATUS_OK, store_->status()); | 193 EXPECT_EQ(CloudPolicyStore::STATUS_OK, store_->status()); |
193 } | 194 } |
194 | 195 |
195 void VerifyStoreHasValidationError() { | 196 void VerifyStoreHasValidationError() { |
196 EXPECT_FALSE(store_->policy()); | 197 EXPECT_FALSE(store_->policy()); |
197 EXPECT_TRUE(store_->policy_map().empty()); | 198 EXPECT_TRUE(store_->policy_map().empty()); |
198 EXPECT_EQ(CloudPolicyStore::STATUS_VALIDATION_ERROR, store_->status()); | 199 EXPECT_EQ(CloudPolicyStore::STATUS_VALIDATION_ERROR, store_->status()); |
199 } | 200 } |
200 | 201 |
201 void RunUntilIdle() { | |
202 loop_.RunUntilIdle(); | |
203 loop_.RunUntilIdle(); | |
204 } | |
205 | |
206 base::FilePath user_policy_dir() { | 202 base::FilePath user_policy_dir() { |
207 return tmp_dir_.GetPath().AppendASCII("var_run_user_policy"); | 203 return tmp_dir_.GetPath().AppendASCII("var_run_user_policy"); |
208 } | 204 } |
209 | 205 |
210 base::FilePath user_policy_key_file() { | 206 base::FilePath user_policy_key_file() { |
211 return user_policy_dir().AppendASCII(kSanitizedUsername) | 207 return user_policy_dir().AppendASCII(kSanitizedUsername) |
212 .AppendASCII("policy.pub"); | 208 .AppendASCII("policy.pub"); |
213 } | 209 } |
214 | 210 |
215 base::FilePath token_file() { | 211 base::FilePath token_file() { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 ASSERT_TRUE(base::DeleteFile(user_policy_key_file(), false)); | 250 ASSERT_TRUE(base::DeleteFile(user_policy_key_file(), false)); |
255 // Make the policy blob contain a new public key. | 251 // Make the policy blob contain a new public key. |
256 policy_.SetDefaultSigningKey(); | 252 policy_.SetDefaultSigningKey(); |
257 policy_.Build(); | 253 policy_.Build(); |
258 *policy_.policy().mutable_new_public_key_verification_signature() = "garbage"; | 254 *policy_.policy().mutable_new_public_key_verification_signature() = "garbage"; |
259 | 255 |
260 EXPECT_CALL(session_manager_client_, | 256 EXPECT_CALL(session_manager_client_, |
261 StorePolicyForUser(cryptohome_id_, policy_.GetBlob(), _)) | 257 StorePolicyForUser(cryptohome_id_, policy_.GetBlob(), _)) |
262 .Times(0); | 258 .Times(0); |
263 store_->Store(policy_.policy()); | 259 store_->Store(policy_.policy()); |
264 RunUntilIdle(); | 260 base::RunLoop().RunUntilIdle(); |
265 Mock::VerifyAndClearExpectations(&session_manager_client_); | 261 Mock::VerifyAndClearExpectations(&session_manager_client_); |
266 } | 262 } |
267 | 263 |
268 TEST_F(UserCloudPolicyStoreChromeOSTest, InitialStoreMissingSignatureFailure) { | 264 TEST_F(UserCloudPolicyStoreChromeOSTest, InitialStoreMissingSignatureFailure) { |
269 // Start without any public key to trigger the initial key checks. | 265 // Start without any public key to trigger the initial key checks. |
270 ASSERT_TRUE(base::DeleteFile(user_policy_key_file(), false)); | 266 ASSERT_TRUE(base::DeleteFile(user_policy_key_file(), false)); |
271 // Make the policy blob contain a new public key. | 267 // Make the policy blob contain a new public key. |
272 policy_.SetDefaultSigningKey(); | 268 policy_.SetDefaultSigningKey(); |
273 policy_.Build(); | 269 policy_.Build(); |
274 policy_.policy().clear_new_public_key_verification_signature(); | 270 policy_.policy().clear_new_public_key_verification_signature(); |
275 | 271 |
276 EXPECT_CALL(session_manager_client_, | 272 EXPECT_CALL(session_manager_client_, |
277 StorePolicyForUser(cryptohome_id_, policy_.GetBlob(), _)) | 273 StorePolicyForUser(cryptohome_id_, policy_.GetBlob(), _)) |
278 .Times(0); | 274 .Times(0); |
279 store_->Store(policy_.policy()); | 275 store_->Store(policy_.policy()); |
280 RunUntilIdle(); | 276 base::RunLoop().RunUntilIdle(); |
281 Mock::VerifyAndClearExpectations(&session_manager_client_); | 277 Mock::VerifyAndClearExpectations(&session_manager_client_); |
282 } | 278 } |
283 | 279 |
284 TEST_F(UserCloudPolicyStoreChromeOSTest, StoreWithExistingKey) { | 280 TEST_F(UserCloudPolicyStoreChromeOSTest, StoreWithExistingKey) { |
285 ASSERT_NO_FATAL_FAILURE( | 281 ASSERT_NO_FATAL_FAILURE( |
286 PerformStorePolicy(NULL, NULL, kDefaultHomepage)); | 282 PerformStorePolicy(NULL, NULL, kDefaultHomepage)); |
287 } | 283 } |
288 | 284 |
289 TEST_F(UserCloudPolicyStoreChromeOSTest, StoreWithRotation) { | 285 TEST_F(UserCloudPolicyStoreChromeOSTest, StoreWithRotation) { |
290 // Make the policy blob contain a new public key. | 286 // Make the policy blob contain a new public key. |
291 policy_.SetDefaultNewSigningKey(); | 287 policy_.SetDefaultNewSigningKey(); |
292 policy_.Build(); | 288 policy_.Build(); |
293 std::vector<uint8_t> new_public_key; | 289 std::vector<uint8_t> new_public_key; |
294 ASSERT_TRUE(policy_.GetNewSigningKey()->ExportPublicKey(&new_public_key)); | 290 ASSERT_TRUE(policy_.GetNewSigningKey()->ExportPublicKey(&new_public_key)); |
295 ASSERT_NO_FATAL_FAILURE( | 291 ASSERT_NO_FATAL_FAILURE( |
296 PerformStorePolicy(&new_public_key, NULL, kDefaultHomepage)); | 292 PerformStorePolicy(&new_public_key, NULL, kDefaultHomepage)); |
297 } | 293 } |
298 | 294 |
299 TEST_F(UserCloudPolicyStoreChromeOSTest, | 295 TEST_F(UserCloudPolicyStoreChromeOSTest, |
300 StoreWithRotationMissingSignatureError) { | 296 StoreWithRotationMissingSignatureError) { |
301 // Make the policy blob contain a new public key. | 297 // Make the policy blob contain a new public key. |
302 policy_.SetDefaultNewSigningKey(); | 298 policy_.SetDefaultNewSigningKey(); |
303 policy_.Build(); | 299 policy_.Build(); |
304 policy_.policy().clear_new_public_key_verification_signature(); | 300 policy_.policy().clear_new_public_key_verification_signature(); |
305 | 301 |
306 EXPECT_CALL(session_manager_client_, | 302 EXPECT_CALL(session_manager_client_, |
307 StorePolicyForUser(cryptohome_id_, policy_.GetBlob(), _)) | 303 StorePolicyForUser(cryptohome_id_, policy_.GetBlob(), _)) |
308 .Times(0); | 304 .Times(0); |
309 store_->Store(policy_.policy()); | 305 store_->Store(policy_.policy()); |
310 RunUntilIdle(); | 306 base::RunLoop().RunUntilIdle(); |
311 Mock::VerifyAndClearExpectations(&session_manager_client_); | 307 Mock::VerifyAndClearExpectations(&session_manager_client_); |
312 } | 308 } |
313 | 309 |
314 TEST_F(UserCloudPolicyStoreChromeOSTest, StoreWithRotationValidationError) { | 310 TEST_F(UserCloudPolicyStoreChromeOSTest, StoreWithRotationValidationError) { |
315 // Make the policy blob contain a new public key. | 311 // Make the policy blob contain a new public key. |
316 policy_.SetDefaultNewSigningKey(); | 312 policy_.SetDefaultNewSigningKey(); |
317 policy_.Build(); | 313 policy_.Build(); |
318 *policy_.policy().mutable_new_public_key_verification_signature() = "garbage"; | 314 *policy_.policy().mutable_new_public_key_verification_signature() = "garbage"; |
319 | 315 |
320 EXPECT_CALL(session_manager_client_, | 316 EXPECT_CALL(session_manager_client_, |
321 StorePolicyForUser(cryptohome_id_, policy_.GetBlob(), _)) | 317 StorePolicyForUser(cryptohome_id_, policy_.GetBlob(), _)) |
322 .Times(0); | 318 .Times(0); |
323 store_->Store(policy_.policy()); | 319 store_->Store(policy_.policy()); |
324 RunUntilIdle(); | 320 base::RunLoop().RunUntilIdle(); |
325 Mock::VerifyAndClearExpectations(&session_manager_client_); | 321 Mock::VerifyAndClearExpectations(&session_manager_client_); |
326 } | 322 } |
327 | 323 |
328 TEST_F(UserCloudPolicyStoreChromeOSTest, StoreFail) { | 324 TEST_F(UserCloudPolicyStoreChromeOSTest, StoreFail) { |
329 // Store policy. | 325 // Store policy. |
330 chromeos::SessionManagerClient::StorePolicyCallback store_callback; | 326 chromeos::SessionManagerClient::StorePolicyCallback store_callback; |
331 EXPECT_CALL(session_manager_client_, | 327 EXPECT_CALL(session_manager_client_, |
332 StorePolicyForUser(cryptohome_id_, policy_.GetBlob(), _)) | 328 StorePolicyForUser(cryptohome_id_, policy_.GetBlob(), _)) |
333 .WillOnce(SaveArg<2>(&store_callback)); | 329 .WillOnce(SaveArg<2>(&store_callback)); |
334 store_->Store(policy_.policy()); | 330 store_->Store(policy_.policy()); |
335 RunUntilIdle(); | 331 base::RunLoop().RunUntilIdle(); |
336 Mock::VerifyAndClearExpectations(&session_manager_client_); | 332 Mock::VerifyAndClearExpectations(&session_manager_client_); |
337 ASSERT_FALSE(store_callback.is_null()); | 333 ASSERT_FALSE(store_callback.is_null()); |
338 | 334 |
339 // Let the store operation complete. | 335 // Let the store operation complete. |
340 ExpectError(CloudPolicyStore::STATUS_STORE_ERROR); | 336 ExpectError(CloudPolicyStore::STATUS_STORE_ERROR); |
341 store_callback.Run(false); | 337 store_callback.Run(false); |
342 RunUntilIdle(); | 338 base::RunLoop().RunUntilIdle(); |
343 EXPECT_FALSE(store_->policy()); | 339 EXPECT_FALSE(store_->policy()); |
344 EXPECT_TRUE(store_->policy_map().empty()); | 340 EXPECT_TRUE(store_->policy_map().empty()); |
345 EXPECT_EQ(CloudPolicyStore::STATUS_STORE_ERROR, store_->status()); | 341 EXPECT_EQ(CloudPolicyStore::STATUS_STORE_ERROR, store_->status()); |
346 } | 342 } |
347 | 343 |
348 TEST_F(UserCloudPolicyStoreChromeOSTest, StoreValidationError) { | 344 TEST_F(UserCloudPolicyStoreChromeOSTest, StoreValidationError) { |
349 policy_.policy_data().clear_policy_type(); | 345 policy_.policy_data().clear_policy_type(); |
350 policy_.Build(); | 346 policy_.Build(); |
351 | 347 |
352 // Store policy. | 348 // Store policy. |
353 chromeos::SessionManagerClient::StorePolicyCallback store_callback; | 349 chromeos::SessionManagerClient::StorePolicyCallback store_callback; |
354 ExpectError(CloudPolicyStore::STATUS_VALIDATION_ERROR); | 350 ExpectError(CloudPolicyStore::STATUS_VALIDATION_ERROR); |
355 EXPECT_CALL(session_manager_client_, | 351 EXPECT_CALL(session_manager_client_, |
356 StorePolicyForUser(cryptohome_id_, policy_.GetBlob(), _)) | 352 StorePolicyForUser(cryptohome_id_, policy_.GetBlob(), _)) |
357 .Times(0); | 353 .Times(0); |
358 store_->Store(policy_.policy()); | 354 store_->Store(policy_.policy()); |
359 RunUntilIdle(); | 355 base::RunLoop().RunUntilIdle(); |
360 Mock::VerifyAndClearExpectations(&session_manager_client_); | 356 Mock::VerifyAndClearExpectations(&session_manager_client_); |
361 } | 357 } |
362 | 358 |
363 TEST_F(UserCloudPolicyStoreChromeOSTest, StoreWithoutPolicyKey) { | 359 TEST_F(UserCloudPolicyStoreChromeOSTest, StoreWithoutPolicyKey) { |
364 // Make the dbus call to cryptohome fail. | 360 // Make the dbus call to cryptohome fail. |
365 Mock::VerifyAndClearExpectations(&cryptohome_client_); | 361 Mock::VerifyAndClearExpectations(&cryptohome_client_); |
366 EXPECT_CALL(cryptohome_client_, GetSanitizedUsername(cryptohome_id_, _)) | 362 EXPECT_CALL(cryptohome_client_, GetSanitizedUsername(cryptohome_id_, _)) |
367 .Times(AnyNumber()) | 363 .Times(AnyNumber()) |
368 .WillRepeatedly(SendSanitizedUsername(chromeos::DBUS_METHOD_CALL_FAILURE, | 364 .WillRepeatedly(SendSanitizedUsername(chromeos::DBUS_METHOD_CALL_FAILURE, |
369 std::string())); | 365 std::string())); |
370 | 366 |
371 // Store policy. | 367 // Store policy. |
372 chromeos::SessionManagerClient::StorePolicyCallback store_callback; | 368 chromeos::SessionManagerClient::StorePolicyCallback store_callback; |
373 ExpectError(CloudPolicyStore::STATUS_VALIDATION_ERROR); | 369 ExpectError(CloudPolicyStore::STATUS_VALIDATION_ERROR); |
374 EXPECT_CALL(session_manager_client_, | 370 EXPECT_CALL(session_manager_client_, |
375 StorePolicyForUser(cryptohome_id_, policy_.GetBlob(), _)) | 371 StorePolicyForUser(cryptohome_id_, policy_.GetBlob(), _)) |
376 .Times(0); | 372 .Times(0); |
377 store_->Store(policy_.policy()); | 373 store_->Store(policy_.policy()); |
378 RunUntilIdle(); | 374 base::RunLoop().RunUntilIdle(); |
379 Mock::VerifyAndClearExpectations(&session_manager_client_); | 375 Mock::VerifyAndClearExpectations(&session_manager_client_); |
380 } | 376 } |
381 | 377 |
382 TEST_F(UserCloudPolicyStoreChromeOSTest, StoreWithInvalidSignature) { | 378 TEST_F(UserCloudPolicyStoreChromeOSTest, StoreWithInvalidSignature) { |
383 // Break the signature. | 379 // Break the signature. |
384 policy_.policy().mutable_policy_data_signature()->append("garbage"); | 380 policy_.policy().mutable_policy_data_signature()->append("garbage"); |
385 | 381 |
386 // Store policy. | 382 // Store policy. |
387 chromeos::SessionManagerClient::StorePolicyCallback store_callback; | 383 chromeos::SessionManagerClient::StorePolicyCallback store_callback; |
388 ExpectError(CloudPolicyStore::STATUS_VALIDATION_ERROR); | 384 ExpectError(CloudPolicyStore::STATUS_VALIDATION_ERROR); |
389 EXPECT_CALL(session_manager_client_, | 385 EXPECT_CALL(session_manager_client_, |
390 StorePolicyForUser(cryptohome_id_, policy_.GetBlob(), _)) | 386 StorePolicyForUser(cryptohome_id_, policy_.GetBlob(), _)) |
391 .Times(0); | 387 .Times(0); |
392 store_->Store(policy_.policy()); | 388 store_->Store(policy_.policy()); |
393 RunUntilIdle(); | 389 base::RunLoop().RunUntilIdle(); |
394 Mock::VerifyAndClearExpectations(&session_manager_client_); | 390 Mock::VerifyAndClearExpectations(&session_manager_client_); |
395 } | 391 } |
396 | 392 |
397 TEST_F(UserCloudPolicyStoreChromeOSTest, Load) { | 393 TEST_F(UserCloudPolicyStoreChromeOSTest, Load) { |
398 EXPECT_CALL(observer_, OnStoreLoaded(store_.get())); | 394 EXPECT_CALL(observer_, OnStoreLoaded(store_.get())); |
399 ASSERT_NO_FATAL_FAILURE(PerformPolicyLoad(policy_.GetBlob())); | 395 ASSERT_NO_FATAL_FAILURE(PerformPolicyLoad(policy_.GetBlob())); |
400 Mock::VerifyAndClearExpectations(&observer_); | 396 Mock::VerifyAndClearExpectations(&observer_); |
401 | 397 |
402 // Verify that the policy has been loaded. | 398 // Verify that the policy has been loaded. |
403 ASSERT_TRUE(store_->policy()); | 399 ASSERT_TRUE(store_->policy()); |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 Mock::VerifyAndClearExpectations(&cryptohome_client_); | 662 Mock::VerifyAndClearExpectations(&cryptohome_client_); |
667 | 663 |
668 EXPECT_FALSE(store_->policy()); | 664 EXPECT_FALSE(store_->policy()); |
669 EXPECT_TRUE(store_->policy_map().empty()); | 665 EXPECT_TRUE(store_->policy_map().empty()); |
670 EXPECT_EQ(CloudPolicyStore::STATUS_VALIDATION_ERROR, store_->status()); | 666 EXPECT_EQ(CloudPolicyStore::STATUS_VALIDATION_ERROR, store_->status()); |
671 } | 667 } |
672 | 668 |
673 } // namespace | 669 } // namespace |
674 | 670 |
675 } // namespace policy | 671 } // namespace policy |
OLD | NEW |