Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(708)

Side by Side Diff: chrome/browser/chromeos/policy/user_cloud_policy_store_chromeos_unittest.cc

Issue 14761012: Updated SessionManagerClient to use the multi-profile user policy calls. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: added TODO Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <vector> 7 #include <vector>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 OnStoreError(AllOf(Eq(store_.get()), 95 OnStoreError(AllOf(Eq(store_.get()),
96 Property(&CloudPolicyStore::status, 96 Property(&CloudPolicyStore::status,
97 Eq(error))))); 97 Eq(error)))));
98 } 98 }
99 99
100 // Triggers a store_->Load() operation, handles the expected call to 100 // Triggers a store_->Load() operation, handles the expected call to
101 // |session_manager_client_| and sends |response|. 101 // |session_manager_client_| and sends |response|.
102 void PerformPolicyLoad(const std::string& response) { 102 void PerformPolicyLoad(const std::string& response) {
103 // Issue a load command. 103 // Issue a load command.
104 chromeos::SessionManagerClient::RetrievePolicyCallback retrieve_callback; 104 chromeos::SessionManagerClient::RetrievePolicyCallback retrieve_callback;
105 EXPECT_CALL(session_manager_client_, RetrieveUserPolicy(_)) 105 EXPECT_CALL(session_manager_client_,
106 .WillOnce(SaveArg<0>(&retrieve_callback)); 106 RetrievePolicyForUser(PolicyBuilder::kFakeUsername, _))
107 .WillOnce(SaveArg<1>(&retrieve_callback));
107 store_->Load(); 108 store_->Load();
108 RunUntilIdle(); 109 RunUntilIdle();
109 Mock::VerifyAndClearExpectations(&session_manager_client_); 110 Mock::VerifyAndClearExpectations(&session_manager_client_);
110 ASSERT_FALSE(retrieve_callback.is_null()); 111 ASSERT_FALSE(retrieve_callback.is_null());
111 112
112 // Run the callback. 113 // Run the callback.
113 retrieve_callback.Run(response); 114 retrieve_callback.Run(response);
114 RunUntilIdle(); 115 RunUntilIdle();
115 } 116 }
116 117
(...skipping 19 matching lines...) Expand all
136 // If |new_public_key| is set then it will be persisted after storing but 137 // If |new_public_key| is set then it will be persisted after storing but
137 // before loading the policy, so that the signature validation can succeed. 138 // before loading the policy, so that the signature validation can succeed.
138 // If |previous_value| is set then a previously existing policy with that 139 // If |previous_value| is set then a previously existing policy with that
139 // value will be expected; otherwise no previous policy is expected. 140 // value will be expected; otherwise no previous policy is expected.
140 // If |new_value| is set then a new policy with that value is expected after 141 // If |new_value| is set then a new policy with that value is expected after
141 // storing the |policy_| blob. 142 // storing the |policy_| blob.
142 void PerformStorePolicy(const std::vector<uint8>* new_public_key, 143 void PerformStorePolicy(const std::vector<uint8>* new_public_key,
143 const char* previous_value, 144 const char* previous_value,
144 const char* new_value) { 145 const char* new_value) {
145 chromeos::SessionManagerClient::StorePolicyCallback store_callback; 146 chromeos::SessionManagerClient::StorePolicyCallback store_callback;
146 EXPECT_CALL(session_manager_client_, StoreUserPolicy(policy_.GetBlob(), _)) 147 EXPECT_CALL(session_manager_client_,
147 .WillOnce(SaveArg<1>(&store_callback)); 148 StorePolicyForUser(PolicyBuilder::kFakeUsername,
149 policy_.GetBlob(), _, _))
150 .WillOnce(SaveArg<3>(&store_callback));
148 store_->Store(policy_.policy()); 151 store_->Store(policy_.policy());
149 RunUntilIdle(); 152 RunUntilIdle();
150 Mock::VerifyAndClearExpectations(&session_manager_client_); 153 Mock::VerifyAndClearExpectations(&session_manager_client_);
151 ASSERT_FALSE(store_callback.is_null()); 154 ASSERT_FALSE(store_callback.is_null());
152 155
153 // The new policy shouldn't be present yet. 156 // The new policy shouldn't be present yet.
154 PolicyMap previous_policy; 157 PolicyMap previous_policy;
155 EXPECT_EQ(previous_value != NULL, store_->policy() != NULL); 158 EXPECT_EQ(previous_value != NULL, store_->policy() != NULL);
156 if (previous_value) { 159 if (previous_value) {
157 previous_policy.Set(key::kHomepageLocation, 160 previous_policy.Set(key::kHomepageLocation,
158 POLICY_LEVEL_MANDATORY, 161 POLICY_LEVEL_MANDATORY,
159 POLICY_SCOPE_USER, 162 POLICY_SCOPE_USER,
160 base::Value::CreateStringValue(previous_value)); 163 base::Value::CreateStringValue(previous_value));
161 } 164 }
162 EXPECT_TRUE(previous_policy.Equals(store_->policy_map())); 165 EXPECT_TRUE(previous_policy.Equals(store_->policy_map()));
163 EXPECT_EQ(CloudPolicyStore::STATUS_OK, store_->status()); 166 EXPECT_EQ(CloudPolicyStore::STATUS_OK, store_->status());
164 167
165 // 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
166 // operation completes can verify the signature. 169 // operation completes can verify the signature.
167 if (new_public_key) 170 if (new_public_key)
168 StoreUserPolicyKey(*new_public_key); 171 StoreUserPolicyKey(*new_public_key);
169 172
170 // Let the store operation complete. 173 // Let the store operation complete.
171 chromeos::SessionManagerClient::RetrievePolicyCallback retrieve_callback; 174 chromeos::SessionManagerClient::RetrievePolicyCallback retrieve_callback;
172 EXPECT_CALL(session_manager_client_, RetrieveUserPolicy(_)) 175 EXPECT_CALL(session_manager_client_,
173 .WillOnce(SaveArg<0>(&retrieve_callback)); 176 RetrievePolicyForUser(PolicyBuilder::kFakeUsername, _))
177 .WillOnce(SaveArg<1>(&retrieve_callback));
174 store_callback.Run(true); 178 store_callback.Run(true);
175 RunUntilIdle(); 179 RunUntilIdle();
176 EXPECT_TRUE(previous_policy.Equals(store_->policy_map())); 180 EXPECT_TRUE(previous_policy.Equals(store_->policy_map()));
177 EXPECT_EQ(CloudPolicyStore::STATUS_OK, store_->status()); 181 EXPECT_EQ(CloudPolicyStore::STATUS_OK, store_->status());
178 Mock::VerifyAndClearExpectations(&session_manager_client_); 182 Mock::VerifyAndClearExpectations(&session_manager_client_);
179 ASSERT_FALSE(retrieve_callback.is_null()); 183 ASSERT_FALSE(retrieve_callback.is_null());
180 184
181 // Finish the retrieve callback. 185 // Finish the retrieve callback.
182 EXPECT_CALL(observer_, OnStoreLoaded(store_.get())); 186 EXPECT_CALL(observer_, OnStoreLoaded(store_.get()));
183 retrieve_callback.Run(policy_.GetBlob()); 187 retrieve_callback.Run(policy_.GetBlob());
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 policy_.Build(); 260 policy_.Build();
257 std::vector<uint8> new_public_key; 261 std::vector<uint8> new_public_key;
258 ASSERT_TRUE(policy_.new_signing_key()->ExportPublicKey(&new_public_key)); 262 ASSERT_TRUE(policy_.new_signing_key()->ExportPublicKey(&new_public_key));
259 ASSERT_NO_FATAL_FAILURE( 263 ASSERT_NO_FATAL_FAILURE(
260 PerformStorePolicy(&new_public_key, NULL, kDefaultHomepage)); 264 PerformStorePolicy(&new_public_key, NULL, kDefaultHomepage));
261 } 265 }
262 266
263 TEST_F(UserCloudPolicyStoreChromeOSTest, StoreFail) { 267 TEST_F(UserCloudPolicyStoreChromeOSTest, StoreFail) {
264 // Store policy. 268 // Store policy.
265 chromeos::SessionManagerClient::StorePolicyCallback store_callback; 269 chromeos::SessionManagerClient::StorePolicyCallback store_callback;
266 EXPECT_CALL(session_manager_client_, StoreUserPolicy(policy_.GetBlob(), _)) 270 EXPECT_CALL(session_manager_client_,
267 .WillOnce(SaveArg<1>(&store_callback)); 271 StorePolicyForUser(PolicyBuilder::kFakeUsername,
272 policy_.GetBlob(), _, _))
273 .WillOnce(SaveArg<3>(&store_callback));
268 store_->Store(policy_.policy()); 274 store_->Store(policy_.policy());
269 RunUntilIdle(); 275 RunUntilIdle();
270 Mock::VerifyAndClearExpectations(&session_manager_client_); 276 Mock::VerifyAndClearExpectations(&session_manager_client_);
271 ASSERT_FALSE(store_callback.is_null()); 277 ASSERT_FALSE(store_callback.is_null());
272 278
273 // Let the store operation complete. 279 // Let the store operation complete.
274 ExpectError(CloudPolicyStore::STATUS_STORE_ERROR); 280 ExpectError(CloudPolicyStore::STATUS_STORE_ERROR);
275 store_callback.Run(false); 281 store_callback.Run(false);
276 RunUntilIdle(); 282 RunUntilIdle();
277 EXPECT_FALSE(store_->policy()); 283 EXPECT_FALSE(store_->policy());
278 EXPECT_TRUE(store_->policy_map().empty()); 284 EXPECT_TRUE(store_->policy_map().empty());
279 EXPECT_EQ(CloudPolicyStore::STATUS_STORE_ERROR, store_->status()); 285 EXPECT_EQ(CloudPolicyStore::STATUS_STORE_ERROR, store_->status());
280 } 286 }
281 287
282 TEST_F(UserCloudPolicyStoreChromeOSTest, StoreValidationError) { 288 TEST_F(UserCloudPolicyStoreChromeOSTest, StoreValidationError) {
283 policy_.policy_data().clear_policy_type(); 289 policy_.policy_data().clear_policy_type();
284 policy_.Build(); 290 policy_.Build();
285 291
286 // Store policy. 292 // Store policy.
287 chromeos::SessionManagerClient::StorePolicyCallback store_callback; 293 chromeos::SessionManagerClient::StorePolicyCallback store_callback;
288 ExpectError(CloudPolicyStore::STATUS_VALIDATION_ERROR); 294 ExpectError(CloudPolicyStore::STATUS_VALIDATION_ERROR);
289 EXPECT_CALL(session_manager_client_, StoreUserPolicy(policy_.GetBlob(), _)) 295 EXPECT_CALL(session_manager_client_,
296 StorePolicyForUser(PolicyBuilder::kFakeUsername,
297 policy_.GetBlob(), _, _))
290 .Times(0); 298 .Times(0);
291 store_->Store(policy_.policy()); 299 store_->Store(policy_.policy());
292 RunUntilIdle(); 300 RunUntilIdle();
293 Mock::VerifyAndClearExpectations(&session_manager_client_); 301 Mock::VerifyAndClearExpectations(&session_manager_client_);
294 } 302 }
295 303
296 TEST_F(UserCloudPolicyStoreChromeOSTest, StoreWithoutPolicyKey) { 304 TEST_F(UserCloudPolicyStoreChromeOSTest, StoreWithoutPolicyKey) {
297 // Make the dbus call to cryptohome fail. 305 // Make the dbus call to cryptohome fail.
298 Mock::VerifyAndClearExpectations(&cryptohome_client_); 306 Mock::VerifyAndClearExpectations(&cryptohome_client_);
299 EXPECT_CALL(cryptohome_client_, 307 EXPECT_CALL(cryptohome_client_,
300 GetSanitizedUsername(PolicyBuilder::kFakeUsername, _)) 308 GetSanitizedUsername(PolicyBuilder::kFakeUsername, _))
301 .Times(AnyNumber()) 309 .Times(AnyNumber())
302 .WillRepeatedly(SendSanitizedUsername(chromeos::DBUS_METHOD_CALL_FAILURE, 310 .WillRepeatedly(SendSanitizedUsername(chromeos::DBUS_METHOD_CALL_FAILURE,
303 std::string())); 311 std::string()));
304 312
305 // Store policy. 313 // Store policy.
306 chromeos::SessionManagerClient::StorePolicyCallback store_callback; 314 chromeos::SessionManagerClient::StorePolicyCallback store_callback;
307 ExpectError(CloudPolicyStore::STATUS_VALIDATION_ERROR); 315 ExpectError(CloudPolicyStore::STATUS_VALIDATION_ERROR);
308 EXPECT_CALL(session_manager_client_, StoreUserPolicy(policy_.GetBlob(), _)) 316 EXPECT_CALL(session_manager_client_,
317 StorePolicyForUser(PolicyBuilder::kFakeUsername,
318 policy_.GetBlob(), _, _))
309 .Times(0); 319 .Times(0);
310 store_->Store(policy_.policy()); 320 store_->Store(policy_.policy());
311 RunUntilIdle(); 321 RunUntilIdle();
312 Mock::VerifyAndClearExpectations(&session_manager_client_); 322 Mock::VerifyAndClearExpectations(&session_manager_client_);
313 } 323 }
314 324
315 TEST_F(UserCloudPolicyStoreChromeOSTest, StoreWithInvalidSignature) { 325 TEST_F(UserCloudPolicyStoreChromeOSTest, StoreWithInvalidSignature) {
316 // Break the signature. 326 // Break the signature.
317 policy_.policy().mutable_policy_data_signature()->append("garbage"); 327 policy_.policy().mutable_policy_data_signature()->append("garbage");
318 328
319 // Store policy. 329 // Store policy.
320 chromeos::SessionManagerClient::StorePolicyCallback store_callback; 330 chromeos::SessionManagerClient::StorePolicyCallback store_callback;
321 ExpectError(CloudPolicyStore::STATUS_VALIDATION_ERROR); 331 ExpectError(CloudPolicyStore::STATUS_VALIDATION_ERROR);
322 EXPECT_CALL(session_manager_client_, StoreUserPolicy(policy_.GetBlob(), _)) 332 EXPECT_CALL(session_manager_client_,
333 StorePolicyForUser(PolicyBuilder::kFakeUsername,
334 policy_.GetBlob(), _, _))
323 .Times(0); 335 .Times(0);
324 store_->Store(policy_.policy()); 336 store_->Store(policy_.policy());
325 RunUntilIdle(); 337 RunUntilIdle();
326 Mock::VerifyAndClearExpectations(&session_manager_client_); 338 Mock::VerifyAndClearExpectations(&session_manager_client_);
327 } 339 }
328 340
329 TEST_F(UserCloudPolicyStoreChromeOSTest, Load) { 341 TEST_F(UserCloudPolicyStoreChromeOSTest, Load) {
330 EXPECT_CALL(observer_, OnStoreLoaded(store_.get())); 342 EXPECT_CALL(observer_, OnStoreLoaded(store_.get()));
331 ASSERT_NO_FATAL_FAILURE(PerformPolicyLoad(policy_.GetBlob())); 343 ASSERT_NO_FATAL_FAILURE(PerformPolicyLoad(policy_.GetBlob()));
332 Mock::VerifyAndClearExpectations(&observer_); 344 Mock::VerifyAndClearExpectations(&observer_);
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 PerformStorePolicy(&new_public_key, kDefaultHomepage, kNewHomepage)); 515 PerformStorePolicy(&new_public_key, kDefaultHomepage, kNewHomepage));
504 VerifyPolicyMap(kNewHomepage); 516 VerifyPolicyMap(kNewHomepage);
505 517
506 // Verify that the legacy cache has been removed. 518 // Verify that the legacy cache has been removed.
507 EXPECT_FALSE(file_util::PathExists(policy_file())); 519 EXPECT_FALSE(file_util::PathExists(policy_file()));
508 } 520 }
509 521
510 } // namespace 522 } // namespace
511 523
512 } // namespace policy 524 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698