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

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

Issue 265013002: Revert of Enable Enterprise enrollment on desktop builds. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 // If |previous_value| is set then a previously existing policy with that 138 // If |previous_value| is set then a previously existing policy with that
139 // value will be expected; otherwise no previous policy is expected. 139 // 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 140 // If |new_value| is set then a new policy with that value is expected after
141 // storing the |policy_| blob. 141 // storing the |policy_| blob.
142 void PerformStorePolicy(const std::vector<uint8>* new_public_key, 142 void PerformStorePolicy(const std::vector<uint8>* new_public_key,
143 const char* previous_value, 143 const char* previous_value,
144 const char* new_value) { 144 const char* new_value) {
145 chromeos::SessionManagerClient::StorePolicyCallback store_callback; 145 chromeos::SessionManagerClient::StorePolicyCallback store_callback;
146 EXPECT_CALL(session_manager_client_, 146 EXPECT_CALL(session_manager_client_,
147 StorePolicyForUser(PolicyBuilder::kFakeUsername, 147 StorePolicyForUser(PolicyBuilder::kFakeUsername,
148 policy_.GetBlob(), _)) 148 policy_.GetBlob(), _, _))
149 .WillOnce(SaveArg<2>(&store_callback)); 149 .WillOnce(SaveArg<3>(&store_callback));
150 store_->Store(policy_.policy()); 150 store_->Store(policy_.policy());
151 RunUntilIdle(); 151 RunUntilIdle();
152 Mock::VerifyAndClearExpectations(&session_manager_client_); 152 Mock::VerifyAndClearExpectations(&session_manager_client_);
153 ASSERT_FALSE(store_callback.is_null()); 153 ASSERT_FALSE(store_callback.is_null());
154 154
155 // The new policy shouldn't be present yet. 155 // The new policy shouldn't be present yet.
156 PolicyMap previous_policy; 156 PolicyMap previous_policy;
157 EXPECT_EQ(previous_value != NULL, store_->policy() != NULL); 157 EXPECT_EQ(previous_value != NULL, store_->policy() != NULL);
158 if (previous_value) { 158 if (previous_value) {
159 previous_policy.Set(key::kHomepageLocation, 159 previous_policy.Set(key::kHomepageLocation,
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 ASSERT_TRUE(policy_.GetNewSigningKey()->ExportPublicKey(&new_public_key)); 258 ASSERT_TRUE(policy_.GetNewSigningKey()->ExportPublicKey(&new_public_key));
259 ASSERT_NO_FATAL_FAILURE( 259 ASSERT_NO_FATAL_FAILURE(
260 PerformStorePolicy(&new_public_key, NULL, kDefaultHomepage)); 260 PerformStorePolicy(&new_public_key, NULL, kDefaultHomepage));
261 } 261 }
262 262
263 TEST_F(UserCloudPolicyStoreChromeOSTest, StoreFail) { 263 TEST_F(UserCloudPolicyStoreChromeOSTest, StoreFail) {
264 // Store policy. 264 // Store policy.
265 chromeos::SessionManagerClient::StorePolicyCallback store_callback; 265 chromeos::SessionManagerClient::StorePolicyCallback store_callback;
266 EXPECT_CALL(session_manager_client_, 266 EXPECT_CALL(session_manager_client_,
267 StorePolicyForUser(PolicyBuilder::kFakeUsername, 267 StorePolicyForUser(PolicyBuilder::kFakeUsername,
268 policy_.GetBlob(), _)) 268 policy_.GetBlob(), _, _))
269 .WillOnce(SaveArg<2>(&store_callback)); 269 .WillOnce(SaveArg<3>(&store_callback));
270 store_->Store(policy_.policy()); 270 store_->Store(policy_.policy());
271 RunUntilIdle(); 271 RunUntilIdle();
272 Mock::VerifyAndClearExpectations(&session_manager_client_); 272 Mock::VerifyAndClearExpectations(&session_manager_client_);
273 ASSERT_FALSE(store_callback.is_null()); 273 ASSERT_FALSE(store_callback.is_null());
274 274
275 // Let the store operation complete. 275 // Let the store operation complete.
276 ExpectError(CloudPolicyStore::STATUS_STORE_ERROR); 276 ExpectError(CloudPolicyStore::STATUS_STORE_ERROR);
277 store_callback.Run(false); 277 store_callback.Run(false);
278 RunUntilIdle(); 278 RunUntilIdle();
279 EXPECT_FALSE(store_->policy()); 279 EXPECT_FALSE(store_->policy());
280 EXPECT_TRUE(store_->policy_map().empty()); 280 EXPECT_TRUE(store_->policy_map().empty());
281 EXPECT_EQ(CloudPolicyStore::STATUS_STORE_ERROR, store_->status()); 281 EXPECT_EQ(CloudPolicyStore::STATUS_STORE_ERROR, store_->status());
282 } 282 }
283 283
284 TEST_F(UserCloudPolicyStoreChromeOSTest, StoreValidationError) { 284 TEST_F(UserCloudPolicyStoreChromeOSTest, StoreValidationError) {
285 policy_.policy_data().clear_policy_type(); 285 policy_.policy_data().clear_policy_type();
286 policy_.Build(); 286 policy_.Build();
287 287
288 // Store policy. 288 // Store policy.
289 chromeos::SessionManagerClient::StorePolicyCallback store_callback; 289 chromeos::SessionManagerClient::StorePolicyCallback store_callback;
290 ExpectError(CloudPolicyStore::STATUS_VALIDATION_ERROR); 290 ExpectError(CloudPolicyStore::STATUS_VALIDATION_ERROR);
291 EXPECT_CALL(session_manager_client_, 291 EXPECT_CALL(session_manager_client_,
292 StorePolicyForUser(PolicyBuilder::kFakeUsername, 292 StorePolicyForUser(PolicyBuilder::kFakeUsername,
293 policy_.GetBlob(), _)) 293 policy_.GetBlob(), _, _))
294 .Times(0); 294 .Times(0);
295 store_->Store(policy_.policy()); 295 store_->Store(policy_.policy());
296 RunUntilIdle(); 296 RunUntilIdle();
297 Mock::VerifyAndClearExpectations(&session_manager_client_); 297 Mock::VerifyAndClearExpectations(&session_manager_client_);
298 } 298 }
299 299
300 TEST_F(UserCloudPolicyStoreChromeOSTest, StoreWithoutPolicyKey) { 300 TEST_F(UserCloudPolicyStoreChromeOSTest, StoreWithoutPolicyKey) {
301 // Make the dbus call to cryptohome fail. 301 // Make the dbus call to cryptohome fail.
302 Mock::VerifyAndClearExpectations(&cryptohome_client_); 302 Mock::VerifyAndClearExpectations(&cryptohome_client_);
303 EXPECT_CALL(cryptohome_client_, 303 EXPECT_CALL(cryptohome_client_,
304 GetSanitizedUsername(PolicyBuilder::kFakeUsername, _)) 304 GetSanitizedUsername(PolicyBuilder::kFakeUsername, _))
305 .Times(AnyNumber()) 305 .Times(AnyNumber())
306 .WillRepeatedly(SendSanitizedUsername(chromeos::DBUS_METHOD_CALL_FAILURE, 306 .WillRepeatedly(SendSanitizedUsername(chromeos::DBUS_METHOD_CALL_FAILURE,
307 std::string())); 307 std::string()));
308 308
309 // Store policy. 309 // Store policy.
310 chromeos::SessionManagerClient::StorePolicyCallback store_callback; 310 chromeos::SessionManagerClient::StorePolicyCallback store_callback;
311 ExpectError(CloudPolicyStore::STATUS_VALIDATION_ERROR); 311 ExpectError(CloudPolicyStore::STATUS_VALIDATION_ERROR);
312 EXPECT_CALL(session_manager_client_, 312 EXPECT_CALL(session_manager_client_,
313 StorePolicyForUser(PolicyBuilder::kFakeUsername, 313 StorePolicyForUser(PolicyBuilder::kFakeUsername,
314 policy_.GetBlob(), _)) 314 policy_.GetBlob(), _, _))
315 .Times(0); 315 .Times(0);
316 store_->Store(policy_.policy()); 316 store_->Store(policy_.policy());
317 RunUntilIdle(); 317 RunUntilIdle();
318 Mock::VerifyAndClearExpectations(&session_manager_client_); 318 Mock::VerifyAndClearExpectations(&session_manager_client_);
319 } 319 }
320 320
321 TEST_F(UserCloudPolicyStoreChromeOSTest, StoreWithInvalidSignature) { 321 TEST_F(UserCloudPolicyStoreChromeOSTest, StoreWithInvalidSignature) {
322 // Break the signature. 322 // Break the signature.
323 policy_.policy().mutable_policy_data_signature()->append("garbage"); 323 policy_.policy().mutable_policy_data_signature()->append("garbage");
324 324
325 // Store policy. 325 // Store policy.
326 chromeos::SessionManagerClient::StorePolicyCallback store_callback; 326 chromeos::SessionManagerClient::StorePolicyCallback store_callback;
327 ExpectError(CloudPolicyStore::STATUS_VALIDATION_ERROR); 327 ExpectError(CloudPolicyStore::STATUS_VALIDATION_ERROR);
328 EXPECT_CALL(session_manager_client_, 328 EXPECT_CALL(session_manager_client_,
329 StorePolicyForUser(PolicyBuilder::kFakeUsername, 329 StorePolicyForUser(PolicyBuilder::kFakeUsername,
330 policy_.GetBlob(), _)) 330 policy_.GetBlob(), _, _))
331 .Times(0); 331 .Times(0);
332 store_->Store(policy_.policy()); 332 store_->Store(policy_.policy());
333 RunUntilIdle(); 333 RunUntilIdle();
334 Mock::VerifyAndClearExpectations(&session_manager_client_); 334 Mock::VerifyAndClearExpectations(&session_manager_client_);
335 } 335 }
336 336
337 TEST_F(UserCloudPolicyStoreChromeOSTest, Load) { 337 TEST_F(UserCloudPolicyStoreChromeOSTest, Load) {
338 EXPECT_CALL(observer_, OnStoreLoaded(store_.get())); 338 EXPECT_CALL(observer_, OnStoreLoaded(store_.get()));
339 ASSERT_NO_FATAL_FAILURE(PerformPolicyLoad(policy_.GetBlob())); 339 ASSERT_NO_FATAL_FAILURE(PerformPolicyLoad(policy_.GetBlob()));
340 Mock::VerifyAndClearExpectations(&observer_); 340 Mock::VerifyAndClearExpectations(&observer_);
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 Mock::VerifyAndClearExpectations(&cryptohome_client_); 609 Mock::VerifyAndClearExpectations(&cryptohome_client_);
610 610
611 EXPECT_FALSE(store_->policy()); 611 EXPECT_FALSE(store_->policy());
612 EXPECT_TRUE(store_->policy_map().empty()); 612 EXPECT_TRUE(store_->policy_map().empty());
613 EXPECT_EQ(CloudPolicyStore::STATUS_VALIDATION_ERROR, store_->status()); 613 EXPECT_EQ(CloudPolicyStore::STATUS_VALIDATION_ERROR, store_->status());
614 } 614 }
615 615
616 } // namespace 616 } // namespace
617 617
618 } // namespace policy 618 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698