| 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(&fake_signing_service_); |
| 214 initializer_->Init(); | 216 initializer_->Init(); |
| 215 } | 217 } |
| 216 | 218 |
| 217 void VerifyPolicyPopulated() { | 219 void VerifyPolicyPopulated() { |
| 218 PolicyBundle bundle; | 220 PolicyBundle bundle; |
| 219 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | 221 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) |
| 220 .Set(key::kDeviceMetricsReportingEnabled, POLICY_LEVEL_MANDATORY, | 222 .Set(key::kDeviceMetricsReportingEnabled, POLICY_LEVEL_MANDATORY, |
| 221 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, | 223 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
| 222 base::MakeUnique<base::FundamentalValue>(false), nullptr); | 224 base::MakeUnique<base::FundamentalValue>(false), nullptr); |
| 223 EXPECT_TRUE(manager_->policies().Equals(bundle)); | 225 EXPECT_TRUE(manager_->policies().Equals(bundle)); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 246 net::TestURLFetcherFactory url_fetcher_factory_; | 248 net::TestURLFetcherFactory url_fetcher_factory_; |
| 247 int url_fetcher_response_code_; | 249 int url_fetcher_response_code_; |
| 248 std::string url_fetcher_response_string_; | 250 std::string url_fetcher_response_string_; |
| 249 TestingPrefServiceSimple local_state_; | 251 TestingPrefServiceSimple local_state_; |
| 250 MockDeviceManagementService device_management_service_; | 252 MockDeviceManagementService device_management_service_; |
| 251 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | 253 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
| 252 chromeos::ScopedTestCrosSettings test_cros_settings_; | 254 chromeos::ScopedTestCrosSettings test_cros_settings_; |
| 253 chromeos::system::ScopedFakeStatisticsProvider fake_statistics_provider_; | 255 chromeos::system::ScopedFakeStatisticsProvider fake_statistics_provider_; |
| 254 chromeos::FakeSessionManagerClient fake_session_manager_client_; | 256 chromeos::FakeSessionManagerClient fake_session_manager_client_; |
| 255 chromeos::FakeCryptohomeClient* fake_cryptohome_client_; | 257 chromeos::FakeCryptohomeClient* fake_cryptohome_client_; |
| 258 policy::FakeSigningService fake_signing_service_; |
| 256 ServerBackedStateKeysBroker state_keys_broker_; | 259 ServerBackedStateKeysBroker state_keys_broker_; |
| 257 | 260 |
| 258 DeviceCloudPolicyStoreChromeOS* store_; | 261 DeviceCloudPolicyStoreChromeOS* store_; |
| 259 SchemaRegistry schema_registry_; | 262 SchemaRegistry schema_registry_; |
| 260 std::unique_ptr<TestingDeviceCloudPolicyManagerChromeOS> manager_; | 263 std::unique_ptr<TestingDeviceCloudPolicyManagerChromeOS> manager_; |
| 261 std::unique_ptr<DeviceCloudPolicyInitializer> initializer_; | 264 std::unique_ptr<DeviceCloudPolicyInitializer> initializer_; |
| 262 private: | 265 private: |
| 263 DISALLOW_COPY_AND_ASSIGN(DeviceCloudPolicyManagerChromeOSTest); | 266 DISALLOW_COPY_AND_ASSIGN(DeviceCloudPolicyManagerChromeOSTest); |
| 264 }; | 267 }; |
| 265 | 268 |
| (...skipping 121 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 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 |
| 601 DeviceManagementStatus register_status_; | 624 DeviceManagementStatus register_status_; |
| 602 em::DeviceManagementResponse register_response_; | 625 em::DeviceManagementResponse register_response_; |
| 603 | 626 |
| 604 DeviceManagementStatus policy_fetch_status_; | 627 DeviceManagementStatus policy_fetch_status_; |
| 605 em::DeviceManagementResponse policy_fetch_response_; | 628 em::DeviceManagementResponse policy_fetch_response_; |
| 606 | 629 |
| 607 DeviceManagementStatus robot_auth_fetch_status_; | 630 DeviceManagementStatus robot_auth_fetch_status_; |
| 608 em::DeviceManagementResponse robot_auth_fetch_response_; | 631 em::DeviceManagementResponse robot_auth_fetch_response_; |
| 609 | 632 |
| 610 bool store_result_; | 633 bool store_result_; |
| 611 std::string loaded_blob_; | 634 std::string loaded_blob_; |
| 612 | 635 |
| 613 em::DeviceManagementRequest register_request_; | 636 em::DeviceManagementRequest register_request_; |
| 614 std::string client_id_; | 637 std::string client_id_; |
| 615 EnrollmentStatus status_; | 638 EnrollmentStatus status_; |
| 616 | 639 |
| 617 bool done_; | 640 bool done_; |
| 618 | 641 |
| 619 private: | 642 private: |
| 620 DISALLOW_COPY_AND_ASSIGN(DeviceCloudPolicyManagerChromeOSEnrollmentTest); | 643 DISALLOW_COPY_AND_ASSIGN(DeviceCloudPolicyManagerChromeOSEnrollmentTest); |
| 621 }; | 644 }; |
| 622 | 645 |
| 623 // TODO(drcrash): Handle cert-based tests (http://crbug.com/641447). | 646 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(); | 647 RunTest(); |
| 641 ExpectSuccessfulEnrollment(); | 648 ExpectSuccessfulEnrollment(); |
| 642 } | 649 } |
| 643 | 650 |
| 644 TEST_P(ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest, | 651 TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, Reenrollment) { |
| 645 RegistrationFailed) { | 652 LockDevice(); |
| 653 RunTest(); |
| 654 ExpectSuccessfulEnrollment(); |
| 655 EXPECT_TRUE(GetDeviceRegisterRequest().reregister()); |
| 656 EXPECT_EQ(PolicyBuilder::kFakeDeviceId, client_id_); |
| 657 } |
| 658 |
| 659 TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, RegistrationFailed) { |
| 646 register_status_ = DM_STATUS_REQUEST_FAILED; | 660 register_status_ = DM_STATUS_REQUEST_FAILED; |
| 647 RunTest(); | 661 RunTest(); |
| 648 ExpectFailedEnrollment(EnrollmentStatus::STATUS_REGISTRATION_FAILED); | 662 ExpectFailedEnrollment(EnrollmentStatus::STATUS_REGISTRATION_FAILED); |
| 649 EXPECT_EQ(DM_STATUS_REQUEST_FAILED, status_.client_status()); | 663 EXPECT_EQ(DM_STATUS_REQUEST_FAILED, status_.client_status()); |
| 650 } | 664 } |
| 651 | 665 |
| 652 TEST_P(ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest, | 666 TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, |
| 653 RobotAuthCodeFetchFailed) { | 667 RobotAuthCodeFetchFailed) { |
| 654 robot_auth_fetch_status_ = DM_STATUS_REQUEST_FAILED; | 668 robot_auth_fetch_status_ = DM_STATUS_REQUEST_FAILED; |
| 655 RunTest(); | 669 RunTest(); |
| 656 ExpectFailedEnrollment(EnrollmentStatus::STATUS_ROBOT_AUTH_FETCH_FAILED); | 670 ExpectFailedEnrollment(EnrollmentStatus::STATUS_ROBOT_AUTH_FETCH_FAILED); |
| 657 } | 671 } |
| 658 | 672 |
| 659 TEST_P(ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest, | 673 TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, |
| 660 RobotRefreshTokenFetchResponseCodeFailed) { | 674 RobotRefreshTokenFetchResponseCodeFailed) { |
| 661 url_fetcher_response_code_ = 400; | 675 url_fetcher_response_code_ = 400; |
| 662 RunTest(); | 676 RunTest(); |
| 663 ExpectFailedEnrollment(EnrollmentStatus::STATUS_ROBOT_REFRESH_FETCH_FAILED); | 677 ExpectFailedEnrollment(EnrollmentStatus::STATUS_ROBOT_REFRESH_FETCH_FAILED); |
| 664 EXPECT_EQ(400, status_.http_status()); | 678 EXPECT_EQ(400, status_.http_status()); |
| 665 } | 679 } |
| 666 | 680 |
| 667 TEST_P(ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest, | 681 TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, |
| 668 RobotRefreshTokenFetchResponseStringFailed) { | 682 RobotRefreshTokenFetchResponseStringFailed) { |
| 669 url_fetcher_response_string_ = "invalid response json"; | 683 url_fetcher_response_string_ = "invalid response json"; |
| 670 RunTest(); | 684 RunTest(); |
| 671 ExpectFailedEnrollment(EnrollmentStatus::STATUS_ROBOT_REFRESH_FETCH_FAILED); | 685 ExpectFailedEnrollment(EnrollmentStatus::STATUS_ROBOT_REFRESH_FETCH_FAILED); |
| 672 } | 686 } |
| 673 | 687 |
| 674 TEST_P(ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest, | 688 TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, |
| 675 RobotRefreshEncryptionFailed) { | 689 RobotRefreshEncryptionFailed) { |
| 676 // The encryption lib is a noop for tests, but empty results from encryption | 690 // 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 | 691 // is an error, so we simulate an encryption error by returning an empty |
| 678 // refresh token. | 692 // refresh token. |
| 679 url_fetcher_response_string_ = "{\"access_token\":\"accessToken4Test\"," | 693 url_fetcher_response_string_ = "{\"access_token\":\"accessToken4Test\"," |
| 680 "\"expires_in\":1234," | 694 "\"expires_in\":1234," |
| 681 "\"refresh_token\":\"\"}"; | 695 "\"refresh_token\":\"\"}"; |
| 682 RunTest(); | 696 RunTest(); |
| 683 ExpectFailedEnrollment(EnrollmentStatus::STATUS_ROBOT_REFRESH_STORE_FAILED); | 697 ExpectFailedEnrollment(EnrollmentStatus::STATUS_ROBOT_REFRESH_STORE_FAILED); |
| 684 } | 698 } |
| 685 | 699 |
| 686 TEST_P(ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest, | 700 TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, PolicyFetchFailed) { |
| 687 PolicyFetchFailed) { | |
| 688 policy_fetch_status_ = DM_STATUS_REQUEST_FAILED; | 701 policy_fetch_status_ = DM_STATUS_REQUEST_FAILED; |
| 689 RunTest(); | 702 RunTest(); |
| 690 ExpectFailedEnrollment(EnrollmentStatus::STATUS_POLICY_FETCH_FAILED); | 703 ExpectFailedEnrollment(EnrollmentStatus::STATUS_POLICY_FETCH_FAILED); |
| 691 EXPECT_EQ(DM_STATUS_REQUEST_FAILED, status_.client_status()); | 704 EXPECT_EQ(DM_STATUS_REQUEST_FAILED, status_.client_status()); |
| 692 } | 705 } |
| 693 | 706 |
| 694 TEST_P(ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest, | 707 TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, ValidationFailed) { |
| 695 ValidationFailed) { | |
| 696 device_policy_.policy().set_policy_data_signature("bad"); | 708 device_policy_.policy().set_policy_data_signature("bad"); |
| 697 policy_fetch_response_.clear_policy_response(); | 709 policy_fetch_response_.clear_policy_response(); |
| 698 policy_fetch_response_.mutable_policy_response()->add_response()->CopyFrom( | 710 policy_fetch_response_.mutable_policy_response()->add_response()->CopyFrom( |
| 699 device_policy_.policy()); | 711 device_policy_.policy()); |
| 700 RunTest(); | 712 RunTest(); |
| 701 ExpectFailedEnrollment(EnrollmentStatus::STATUS_VALIDATION_FAILED); | 713 ExpectFailedEnrollment(EnrollmentStatus::STATUS_VALIDATION_FAILED); |
| 702 EXPECT_EQ(CloudPolicyValidatorBase::VALIDATION_BAD_INITIAL_SIGNATURE, | 714 EXPECT_EQ(CloudPolicyValidatorBase::VALIDATION_BAD_INITIAL_SIGNATURE, |
| 703 status_.validation_status()); | 715 status_.validation_status()); |
| 704 } | 716 } |
| 705 | 717 |
| 706 TEST_P(ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest, | 718 TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, StoreError) { |
| 707 StoreError) { | |
| 708 store_result_ = false; | 719 store_result_ = false; |
| 709 RunTest(); | 720 RunTest(); |
| 710 ExpectFailedEnrollment(EnrollmentStatus::STATUS_STORE_ERROR); | 721 ExpectFailedEnrollment(EnrollmentStatus::STATUS_STORE_ERROR); |
| 711 EXPECT_EQ(CloudPolicyStore::STATUS_STORE_ERROR, | 722 EXPECT_EQ(CloudPolicyStore::STATUS_STORE_ERROR, |
| 712 status_.store_status()); | 723 status_.store_status()); |
| 713 } | 724 } |
| 714 | 725 |
| 715 TEST_P(ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest, LoadError) { | 726 TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, LoadError) { |
| 716 loaded_blob_.clear(); | 727 loaded_blob_.clear(); |
| 717 RunTest(); | 728 RunTest(); |
| 718 ExpectFailedEnrollment(EnrollmentStatus::STATUS_STORE_ERROR); | 729 ExpectFailedEnrollment(EnrollmentStatus::STATUS_STORE_ERROR); |
| 719 EXPECT_EQ(CloudPolicyStore::STATUS_LOAD_ERROR, | 730 EXPECT_EQ(CloudPolicyStore::STATUS_LOAD_ERROR, |
| 720 status_.store_status()); | 731 status_.store_status()); |
| 721 } | 732 } |
| 722 | 733 |
| 723 TEST_P(ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest, | 734 TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, UnregisterSucceeds) { |
| 724 UnregisterSucceeds) { | |
| 725 // Enroll first. | 735 // Enroll first. |
| 726 RunTest(); | 736 RunTest(); |
| 727 ExpectSuccessfulEnrollment(); | 737 ExpectSuccessfulEnrollment(); |
| 728 | 738 |
| 729 // Set up mock objects for the upcoming unregistration job. | 739 // Set up mock objects for the upcoming unregistration job. |
| 730 em::DeviceManagementResponse response; | 740 em::DeviceManagementResponse response; |
| 731 response.mutable_unregister_response(); | 741 response.mutable_unregister_response(); |
| 732 EXPECT_CALL(device_management_service_, | 742 EXPECT_CALL(device_management_service_, |
| 733 CreateJob(DeviceManagementRequestJob::TYPE_UNREGISTRATION, _)) | 743 CreateJob(DeviceManagementRequestJob::TYPE_UNREGISTRATION, _)) |
| 734 .WillOnce(device_management_service_.SucceedJob(response)); | 744 .WillOnce(device_management_service_.SucceedJob(response)); |
| 735 EXPECT_CALL(device_management_service_, StartJob(_, _, _, _, _, _)); | 745 EXPECT_CALL(device_management_service_, StartJob(_, _, _, _, _, _)); |
| 736 EXPECT_CALL(*this, OnUnregistered(true)); | 746 EXPECT_CALL(*this, OnUnregistered(true)); |
| 737 | 747 |
| 738 // Start unregistering. | 748 // Start unregistering. |
| 739 manager_->Unregister(base::Bind( | 749 manager_->Unregister(base::Bind( |
| 740 &DeviceCloudPolicyManagerChromeOSEnrollmentTest::OnUnregistered, | 750 &DeviceCloudPolicyManagerChromeOSEnrollmentTest::OnUnregistered, |
| 741 base::Unretained(this))); | 751 base::Unretained(this))); |
| 742 } | 752 } |
| 743 | 753 |
| 744 TEST_P(ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest, | 754 TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, UnregisterFails) { |
| 745 UnregisterFails) { | |
| 746 // Enroll first. | 755 // Enroll first. |
| 747 RunTest(); | 756 RunTest(); |
| 748 ExpectSuccessfulEnrollment(); | 757 ExpectSuccessfulEnrollment(); |
| 749 | 758 |
| 750 // Set up mock objects for the upcoming unregistration job. | 759 // Set up mock objects for the upcoming unregistration job. |
| 751 EXPECT_CALL(device_management_service_, | 760 EXPECT_CALL(device_management_service_, |
| 752 CreateJob(DeviceManagementRequestJob::TYPE_UNREGISTRATION, _)) | 761 CreateJob(DeviceManagementRequestJob::TYPE_UNREGISTRATION, _)) |
| 753 .WillOnce(device_management_service_.FailJob(DM_STATUS_REQUEST_FAILED)); | 762 .WillOnce(device_management_service_.FailJob(DM_STATUS_REQUEST_FAILED)); |
| 754 EXPECT_CALL(device_management_service_, StartJob(_, _, _, _, _, _)); | 763 EXPECT_CALL(device_management_service_, StartJob(_, _, _, _, _, _)); |
| 755 EXPECT_CALL(*this, OnUnregistered(false)); | 764 EXPECT_CALL(*this, OnUnregistered(false)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 770 } | 779 } |
| 771 }; | 780 }; |
| 772 | 781 |
| 773 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest, | 782 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest, |
| 774 RobotRefreshSaveFailed) { | 783 RobotRefreshSaveFailed) { |
| 775 // Without the system salt, the robot token can't be stored. | 784 // Without the system salt, the robot token can't be stored. |
| 776 RunTest(); | 785 RunTest(); |
| 777 ExpectFailedEnrollment(EnrollmentStatus::STATUS_ROBOT_REFRESH_STORE_FAILED); | 786 ExpectFailedEnrollment(EnrollmentStatus::STATUS_ROBOT_REFRESH_STORE_FAILED); |
| 778 } | 787 } |
| 779 | 788 |
| 780 INSTANTIATE_TEST_CASE_P( | 789 INSTANTIATE_TEST_CASE_P(Cert, |
| 781 Cert, | 790 DeviceCloudPolicyManagerChromeOSEnrollmentTest, |
| 782 ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest, | 791 ::testing::Values(false, true)); |
| 783 ::testing::Values(false, true)); | |
| 784 | 792 |
| 785 } // namespace | 793 } // namespace |
| 786 } // namespace policy | 794 } // namespace policy |
| OLD | NEW |