| 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 "components/policy/core/common/policy_loader_win.h" | 5 #include "components/policy/core/common/policy_loader_win.h" | 
| 6 | 6 | 
| 7 #include <windows.h> | 7 #include <windows.h> | 
| 8 #include <userenv.h> | 8 #include <userenv.h> | 
| 9 | 9 | 
| 10 #include <algorithm> | 10 #include <algorithm> | 
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 166 }; | 166 }; | 
| 167 | 167 | 
| 168 // A test harness that feeds policy via the Chrome GPO registry subtree. | 168 // A test harness that feeds policy via the Chrome GPO registry subtree. | 
| 169 class RegistryTestHarness : public PolicyProviderTestHarness, | 169 class RegistryTestHarness : public PolicyProviderTestHarness, | 
| 170                             public AppliedGPOListProvider { | 170                             public AppliedGPOListProvider { | 
| 171  public: | 171  public: | 
| 172   RegistryTestHarness(HKEY hive, PolicyScope scope); | 172   RegistryTestHarness(HKEY hive, PolicyScope scope); | 
| 173   virtual ~RegistryTestHarness(); | 173   virtual ~RegistryTestHarness(); | 
| 174 | 174 | 
| 175   // PolicyProviderTestHarness: | 175   // PolicyProviderTestHarness: | 
| 176   virtual void SetUp() OVERRIDE; | 176   virtual void SetUp() override; | 
| 177 | 177 | 
| 178   virtual ConfigurationPolicyProvider* CreateProvider( | 178   virtual ConfigurationPolicyProvider* CreateProvider( | 
| 179       SchemaRegistry* registry, | 179       SchemaRegistry* registry, | 
| 180       scoped_refptr<base::SequencedTaskRunner> task_runner) OVERRIDE; | 180       scoped_refptr<base::SequencedTaskRunner> task_runner) override; | 
| 181 | 181 | 
| 182   virtual void InstallEmptyPolicy() OVERRIDE; | 182   virtual void InstallEmptyPolicy() override; | 
| 183   virtual void InstallStringPolicy(const std::string& policy_name, | 183   virtual void InstallStringPolicy(const std::string& policy_name, | 
| 184                                    const std::string& policy_value) OVERRIDE; | 184                                    const std::string& policy_value) override; | 
| 185   virtual void InstallIntegerPolicy(const std::string& policy_name, | 185   virtual void InstallIntegerPolicy(const std::string& policy_name, | 
| 186                                     int policy_value) OVERRIDE; | 186                                     int policy_value) override; | 
| 187   virtual void InstallBooleanPolicy(const std::string& policy_name, | 187   virtual void InstallBooleanPolicy(const std::string& policy_name, | 
| 188                                     bool policy_value) OVERRIDE; | 188                                     bool policy_value) override; | 
| 189   virtual void InstallStringListPolicy( | 189   virtual void InstallStringListPolicy( | 
| 190       const std::string& policy_name, | 190       const std::string& policy_name, | 
| 191       const base::ListValue* policy_value) OVERRIDE; | 191       const base::ListValue* policy_value) override; | 
| 192   virtual void InstallDictionaryPolicy( | 192   virtual void InstallDictionaryPolicy( | 
| 193       const std::string& policy_name, | 193       const std::string& policy_name, | 
| 194       const base::DictionaryValue* policy_value) OVERRIDE; | 194       const base::DictionaryValue* policy_value) override; | 
| 195   virtual void Install3rdPartyPolicy( | 195   virtual void Install3rdPartyPolicy( | 
| 196       const base::DictionaryValue* policies) OVERRIDE; | 196       const base::DictionaryValue* policies) override; | 
| 197 | 197 | 
| 198   // AppliedGPOListProvider: | 198   // AppliedGPOListProvider: | 
| 199   virtual DWORD GetAppliedGPOList(DWORD flags, | 199   virtual DWORD GetAppliedGPOList(DWORD flags, | 
| 200                                   LPCTSTR machine_name, | 200                                   LPCTSTR machine_name, | 
| 201                                   PSID sid_user, | 201                                   PSID sid_user, | 
| 202                                   GUID* extension_guid, | 202                                   GUID* extension_guid, | 
| 203                                   PGROUP_POLICY_OBJECT* gpo_list) OVERRIDE; | 203                                   PGROUP_POLICY_OBJECT* gpo_list) override; | 
| 204   virtual BOOL FreeGPOList(PGROUP_POLICY_OBJECT gpo_list) OVERRIDE; | 204   virtual BOOL FreeGPOList(PGROUP_POLICY_OBJECT gpo_list) override; | 
| 205 | 205 | 
| 206   // Creates a harness instance that will install policy in HKCU or HKLM, | 206   // Creates a harness instance that will install policy in HKCU or HKLM, | 
| 207   // respectively. | 207   // respectively. | 
| 208   static PolicyProviderTestHarness* CreateHKCU(); | 208   static PolicyProviderTestHarness* CreateHKCU(); | 
| 209   static PolicyProviderTestHarness* CreateHKLM(); | 209   static PolicyProviderTestHarness* CreateHKLM(); | 
| 210 | 210 | 
| 211  private: | 211  private: | 
| 212   HKEY hive_; | 212   HKEY hive_; | 
| 213 | 213 | 
| 214   ScopedGroupPolicyRegistrySandbox registry_sandbox_; | 214   ScopedGroupPolicyRegistrySandbox registry_sandbox_; | 
| 215 | 215 | 
| 216   DISALLOW_COPY_AND_ASSIGN(RegistryTestHarness); | 216   DISALLOW_COPY_AND_ASSIGN(RegistryTestHarness); | 
| 217 }; | 217 }; | 
| 218 | 218 | 
| 219 // A test harness that generates PReg files for the provider to read. | 219 // A test harness that generates PReg files for the provider to read. | 
| 220 class PRegTestHarness : public PolicyProviderTestHarness, | 220 class PRegTestHarness : public PolicyProviderTestHarness, | 
| 221                         public AppliedGPOListProvider { | 221                         public AppliedGPOListProvider { | 
| 222  public: | 222  public: | 
| 223   PRegTestHarness(); | 223   PRegTestHarness(); | 
| 224   virtual ~PRegTestHarness(); | 224   virtual ~PRegTestHarness(); | 
| 225 | 225 | 
| 226   // PolicyProviderTestHarness: | 226   // PolicyProviderTestHarness: | 
| 227   virtual void SetUp() OVERRIDE; | 227   virtual void SetUp() override; | 
| 228 | 228 | 
| 229   virtual ConfigurationPolicyProvider* CreateProvider( | 229   virtual ConfigurationPolicyProvider* CreateProvider( | 
| 230       SchemaRegistry* registry, | 230       SchemaRegistry* registry, | 
| 231       scoped_refptr<base::SequencedTaskRunner> task_runner) OVERRIDE; | 231       scoped_refptr<base::SequencedTaskRunner> task_runner) override; | 
| 232 | 232 | 
| 233   virtual void InstallEmptyPolicy() OVERRIDE; | 233   virtual void InstallEmptyPolicy() override; | 
| 234   virtual void InstallStringPolicy(const std::string& policy_name, | 234   virtual void InstallStringPolicy(const std::string& policy_name, | 
| 235                                    const std::string& policy_value) OVERRIDE; | 235                                    const std::string& policy_value) override; | 
| 236   virtual void InstallIntegerPolicy(const std::string& policy_name, | 236   virtual void InstallIntegerPolicy(const std::string& policy_name, | 
| 237                                     int policy_value) OVERRIDE; | 237                                     int policy_value) override; | 
| 238   virtual void InstallBooleanPolicy(const std::string& policy_name, | 238   virtual void InstallBooleanPolicy(const std::string& policy_name, | 
| 239                                     bool policy_value) OVERRIDE; | 239                                     bool policy_value) override; | 
| 240   virtual void InstallStringListPolicy( | 240   virtual void InstallStringListPolicy( | 
| 241       const std::string& policy_name, | 241       const std::string& policy_name, | 
| 242       const base::ListValue* policy_value) OVERRIDE; | 242       const base::ListValue* policy_value) override; | 
| 243   virtual void InstallDictionaryPolicy( | 243   virtual void InstallDictionaryPolicy( | 
| 244       const std::string& policy_name, | 244       const std::string& policy_name, | 
| 245       const base::DictionaryValue* policy_value) OVERRIDE; | 245       const base::DictionaryValue* policy_value) override; | 
| 246   virtual void Install3rdPartyPolicy( | 246   virtual void Install3rdPartyPolicy( | 
| 247       const base::DictionaryValue* policies) OVERRIDE; | 247       const base::DictionaryValue* policies) override; | 
| 248 | 248 | 
| 249   // AppliedGPOListProvider: | 249   // AppliedGPOListProvider: | 
| 250   virtual DWORD GetAppliedGPOList(DWORD flags, | 250   virtual DWORD GetAppliedGPOList(DWORD flags, | 
| 251                                   LPCTSTR machine_name, | 251                                   LPCTSTR machine_name, | 
| 252                                   PSID sid_user, | 252                                   PSID sid_user, | 
| 253                                   GUID* extension_guid, | 253                                   GUID* extension_guid, | 
| 254                                   PGROUP_POLICY_OBJECT* gpo_list) OVERRIDE; | 254                                   PGROUP_POLICY_OBJECT* gpo_list) override; | 
| 255   virtual BOOL FreeGPOList(PGROUP_POLICY_OBJECT gpo_list) OVERRIDE; | 255   virtual BOOL FreeGPOList(PGROUP_POLICY_OBJECT gpo_list) override; | 
| 256 | 256 | 
| 257   // Creates a harness instance. | 257   // Creates a harness instance. | 
| 258   static PolicyProviderTestHarness* Create(); | 258   static PolicyProviderTestHarness* Create(); | 
| 259 | 259 | 
| 260  private: | 260  private: | 
| 261   // Helper to append a base::string16 to an uint8 buffer. | 261   // Helper to append a base::string16 to an uint8 buffer. | 
| 262   static void AppendChars(std::vector<uint8>* buffer, | 262   static void AppendChars(std::vector<uint8>* buffer, | 
| 263                           const base::string16& chars); | 263                           const base::string16& chars); | 
| 264 | 264 | 
| 265   // Appends a record with the given fields to the PReg file. | 265   // Appends a record with the given fields to the PReg file. | 
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 697  protected: | 697  protected: | 
| 698   // The policy key this tests places data under. This must match the data | 698   // The policy key this tests places data under. This must match the data | 
| 699   // files in chrome/test/data/policy/gpo. | 699   // files in chrome/test/data/policy/gpo. | 
| 700   static const base::char16 kTestPolicyKey[]; | 700   static const base::char16 kTestPolicyKey[]; | 
| 701 | 701 | 
| 702   PolicyLoaderWinTest() | 702   PolicyLoaderWinTest() | 
| 703       : gpo_list_(NULL), | 703       : gpo_list_(NULL), | 
| 704         gpo_list_status_(ERROR_ACCESS_DENIED) {} | 704         gpo_list_status_(ERROR_ACCESS_DENIED) {} | 
| 705   virtual ~PolicyLoaderWinTest() {} | 705   virtual ~PolicyLoaderWinTest() {} | 
| 706 | 706 | 
| 707   virtual void SetUp() OVERRIDE { | 707   virtual void SetUp() override { | 
| 708     base::win::SetDomainStateForTesting(false); | 708     base::win::SetDomainStateForTesting(false); | 
| 709     PolicyTestBase::SetUp(); | 709     PolicyTestBase::SetUp(); | 
| 710 | 710 | 
| 711     ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &test_data_dir_)); | 711     ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &test_data_dir_)); | 
| 712     test_data_dir_ = test_data_dir_.AppendASCII("chrome") | 712     test_data_dir_ = test_data_dir_.AppendASCII("chrome") | 
| 713                                    .AppendASCII("test") | 713                                    .AppendASCII("test") | 
| 714                                    .AppendASCII("data") | 714                                    .AppendASCII("data") | 
| 715                                    .AppendASCII("policy") | 715                                    .AppendASCII("policy") | 
| 716                                    .AppendASCII("gpo"); | 716                                    .AppendASCII("gpo"); | 
| 717   } | 717   } | 
| 718 | 718 | 
| 719   // AppliedGPOListProvider: | 719   // AppliedGPOListProvider: | 
| 720   virtual DWORD GetAppliedGPOList(DWORD flags, | 720   virtual DWORD GetAppliedGPOList(DWORD flags, | 
| 721                                   LPCTSTR machine_name, | 721                                   LPCTSTR machine_name, | 
| 722                                   PSID sid_user, | 722                                   PSID sid_user, | 
| 723                                   GUID* extension_guid, | 723                                   GUID* extension_guid, | 
| 724                                   PGROUP_POLICY_OBJECT* gpo_list) OVERRIDE { | 724                                   PGROUP_POLICY_OBJECT* gpo_list) override { | 
| 725     *gpo_list = gpo_list_; | 725     *gpo_list = gpo_list_; | 
| 726     return gpo_list_status_; | 726     return gpo_list_status_; | 
| 727   } | 727   } | 
| 728   virtual BOOL FreeGPOList(PGROUP_POLICY_OBJECT gpo_list) OVERRIDE { | 728   virtual BOOL FreeGPOList(PGROUP_POLICY_OBJECT gpo_list) override { | 
| 729     return TRUE; | 729     return TRUE; | 
| 730   } | 730   } | 
| 731 | 731 | 
| 732   void InitGPO(GROUP_POLICY_OBJECT* gpo, | 732   void InitGPO(GROUP_POLICY_OBJECT* gpo, | 
| 733                DWORD options, | 733                DWORD options, | 
| 734                const base::FilePath& path, | 734                const base::FilePath& path, | 
| 735                GROUP_POLICY_OBJECT* next, | 735                GROUP_POLICY_OBJECT* next, | 
| 736                GROUP_POLICY_OBJECT* prev) { | 736                GROUP_POLICY_OBJECT* prev) { | 
| 737     memset(gpo, 0, sizeof(GROUP_POLICY_OBJECT)); | 737     memset(gpo, 0, sizeof(GROUP_POLICY_OBJECT)); | 
| 738     gpo->dwOptions = options; | 738     gpo->dwOptions = options; | 
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1209   PolicyMap& expected_policy = expected.Get(ns); | 1209   PolicyMap& expected_policy = expected.Get(ns); | 
| 1210   expected_policy.Set("alternative_browser_path", | 1210   expected_policy.Set("alternative_browser_path", | 
| 1211                       POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, | 1211                       POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, | 
| 1212                       new base::StringValue("c:\\legacy\\browser.exe"), NULL); | 1212                       new base::StringValue("c:\\legacy\\browser.exe"), NULL); | 
| 1213   expected_policy.Set("url_list", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, | 1213   expected_policy.Set("url_list", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, | 
| 1214                       list.DeepCopy(), NULL); | 1214                       list.DeepCopy(), NULL); | 
| 1215   EXPECT_TRUE(Matches(expected)); | 1215   EXPECT_TRUE(Matches(expected)); | 
| 1216 } | 1216 } | 
| 1217 | 1217 | 
| 1218 }  // namespace policy | 1218 }  // namespace policy | 
| OLD | NEW | 
|---|