Chromium Code Reviews| 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 <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 15 #include "base/prefs/pref_registry_simple.h" | 15 #include "base/prefs/pref_registry_simple.h" |
| 16 #include "base/prefs/testing_pref_service.h" | 16 #include "base/prefs/testing_pref_service.h" |
| 17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| 18 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" | 18 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" |
| 19 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h" | 19 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h" |
| 20 #include "chrome/browser/chromeos/policy/device_cloud_policy_initializer.h" | 20 #include "chrome/browser/chromeos/policy/device_cloud_policy_initializer.h" |
| 21 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h" | 21 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h" |
| 22 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" | 22 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" |
| 23 #include "chrome/browser/chromeos/policy/fake_consumer_management_service.h" | |
|
bartfab (slow)
2014/12/15 15:35:50
Nit: No longer used.
davidyu
2014/12/26 08:17:19
Done.
| |
| 23 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" | 24 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" |
| 24 #include "chrome/browser/chromeos/settings/cros_settings.h" | 25 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 25 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" | 26 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" |
| 26 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h " | 27 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h " |
| 27 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 28 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| 28 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" | 29 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" |
| 29 #include "chrome/browser/prefs/browser_prefs.h" | 30 #include "chrome/browser/prefs/browser_prefs.h" |
| 30 #include "chrome/test/base/testing_browser_process.h" | 31 #include "chrome/test/base/testing_browser_process.h" |
| 31 #include "chrome/test/base/testing_profile.h" | 32 #include "chrome/test/base/testing_profile.h" |
| 32 #include "chromeos/cryptohome/system_salt_getter.h" | 33 #include "chromeos/cryptohome/system_salt_getter.h" |
| 33 #include "chromeos/dbus/dbus_client_implementation_type.h" | 34 #include "chromeos/dbus/dbus_client_implementation_type.h" |
| 34 #include "chromeos/dbus/dbus_thread_manager.h" | 35 #include "chromeos/dbus/dbus_thread_manager.h" |
| 35 #include "chromeos/dbus/fake_cryptohome_client.h" | 36 #include "chromeos/dbus/fake_cryptohome_client.h" |
| 36 #include "chromeos/dbus/fake_session_manager_client.h" | 37 #include "chromeos/dbus/fake_session_manager_client.h" |
| 37 #include "chromeos/system/fake_statistics_provider.h" | 38 #include "chromeos/system/fake_statistics_provider.h" |
| 38 #include "chromeos/system/statistics_provider.h" | 39 #include "chromeos/system/statistics_provider.h" |
| 39 #include "components/policy/core/common/cloud/cloud_policy_client.h" | 40 #include "components/policy/core/common/cloud/cloud_policy_client.h" |
| 40 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | 41 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
| 42 #include "components/policy/core/common/cloud/cloud_policy_core.h" | |
| 41 #include "components/policy/core/common/cloud/mock_device_management_service.h" | 43 #include "components/policy/core/common/cloud/mock_device_management_service.h" |
| 42 #include "components/policy/core/common/external_data_fetcher.h" | 44 #include "components/policy/core/common/external_data_fetcher.h" |
| 43 #include "components/policy/core/common/schema_registry.h" | 45 #include "components/policy/core/common/schema_registry.h" |
| 44 #include "google_apis/gaia/gaia_oauth_client.h" | 46 #include "google_apis/gaia/gaia_oauth_client.h" |
| 45 #include "net/url_request/test_url_fetcher_factory.h" | 47 #include "net/url_request/test_url_fetcher_factory.h" |
| 46 #include "net/url_request/url_request_test_util.h" | 48 #include "net/url_request/url_request_test_util.h" |
| 47 #include "policy/policy_constants.h" | 49 #include "policy/policy_constants.h" |
| 48 #include "policy/proto/device_management_backend.pb.h" | 50 #include "policy/proto/device_management_backend.pb.h" |
| 49 #include "testing/gmock/include/gmock/gmock.h" | 51 #include "testing/gmock/include/gmock/gmock.h" |
| 50 #include "testing/gtest/include/gtest/gtest.h" | 52 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | 191 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) |
| 190 .Set(key::kDeviceMetricsReportingEnabled, | 192 .Set(key::kDeviceMetricsReportingEnabled, |
| 191 POLICY_LEVEL_MANDATORY, | 193 POLICY_LEVEL_MANDATORY, |
| 192 POLICY_SCOPE_MACHINE, | 194 POLICY_SCOPE_MACHINE, |
| 193 new base::FundamentalValue(false), | 195 new base::FundamentalValue(false), |
| 194 NULL); | 196 NULL); |
| 195 EXPECT_TRUE(manager_->policies().Equals(bundle)); | 197 EXPECT_TRUE(manager_->policies().Equals(bundle)); |
| 196 } | 198 } |
| 197 | 199 |
| 198 MOCK_METHOD0(OnDeviceCloudPolicyManagerConnected, void()); | 200 MOCK_METHOD0(OnDeviceCloudPolicyManagerConnected, void()); |
| 201 MOCK_METHOD0(OnDeviceCloudPolicyManagerDisconnected, void()); | |
| 199 | 202 |
| 200 scoped_ptr<EnterpriseInstallAttributes> install_attributes_; | 203 scoped_ptr<EnterpriseInstallAttributes> install_attributes_; |
| 201 | 204 |
| 202 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 205 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
| 203 net::TestURLFetcherFactory url_fetcher_factory_; | 206 net::TestURLFetcherFactory url_fetcher_factory_; |
| 204 int url_fetcher_response_code_; | 207 int url_fetcher_response_code_; |
| 205 string url_fetcher_response_string_; | 208 string url_fetcher_response_string_; |
| 206 TestingPrefServiceSimple local_state_; | 209 TestingPrefServiceSimple local_state_; |
| 207 MockDeviceManagementService device_management_service_; | 210 MockDeviceManagementService device_management_service_; |
| 208 MockDeviceManagementService consumer_device_management_service_; | 211 MockDeviceManagementService consumer_device_management_service_; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 318 | 321 |
| 319 ConnectManager(); | 322 ConnectManager(); |
| 320 EXPECT_TRUE(manager_->policies().Equals(bundle)); | 323 EXPECT_TRUE(manager_->policies().Equals(bundle)); |
| 321 // Should not create a status provider for reporting on consumer devices. | 324 // Should not create a status provider for reporting on consumer devices. |
| 322 EXPECT_FALSE(manager_->HasStatusProvider()); | 325 EXPECT_FALSE(manager_->HasStatusProvider()); |
| 323 | 326 |
| 324 manager_->Shutdown(); | 327 manager_->Shutdown(); |
| 325 EXPECT_TRUE(manager_->policies().Equals(bundle)); | 328 EXPECT_TRUE(manager_->policies().Equals(bundle)); |
| 326 } | 329 } |
| 327 | 330 |
| 328 TEST_F(DeviceCloudPolicyManagerChromeOSTest, ObserverIsNotifiedOnConnected) { | 331 TEST_F(DeviceCloudPolicyManagerChromeOSTest, ConnectAndDisconnect) { |
| 329 LockDevice(); | 332 LockDevice(); |
| 330 FlushDeviceSettings(); | 333 FlushDeviceSettings(); |
| 334 EXPECT_FALSE(manager_->core()->service()); // Not connected. | |
| 331 | 335 |
| 336 // Connect the manager. | |
| 332 MockDeviceManagementJob* policy_fetch_job = nullptr; | 337 MockDeviceManagementJob* policy_fetch_job = nullptr; |
| 333 EXPECT_CALL(device_management_service_, | 338 EXPECT_CALL(device_management_service_, |
| 334 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH, _)) | 339 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH, _)) |
| 335 .WillOnce(device_management_service_.CreateAsyncJob(&policy_fetch_job)); | 340 .WillOnce(device_management_service_.CreateAsyncJob(&policy_fetch_job)); |
| 336 EXPECT_CALL(device_management_service_, StartJob(_, _, _, _, _, _, _)); | 341 EXPECT_CALL(device_management_service_, StartJob(_, _, _, _, _, _, _)); |
| 337 EXPECT_CALL(*this, OnDeviceCloudPolicyManagerConnected()); | 342 EXPECT_CALL(*this, OnDeviceCloudPolicyManagerConnected()); |
| 338 | |
| 339 ConnectManager(); | 343 ConnectManager(); |
| 340 base::RunLoop().RunUntilIdle(); | 344 base::RunLoop().RunUntilIdle(); |
| 345 Mock::VerifyAndClearExpectations(&device_management_service_); | |
| 346 Mock::VerifyAndClearExpectations(this); | |
| 347 EXPECT_TRUE(manager_->core()->service()); // Connected. | |
| 348 | |
| 349 // Disconnect the manager. | |
| 350 EXPECT_CALL(*this, OnDeviceCloudPolicyManagerDisconnected()); | |
| 351 manager_->Disconnect(); | |
| 352 EXPECT_FALSE(manager_->core()->service()); // Not connnected. | |
| 341 } | 353 } |
| 342 | 354 |
| 343 class DeviceCloudPolicyManagerChromeOSEnrollmentTest | 355 class DeviceCloudPolicyManagerChromeOSEnrollmentTest |
| 344 : public DeviceCloudPolicyManagerChromeOSTest { | 356 : public DeviceCloudPolicyManagerChromeOSTest { |
| 345 public: | 357 public: |
| 346 void Done(EnrollmentStatus status) { | 358 void Done(EnrollmentStatus status) { |
| 347 status_ = status; | 359 status_ = status; |
| 348 done_ = true; | 360 done_ = true; |
| 349 } | 361 } |
| 350 | 362 |
| 363 MOCK_METHOD1(OnUnregistered, void(bool)); | |
| 364 | |
| 351 protected: | 365 protected: |
| 352 DeviceCloudPolicyManagerChromeOSEnrollmentTest() | 366 DeviceCloudPolicyManagerChromeOSEnrollmentTest() |
| 353 : management_mode_(MANAGEMENT_MODE_ENTERPRISE_MANAGED), | 367 : management_mode_(MANAGEMENT_MODE_ENTERPRISE_MANAGED), |
| 354 register_status_(DM_STATUS_SUCCESS), | 368 register_status_(DM_STATUS_SUCCESS), |
| 355 policy_fetch_status_(DM_STATUS_SUCCESS), | 369 policy_fetch_status_(DM_STATUS_SUCCESS), |
| 356 robot_auth_fetch_status_(DM_STATUS_SUCCESS), | 370 robot_auth_fetch_status_(DM_STATUS_SUCCESS), |
| 357 store_result_(true), | 371 store_result_(true), |
| 358 status_(EnrollmentStatus::ForStatus(EnrollmentStatus::STATUS_SUCCESS)), | 372 status_(EnrollmentStatus::ForStatus(EnrollmentStatus::STATUS_SUCCESS)), |
| 359 done_(false) {} | 373 done_(false) {} |
| 360 | 374 |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 652 | 666 |
| 653 device_policy_.policy_data().set_management_mode(em::PolicyData::LOCAL_OWNER); | 667 device_policy_.policy_data().set_management_mode(em::PolicyData::LOCAL_OWNER); |
| 654 device_policy_.Build(); | 668 device_policy_.Build(); |
| 655 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); | 669 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); |
| 656 ReloadDeviceSettings(); | 670 ReloadDeviceSettings(); |
| 657 | 671 |
| 658 RunTest(); | 672 RunTest(); |
| 659 ExpectSuccessfulEnrollment(); | 673 ExpectSuccessfulEnrollment(); |
| 660 } | 674 } |
| 661 | 675 |
| 676 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentTest, UnregisterSucceeds) { | |
| 677 // Enroll first. | |
| 678 RunTest(); | |
| 679 ExpectSuccessfulEnrollment(); | |
| 680 | |
| 681 // Set up mock objects for the upcoming unregistration job. | |
| 682 em::DeviceManagementResponse response; | |
| 683 response.mutable_unregister_response(); | |
| 684 EXPECT_CALL(device_management_service_, | |
| 685 CreateJob(DeviceManagementRequestJob::TYPE_UNREGISTRATION, _)) | |
| 686 .WillOnce(device_management_service_.SucceedJob(response)); | |
| 687 EXPECT_CALL(device_management_service_, StartJob(_, _, _, _, _, _, _)); | |
| 688 EXPECT_CALL(*this, OnUnregistered(true)); | |
| 689 | |
| 690 // Start unregistering. | |
| 691 manager_->Unregister(base::Bind( | |
| 692 &DeviceCloudPolicyManagerChromeOSEnrollmentTest::OnUnregistered, | |
| 693 base::Unretained(this))); | |
| 694 } | |
| 695 | |
| 696 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentTest, UnregisterFails) { | |
| 697 // Enroll first. | |
| 698 RunTest(); | |
| 699 ExpectSuccessfulEnrollment(); | |
| 700 | |
| 701 // Set up mock objects for the upcoming unregistration job. | |
| 702 EXPECT_CALL(device_management_service_, | |
| 703 CreateJob(DeviceManagementRequestJob::TYPE_UNREGISTRATION, _)) | |
| 704 .WillOnce(device_management_service_.FailJob(DM_STATUS_REQUEST_FAILED)); | |
| 705 EXPECT_CALL(device_management_service_, StartJob(_, _, _, _, _, _, _)); | |
| 706 EXPECT_CALL(*this, OnUnregistered(false)); | |
| 707 | |
| 708 // Start unregistering. | |
| 709 manager_->Unregister(base::Bind( | |
| 710 &DeviceCloudPolicyManagerChromeOSEnrollmentTest::OnUnregistered, | |
| 711 base::Unretained(this))); | |
| 712 } | |
| 713 | |
| 662 // A subclass that runs with a blank system salt. | 714 // A subclass that runs with a blank system salt. |
| 663 class DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest | 715 class DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest |
| 664 : public DeviceCloudPolicyManagerChromeOSEnrollmentTest { | 716 : public DeviceCloudPolicyManagerChromeOSEnrollmentTest { |
| 665 protected: | 717 protected: |
| 666 DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest() { | 718 DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest() { |
| 667 // Set up a FakeCryptohomeClient with a blank system salt. | 719 // Set up a FakeCryptohomeClient with a blank system salt. |
| 668 fake_cryptohome_client_->set_system_salt(std::vector<uint8>()); | 720 fake_cryptohome_client_->set_system_salt(std::vector<uint8>()); |
| 669 } | 721 } |
| 670 }; | 722 }; |
| 671 | 723 |
| 672 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest, | 724 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest, |
| 673 RobotRefreshSaveFailed) { | 725 RobotRefreshSaveFailed) { |
| 674 // Without the system salt, the robot token can't be stored. | 726 // Without the system salt, the robot token can't be stored. |
| 675 RunTest(); | 727 RunTest(); |
| 676 ExpectFailedEnrollment(EnrollmentStatus::STATUS_ROBOT_REFRESH_STORE_FAILED); | 728 ExpectFailedEnrollment(EnrollmentStatus::STATUS_ROBOT_REFRESH_STORE_FAILED); |
| 677 } | 729 } |
| 678 | 730 |
| 679 } // namespace | 731 } // namespace |
| 680 } // namespace policy | 732 } // namespace policy |
| OLD | NEW |