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/device_cloud_policy_manager_chromeos.h" | 5 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 28 matching lines...) Expand all Loading... |
39 #include "chromeos/dbus/dbus_client_implementation_type.h" | 39 #include "chromeos/dbus/dbus_client_implementation_type.h" |
40 #include "chromeos/dbus/dbus_thread_manager.h" | 40 #include "chromeos/dbus/dbus_thread_manager.h" |
41 #include "chromeos/dbus/fake_cryptohome_client.h" | 41 #include "chromeos/dbus/fake_cryptohome_client.h" |
42 #include "chromeos/dbus/fake_session_manager_client.h" | 42 #include "chromeos/dbus/fake_session_manager_client.h" |
43 #include "chromeos/system/fake_statistics_provider.h" | 43 #include "chromeos/system/fake_statistics_provider.h" |
44 #include "chromeos/system/statistics_provider.h" | 44 #include "chromeos/system/statistics_provider.h" |
45 #include "components/policy/core/common/cloud/cloud_policy_client.h" | 45 #include "components/policy/core/common/cloud/cloud_policy_client.h" |
46 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | 46 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
47 #include "components/policy/core/common/cloud/cloud_policy_core.h" | 47 #include "components/policy/core/common/cloud/cloud_policy_core.h" |
48 #include "components/policy/core/common/cloud/mock_device_management_service.h" | 48 #include "components/policy/core/common/cloud/mock_device_management_service.h" |
49 #include "components/policy/core/common/cloud/mock_signing_service.h" | |
50 #include "components/policy/core/common/external_data_fetcher.h" | 49 #include "components/policy/core/common/external_data_fetcher.h" |
51 #include "components/policy/core/common/policy_types.h" | 50 #include "components/policy/core/common/policy_types.h" |
52 #include "components/policy/core/common/schema_registry.h" | 51 #include "components/policy/core/common/schema_registry.h" |
53 #include "components/policy/policy_constants.h" | 52 #include "components/policy/policy_constants.h" |
54 #include "components/policy/proto/device_management_backend.pb.h" | 53 #include "components/policy/proto/device_management_backend.pb.h" |
55 #include "components/prefs/pref_registry_simple.h" | 54 #include "components/prefs/pref_registry_simple.h" |
56 #include "components/prefs/testing_pref_service.h" | 55 #include "components/prefs/testing_pref_service.h" |
57 #include "google_apis/gaia/gaia_oauth_client.h" | 56 #include "google_apis/gaia/gaia_oauth_client.h" |
58 #include "net/url_request/test_url_fetcher_factory.h" | 57 #include "net/url_request/test_url_fetcher_factory.h" |
59 #include "net/url_request/url_request_test_util.h" | 58 #include "net/url_request/url_request_test_util.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 state_keys.push_back("1"); | 117 state_keys.push_back("1"); |
119 state_keys.push_back("2"); | 118 state_keys.push_back("2"); |
120 state_keys.push_back("3"); | 119 state_keys.push_back("3"); |
121 fake_session_manager_client_.set_server_backed_state_keys(state_keys); | 120 fake_session_manager_client_.set_server_backed_state_keys(state_keys); |
122 } | 121 } |
123 | 122 |
124 ~DeviceCloudPolicyManagerChromeOSTest() override { | 123 ~DeviceCloudPolicyManagerChromeOSTest() override { |
125 chromeos::system::StatisticsProvider::SetTestProvider(NULL); | 124 chromeos::system::StatisticsProvider::SetTestProvider(NULL); |
126 } | 125 } |
127 | 126 |
128 virtual bool ShouldRegisterWithCert() const { return false; } | 127 virtual bool ShouldRegisterWitCert() const { return false; } |
129 | 128 |
130 void SetUp() override { | 129 void SetUp() override { |
131 DeviceSettingsTestBase::SetUp(); | 130 DeviceSettingsTestBase::SetUp(); |
132 dbus_setter_->SetCryptohomeClient( | 131 dbus_setter_->SetCryptohomeClient( |
133 std::unique_ptr<chromeos::CryptohomeClient>(fake_cryptohome_client_)); | 132 std::unique_ptr<chromeos::CryptohomeClient>(fake_cryptohome_client_)); |
134 chromeos::DBusThreadManager::Get()->GetCryptohomeClient(); | 133 chromeos::DBusThreadManager::Get()->GetCryptohomeClient(); |
135 cryptohome::AsyncMethodCaller::Initialize(); | 134 cryptohome::AsyncMethodCaller::Initialize(); |
136 | 135 |
137 install_attributes_.reset( | 136 install_attributes_.reset( |
138 new EnterpriseInstallAttributes(fake_cryptohome_client_)); | 137 new EnterpriseInstallAttributes(fake_cryptohome_client_)); |
(...skipping 23 matching lines...) Expand all Loading... |
162 "\"expires_in\":1234," | 161 "\"expires_in\":1234," |
163 "\"refresh_token\":\"refreshToken4Test\"}"; | 162 "\"refresh_token\":\"refreshToken4Test\"}"; |
164 | 163 |
165 AllowUninterestingRemoteCommandFetches(); | 164 AllowUninterestingRemoteCommandFetches(); |
166 } | 165 } |
167 | 166 |
168 StrictMock<chromeos::attestation::MockAttestationFlow>* | 167 StrictMock<chromeos::attestation::MockAttestationFlow>* |
169 CreateAttestationFlow() { | 168 CreateAttestationFlow() { |
170 StrictMock<chromeos::attestation::MockAttestationFlow>* mock = | 169 StrictMock<chromeos::attestation::MockAttestationFlow>* mock = |
171 new StrictMock<chromeos::attestation::MockAttestationFlow>(); | 170 new StrictMock<chromeos::attestation::MockAttestationFlow>(); |
172 if (ShouldRegisterWithCert()) { | 171 if (ShouldRegisterWitCert()) { |
173 EXPECT_CALL(*mock, GetCertificate(_, _, _, _, _)) | 172 EXPECT_CALL(*mock, GetCertificate(_, _, _, _, _)) |
174 .WillOnce(WithArgs<4>(Invoke(CertCallbackSuccess))); | 173 .WillOnce(WithArgs<4>(Invoke(CertCallbackSuccess))); |
175 } | 174 } |
176 return mock; | 175 return mock; |
177 } | 176 } |
178 | 177 |
179 void TearDown() override { | 178 void TearDown() override { |
180 cryptohome::AsyncMethodCaller::Shutdown(); | 179 cryptohome::AsyncMethodCaller::Shutdown(); |
181 | 180 |
182 manager_->RemoveDeviceCloudPolicyManagerObserver(this); | 181 manager_->RemoveDeviceCloudPolicyManagerObserver(this); |
(...skipping 22 matching lines...) Expand all Loading... |
205 void ConnectManager() { | 204 void ConnectManager() { |
206 std::unique_ptr<chromeos::attestation::AttestationFlow> unique_flow( | 205 std::unique_ptr<chromeos::attestation::AttestationFlow> unique_flow( |
207 CreateAttestationFlow()); | 206 CreateAttestationFlow()); |
208 manager_->Initialize(&local_state_); | 207 manager_->Initialize(&local_state_); |
209 manager_->AddDeviceCloudPolicyManagerObserver(this); | 208 manager_->AddDeviceCloudPolicyManagerObserver(this); |
210 initializer_.reset(new DeviceCloudPolicyInitializer( | 209 initializer_.reset(new DeviceCloudPolicyInitializer( |
211 &local_state_, &device_management_service_, | 210 &local_state_, &device_management_service_, |
212 base::ThreadTaskRunnerHandle::Get(), install_attributes_.get(), | 211 base::ThreadTaskRunnerHandle::Get(), install_attributes_.get(), |
213 &state_keys_broker_, store_, manager_.get(), | 212 &state_keys_broker_, store_, manager_.get(), |
214 cryptohome::AsyncMethodCaller::GetInstance(), std::move(unique_flow))); | 213 cryptohome::AsyncMethodCaller::GetInstance(), std::move(unique_flow))); |
215 initializer_->SetSigningServiceForTesting( | |
216 base::MakeUnique<FakeSigningService>()); | |
217 initializer_->Init(); | 214 initializer_->Init(); |
218 } | 215 } |
219 | 216 |
220 void VerifyPolicyPopulated() { | 217 void VerifyPolicyPopulated() { |
221 PolicyBundle bundle; | 218 PolicyBundle bundle; |
222 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | 219 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) |
223 .Set(key::kDeviceMetricsReportingEnabled, POLICY_LEVEL_MANDATORY, | 220 .Set(key::kDeviceMetricsReportingEnabled, POLICY_LEVEL_MANDATORY, |
224 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, | 221 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
225 base::MakeUnique<base::FundamentalValue>(false), nullptr); | 222 base::MakeUnique<base::FundamentalValue>(false), nullptr); |
226 EXPECT_TRUE(manager_->policies().Equals(bundle)); | 223 EXPECT_TRUE(manager_->policies().Equals(bundle)); |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 Mock::VerifyAndClearExpectations(this); | 387 Mock::VerifyAndClearExpectations(this); |
391 EXPECT_TRUE(manager_->core()->service()); // Connected. | 388 EXPECT_TRUE(manager_->core()->service()); // Connected. |
392 | 389 |
393 // Disconnect the manager. | 390 // Disconnect the manager. |
394 EXPECT_CALL(*this, OnDeviceCloudPolicyManagerDisconnected()); | 391 EXPECT_CALL(*this, OnDeviceCloudPolicyManagerDisconnected()); |
395 manager_->Disconnect(); | 392 manager_->Disconnect(); |
396 EXPECT_FALSE(manager_->core()->service()); // Not connnected. | 393 EXPECT_FALSE(manager_->core()->service()); // Not connnected. |
397 } | 394 } |
398 | 395 |
399 class DeviceCloudPolicyManagerChromeOSEnrollmentTest | 396 class DeviceCloudPolicyManagerChromeOSEnrollmentTest |
400 : public DeviceCloudPolicyManagerChromeOSTest, | 397 : public DeviceCloudPolicyManagerChromeOSTest { |
401 public testing::WithParamInterface<bool> { | |
402 public: | 398 public: |
403 void Done(EnrollmentStatus status) { | 399 void Done(EnrollmentStatus status) { |
404 status_ = status; | 400 status_ = status; |
405 done_ = true; | 401 done_ = true; |
406 } | 402 } |
407 | 403 |
408 MOCK_METHOD1(OnUnregistered, void(bool)); | 404 MOCK_METHOD1(OnUnregistered, void(bool)); |
409 | 405 |
410 protected: | 406 protected: |
411 DeviceCloudPolicyManagerChromeOSEnrollmentTest() | 407 DeviceCloudPolicyManagerChromeOSEnrollmentTest() |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 EXPECT_EQ(EnrollmentStatus::STATUS_SUCCESS, status_.status()); | 452 EXPECT_EQ(EnrollmentStatus::STATUS_SUCCESS, status_.status()); |
457 ASSERT_TRUE(manager_->core()->client()); | 453 ASSERT_TRUE(manager_->core()->client()); |
458 EXPECT_TRUE(manager_->core()->client()->is_registered()); | 454 EXPECT_TRUE(manager_->core()->client()->is_registered()); |
459 EXPECT_EQ(DEVICE_MODE_ENTERPRISE, install_attributes_->GetMode()); | 455 EXPECT_EQ(DEVICE_MODE_ENTERPRISE, install_attributes_->GetMode()); |
460 EXPECT_TRUE(store_->has_policy()); | 456 EXPECT_TRUE(store_->has_policy()); |
461 EXPECT_TRUE(store_->is_managed()); | 457 EXPECT_TRUE(store_->is_managed()); |
462 VerifyPolicyPopulated(); | 458 VerifyPolicyPopulated(); |
463 } | 459 } |
464 | 460 |
465 void RunTest() { | 461 void RunTest() { |
466 const bool with_cert = ShouldRegisterWithCert(); | 462 const bool with_cert = ShouldRegisterWitCert(); |
467 // Trigger enrollment. | 463 // Trigger enrollment. |
468 MockDeviceManagementJob* register_job = NULL; | 464 MockDeviceManagementJob* register_job = NULL; |
469 EXPECT_CALL( | 465 EXPECT_CALL( |
470 device_management_service_, | 466 device_management_service_, |
471 CreateJob(with_cert | 467 CreateJob(with_cert |
472 ? DeviceManagementRequestJob::TYPE_CERT_BASED_REGISTRATION | 468 ? DeviceManagementRequestJob::TYPE_CERT_BASED_REGISTRATION |
473 : DeviceManagementRequestJob::TYPE_REGISTRATION, | 469 : DeviceManagementRequestJob::TYPE_REGISTRATION, |
474 _)) | 470 _)) |
475 .Times(AtMost(1)) | 471 .Times(AtMost(1)) |
476 .WillOnce(device_management_service_.CreateAsyncJob(®ister_job)); | 472 .WillOnce(device_management_service_.CreateAsyncJob(®ister_job)); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 if (done_) | 591 if (done_) |
596 return; | 592 return; |
597 | 593 |
598 // Key installation and policy load. | 594 // Key installation and policy load. |
599 device_settings_test_helper_.set_policy_blob(loaded_blob_); | 595 device_settings_test_helper_.set_policy_blob(loaded_blob_); |
600 owner_key_util_->SetPublicKeyFromPrivateKey( | 596 owner_key_util_->SetPublicKeyFromPrivateKey( |
601 *device_policy_.GetNewSigningKey()); | 597 *device_policy_.GetNewSigningKey()); |
602 ReloadDeviceSettings(); | 598 ReloadDeviceSettings(); |
603 } | 599 } |
604 | 600 |
605 bool ShouldRegisterWithCert() const override { return GetParam(); } | |
606 | |
607 const em::DeviceRegisterRequest& GetDeviceRegisterRequest() { | |
608 if (ShouldRegisterWithCert()) { | |
609 const em::SignedData& signed_request = | |
610 register_request_.cert_based_register_request().signed_request(); | |
611 em::CertificateBasedDeviceRegistrationData data; | |
612 EXPECT_TRUE(data.ParseFromString(signed_request.data().substr( | |
613 0, | |
614 signed_request.data().size() - signed_request.extra_data_bytes()))); | |
615 EXPECT_EQ(em::CertificateBasedDeviceRegistrationData:: | |
616 ENTERPRISE_ENROLLMENT_CERTIFICATE, | |
617 data.certificate_type()); | |
618 return data.device_register_request(); | |
619 } else { | |
620 return register_request_.register_request(); | |
621 } | |
622 } | |
623 | |
624 DeviceManagementStatus register_status_; | 601 DeviceManagementStatus register_status_; |
625 em::DeviceManagementResponse register_response_; | 602 em::DeviceManagementResponse register_response_; |
626 | 603 |
627 DeviceManagementStatus policy_fetch_status_; | 604 DeviceManagementStatus policy_fetch_status_; |
628 em::DeviceManagementResponse policy_fetch_response_; | 605 em::DeviceManagementResponse policy_fetch_response_; |
629 | 606 |
630 DeviceManagementStatus robot_auth_fetch_status_; | 607 DeviceManagementStatus robot_auth_fetch_status_; |
631 em::DeviceManagementResponse robot_auth_fetch_response_; | 608 em::DeviceManagementResponse robot_auth_fetch_response_; |
632 | 609 |
633 bool store_result_; | 610 bool store_result_; |
634 std::string loaded_blob_; | 611 std::string loaded_blob_; |
635 | 612 |
636 em::DeviceManagementRequest register_request_; | 613 em::DeviceManagementRequest register_request_; |
637 std::string client_id_; | 614 std::string client_id_; |
638 EnrollmentStatus status_; | 615 EnrollmentStatus status_; |
639 | 616 |
640 bool done_; | 617 bool done_; |
641 | 618 |
642 private: | 619 private: |
643 DISALLOW_COPY_AND_ASSIGN(DeviceCloudPolicyManagerChromeOSEnrollmentTest); | 620 DISALLOW_COPY_AND_ASSIGN(DeviceCloudPolicyManagerChromeOSEnrollmentTest); |
644 }; | 621 }; |
645 | 622 |
646 TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, Success) { | 623 // TODO(drcrash): Handle cert-based tests (http://crbug.com/641447). |
| 624 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentTest, Reenrollment) { |
| 625 LockDevice(); |
| 626 RunTest(); |
| 627 ExpectSuccessfulEnrollment(); |
| 628 EXPECT_TRUE(register_request_.register_request().reregister()); |
| 629 EXPECT_EQ(PolicyBuilder::kFakeDeviceId, client_id_); |
| 630 } |
| 631 |
| 632 class ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest |
| 633 : public DeviceCloudPolicyManagerChromeOSEnrollmentTest, |
| 634 public testing::WithParamInterface<bool> { |
| 635 protected: |
| 636 bool ShouldRegisterWitCert() const override { return GetParam(); } |
| 637 }; |
| 638 |
| 639 TEST_P(ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest, Success) { |
647 RunTest(); | 640 RunTest(); |
648 ExpectSuccessfulEnrollment(); | 641 ExpectSuccessfulEnrollment(); |
649 } | 642 } |
650 | 643 |
651 TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, Reenrollment) { | 644 TEST_P(ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest, |
652 LockDevice(); | 645 RegistrationFailed) { |
653 RunTest(); | |
654 ExpectSuccessfulEnrollment(); | |
655 EXPECT_TRUE(GetDeviceRegisterRequest().reregister()); | |
656 EXPECT_EQ(PolicyBuilder::kFakeDeviceId, client_id_); | |
657 } | |
658 | |
659 TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, RegistrationFailed) { | |
660 register_status_ = DM_STATUS_REQUEST_FAILED; | 646 register_status_ = DM_STATUS_REQUEST_FAILED; |
661 RunTest(); | 647 RunTest(); |
662 ExpectFailedEnrollment(EnrollmentStatus::STATUS_REGISTRATION_FAILED); | 648 ExpectFailedEnrollment(EnrollmentStatus::STATUS_REGISTRATION_FAILED); |
663 EXPECT_EQ(DM_STATUS_REQUEST_FAILED, status_.client_status()); | 649 EXPECT_EQ(DM_STATUS_REQUEST_FAILED, status_.client_status()); |
664 } | 650 } |
665 | 651 |
666 TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, | 652 TEST_P(ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest, |
667 RobotAuthCodeFetchFailed) { | 653 RobotAuthCodeFetchFailed) { |
668 robot_auth_fetch_status_ = DM_STATUS_REQUEST_FAILED; | 654 robot_auth_fetch_status_ = DM_STATUS_REQUEST_FAILED; |
669 RunTest(); | 655 RunTest(); |
670 ExpectFailedEnrollment(EnrollmentStatus::STATUS_ROBOT_AUTH_FETCH_FAILED); | 656 ExpectFailedEnrollment(EnrollmentStatus::STATUS_ROBOT_AUTH_FETCH_FAILED); |
671 } | 657 } |
672 | 658 |
673 TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, | 659 TEST_P(ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest, |
674 RobotRefreshTokenFetchResponseCodeFailed) { | 660 RobotRefreshTokenFetchResponseCodeFailed) { |
675 url_fetcher_response_code_ = 400; | 661 url_fetcher_response_code_ = 400; |
676 RunTest(); | 662 RunTest(); |
677 ExpectFailedEnrollment(EnrollmentStatus::STATUS_ROBOT_REFRESH_FETCH_FAILED); | 663 ExpectFailedEnrollment(EnrollmentStatus::STATUS_ROBOT_REFRESH_FETCH_FAILED); |
678 EXPECT_EQ(400, status_.http_status()); | 664 EXPECT_EQ(400, status_.http_status()); |
679 } | 665 } |
680 | 666 |
681 TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, | 667 TEST_P(ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest, |
682 RobotRefreshTokenFetchResponseStringFailed) { | 668 RobotRefreshTokenFetchResponseStringFailed) { |
683 url_fetcher_response_string_ = "invalid response json"; | 669 url_fetcher_response_string_ = "invalid response json"; |
684 RunTest(); | 670 RunTest(); |
685 ExpectFailedEnrollment(EnrollmentStatus::STATUS_ROBOT_REFRESH_FETCH_FAILED); | 671 ExpectFailedEnrollment(EnrollmentStatus::STATUS_ROBOT_REFRESH_FETCH_FAILED); |
686 } | 672 } |
687 | 673 |
688 TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, | 674 TEST_P(ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest, |
689 RobotRefreshEncryptionFailed) { | 675 RobotRefreshEncryptionFailed) { |
690 // The encryption lib is a noop for tests, but empty results from encryption | 676 // The encryption lib is a noop for tests, but empty results from encryption |
691 // is an error, so we simulate an encryption error by returning an empty | 677 // is an error, so we simulate an encryption error by returning an empty |
692 // refresh token. | 678 // refresh token. |
693 url_fetcher_response_string_ = "{\"access_token\":\"accessToken4Test\"," | 679 url_fetcher_response_string_ = "{\"access_token\":\"accessToken4Test\"," |
694 "\"expires_in\":1234," | 680 "\"expires_in\":1234," |
695 "\"refresh_token\":\"\"}"; | 681 "\"refresh_token\":\"\"}"; |
696 RunTest(); | 682 RunTest(); |
697 ExpectFailedEnrollment(EnrollmentStatus::STATUS_ROBOT_REFRESH_STORE_FAILED); | 683 ExpectFailedEnrollment(EnrollmentStatus::STATUS_ROBOT_REFRESH_STORE_FAILED); |
698 } | 684 } |
699 | 685 |
700 TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, PolicyFetchFailed) { | 686 TEST_P(ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest, |
| 687 PolicyFetchFailed) { |
701 policy_fetch_status_ = DM_STATUS_REQUEST_FAILED; | 688 policy_fetch_status_ = DM_STATUS_REQUEST_FAILED; |
702 RunTest(); | 689 RunTest(); |
703 ExpectFailedEnrollment(EnrollmentStatus::STATUS_POLICY_FETCH_FAILED); | 690 ExpectFailedEnrollment(EnrollmentStatus::STATUS_POLICY_FETCH_FAILED); |
704 EXPECT_EQ(DM_STATUS_REQUEST_FAILED, status_.client_status()); | 691 EXPECT_EQ(DM_STATUS_REQUEST_FAILED, status_.client_status()); |
705 } | 692 } |
706 | 693 |
707 TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, ValidationFailed) { | 694 TEST_P(ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest, |
| 695 ValidationFailed) { |
708 device_policy_.policy().set_policy_data_signature("bad"); | 696 device_policy_.policy().set_policy_data_signature("bad"); |
709 policy_fetch_response_.clear_policy_response(); | 697 policy_fetch_response_.clear_policy_response(); |
710 policy_fetch_response_.mutable_policy_response()->add_response()->CopyFrom( | 698 policy_fetch_response_.mutable_policy_response()->add_response()->CopyFrom( |
711 device_policy_.policy()); | 699 device_policy_.policy()); |
712 RunTest(); | 700 RunTest(); |
713 ExpectFailedEnrollment(EnrollmentStatus::STATUS_VALIDATION_FAILED); | 701 ExpectFailedEnrollment(EnrollmentStatus::STATUS_VALIDATION_FAILED); |
714 EXPECT_EQ(CloudPolicyValidatorBase::VALIDATION_BAD_INITIAL_SIGNATURE, | 702 EXPECT_EQ(CloudPolicyValidatorBase::VALIDATION_BAD_INITIAL_SIGNATURE, |
715 status_.validation_status()); | 703 status_.validation_status()); |
716 } | 704 } |
717 | 705 |
718 TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, StoreError) { | 706 TEST_P(ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest, |
| 707 StoreError) { |
719 store_result_ = false; | 708 store_result_ = false; |
720 RunTest(); | 709 RunTest(); |
721 ExpectFailedEnrollment(EnrollmentStatus::STATUS_STORE_ERROR); | 710 ExpectFailedEnrollment(EnrollmentStatus::STATUS_STORE_ERROR); |
722 EXPECT_EQ(CloudPolicyStore::STATUS_STORE_ERROR, | 711 EXPECT_EQ(CloudPolicyStore::STATUS_STORE_ERROR, |
723 status_.store_status()); | 712 status_.store_status()); |
724 } | 713 } |
725 | 714 |
726 TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, LoadError) { | 715 TEST_P(ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest, LoadError) { |
727 loaded_blob_.clear(); | 716 loaded_blob_.clear(); |
728 RunTest(); | 717 RunTest(); |
729 ExpectFailedEnrollment(EnrollmentStatus::STATUS_STORE_ERROR); | 718 ExpectFailedEnrollment(EnrollmentStatus::STATUS_STORE_ERROR); |
730 EXPECT_EQ(CloudPolicyStore::STATUS_LOAD_ERROR, | 719 EXPECT_EQ(CloudPolicyStore::STATUS_LOAD_ERROR, |
731 status_.store_status()); | 720 status_.store_status()); |
732 } | 721 } |
733 | 722 |
734 TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, UnregisterSucceeds) { | 723 TEST_P(ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest, |
| 724 UnregisterSucceeds) { |
735 // Enroll first. | 725 // Enroll first. |
736 RunTest(); | 726 RunTest(); |
737 ExpectSuccessfulEnrollment(); | 727 ExpectSuccessfulEnrollment(); |
738 | 728 |
739 // Set up mock objects for the upcoming unregistration job. | 729 // Set up mock objects for the upcoming unregistration job. |
740 em::DeviceManagementResponse response; | 730 em::DeviceManagementResponse response; |
741 response.mutable_unregister_response(); | 731 response.mutable_unregister_response(); |
742 EXPECT_CALL(device_management_service_, | 732 EXPECT_CALL(device_management_service_, |
743 CreateJob(DeviceManagementRequestJob::TYPE_UNREGISTRATION, _)) | 733 CreateJob(DeviceManagementRequestJob::TYPE_UNREGISTRATION, _)) |
744 .WillOnce(device_management_service_.SucceedJob(response)); | 734 .WillOnce(device_management_service_.SucceedJob(response)); |
745 EXPECT_CALL(device_management_service_, StartJob(_, _, _, _, _, _)); | 735 EXPECT_CALL(device_management_service_, StartJob(_, _, _, _, _, _)); |
746 EXPECT_CALL(*this, OnUnregistered(true)); | 736 EXPECT_CALL(*this, OnUnregistered(true)); |
747 | 737 |
748 // Start unregistering. | 738 // Start unregistering. |
749 manager_->Unregister(base::Bind( | 739 manager_->Unregister(base::Bind( |
750 &DeviceCloudPolicyManagerChromeOSEnrollmentTest::OnUnregistered, | 740 &DeviceCloudPolicyManagerChromeOSEnrollmentTest::OnUnregistered, |
751 base::Unretained(this))); | 741 base::Unretained(this))); |
752 } | 742 } |
753 | 743 |
754 TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, UnregisterFails) { | 744 TEST_P(ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest, |
| 745 UnregisterFails) { |
755 // Enroll first. | 746 // Enroll first. |
756 RunTest(); | 747 RunTest(); |
757 ExpectSuccessfulEnrollment(); | 748 ExpectSuccessfulEnrollment(); |
758 | 749 |
759 // Set up mock objects for the upcoming unregistration job. | 750 // Set up mock objects for the upcoming unregistration job. |
760 EXPECT_CALL(device_management_service_, | 751 EXPECT_CALL(device_management_service_, |
761 CreateJob(DeviceManagementRequestJob::TYPE_UNREGISTRATION, _)) | 752 CreateJob(DeviceManagementRequestJob::TYPE_UNREGISTRATION, _)) |
762 .WillOnce(device_management_service_.FailJob(DM_STATUS_REQUEST_FAILED)); | 753 .WillOnce(device_management_service_.FailJob(DM_STATUS_REQUEST_FAILED)); |
763 EXPECT_CALL(device_management_service_, StartJob(_, _, _, _, _, _)); | 754 EXPECT_CALL(device_management_service_, StartJob(_, _, _, _, _, _)); |
764 EXPECT_CALL(*this, OnUnregistered(false)); | 755 EXPECT_CALL(*this, OnUnregistered(false)); |
765 | 756 |
766 // Start unregistering. | 757 // Start unregistering. |
767 manager_->Unregister(base::Bind( | 758 manager_->Unregister(base::Bind( |
768 &DeviceCloudPolicyManagerChromeOSEnrollmentTest::OnUnregistered, | 759 &DeviceCloudPolicyManagerChromeOSEnrollmentTest::OnUnregistered, |
769 base::Unretained(this))); | 760 base::Unretained(this))); |
770 } | 761 } |
771 | 762 |
772 // A subclass that runs with a blank system salt. | 763 // A subclass that runs with a blank system salt. |
773 class DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest | 764 class DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest |
774 : public DeviceCloudPolicyManagerChromeOSEnrollmentTest { | 765 : public DeviceCloudPolicyManagerChromeOSEnrollmentTest { |
775 protected: | 766 protected: |
776 DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest() { | 767 DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest() { |
777 // Set up a FakeCryptohomeClient with a blank system salt. | 768 // Set up a FakeCryptohomeClient with a blank system salt. |
778 fake_cryptohome_client_->set_system_salt(std::vector<uint8_t>()); | 769 fake_cryptohome_client_->set_system_salt(std::vector<uint8_t>()); |
779 } | 770 } |
780 }; | 771 }; |
781 | 772 |
782 TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest, | 773 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest, |
783 RobotRefreshSaveFailed) { | 774 RobotRefreshSaveFailed) { |
784 // Without the system salt, the robot token can't be stored. | 775 // Without the system salt, the robot token can't be stored. |
785 RunTest(); | 776 RunTest(); |
786 ExpectFailedEnrollment(EnrollmentStatus::STATUS_ROBOT_REFRESH_STORE_FAILED); | 777 ExpectFailedEnrollment(EnrollmentStatus::STATUS_ROBOT_REFRESH_STORE_FAILED); |
787 } | 778 } |
788 | 779 |
789 INSTANTIATE_TEST_CASE_P(Cert, | |
790 DeviceCloudPolicyManagerChromeOSEnrollmentTest, | |
791 ::testing::Values(false, true)); | |
792 | |
793 INSTANTIATE_TEST_CASE_P( | 780 INSTANTIATE_TEST_CASE_P( |
794 Cert, | 781 Cert, |
795 DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest, | 782 ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest, |
796 ::testing::Values(false, true)); | 783 ::testing::Values(false, true)); |
797 | 784 |
798 } // namespace | 785 } // namespace |
799 } // namespace policy | 786 } // namespace policy |
OLD | NEW |