| 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_store_chromeos.h" | 5 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" | |
| 16 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" | 15 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" |
| 17 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" | 16 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" |
| 17 #include "chrome/browser/chromeos/settings/install_attributes.h" |
| 18 #include "chrome/test/base/scoped_testing_local_state.h" | 18 #include "chrome/test/base/scoped_testing_local_state.h" |
| 19 #include "chrome/test/base/testing_browser_process.h" | 19 #include "chrome/test/base/testing_browser_process.h" |
| 20 #include "chromeos/cryptohome/cryptohome_util.h" | 20 #include "chromeos/cryptohome/cryptohome_util.h" |
| 21 #include "chromeos/dbus/dbus_thread_manager.h" | 21 #include "chromeos/dbus/dbus_thread_manager.h" |
| 22 #include "chromeos/dbus/fake_cryptohome_client.h" | 22 #include "chromeos/dbus/fake_cryptohome_client.h" |
| 23 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | 23 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
| 24 #include "components/policy/policy_constants.h" | 24 #include "components/policy/policy_constants.h" |
| 25 #include "components/policy/proto/device_management_backend.pb.h" | 25 #include "components/policy/proto/device_management_backend.pb.h" |
| 26 #include "content/public/test/test_utils.h" | 26 #include "content/public/test/test_utils.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 28 | 28 |
| 29 namespace em = enterprise_management; | 29 namespace em = enterprise_management; |
| 30 | 30 |
| 31 namespace policy { | 31 namespace policy { |
| 32 | 32 |
| 33 namespace { | 33 namespace { |
| 34 | 34 |
| 35 void CopyLockResult(base::RunLoop* loop, | 35 void CopyLockResult(base::RunLoop* loop, |
| 36 EnterpriseInstallAttributes::LockResult* out, | 36 chromeos::InstallAttributes::LockResult* out, |
| 37 EnterpriseInstallAttributes::LockResult result) { | 37 chromeos::InstallAttributes::LockResult result) { |
| 38 *out = result; | 38 *out = result; |
| 39 loop->Quit(); | 39 loop->Quit(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 } // namespace | 42 } // namespace |
| 43 | 43 |
| 44 class DeviceCloudPolicyStoreChromeOSTest | 44 class DeviceCloudPolicyStoreChromeOSTest |
| 45 : public chromeos::DeviceSettingsTestBase { | 45 : public chromeos::DeviceSettingsTestBase { |
| 46 protected: | 46 protected: |
| 47 DeviceCloudPolicyStoreChromeOSTest() | 47 DeviceCloudPolicyStoreChromeOSTest() |
| 48 : local_state_(TestingBrowserProcess::GetGlobal()), | 48 : local_state_(TestingBrowserProcess::GetGlobal()), |
| 49 fake_cryptohome_client_(new chromeos::FakeCryptohomeClient()), | 49 fake_cryptohome_client_(new chromeos::FakeCryptohomeClient()), |
| 50 install_attributes_( | 50 install_attributes_( |
| 51 new EnterpriseInstallAttributes(fake_cryptohome_client_)), | 51 new chromeos::InstallAttributes(fake_cryptohome_client_)), |
| 52 store_(new DeviceCloudPolicyStoreChromeOS( | 52 store_(new DeviceCloudPolicyStoreChromeOS( |
| 53 &device_settings_service_, | 53 &device_settings_service_, |
| 54 install_attributes_.get(), | 54 install_attributes_.get(), |
| 55 base::ThreadTaskRunnerHandle::Get())) {} | 55 base::ThreadTaskRunnerHandle::Get())) {} |
| 56 | 56 |
| 57 void SetUp() override { | 57 void SetUp() override { |
| 58 DeviceSettingsTestBase::SetUp(); | 58 DeviceSettingsTestBase::SetUp(); |
| 59 | 59 |
| 60 dbus_setter_->SetCryptohomeClient( | 60 dbus_setter_->SetCryptohomeClient( |
| 61 std::unique_ptr<chromeos::CryptohomeClient>(fake_cryptohome_client_)); | 61 std::unique_ptr<chromeos::CryptohomeClient>(fake_cryptohome_client_)); |
| 62 | 62 |
| 63 base::RunLoop loop; | 63 base::RunLoop loop; |
| 64 EnterpriseInstallAttributes::LockResult result; | 64 chromeos::InstallAttributes::LockResult result; |
| 65 install_attributes_->LockDevice( | 65 install_attributes_->LockDevice( |
| 66 PolicyBuilder::kFakeUsername, | 66 PolicyBuilder::kFakeUsername, |
| 67 DEVICE_MODE_ENTERPRISE, | 67 DEVICE_MODE_ENTERPRISE, |
| 68 PolicyBuilder::kFakeDeviceId, | 68 PolicyBuilder::kFakeDeviceId, |
| 69 base::Bind(&CopyLockResult, &loop, &result)); | 69 base::Bind(&CopyLockResult, &loop, &result)); |
| 70 loop.Run(); | 70 loop.Run(); |
| 71 ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS, result); | 71 ASSERT_EQ(chromeos::InstallAttributes::LOCK_SUCCESS, result); |
| 72 } | 72 } |
| 73 | 73 |
| 74 void ExpectFailure(CloudPolicyStore::Status expected_status) { | 74 void ExpectFailure(CloudPolicyStore::Status expected_status) { |
| 75 EXPECT_EQ(expected_status, store_->status()); | 75 EXPECT_EQ(expected_status, store_->status()); |
| 76 EXPECT_TRUE(store_->is_initialized()); | 76 EXPECT_TRUE(store_->is_initialized()); |
| 77 EXPECT_FALSE(store_->has_policy()); | 77 EXPECT_FALSE(store_->has_policy()); |
| 78 EXPECT_FALSE(store_->is_managed()); | 78 EXPECT_FALSE(store_->is_managed()); |
| 79 } | 79 } |
| 80 | 80 |
| 81 void ExpectSuccess() { | 81 void ExpectSuccess() { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 105 device_policy_.Build(); | 105 device_policy_.Build(); |
| 106 owner_key_util_->SetPublicKeyFromPrivateKey( | 106 owner_key_util_->SetPublicKeyFromPrivateKey( |
| 107 *device_policy_.GetNewSigningKey()); | 107 *device_policy_.GetNewSigningKey()); |
| 108 } | 108 } |
| 109 | 109 |
| 110 void ResetToNonEnterprise() { | 110 void ResetToNonEnterprise() { |
| 111 store_.reset(); | 111 store_.reset(); |
| 112 chromeos::cryptohome_util::InstallAttributesSet("enterprise.owned", | 112 chromeos::cryptohome_util::InstallAttributesSet("enterprise.owned", |
| 113 std::string()); | 113 std::string()); |
| 114 install_attributes_.reset( | 114 install_attributes_.reset( |
| 115 new EnterpriseInstallAttributes(fake_cryptohome_client_)); | 115 new chromeos::InstallAttributes(fake_cryptohome_client_)); |
| 116 store_.reset(new DeviceCloudPolicyStoreChromeOS( | 116 store_.reset(new DeviceCloudPolicyStoreChromeOS( |
| 117 &device_settings_service_, install_attributes_.get(), | 117 &device_settings_service_, install_attributes_.get(), |
| 118 base::ThreadTaskRunnerHandle::Get())); | 118 base::ThreadTaskRunnerHandle::Get())); |
| 119 } | 119 } |
| 120 | 120 |
| 121 ScopedTestingLocalState local_state_; | 121 ScopedTestingLocalState local_state_; |
| 122 chromeos::FakeCryptohomeClient* fake_cryptohome_client_; | 122 chromeos::FakeCryptohomeClient* fake_cryptohome_client_; |
| 123 std::unique_ptr<EnterpriseInstallAttributes> install_attributes_; | 123 std::unique_ptr<chromeos::InstallAttributes> install_attributes_; |
| 124 | 124 |
| 125 std::unique_ptr<DeviceCloudPolicyStoreChromeOS> store_; | 125 std::unique_ptr<DeviceCloudPolicyStoreChromeOS> store_; |
| 126 | 126 |
| 127 private: | 127 private: |
| 128 DISALLOW_COPY_AND_ASSIGN(DeviceCloudPolicyStoreChromeOSTest); | 128 DISALLOW_COPY_AND_ASSIGN(DeviceCloudPolicyStoreChromeOSTest); |
| 129 }; | 129 }; |
| 130 | 130 |
| 131 TEST_F(DeviceCloudPolicyStoreChromeOSTest, LoadNoKey) { | 131 TEST_F(DeviceCloudPolicyStoreChromeOSTest, LoadNoKey) { |
| 132 owner_key_util_->Clear(); | 132 owner_key_util_->Clear(); |
| 133 store_->Load(); | 133 store_->Load(); |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 | 274 |
| 275 TEST_F(DeviceCloudPolicyStoreChromeOSTest, InstallInitialPolicyNotEnterprise) { | 275 TEST_F(DeviceCloudPolicyStoreChromeOSTest, InstallInitialPolicyNotEnterprise) { |
| 276 PrepareNewSigningKey(); | 276 PrepareNewSigningKey(); |
| 277 ResetToNonEnterprise(); | 277 ResetToNonEnterprise(); |
| 278 store_->InstallInitialPolicy(device_policy_.policy()); | 278 store_->InstallInitialPolicy(device_policy_.policy()); |
| 279 FlushDeviceSettings(); | 279 FlushDeviceSettings(); |
| 280 ExpectFailure(CloudPolicyStore::STATUS_BAD_STATE); | 280 ExpectFailure(CloudPolicyStore::STATUS_BAD_STATE); |
| 281 } | 281 } |
| 282 | 282 |
| 283 } // namespace policy | 283 } // namespace policy |
| OLD | NEW |