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

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

Issue 2890433002: Revert "Abandon user sign in when policy is retrieved before session started." (Closed)
Patch Set: Created 3 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
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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
(...skipping 17 matching lines...) Expand all
28 #include "components/policy/core/common/policy_types.h" 28 #include "components/policy/core/common/policy_types.h"
29 #include "components/policy/policy_constants.h" 29 #include "components/policy/policy_constants.h"
30 #include "components/policy/proto/cloud_policy.pb.h" 30 #include "components/policy/proto/cloud_policy.pb.h"
31 #include "components/policy/proto/device_management_local.pb.h" 31 #include "components/policy/proto/device_management_local.pb.h"
32 #include "crypto/rsa_private_key.h" 32 #include "crypto/rsa_private_key.h"
33 #include "testing/gmock/include/gmock/gmock.h" 33 #include "testing/gmock/include/gmock/gmock.h"
34 #include "testing/gtest/include/gtest/gtest.h" 34 #include "testing/gtest/include/gtest/gtest.h"
35 35
36 namespace em = enterprise_management; 36 namespace em = enterprise_management;
37 37
38 using RetrievePolicyResponseType =
39 chromeos::SessionManagerClient::RetrievePolicyResponseType;
40
41 using testing::AllOf; 38 using testing::AllOf;
42 using testing::AnyNumber; 39 using testing::AnyNumber;
43 using testing::Eq; 40 using testing::Eq;
44 using testing::Mock; 41 using testing::Mock;
45 using testing::Property; 42 using testing::Property;
46 using testing::Return; 43 using testing::Return;
47 using testing::SaveArg; 44 using testing::SaveArg;
48 using testing::SetArgPointee;
49 using testing::_; 45 using testing::_;
50 46
51 namespace policy { 47 namespace policy {
52 48
53 namespace { 49 namespace {
54 50
55 const char kSanitizedUsername[] = 51 const char kSanitizedUsername[] =
56 "0123456789ABCDEF0123456789ABCDEF012345678@example.com"; 52 "0123456789ABCDEF0123456789ABCDEF012345678@example.com";
57 const char kDefaultHomepage[] = "http://chromium.org"; 53 const char kDefaultHomepage[] = "http://chromium.org";
58 54
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 chromeos::SessionManagerClient::RetrievePolicyCallback retrieve_callback; 104 chromeos::SessionManagerClient::RetrievePolicyCallback retrieve_callback;
109 EXPECT_CALL(session_manager_client_, 105 EXPECT_CALL(session_manager_client_,
110 RetrievePolicyForUser(cryptohome_id_, _)) 106 RetrievePolicyForUser(cryptohome_id_, _))
111 .WillOnce(SaveArg<1>(&retrieve_callback)); 107 .WillOnce(SaveArg<1>(&retrieve_callback));
112 store_->Load(); 108 store_->Load();
113 base::RunLoop().RunUntilIdle(); 109 base::RunLoop().RunUntilIdle();
114 Mock::VerifyAndClearExpectations(&session_manager_client_); 110 Mock::VerifyAndClearExpectations(&session_manager_client_);
115 ASSERT_FALSE(retrieve_callback.is_null()); 111 ASSERT_FALSE(retrieve_callback.is_null());
116 112
117 // Run the callback. 113 // Run the callback.
118 retrieve_callback.Run(response, RetrievePolicyResponseType::SUCCESS); 114 retrieve_callback.Run(response);
119 base::RunLoop().RunUntilIdle(); 115 base::RunLoop().RunUntilIdle();
120 } 116 }
121 117
122 // Verifies that store_->policy_map() has the HomepageLocation entry with 118 // Verifies that store_->policy_map() has the HomepageLocation entry with
123 // the |expected_value|. 119 // the |expected_value|.
124 void VerifyPolicyMap(const char* expected_value) { 120 void VerifyPolicyMap(const char* expected_value) {
125 EXPECT_EQ(1U, store_->policy_map().size()); 121 EXPECT_EQ(1U, store_->policy_map().size());
126 const PolicyMap::Entry* entry = 122 const PolicyMap::Entry* entry =
127 store_->policy_map().Get(key::kHomepageLocation); 123 store_->policy_map().Get(key::kHomepageLocation);
128 ASSERT_TRUE(entry); 124 ASSERT_TRUE(entry);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 .WillOnce(SaveArg<1>(&retrieve_callback)); 177 .WillOnce(SaveArg<1>(&retrieve_callback));
182 store_callback.Run(true); 178 store_callback.Run(true);
183 base::RunLoop().RunUntilIdle(); 179 base::RunLoop().RunUntilIdle();
184 EXPECT_TRUE(previous_policy.Equals(store_->policy_map())); 180 EXPECT_TRUE(previous_policy.Equals(store_->policy_map()));
185 EXPECT_EQ(initial_status, store_->status()); 181 EXPECT_EQ(initial_status, store_->status());
186 Mock::VerifyAndClearExpectations(&session_manager_client_); 182 Mock::VerifyAndClearExpectations(&session_manager_client_);
187 ASSERT_FALSE(retrieve_callback.is_null()); 183 ASSERT_FALSE(retrieve_callback.is_null());
188 184
189 // Finish the retrieve callback. 185 // Finish the retrieve callback.
190 EXPECT_CALL(observer_, OnStoreLoaded(store_.get())); 186 EXPECT_CALL(observer_, OnStoreLoaded(store_.get()));
191 retrieve_callback.Run(policy_.GetBlob(), 187 retrieve_callback.Run(policy_.GetBlob());
192 RetrievePolicyResponseType::SUCCESS);
193 base::RunLoop().RunUntilIdle(); 188 base::RunLoop().RunUntilIdle();
194 ASSERT_TRUE(store_->policy()); 189 ASSERT_TRUE(store_->policy());
195 EXPECT_EQ(policy_.policy_data().SerializeAsString(), 190 EXPECT_EQ(policy_.policy_data().SerializeAsString(),
196 store_->policy()->SerializeAsString()); 191 store_->policy()->SerializeAsString());
197 VerifyPolicyMap(new_value); 192 VerifyPolicyMap(new_value);
198 EXPECT_EQ(CloudPolicyStore::STATUS_OK, store_->status()); 193 EXPECT_EQ(CloudPolicyStore::STATUS_OK, store_->status());
199 } 194 }
200 195
201 void VerifyStoreHasValidationError() { 196 void VerifyStoreHasValidationError() {
202 EXPECT_FALSE(store_->policy()); 197 EXPECT_FALSE(store_->policy());
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 policy_.policy().mutable_policy_data_signature()->append("garbage"); 486 policy_.policy().mutable_policy_data_signature()->append("garbage");
492 ExpectError(CloudPolicyStore::STATUS_VALIDATION_ERROR); 487 ExpectError(CloudPolicyStore::STATUS_VALIDATION_ERROR);
493 ASSERT_NO_FATAL_FAILURE(PerformPolicyLoad(policy_.GetBlob())); 488 ASSERT_NO_FATAL_FAILURE(PerformPolicyLoad(policy_.GetBlob()));
494 VerifyStoreHasValidationError(); 489 VerifyStoreHasValidationError();
495 EXPECT_EQ(std::string(), store_->policy_signature_public_key()); 490 EXPECT_EQ(std::string(), store_->policy_signature_public_key());
496 } 491 }
497 492
498 TEST_F(UserCloudPolicyStoreChromeOSTest, LoadImmediately) { 493 TEST_F(UserCloudPolicyStoreChromeOSTest, LoadImmediately) {
499 EXPECT_CALL(observer_, OnStoreLoaded(store_.get())); 494 EXPECT_CALL(observer_, OnStoreLoaded(store_.get()));
500 EXPECT_CALL(session_manager_client_, 495 EXPECT_CALL(session_manager_client_,
501 BlockingRetrievePolicyForUser(cryptohome_id_, _)) 496 BlockingRetrievePolicyForUser(cryptohome_id_))
502 .WillOnce(DoAll(SetArgPointee<1>(policy_.GetBlob()), 497 .WillOnce(Return(policy_.GetBlob()));
503 Return(RetrievePolicyResponseType::SUCCESS)));
504 EXPECT_CALL(cryptohome_client_, BlockingGetSanitizedUsername(cryptohome_id_)) 498 EXPECT_CALL(cryptohome_client_, BlockingGetSanitizedUsername(cryptohome_id_))
505 .WillOnce(Return(kSanitizedUsername)); 499 .WillOnce(Return(kSanitizedUsername));
506 500
507 EXPECT_FALSE(store_->policy()); 501 EXPECT_FALSE(store_->policy());
508 store_->LoadImmediately(); 502 store_->LoadImmediately();
509 // Note: verify that the |observer_| got notified synchronously, without 503 // Note: verify that the |observer_| got notified synchronously, without
510 // having to spin the current loop. TearDown() will flush the loop so this 504 // having to spin the current loop. TearDown() will flush the loop so this
511 // must be done within the test. 505 // must be done within the test.
512 Mock::VerifyAndClearExpectations(&observer_); 506 Mock::VerifyAndClearExpectations(&observer_);
513 Mock::VerifyAndClearExpectations(&session_manager_client_); 507 Mock::VerifyAndClearExpectations(&session_manager_client_);
514 Mock::VerifyAndClearExpectations(&cryptohome_client_); 508 Mock::VerifyAndClearExpectations(&cryptohome_client_);
515 509
516 // The policy should become available without having to spin any loops. 510 // The policy should become available without having to spin any loops.
517 ASSERT_TRUE(store_->policy()); 511 ASSERT_TRUE(store_->policy());
518 EXPECT_EQ(policy_.policy_data().SerializeAsString(), 512 EXPECT_EQ(policy_.policy_data().SerializeAsString(),
519 store_->policy()->SerializeAsString()); 513 store_->policy()->SerializeAsString());
520 VerifyPolicyMap(kDefaultHomepage); 514 VerifyPolicyMap(kDefaultHomepage);
521 EXPECT_EQ(CloudPolicyStore::STATUS_OK, store_->status()); 515 EXPECT_EQ(CloudPolicyStore::STATUS_OK, store_->status());
522 EXPECT_EQ(policy_.GetPublicSigningKeyAsString(), 516 EXPECT_EQ(policy_.GetPublicSigningKeyAsString(),
523 store_->policy_signature_public_key()); 517 store_->policy_signature_public_key());
524 } 518 }
525 519
526 TEST_F(UserCloudPolicyStoreChromeOSTest, LoadImmediatelyNoPolicy) { 520 TEST_F(UserCloudPolicyStoreChromeOSTest, LoadImmediatelyNoPolicy) {
527 EXPECT_CALL(observer_, OnStoreLoaded(store_.get())); 521 EXPECT_CALL(observer_, OnStoreLoaded(store_.get()));
528 EXPECT_CALL(session_manager_client_, 522 EXPECT_CALL(session_manager_client_,
529 BlockingRetrievePolicyForUser(cryptohome_id_, _)) 523 BlockingRetrievePolicyForUser(cryptohome_id_))
530 .WillOnce(DoAll(SetArgPointee<1>(""), 524 .WillOnce(Return(""));
531 Return(RetrievePolicyResponseType::SUCCESS)));
532 525
533 EXPECT_FALSE(store_->policy()); 526 EXPECT_FALSE(store_->policy());
534 store_->LoadImmediately(); 527 store_->LoadImmediately();
535 Mock::VerifyAndClearExpectations(&observer_); 528 Mock::VerifyAndClearExpectations(&observer_);
536 Mock::VerifyAndClearExpectations(&session_manager_client_); 529 Mock::VerifyAndClearExpectations(&session_manager_client_);
537 530
538 EXPECT_FALSE(store_->policy()); 531 EXPECT_FALSE(store_->policy());
539 EXPECT_TRUE(store_->policy_map().empty()); 532 EXPECT_TRUE(store_->policy_map().empty());
540 EXPECT_EQ(CloudPolicyStore::STATUS_OK, store_->status()); 533 EXPECT_EQ(CloudPolicyStore::STATUS_OK, store_->status());
541 EXPECT_EQ(std::string(), store_->policy_signature_public_key()); 534 EXPECT_EQ(std::string(), store_->policy_signature_public_key());
542 } 535 }
543 536
544 TEST_F(UserCloudPolicyStoreChromeOSTest, LoadImmediatelyInvalidBlob) { 537 TEST_F(UserCloudPolicyStoreChromeOSTest, LoadImmediatelyInvalidBlob) {
545 EXPECT_CALL(observer_, OnStoreError(store_.get())); 538 EXPECT_CALL(observer_, OnStoreError(store_.get()));
546 EXPECT_CALL(session_manager_client_, 539 EXPECT_CALL(session_manager_client_,
547 BlockingRetrievePolicyForUser(cryptohome_id_, _)) 540 BlockingRetrievePolicyForUser(cryptohome_id_))
548 .WillOnce(DoAll(SetArgPointee<1>("le blob"), 541 .WillOnce(Return("le blob"));
549 Return(RetrievePolicyResponseType::SUCCESS)));
550 542
551 EXPECT_FALSE(store_->policy()); 543 EXPECT_FALSE(store_->policy());
552 store_->LoadImmediately(); 544 store_->LoadImmediately();
553 Mock::VerifyAndClearExpectations(&observer_); 545 Mock::VerifyAndClearExpectations(&observer_);
554 Mock::VerifyAndClearExpectations(&session_manager_client_); 546 Mock::VerifyAndClearExpectations(&session_manager_client_);
555 547
556 EXPECT_FALSE(store_->policy()); 548 EXPECT_FALSE(store_->policy());
557 EXPECT_TRUE(store_->policy_map().empty()); 549 EXPECT_TRUE(store_->policy_map().empty());
558 EXPECT_EQ(CloudPolicyStore::STATUS_PARSE_ERROR, store_->status()); 550 EXPECT_EQ(CloudPolicyStore::STATUS_PARSE_ERROR, store_->status());
559 EXPECT_EQ(std::string(), store_->policy_signature_public_key()); 551 EXPECT_EQ(std::string(), store_->policy_signature_public_key());
560 } 552 }
561 553
562 TEST_F(UserCloudPolicyStoreChromeOSTest, LoadImmediatelyDBusFailure) { 554 TEST_F(UserCloudPolicyStoreChromeOSTest, LoadImmediatelyDBusFailure) {
563 EXPECT_CALL(observer_, OnStoreError(store_.get())); 555 EXPECT_CALL(observer_, OnStoreError(store_.get()));
564 EXPECT_CALL(session_manager_client_, 556 EXPECT_CALL(session_manager_client_,
565 BlockingRetrievePolicyForUser(cryptohome_id_, _)) 557 BlockingRetrievePolicyForUser(cryptohome_id_))
566 .WillOnce(DoAll(SetArgPointee<1>(policy_.GetBlob()), 558 .WillOnce(Return(policy_.GetBlob()));
567 Return(RetrievePolicyResponseType::SUCCESS)));
568 EXPECT_CALL(cryptohome_client_, BlockingGetSanitizedUsername(cryptohome_id_)) 559 EXPECT_CALL(cryptohome_client_, BlockingGetSanitizedUsername(cryptohome_id_))
569 .WillOnce(Return("")); 560 .WillOnce(Return(""));
570 561
571 EXPECT_FALSE(store_->policy()); 562 EXPECT_FALSE(store_->policy());
572 store_->LoadImmediately(); 563 store_->LoadImmediately();
573 Mock::VerifyAndClearExpectations(&observer_); 564 Mock::VerifyAndClearExpectations(&observer_);
574 Mock::VerifyAndClearExpectations(&session_manager_client_); 565 Mock::VerifyAndClearExpectations(&session_manager_client_);
575 Mock::VerifyAndClearExpectations(&cryptohome_client_); 566 Mock::VerifyAndClearExpectations(&cryptohome_client_);
576 567
577 EXPECT_FALSE(store_->policy()); 568 EXPECT_FALSE(store_->policy());
578 EXPECT_TRUE(store_->policy_map().empty()); 569 EXPECT_TRUE(store_->policy_map().empty());
579 EXPECT_EQ(CloudPolicyStore::STATUS_LOAD_ERROR, store_->status()); 570 EXPECT_EQ(CloudPolicyStore::STATUS_LOAD_ERROR, store_->status());
580 EXPECT_EQ(std::string(), store_->policy_signature_public_key()); 571 EXPECT_EQ(std::string(), store_->policy_signature_public_key());
581 } 572 }
582 573
583 TEST_F(UserCloudPolicyStoreChromeOSTest, LoadImmediatelyNoUserPolicyKey) { 574 TEST_F(UserCloudPolicyStoreChromeOSTest, LoadImmediatelyNoUserPolicyKey) {
584 EXPECT_CALL(observer_, OnStoreError(store_.get())); 575 EXPECT_CALL(observer_, OnStoreError(store_.get()));
585 EXPECT_CALL(session_manager_client_, 576 EXPECT_CALL(session_manager_client_,
586 BlockingRetrievePolicyForUser(cryptohome_id_, _)) 577 BlockingRetrievePolicyForUser(cryptohome_id_))
587 .WillOnce(DoAll(SetArgPointee<1>(policy_.GetBlob()), 578 .WillOnce(Return(policy_.GetBlob()));
588 Return(RetrievePolicyResponseType::SUCCESS)));
589 EXPECT_CALL(cryptohome_client_, BlockingGetSanitizedUsername(cryptohome_id_)) 579 EXPECT_CALL(cryptohome_client_, BlockingGetSanitizedUsername(cryptohome_id_))
590 .WillOnce(Return("wrong@example.com")); 580 .WillOnce(Return("wrong@example.com"));
591 581
592 EXPECT_FALSE(store_->policy()); 582 EXPECT_FALSE(store_->policy());
593 store_->LoadImmediately(); 583 store_->LoadImmediately();
594 Mock::VerifyAndClearExpectations(&observer_); 584 Mock::VerifyAndClearExpectations(&observer_);
595 Mock::VerifyAndClearExpectations(&session_manager_client_); 585 Mock::VerifyAndClearExpectations(&session_manager_client_);
596 Mock::VerifyAndClearExpectations(&cryptohome_client_); 586 Mock::VerifyAndClearExpectations(&cryptohome_client_);
597 587
598 EXPECT_FALSE(store_->policy()); 588 EXPECT_FALSE(store_->policy());
599 EXPECT_TRUE(store_->policy_map().empty()); 589 EXPECT_TRUE(store_->policy_map().empty());
600 EXPECT_EQ(CloudPolicyStore::STATUS_VALIDATION_ERROR, store_->status()); 590 EXPECT_EQ(CloudPolicyStore::STATUS_VALIDATION_ERROR, store_->status());
601 EXPECT_EQ(std::string(), store_->policy_signature_public_key()); 591 EXPECT_EQ(std::string(), store_->policy_signature_public_key());
602 } 592 }
603 593
604 } // namespace 594 } // namespace
605 595
606 } // namespace policy 596 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698