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