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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 : public DeviceCloudPolicyManagerChromeOSTest { | 287 : public DeviceCloudPolicyManagerChromeOSTest { |
287 public: | 288 public: |
288 void Done(EnrollmentStatus status) { | 289 void Done(EnrollmentStatus status) { |
289 status_ = status; | 290 status_ = status; |
290 done_ = true; | 291 done_ = true; |
291 } | 292 } |
292 | 293 |
293 protected: | 294 protected: |
294 DeviceCloudPolicyManagerChromeOSEnrollmentTest() | 295 DeviceCloudPolicyManagerChromeOSEnrollmentTest() |
295 : is_auto_enrollment_(false), | 296 : is_auto_enrollment_(false), |
296 management_mode_(em::PolicyData::ENTERPRISE_MANAGED), | 297 management_mode_(MANAGEMENT_MODE_ENTERPRISE), |
297 register_status_(DM_STATUS_SUCCESS), | 298 register_status_(DM_STATUS_SUCCESS), |
298 policy_fetch_status_(DM_STATUS_SUCCESS), | 299 policy_fetch_status_(DM_STATUS_SUCCESS), |
299 robot_auth_fetch_status_(DM_STATUS_SUCCESS), | 300 robot_auth_fetch_status_(DM_STATUS_SUCCESS), |
300 store_result_(true), | 301 store_result_(true), |
301 status_(EnrollmentStatus::ForStatus(EnrollmentStatus::STATUS_SUCCESS)), | 302 status_(EnrollmentStatus::ForStatus(EnrollmentStatus::STATUS_SUCCESS)), |
302 done_(false) {} | 303 done_(false) {} |
303 | 304 |
304 virtual void SetUp() override { | 305 virtual void SetUp() override { |
305 DeviceCloudPolicyManagerChromeOSTest::SetUp(); | 306 DeviceCloudPolicyManagerChromeOSTest::SetUp(); |
306 | 307 |
(...skipping 28 matching lines...) Expand all Loading... |
335 EXPECT_FALSE(store_->is_managed()); | 336 EXPECT_FALSE(store_->is_managed()); |
336 PolicyBundle empty_bundle; | 337 PolicyBundle empty_bundle; |
337 EXPECT_TRUE(manager_->policies().Equals(empty_bundle)); | 338 EXPECT_TRUE(manager_->policies().Equals(empty_bundle)); |
338 } | 339 } |
339 | 340 |
340 void ExpectSuccessfulEnrollment() { | 341 void ExpectSuccessfulEnrollment() { |
341 EXPECT_EQ(EnrollmentStatus::STATUS_SUCCESS, status_.status()); | 342 EXPECT_EQ(EnrollmentStatus::STATUS_SUCCESS, status_.status()); |
342 ASSERT_TRUE(manager_->core()->client()); | 343 ASSERT_TRUE(manager_->core()->client()); |
343 EXPECT_TRUE(manager_->core()->client()->is_registered()); | 344 EXPECT_TRUE(manager_->core()->client()->is_registered()); |
344 | 345 |
345 if (management_mode_ != em::PolicyData::CONSUMER_MANAGED) { | 346 if (management_mode_ != MANAGEMENT_MODE_CONSUMER) { |
346 EXPECT_EQ(DEVICE_MODE_ENTERPRISE, install_attributes_->GetMode()); | 347 EXPECT_EQ(DEVICE_MODE_ENTERPRISE, install_attributes_->GetMode()); |
347 EXPECT_TRUE(store_->has_policy()); | 348 EXPECT_TRUE(store_->has_policy()); |
348 EXPECT_TRUE(store_->is_managed()); | 349 EXPECT_TRUE(store_->is_managed()); |
349 VerifyPolicyPopulated(); | 350 VerifyPolicyPopulated(); |
350 } | 351 } |
351 } | 352 } |
352 | 353 |
353 void RunTest() { | 354 void RunTest() { |
354 // Trigger enrollment. | 355 // Trigger enrollment. |
355 MockDeviceManagementJob* register_job = NULL; | 356 MockDeviceManagementJob* register_job = NULL; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 net::TestURLFetcher* url_fetcher = url_fetcher_factory_.GetFetcherByID( | 432 net::TestURLFetcher* url_fetcher = url_fetcher_factory_.GetFetcherByID( |
432 gaia::GaiaOAuthClient::kUrlFetcherId); | 433 gaia::GaiaOAuthClient::kUrlFetcherId); |
433 ASSERT_TRUE(url_fetcher); | 434 ASSERT_TRUE(url_fetcher); |
434 url_fetcher->SetMaxRetriesOn5xx(0); | 435 url_fetcher->SetMaxRetriesOn5xx(0); |
435 url_fetcher->set_status(net::URLRequestStatus()); | 436 url_fetcher->set_status(net::URLRequestStatus()); |
436 url_fetcher->set_response_code(url_fetcher_response_code_); | 437 url_fetcher->set_response_code(url_fetcher_response_code_); |
437 url_fetcher->SetResponseString(url_fetcher_response_string_); | 438 url_fetcher->SetResponseString(url_fetcher_response_string_); |
438 url_fetcher->delegate()->OnURLFetchComplete(url_fetcher); | 439 url_fetcher->delegate()->OnURLFetchComplete(url_fetcher); |
439 } | 440 } |
440 | 441 |
441 if (management_mode_ == em::PolicyData::CONSUMER_MANAGED) | 442 if (management_mode_ == MANAGEMENT_MODE_CONSUMER) |
442 FlushDeviceSettings(); | 443 FlushDeviceSettings(); |
443 else | 444 else |
444 base::RunLoop().RunUntilIdle(); | 445 base::RunLoop().RunUntilIdle(); |
445 | 446 |
446 if (done_) | 447 if (done_) |
447 return; | 448 return; |
448 | 449 |
449 // Process robot refresh token store. | 450 // Process robot refresh token store. |
450 chromeos::DeviceOAuth2TokenService* token_service = | 451 chromeos::DeviceOAuth2TokenService* token_service = |
451 chromeos::DeviceOAuth2TokenServiceFactory::Get(); | 452 chromeos::DeviceOAuth2TokenServiceFactory::Get(); |
(...skipping 10 matching lines...) Expand all Loading... |
462 return; | 463 return; |
463 | 464 |
464 // Key installation and policy load. | 465 // Key installation and policy load. |
465 device_settings_test_helper_.set_policy_blob(loaded_blob_); | 466 device_settings_test_helper_.set_policy_blob(loaded_blob_); |
466 owner_key_util_->SetPublicKeyFromPrivateKey( | 467 owner_key_util_->SetPublicKeyFromPrivateKey( |
467 *device_policy_.GetNewSigningKey()); | 468 *device_policy_.GetNewSigningKey()); |
468 ReloadDeviceSettings(); | 469 ReloadDeviceSettings(); |
469 } | 470 } |
470 | 471 |
471 bool is_auto_enrollment_; | 472 bool is_auto_enrollment_; |
472 em::PolicyData::ManagementMode management_mode_; | 473 ManagementMode management_mode_; |
473 | 474 |
474 DeviceManagementStatus register_status_; | 475 DeviceManagementStatus register_status_; |
475 em::DeviceManagementResponse register_response_; | 476 em::DeviceManagementResponse register_response_; |
476 | 477 |
477 DeviceManagementStatus policy_fetch_status_; | 478 DeviceManagementStatus policy_fetch_status_; |
478 em::DeviceManagementResponse policy_fetch_response_; | 479 em::DeviceManagementResponse policy_fetch_response_; |
479 | 480 |
480 DeviceManagementStatus robot_auth_fetch_status_; | 481 DeviceManagementStatus robot_auth_fetch_status_; |
481 em::DeviceManagementResponse robot_auth_fetch_response_; | 482 em::DeviceManagementResponse robot_auth_fetch_response_; |
482 | 483 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentTest, LoadError) { | 585 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentTest, LoadError) { |
585 loaded_blob_.clear(); | 586 loaded_blob_.clear(); |
586 RunTest(); | 587 RunTest(); |
587 ExpectFailedEnrollment(EnrollmentStatus::STATUS_STORE_ERROR); | 588 ExpectFailedEnrollment(EnrollmentStatus::STATUS_STORE_ERROR); |
588 EXPECT_EQ(CloudPolicyStore::STATUS_LOAD_ERROR, | 589 EXPECT_EQ(CloudPolicyStore::STATUS_LOAD_ERROR, |
589 status_.store_status()); | 590 status_.store_status()); |
590 } | 591 } |
591 | 592 |
592 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentTest, | 593 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentTest, |
593 SuccessfulConsumerManagementEnrollment) { | 594 SuccessfulConsumerManagementEnrollment) { |
594 management_mode_ = em::PolicyData::CONSUMER_MANAGED; | 595 management_mode_ = MANAGEMENT_MODE_CONSUMER; |
595 owner_key_util_->SetPrivateKey(device_policy_.GetSigningKey()); | 596 owner_key_util_->SetPrivateKey(device_policy_.GetSigningKey()); |
596 InitOwner(device_policy_.policy_data().username(), true); | 597 InitOwner(device_policy_.policy_data().username(), true); |
597 FlushDeviceSettings(); | 598 FlushDeviceSettings(); |
598 | 599 |
599 RunTest(); | 600 RunTest(); |
600 ExpectSuccessfulEnrollment(); | 601 ExpectSuccessfulEnrollment(); |
601 } | 602 } |
602 | 603 |
603 // A subclass that runs with a blank system salt. | 604 // A subclass that runs with a blank system salt. |
604 class DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest | 605 class DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest |
605 : public DeviceCloudPolicyManagerChromeOSEnrollmentTest { | 606 : public DeviceCloudPolicyManagerChromeOSEnrollmentTest { |
606 protected: | 607 protected: |
607 DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest() { | 608 DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest() { |
608 // Set up a FakeCryptohomeClient with a blank system salt. | 609 // Set up a FakeCryptohomeClient with a blank system salt. |
609 fake_cryptohome_client_->set_system_salt(std::vector<uint8>()); | 610 fake_cryptohome_client_->set_system_salt(std::vector<uint8>()); |
610 } | 611 } |
611 }; | 612 }; |
612 | 613 |
613 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest, | 614 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest, |
614 RobotRefreshSaveFailed) { | 615 RobotRefreshSaveFailed) { |
615 // Without the system salt, the robot token can't be stored. | 616 // Without the system salt, the robot token can't be stored. |
616 RunTest(); | 617 RunTest(); |
617 ExpectFailedEnrollment(EnrollmentStatus::STATUS_ROBOT_REFRESH_STORE_FAILED); | 618 ExpectFailedEnrollment(EnrollmentStatus::STATUS_ROBOT_REFRESH_STORE_FAILED); |
618 } | 619 } |
619 | 620 |
620 } // namespace | 621 } // namespace |
621 } // namespace policy | 622 } // namespace policy |
OLD | NEW |