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/policy/policy_loader_win.h" | 5 #include "chrome/browser/policy/policy_loader_win.h" |
6 | 6 |
7 #include <userenv.h> | 7 #include <userenv.h> |
8 #include <windows.h> | 8 #include <windows.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 public AppliedGPOListProvider { | 247 public AppliedGPOListProvider { |
248 public: | 248 public: |
249 RegistryTestHarness(HKEY hive, PolicyScope scope); | 249 RegistryTestHarness(HKEY hive, PolicyScope scope); |
250 virtual ~RegistryTestHarness(); | 250 virtual ~RegistryTestHarness(); |
251 | 251 |
252 // PolicyProviderTestHarness: | 252 // PolicyProviderTestHarness: |
253 virtual void SetUp() OVERRIDE; | 253 virtual void SetUp() OVERRIDE; |
254 | 254 |
255 virtual ConfigurationPolicyProvider* CreateProvider( | 255 virtual ConfigurationPolicyProvider* CreateProvider( |
256 SchemaRegistry* registry, | 256 SchemaRegistry* registry, |
257 scoped_refptr<base::SequencedTaskRunner> task_runner, | 257 scoped_refptr<base::SequencedTaskRunner> task_runner) OVERRIDE; |
258 const PolicyDefinitionList* policy_list) OVERRIDE; | |
259 | 258 |
260 virtual void InstallEmptyPolicy() OVERRIDE; | 259 virtual void InstallEmptyPolicy() OVERRIDE; |
261 virtual void InstallStringPolicy(const std::string& policy_name, | 260 virtual void InstallStringPolicy(const std::string& policy_name, |
262 const std::string& policy_value) OVERRIDE; | 261 const std::string& policy_value) OVERRIDE; |
263 virtual void InstallIntegerPolicy(const std::string& policy_name, | 262 virtual void InstallIntegerPolicy(const std::string& policy_name, |
264 int policy_value) OVERRIDE; | 263 int policy_value) OVERRIDE; |
265 virtual void InstallBooleanPolicy(const std::string& policy_name, | 264 virtual void InstallBooleanPolicy(const std::string& policy_name, |
266 bool policy_value) OVERRIDE; | 265 bool policy_value) OVERRIDE; |
267 virtual void InstallStringListPolicy( | 266 virtual void InstallStringListPolicy( |
268 const std::string& policy_name, | 267 const std::string& policy_name, |
(...skipping 30 matching lines...) Expand all Loading... |
299 public AppliedGPOListProvider { | 298 public AppliedGPOListProvider { |
300 public: | 299 public: |
301 PRegTestHarness(); | 300 PRegTestHarness(); |
302 virtual ~PRegTestHarness(); | 301 virtual ~PRegTestHarness(); |
303 | 302 |
304 // PolicyProviderTestHarness: | 303 // PolicyProviderTestHarness: |
305 virtual void SetUp() OVERRIDE; | 304 virtual void SetUp() OVERRIDE; |
306 | 305 |
307 virtual ConfigurationPolicyProvider* CreateProvider( | 306 virtual ConfigurationPolicyProvider* CreateProvider( |
308 SchemaRegistry* registry, | 307 SchemaRegistry* registry, |
309 scoped_refptr<base::SequencedTaskRunner> task_runner, | 308 scoped_refptr<base::SequencedTaskRunner> task_runner) OVERRIDE; |
310 const PolicyDefinitionList* policy_list) OVERRIDE; | |
311 | 309 |
312 virtual void InstallEmptyPolicy() OVERRIDE; | 310 virtual void InstallEmptyPolicy() OVERRIDE; |
313 virtual void InstallStringPolicy(const std::string& policy_name, | 311 virtual void InstallStringPolicy(const std::string& policy_name, |
314 const std::string& policy_value) OVERRIDE; | 312 const std::string& policy_value) OVERRIDE; |
315 virtual void InstallIntegerPolicy(const std::string& policy_name, | 313 virtual void InstallIntegerPolicy(const std::string& policy_name, |
316 int policy_value) OVERRIDE; | 314 int policy_value) OVERRIDE; |
317 virtual void InstallBooleanPolicy(const std::string& policy_name, | 315 virtual void InstallBooleanPolicy(const std::string& policy_name, |
318 bool policy_value) OVERRIDE; | 316 bool policy_value) OVERRIDE; |
319 virtual void InstallStringListPolicy( | 317 virtual void InstallStringListPolicy( |
320 const std::string& policy_name, | 318 const std::string& policy_name, |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 | 415 |
418 RegistryTestHarness::RegistryTestHarness(HKEY hive, PolicyScope scope) | 416 RegistryTestHarness::RegistryTestHarness(HKEY hive, PolicyScope scope) |
419 : PolicyProviderTestHarness(POLICY_LEVEL_MANDATORY, scope), hive_(hive) {} | 417 : PolicyProviderTestHarness(POLICY_LEVEL_MANDATORY, scope), hive_(hive) {} |
420 | 418 |
421 RegistryTestHarness::~RegistryTestHarness() {} | 419 RegistryTestHarness::~RegistryTestHarness() {} |
422 | 420 |
423 void RegistryTestHarness::SetUp() {} | 421 void RegistryTestHarness::SetUp() {} |
424 | 422 |
425 ConfigurationPolicyProvider* RegistryTestHarness::CreateProvider( | 423 ConfigurationPolicyProvider* RegistryTestHarness::CreateProvider( |
426 SchemaRegistry* registry, | 424 SchemaRegistry* registry, |
427 scoped_refptr<base::SequencedTaskRunner> task_runner, | 425 scoped_refptr<base::SequencedTaskRunner> task_runner) { |
428 const PolicyDefinitionList* policy_list) { | 426 scoped_ptr<AsyncPolicyLoader> loader( |
429 scoped_ptr<AsyncPolicyLoader> loader(new PolicyLoaderWin( | 427 new PolicyLoaderWin(task_runner, kRegistryChromePolicyKey, this)); |
430 task_runner, policy_list, kRegistryChromePolicyKey, this)); | |
431 return new AsyncPolicyProvider(registry, loader.Pass()); | 428 return new AsyncPolicyProvider(registry, loader.Pass()); |
432 } | 429 } |
433 | 430 |
434 void RegistryTestHarness::InstallEmptyPolicy() {} | 431 void RegistryTestHarness::InstallEmptyPolicy() {} |
435 | 432 |
436 void RegistryTestHarness::InstallStringPolicy( | 433 void RegistryTestHarness::InstallStringPolicy( |
437 const std::string& policy_name, | 434 const std::string& policy_name, |
438 const std::string& policy_value) { | 435 const std::string& policy_value) { |
439 RegKey key(hive_, kRegistryChromePolicyKey, KEY_ALL_ACCESS); | 436 RegKey key(hive_, kRegistryChromePolicyKey, KEY_ALL_ACCESS); |
440 ASSERT_TRUE(key.Valid()); | 437 ASSERT_TRUE(key.Valid()); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 ASSERT_TRUE(file_util::WriteFile(preg_file_path_, | 547 ASSERT_TRUE(file_util::WriteFile(preg_file_path_, |
551 preg_parser::kPRegFileHeader, | 548 preg_parser::kPRegFileHeader, |
552 arraysize(preg_parser::kPRegFileHeader))); | 549 arraysize(preg_parser::kPRegFileHeader))); |
553 | 550 |
554 memset(&gpo_, 0, sizeof(GROUP_POLICY_OBJECT)); | 551 memset(&gpo_, 0, sizeof(GROUP_POLICY_OBJECT)); |
555 gpo_.lpFileSysPath = const_cast<wchar_t*>(temp_dir_.path().value().c_str()); | 552 gpo_.lpFileSysPath = const_cast<wchar_t*>(temp_dir_.path().value().c_str()); |
556 } | 553 } |
557 | 554 |
558 ConfigurationPolicyProvider* PRegTestHarness::CreateProvider( | 555 ConfigurationPolicyProvider* PRegTestHarness::CreateProvider( |
559 SchemaRegistry* registry, | 556 SchemaRegistry* registry, |
560 scoped_refptr<base::SequencedTaskRunner> task_runner, | 557 scoped_refptr<base::SequencedTaskRunner> task_runner) { |
561 const PolicyDefinitionList* policy_list) { | 558 scoped_ptr<AsyncPolicyLoader> loader( |
562 scoped_ptr<AsyncPolicyLoader> loader(new PolicyLoaderWin( | 559 new PolicyLoaderWin(task_runner, kRegistryChromePolicyKey, this)); |
563 task_runner, policy_list, kRegistryChromePolicyKey, this)); | |
564 return new AsyncPolicyProvider(registry, loader.Pass()); | 560 return new AsyncPolicyProvider(registry, loader.Pass()); |
565 } | 561 } |
566 | 562 |
567 void PRegTestHarness::InstallEmptyPolicy() {} | 563 void PRegTestHarness::InstallEmptyPolicy() {} |
568 | 564 |
569 void PRegTestHarness::InstallStringPolicy(const std::string& policy_name, | 565 void PRegTestHarness::InstallStringPolicy(const std::string& policy_name, |
570 const std::string& policy_value) { | 566 const std::string& policy_value) { |
571 AppendStringToPRegFile(kRegistryChromePolicyKey, policy_name, policy_value); | 567 AppendStringToPRegFile(kRegistryChromePolicyKey, policy_name, policy_value); |
572 } | 568 } |
573 | 569 |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 GROUP_POLICY_OBJECT* next, | 830 GROUP_POLICY_OBJECT* next, |
835 GROUP_POLICY_OBJECT* prev) { | 831 GROUP_POLICY_OBJECT* prev) { |
836 memset(gpo, 0, sizeof(GROUP_POLICY_OBJECT)); | 832 memset(gpo, 0, sizeof(GROUP_POLICY_OBJECT)); |
837 gpo->dwOptions = options; | 833 gpo->dwOptions = options; |
838 gpo->lpFileSysPath = const_cast<wchar_t*>(path.value().c_str()); | 834 gpo->lpFileSysPath = const_cast<wchar_t*>(path.value().c_str()); |
839 gpo->pNext = next; | 835 gpo->pNext = next; |
840 gpo->pPrev = prev; | 836 gpo->pPrev = prev; |
841 } | 837 } |
842 | 838 |
843 bool Matches(const PolicyBundle& expected) { | 839 bool Matches(const PolicyBundle& expected) { |
844 PolicyLoaderWin loader(loop_.message_loop_proxy(), | 840 PolicyLoaderWin loader(loop_.message_loop_proxy(), kTestPolicyKey, this); |
845 &test_policy_definitions::kList, kTestPolicyKey, | |
846 this); | |
847 scoped_ptr<PolicyBundle> loaded( | 841 scoped_ptr<PolicyBundle> loaded( |
848 loader.InitialLoad(schema_registry_.schema_map())); | 842 loader.InitialLoad(schema_registry_.schema_map())); |
849 return loaded->Equals(expected); | 843 return loaded->Equals(expected); |
850 } | 844 } |
851 | 845 |
852 void InstallRegistrySentinel() { | 846 void InstallRegistrySentinel() { |
853 RegKey hklm_key(HKEY_CURRENT_USER, kTestPolicyKey, KEY_ALL_ACCESS); | 847 RegKey hklm_key(HKEY_CURRENT_USER, kTestPolicyKey, KEY_ALL_ACCESS); |
854 ASSERT_TRUE(hklm_key.Valid()); | 848 ASSERT_TRUE(hklm_key.Valid()); |
855 hklm_key.WriteValue( | 849 hklm_key.WriteValue( |
856 UTF8ToUTF16(test_policy_definitions::kKeyString).c_str(), | 850 UTF8ToUTF16(test_keys::kKeyString).c_str(), |
857 UTF8ToUTF16("registry").c_str()); | 851 UTF8ToUTF16("registry").c_str()); |
858 } | 852 } |
859 | 853 |
860 bool MatchesRegistrySentinel() { | 854 bool MatchesRegistrySentinel() { |
861 base::DictionaryValue expected_policy; | 855 base::DictionaryValue expected_policy; |
862 expected_policy.SetString(test_policy_definitions::kKeyString, "registry"); | 856 expected_policy.SetString(test_keys::kKeyString, "registry"); |
863 PolicyBundle expected; | 857 PolicyBundle expected; |
864 expected.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | 858 expected.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) |
865 .LoadFrom(&expected_policy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER); | 859 .LoadFrom(&expected_policy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER); |
866 return Matches(expected); | 860 return Matches(expected); |
867 } | 861 } |
868 | 862 |
869 bool MatchesTestBundle() { | 863 bool MatchesTestBundle() { |
870 base::DictionaryValue expected_policy; | 864 base::DictionaryValue expected_policy; |
871 expected_policy.SetBoolean(test_policy_definitions::kKeyBoolean, true); | 865 expected_policy.SetBoolean(test_keys::kKeyBoolean, true); |
872 expected_policy.SetString(test_policy_definitions::kKeyString, "GPO"); | 866 expected_policy.SetString(test_keys::kKeyString, "GPO"); |
873 expected_policy.SetInteger(test_policy_definitions::kKeyInteger, 42); | 867 expected_policy.SetInteger(test_keys::kKeyInteger, 42); |
874 scoped_ptr<base::ListValue> list(new base::ListValue()); | 868 scoped_ptr<base::ListValue> list(new base::ListValue()); |
875 list->AppendString("GPO 1"); | 869 list->AppendString("GPO 1"); |
876 list->AppendString("GPO 2"); | 870 list->AppendString("GPO 2"); |
877 expected_policy.Set(test_policy_definitions::kKeyStringList, | 871 expected_policy.Set(test_keys::kKeyStringList, list.release()); |
878 list.release()); | |
879 PolicyBundle expected; | 872 PolicyBundle expected; |
880 expected.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | 873 expected.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) |
881 .LoadFrom(&expected_policy, POLICY_LEVEL_MANDATORY, | 874 .LoadFrom(&expected_policy, POLICY_LEVEL_MANDATORY, |
882 POLICY_SCOPE_MACHINE); | 875 POLICY_SCOPE_MACHINE); |
883 return Matches(expected); | 876 return Matches(expected); |
884 } | 877 } |
885 | 878 |
886 ScopedGroupPolicyRegistrySandbox registry_sandbox_; | 879 ScopedGroupPolicyRegistrySandbox registry_sandbox_; |
887 PGROUP_POLICY_OBJECT gpo_list_; | 880 PGROUP_POLICY_OBJECT gpo_list_; |
888 DWORD gpo_list_status_; | 881 DWORD gpo_list_status_; |
889 base::FilePath test_data_dir_; | 882 base::FilePath test_data_dir_; |
890 }; | 883 }; |
891 | 884 |
892 const char16 PolicyLoaderWinTest::kTestPolicyKey[] = | 885 const char16 PolicyLoaderWinTest::kTestPolicyKey[] = |
893 L"SOFTWARE\\Policies\\Chromium"; | 886 L"SOFTWARE\\Policies\\Chromium"; |
894 | 887 |
895 TEST_F(PolicyLoaderWinTest, HKLMOverHKCU) { | 888 TEST_F(PolicyLoaderWinTest, HKLMOverHKCU) { |
896 RegKey hklm_key(HKEY_LOCAL_MACHINE, kTestPolicyKey, KEY_ALL_ACCESS); | 889 RegKey hklm_key(HKEY_LOCAL_MACHINE, kTestPolicyKey, KEY_ALL_ACCESS); |
897 ASSERT_TRUE(hklm_key.Valid()); | 890 ASSERT_TRUE(hklm_key.Valid()); |
898 hklm_key.WriteValue(UTF8ToUTF16(test_policy_definitions::kKeyString).c_str(), | 891 hklm_key.WriteValue(UTF8ToUTF16(test_keys::kKeyString).c_str(), |
899 UTF8ToUTF16("hklm").c_str()); | 892 UTF8ToUTF16("hklm").c_str()); |
900 RegKey hkcu_key(HKEY_CURRENT_USER, kTestPolicyKey, KEY_ALL_ACCESS); | 893 RegKey hkcu_key(HKEY_CURRENT_USER, kTestPolicyKey, KEY_ALL_ACCESS); |
901 ASSERT_TRUE(hkcu_key.Valid()); | 894 ASSERT_TRUE(hkcu_key.Valid()); |
902 hkcu_key.WriteValue(UTF8ToUTF16(test_policy_definitions::kKeyString).c_str(), | 895 hkcu_key.WriteValue(UTF8ToUTF16(test_keys::kKeyString).c_str(), |
903 UTF8ToUTF16("hkcu").c_str()); | 896 UTF8ToUTF16("hkcu").c_str()); |
904 | 897 |
905 PolicyBundle expected; | 898 PolicyBundle expected; |
906 expected.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | 899 expected.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) |
907 .Set(test_policy_definitions::kKeyString, | 900 .Set(test_keys::kKeyString, |
908 POLICY_LEVEL_MANDATORY, | 901 POLICY_LEVEL_MANDATORY, |
909 POLICY_SCOPE_MACHINE, | 902 POLICY_SCOPE_MACHINE, |
910 base::Value::CreateStringValue("hklm"), NULL); | 903 base::Value::CreateStringValue("hklm"), NULL); |
911 EXPECT_TRUE(Matches(expected)); | 904 EXPECT_TRUE(Matches(expected)); |
912 } | 905 } |
913 | 906 |
914 TEST_F(PolicyLoaderWinTest, Load3rdPartyWithoutSchema) { | 907 TEST_F(PolicyLoaderWinTest, Load3rdPartyWithoutSchema) { |
915 base::DictionaryValue dict; | 908 base::DictionaryValue dict; |
916 dict.SetString("str", "string value"); | 909 dict.SetString("str", "string value"); |
917 dict.SetInteger("int", 123); | 910 dict.SetInteger("int", 123); |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1216 .LoadFrom(&expected_a, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE); | 1209 .LoadFrom(&expected_a, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE); |
1217 base::DictionaryValue expected_b; | 1210 base::DictionaryValue expected_b; |
1218 expected_b.SetInteger("policy 1", 2); | 1211 expected_b.SetInteger("policy 1", 2); |
1219 expected.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, | 1212 expected.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, |
1220 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")) | 1213 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")) |
1221 .LoadFrom(&expected_b, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE); | 1214 .LoadFrom(&expected_b, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE); |
1222 EXPECT_TRUE(Matches(expected)); | 1215 EXPECT_TRUE(Matches(expected)); |
1223 } | 1216 } |
1224 | 1217 |
1225 } // namespace policy | 1218 } // namespace policy |
OLD | NEW |