| 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" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "chrome/browser/prefs/browser_prefs.h" | 27 #include "chrome/browser/prefs/browser_prefs.h" |
| 28 #include "chrome/test/base/testing_browser_process.h" | 28 #include "chrome/test/base/testing_browser_process.h" |
| 29 #include "chromeos/cryptohome/system_salt_getter.h" | 29 #include "chromeos/cryptohome/system_salt_getter.h" |
| 30 #include "chromeos/dbus/dbus_client_implementation_type.h" | 30 #include "chromeos/dbus/dbus_client_implementation_type.h" |
| 31 #include "chromeos/dbus/dbus_thread_manager.h" | 31 #include "chromeos/dbus/dbus_thread_manager.h" |
| 32 #include "chromeos/dbus/fake_cryptohome_client.h" | 32 #include "chromeos/dbus/fake_cryptohome_client.h" |
| 33 #include "chromeos/dbus/fake_session_manager_client.h" | 33 #include "chromeos/dbus/fake_session_manager_client.h" |
| 34 #include "chromeos/system/fake_statistics_provider.h" | 34 #include "chromeos/system/fake_statistics_provider.h" |
| 35 #include "chromeos/system/statistics_provider.h" | 35 #include "chromeos/system/statistics_provider.h" |
| 36 #include "components/policy/core/common/cloud/cloud_policy_client.h" | 36 #include "components/policy/core/common/cloud/cloud_policy_client.h" |
| 37 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
| 37 #include "components/policy/core/common/cloud/mock_device_management_service.h" | 38 #include "components/policy/core/common/cloud/mock_device_management_service.h" |
| 38 #include "components/policy/core/common/external_data_fetcher.h" | 39 #include "components/policy/core/common/external_data_fetcher.h" |
| 39 #include "components/policy/core/common/schema_registry.h" | 40 #include "components/policy/core/common/schema_registry.h" |
| 40 #include "google_apis/gaia/gaia_oauth_client.h" | 41 #include "google_apis/gaia/gaia_oauth_client.h" |
| 41 #include "net/url_request/test_url_fetcher_factory.h" | 42 #include "net/url_request/test_url_fetcher_factory.h" |
| 42 #include "net/url_request/url_request_test_util.h" | 43 #include "net/url_request/url_request_test_util.h" |
| 43 #include "policy/policy_constants.h" | 44 #include "policy/policy_constants.h" |
| 44 #include "policy/proto/device_management_backend.pb.h" | 45 #include "policy/proto/device_management_backend.pb.h" |
| 45 #include "testing/gmock/include/gmock/gmock.h" | 46 #include "testing/gmock/include/gmock/gmock.h" |
| 46 #include "testing/gtest/include/gtest/gtest.h" | 47 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 : public DeviceCloudPolicyManagerChromeOSTest { | 322 : public DeviceCloudPolicyManagerChromeOSTest { |
| 322 public: | 323 public: |
| 323 void Done(EnrollmentStatus status) { | 324 void Done(EnrollmentStatus status) { |
| 324 status_ = status; | 325 status_ = status; |
| 325 done_ = true; | 326 done_ = true; |
| 326 } | 327 } |
| 327 | 328 |
| 328 protected: | 329 protected: |
| 329 DeviceCloudPolicyManagerChromeOSEnrollmentTest() | 330 DeviceCloudPolicyManagerChromeOSEnrollmentTest() |
| 330 : is_auto_enrollment_(false), | 331 : is_auto_enrollment_(false), |
| 331 management_mode_(em::PolicyData::ENTERPRISE_MANAGED), | 332 management_mode_(MANAGEMENT_MODE_ENTERPRISE_MANAGED), |
| 332 register_status_(DM_STATUS_SUCCESS), | 333 register_status_(DM_STATUS_SUCCESS), |
| 333 policy_fetch_status_(DM_STATUS_SUCCESS), | 334 policy_fetch_status_(DM_STATUS_SUCCESS), |
| 334 robot_auth_fetch_status_(DM_STATUS_SUCCESS), | 335 robot_auth_fetch_status_(DM_STATUS_SUCCESS), |
| 335 store_result_(true), | 336 store_result_(true), |
| 336 status_(EnrollmentStatus::ForStatus(EnrollmentStatus::STATUS_SUCCESS)), | 337 status_(EnrollmentStatus::ForStatus(EnrollmentStatus::STATUS_SUCCESS)), |
| 337 done_(false) {} | 338 done_(false) {} |
| 338 | 339 |
| 339 virtual void SetUp() override { | 340 virtual void SetUp() override { |
| 340 DeviceCloudPolicyManagerChromeOSTest::SetUp(); | 341 DeviceCloudPolicyManagerChromeOSTest::SetUp(); |
| 341 | 342 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 370 EXPECT_FALSE(store_->is_managed()); | 371 EXPECT_FALSE(store_->is_managed()); |
| 371 PolicyBundle empty_bundle; | 372 PolicyBundle empty_bundle; |
| 372 EXPECT_TRUE(manager_->policies().Equals(empty_bundle)); | 373 EXPECT_TRUE(manager_->policies().Equals(empty_bundle)); |
| 373 } | 374 } |
| 374 | 375 |
| 375 void ExpectSuccessfulEnrollment() { | 376 void ExpectSuccessfulEnrollment() { |
| 376 EXPECT_EQ(EnrollmentStatus::STATUS_SUCCESS, status_.status()); | 377 EXPECT_EQ(EnrollmentStatus::STATUS_SUCCESS, status_.status()); |
| 377 ASSERT_TRUE(manager_->core()->client()); | 378 ASSERT_TRUE(manager_->core()->client()); |
| 378 EXPECT_TRUE(manager_->core()->client()->is_registered()); | 379 EXPECT_TRUE(manager_->core()->client()->is_registered()); |
| 379 | 380 |
| 380 if (management_mode_ != em::PolicyData::CONSUMER_MANAGED) { | 381 if (management_mode_ != MANAGEMENT_MODE_CONSUMER_MANAGED) { |
| 381 EXPECT_EQ(DEVICE_MODE_ENTERPRISE, install_attributes_->GetMode()); | 382 EXPECT_EQ(DEVICE_MODE_ENTERPRISE, install_attributes_->GetMode()); |
| 382 EXPECT_TRUE(store_->has_policy()); | 383 EXPECT_TRUE(store_->has_policy()); |
| 383 EXPECT_TRUE(store_->is_managed()); | 384 EXPECT_TRUE(store_->is_managed()); |
| 384 VerifyPolicyPopulated(); | 385 VerifyPolicyPopulated(); |
| 385 } | 386 } |
| 386 } | 387 } |
| 387 | 388 |
| 388 void RunTest() { | 389 void RunTest() { |
| 389 // Trigger enrollment. | 390 // Trigger enrollment. |
| 390 MockDeviceManagementJob* register_job = NULL; | 391 MockDeviceManagementJob* register_job = NULL; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 net::TestURLFetcher* url_fetcher = url_fetcher_factory_.GetFetcherByID( | 467 net::TestURLFetcher* url_fetcher = url_fetcher_factory_.GetFetcherByID( |
| 467 gaia::GaiaOAuthClient::kUrlFetcherId); | 468 gaia::GaiaOAuthClient::kUrlFetcherId); |
| 468 ASSERT_TRUE(url_fetcher); | 469 ASSERT_TRUE(url_fetcher); |
| 469 url_fetcher->SetMaxRetriesOn5xx(0); | 470 url_fetcher->SetMaxRetriesOn5xx(0); |
| 470 url_fetcher->set_status(net::URLRequestStatus()); | 471 url_fetcher->set_status(net::URLRequestStatus()); |
| 471 url_fetcher->set_response_code(url_fetcher_response_code_); | 472 url_fetcher->set_response_code(url_fetcher_response_code_); |
| 472 url_fetcher->SetResponseString(url_fetcher_response_string_); | 473 url_fetcher->SetResponseString(url_fetcher_response_string_); |
| 473 url_fetcher->delegate()->OnURLFetchComplete(url_fetcher); | 474 url_fetcher->delegate()->OnURLFetchComplete(url_fetcher); |
| 474 } | 475 } |
| 475 | 476 |
| 476 if (management_mode_ == em::PolicyData::CONSUMER_MANAGED) | 477 if (management_mode_ == MANAGEMENT_MODE_CONSUMER_MANAGED) |
| 477 FlushDeviceSettings(); | 478 FlushDeviceSettings(); |
| 478 else | 479 else |
| 479 base::RunLoop().RunUntilIdle(); | 480 base::RunLoop().RunUntilIdle(); |
| 480 | 481 |
| 481 if (done_) | 482 if (done_) |
| 482 return; | 483 return; |
| 483 | 484 |
| 484 // Process robot refresh token store. | 485 // Process robot refresh token store. |
| 485 chromeos::DeviceOAuth2TokenService* token_service = | 486 chromeos::DeviceOAuth2TokenService* token_service = |
| 486 chromeos::DeviceOAuth2TokenServiceFactory::Get(); | 487 chromeos::DeviceOAuth2TokenServiceFactory::Get(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 497 return; | 498 return; |
| 498 | 499 |
| 499 // Key installation and policy load. | 500 // Key installation and policy load. |
| 500 device_settings_test_helper_.set_policy_blob(loaded_blob_); | 501 device_settings_test_helper_.set_policy_blob(loaded_blob_); |
| 501 owner_key_util_->SetPublicKeyFromPrivateKey( | 502 owner_key_util_->SetPublicKeyFromPrivateKey( |
| 502 *device_policy_.GetNewSigningKey()); | 503 *device_policy_.GetNewSigningKey()); |
| 503 ReloadDeviceSettings(); | 504 ReloadDeviceSettings(); |
| 504 } | 505 } |
| 505 | 506 |
| 506 bool is_auto_enrollment_; | 507 bool is_auto_enrollment_; |
| 507 em::PolicyData::ManagementMode management_mode_; | 508 ManagementMode management_mode_; |
| 508 | 509 |
| 509 DeviceManagementStatus register_status_; | 510 DeviceManagementStatus register_status_; |
| 510 em::DeviceManagementResponse register_response_; | 511 em::DeviceManagementResponse register_response_; |
| 511 | 512 |
| 512 DeviceManagementStatus policy_fetch_status_; | 513 DeviceManagementStatus policy_fetch_status_; |
| 513 em::DeviceManagementResponse policy_fetch_response_; | 514 em::DeviceManagementResponse policy_fetch_response_; |
| 514 | 515 |
| 515 DeviceManagementStatus robot_auth_fetch_status_; | 516 DeviceManagementStatus robot_auth_fetch_status_; |
| 516 em::DeviceManagementResponse robot_auth_fetch_response_; | 517 em::DeviceManagementResponse robot_auth_fetch_response_; |
| 517 | 518 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentTest, LoadError) { | 620 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentTest, LoadError) { |
| 620 loaded_blob_.clear(); | 621 loaded_blob_.clear(); |
| 621 RunTest(); | 622 RunTest(); |
| 622 ExpectFailedEnrollment(EnrollmentStatus::STATUS_STORE_ERROR); | 623 ExpectFailedEnrollment(EnrollmentStatus::STATUS_STORE_ERROR); |
| 623 EXPECT_EQ(CloudPolicyStore::STATUS_LOAD_ERROR, | 624 EXPECT_EQ(CloudPolicyStore::STATUS_LOAD_ERROR, |
| 624 status_.store_status()); | 625 status_.store_status()); |
| 625 } | 626 } |
| 626 | 627 |
| 627 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentTest, | 628 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentTest, |
| 628 SuccessfulConsumerManagementEnrollment) { | 629 SuccessfulConsumerManagementEnrollment) { |
| 629 management_mode_ = em::PolicyData::CONSUMER_MANAGED; | 630 management_mode_ = MANAGEMENT_MODE_CONSUMER_MANAGED; |
| 630 owner_key_util_->SetPrivateKey(device_policy_.GetSigningKey()); | 631 owner_key_util_->SetPrivateKey(device_policy_.GetSigningKey()); |
| 631 InitOwner(device_policy_.policy_data().username(), true); | 632 InitOwner(device_policy_.policy_data().username(), true); |
| 632 FlushDeviceSettings(); | 633 FlushDeviceSettings(); |
| 633 | 634 |
| 634 RunTest(); | 635 RunTest(); |
| 635 ExpectSuccessfulEnrollment(); | 636 ExpectSuccessfulEnrollment(); |
| 636 } | 637 } |
| 637 | 638 |
| 638 // A subclass that runs with a blank system salt. | 639 // A subclass that runs with a blank system salt. |
| 639 class DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest | 640 class DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest |
| 640 : public DeviceCloudPolicyManagerChromeOSEnrollmentTest { | 641 : public DeviceCloudPolicyManagerChromeOSEnrollmentTest { |
| 641 protected: | 642 protected: |
| 642 DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest() { | 643 DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest() { |
| 643 // Set up a FakeCryptohomeClient with a blank system salt. | 644 // Set up a FakeCryptohomeClient with a blank system salt. |
| 644 fake_cryptohome_client_->set_system_salt(std::vector<uint8>()); | 645 fake_cryptohome_client_->set_system_salt(std::vector<uint8>()); |
| 645 } | 646 } |
| 646 }; | 647 }; |
| 647 | 648 |
| 648 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest, | 649 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest, |
| 649 RobotRefreshSaveFailed) { | 650 RobotRefreshSaveFailed) { |
| 650 // Without the system salt, the robot token can't be stored. | 651 // Without the system salt, the robot token can't be stored. |
| 651 RunTest(); | 652 RunTest(); |
| 652 ExpectFailedEnrollment(EnrollmentStatus::STATUS_ROBOT_REFRESH_STORE_FAILED); | 653 ExpectFailedEnrollment(EnrollmentStatus::STATUS_ROBOT_REFRESH_STORE_FAILED); |
| 653 } | 654 } |
| 654 | 655 |
| 655 } // namespace | 656 } // namespace |
| 656 } // namespace policy | 657 } // namespace policy |
| OLD | NEW |