| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" | 13 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" |
| 14 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" | 14 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" |
| 15 #include "chrome/browser/policy/proto/chromeos/chrome_device_policy.pb.h" | 15 #include "chrome/browser/policy/proto/chromeos/chrome_device_policy.pb.h" |
| 16 #include "chromeos/cryptohome/cryptohome_library.h" | 16 #include "chromeos/cryptohome/cryptohome_library.h" |
| 17 #include "chromeos/dbus/cryptohome_client_stub.h" | 17 #include "chromeos/dbus/fake_cryptohome_client.h" |
| 18 #include "policy/policy_constants.h" | 18 #include "policy/policy_constants.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 20 |
| 21 namespace policy { | 21 namespace policy { |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 void CopyLockResult(base::RunLoop* loop, | 25 void CopyLockResult(base::RunLoop* loop, |
| 26 EnterpriseInstallAttributes::LockResult* out, | 26 EnterpriseInstallAttributes::LockResult* out, |
| 27 EnterpriseInstallAttributes::LockResult result) { | 27 EnterpriseInstallAttributes::LockResult result) { |
| 28 *out = result; | 28 *out = result; |
| 29 loop->Quit(); | 29 loop->Quit(); |
| 30 } | 30 } |
| 31 | 31 |
| 32 } // namespace | 32 } // namespace |
| 33 | 33 |
| 34 class DeviceCloudPolicyStoreChromeOSTest | 34 class DeviceCloudPolicyStoreChromeOSTest |
| 35 : public chromeos::DeviceSettingsTestBase { | 35 : public chromeos::DeviceSettingsTestBase { |
| 36 protected: | 36 protected: |
| 37 DeviceCloudPolicyStoreChromeOSTest() | 37 DeviceCloudPolicyStoreChromeOSTest() |
| 38 : cryptohome_library_(chromeos::CryptohomeLibrary::GetTestImpl()), | 38 : cryptohome_library_(chromeos::CryptohomeLibrary::GetTestImpl()), |
| 39 stub_cryptohome_client_(new chromeos::CryptohomeClientStubImpl()), | 39 fake_cryptohome_client_(new chromeos::FakeCryptohomeClient()), |
| 40 install_attributes_(new EnterpriseInstallAttributes( | 40 install_attributes_(new EnterpriseInstallAttributes( |
| 41 cryptohome_library_.get(), stub_cryptohome_client_.get())), | 41 cryptohome_library_.get(), fake_cryptohome_client_.get())), |
| 42 store_(new DeviceCloudPolicyStoreChromeOS(&device_settings_service_, | 42 store_(new DeviceCloudPolicyStoreChromeOS(&device_settings_service_, |
| 43 install_attributes_.get())) { | 43 install_attributes_.get())) { |
| 44 stub_cryptohome_client_->Init(NULL /* no dbus::Bus */); | 44 fake_cryptohome_client_->Init(NULL /* no dbus::Bus */); |
| 45 } | 45 } |
| 46 | 46 |
| 47 virtual void SetUp() OVERRIDE { | 47 virtual void SetUp() OVERRIDE { |
| 48 DeviceSettingsTestBase::SetUp(); | 48 DeviceSettingsTestBase::SetUp(); |
| 49 | 49 |
| 50 base::RunLoop loop; | 50 base::RunLoop loop; |
| 51 EnterpriseInstallAttributes::LockResult result; | 51 EnterpriseInstallAttributes::LockResult result; |
| 52 install_attributes_->LockDevice( | 52 install_attributes_->LockDevice( |
| 53 PolicyBuilder::kFakeUsername, | 53 PolicyBuilder::kFakeUsername, |
| 54 DEVICE_MODE_ENTERPRISE, | 54 DEVICE_MODE_ENTERPRISE, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 device_policy_.Build(); | 92 device_policy_.Build(); |
| 93 owner_key_util_->SetPublicKeyFromPrivateKey( | 93 owner_key_util_->SetPublicKeyFromPrivateKey( |
| 94 *device_policy_.GetNewSigningKey()); | 94 *device_policy_.GetNewSigningKey()); |
| 95 } | 95 } |
| 96 | 96 |
| 97 void ResetToNonEnterprise() { | 97 void ResetToNonEnterprise() { |
| 98 store_.reset(); | 98 store_.reset(); |
| 99 cryptohome_library_->InstallAttributesSet("enterprise.owned", | 99 cryptohome_library_->InstallAttributesSet("enterprise.owned", |
| 100 std::string()); | 100 std::string()); |
| 101 install_attributes_.reset(new EnterpriseInstallAttributes( | 101 install_attributes_.reset(new EnterpriseInstallAttributes( |
| 102 cryptohome_library_.get(), stub_cryptohome_client_.get())); | 102 cryptohome_library_.get(), fake_cryptohome_client_.get())); |
| 103 store_.reset(new DeviceCloudPolicyStoreChromeOS(&device_settings_service_, | 103 store_.reset(new DeviceCloudPolicyStoreChromeOS(&device_settings_service_, |
| 104 install_attributes_.get())); | 104 install_attributes_.get())); |
| 105 } | 105 } |
| 106 | 106 |
| 107 scoped_ptr<chromeos::CryptohomeLibrary> cryptohome_library_; | 107 scoped_ptr<chromeos::CryptohomeLibrary> cryptohome_library_; |
| 108 scoped_ptr<chromeos::CryptohomeClientStubImpl> stub_cryptohome_client_; | 108 scoped_ptr<chromeos::FakeCryptohomeClient> fake_cryptohome_client_; |
| 109 scoped_ptr<EnterpriseInstallAttributes> install_attributes_; | 109 scoped_ptr<EnterpriseInstallAttributes> install_attributes_; |
| 110 | 110 |
| 111 scoped_ptr<DeviceCloudPolicyStoreChromeOS> store_; | 111 scoped_ptr<DeviceCloudPolicyStoreChromeOS> store_; |
| 112 | 112 |
| 113 private: | 113 private: |
| 114 DISALLOW_COPY_AND_ASSIGN(DeviceCloudPolicyStoreChromeOSTest); | 114 DISALLOW_COPY_AND_ASSIGN(DeviceCloudPolicyStoreChromeOSTest); |
| 115 }; | 115 }; |
| 116 | 116 |
| 117 TEST_F(DeviceCloudPolicyStoreChromeOSTest, LoadNoKey) { | 117 TEST_F(DeviceCloudPolicyStoreChromeOSTest, LoadNoKey) { |
| 118 owner_key_util_->Clear(); | 118 owner_key_util_->Clear(); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 | 210 |
| 211 TEST_F(DeviceCloudPolicyStoreChromeOSTest, InstallInitialPolicyNotEnterprise) { | 211 TEST_F(DeviceCloudPolicyStoreChromeOSTest, InstallInitialPolicyNotEnterprise) { |
| 212 PrepareNewSigningKey(); | 212 PrepareNewSigningKey(); |
| 213 ResetToNonEnterprise(); | 213 ResetToNonEnterprise(); |
| 214 store_->InstallInitialPolicy(device_policy_.policy()); | 214 store_->InstallInitialPolicy(device_policy_.policy()); |
| 215 FlushDeviceSettings(); | 215 FlushDeviceSettings(); |
| 216 ExpectFailure(CloudPolicyStore::STATUS_BAD_STATE); | 216 ExpectFailure(CloudPolicyStore::STATUS_BAD_STATE); |
| 217 } | 217 } |
| 218 | 218 |
| 219 } // namespace policy | 219 } // namespace policy |
| OLD | NEW |