Chromium Code Reviews| 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 17 matching lines...) Expand all Loading... | |
| 28 #include "base/strings/utf_string_conversions.h" | 28 #include "base/strings/utf_string_conversions.h" |
| 29 #include "base/sys_byteorder.h" | 29 #include "base/sys_byteorder.h" |
| 30 #include "base/win/registry.h" | 30 #include "base/win/registry.h" |
| 31 #include "chrome/browser/policy/async_policy_provider.h" | 31 #include "chrome/browser/policy/async_policy_provider.h" |
| 32 #include "chrome/browser/policy/configuration_policy_provider_test.h" | 32 #include "chrome/browser/policy/configuration_policy_provider_test.h" |
| 33 #include "chrome/browser/policy/external_data_fetcher.h" | 33 #include "chrome/browser/policy/external_data_fetcher.h" |
| 34 #include "chrome/browser/policy/policy_bundle.h" | 34 #include "chrome/browser/policy/policy_bundle.h" |
| 35 #include "chrome/browser/policy/policy_map.h" | 35 #include "chrome/browser/policy/policy_map.h" |
| 36 #include "chrome/browser/policy/preg_parser_win.h" | 36 #include "chrome/browser/policy/preg_parser_win.h" |
| 37 #include "components/json_schema/json_schema_constants.h" | 37 #include "components/json_schema/json_schema_constants.h" |
| 38 #include "policy/policy_constants.h" | 38 #include "policy/policy_constants.h" |
|
bartfab (slow)
2013/11/05 18:18:33
Nit: Is this still needed?
Joao da Silva
2013/11/07 20:27:27
Done.
| |
| 39 #include "testing/gtest/include/gtest/gtest.h" | 39 #include "testing/gtest/include/gtest/gtest.h" |
| 40 | 40 |
| 41 namespace schema = json_schema_constants; | 41 namespace schema = json_schema_constants; |
| 42 | 42 |
| 43 using base::win::RegKey; | 43 using base::win::RegKey; |
| 44 | 44 |
| 45 namespace policy { | 45 namespace policy { |
| 46 | 46 |
| 47 namespace { | 47 namespace { |
| 48 | 48 |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 public AppliedGPOListProvider { | 246 public AppliedGPOListProvider { |
| 247 public: | 247 public: |
| 248 RegistryTestHarness(HKEY hive, PolicyScope scope); | 248 RegistryTestHarness(HKEY hive, PolicyScope scope); |
| 249 virtual ~RegistryTestHarness(); | 249 virtual ~RegistryTestHarness(); |
| 250 | 250 |
| 251 // PolicyProviderTestHarness: | 251 // PolicyProviderTestHarness: |
| 252 virtual void SetUp() OVERRIDE; | 252 virtual void SetUp() OVERRIDE; |
| 253 | 253 |
| 254 virtual ConfigurationPolicyProvider* CreateProvider( | 254 virtual ConfigurationPolicyProvider* CreateProvider( |
| 255 SchemaRegistry* registry, | 255 SchemaRegistry* registry, |
| 256 scoped_refptr<base::SequencedTaskRunner> task_runner, | 256 scoped_refptr<base::SequencedTaskRunner> task_runner) OVERRIDE; |
| 257 const PolicyDefinitionList* policy_list) OVERRIDE; | |
| 258 | 257 |
| 259 virtual void InstallEmptyPolicy() OVERRIDE; | 258 virtual void InstallEmptyPolicy() OVERRIDE; |
| 260 virtual void InstallStringPolicy(const std::string& policy_name, | 259 virtual void InstallStringPolicy(const std::string& policy_name, |
| 261 const std::string& policy_value) OVERRIDE; | 260 const std::string& policy_value) OVERRIDE; |
| 262 virtual void InstallIntegerPolicy(const std::string& policy_name, | 261 virtual void InstallIntegerPolicy(const std::string& policy_name, |
| 263 int policy_value) OVERRIDE; | 262 int policy_value) OVERRIDE; |
| 264 virtual void InstallBooleanPolicy(const std::string& policy_name, | 263 virtual void InstallBooleanPolicy(const std::string& policy_name, |
| 265 bool policy_value) OVERRIDE; | 264 bool policy_value) OVERRIDE; |
| 266 virtual void InstallStringListPolicy( | 265 virtual void InstallStringListPolicy( |
| 267 const std::string& policy_name, | 266 const std::string& policy_name, |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 298 public AppliedGPOListProvider { | 297 public AppliedGPOListProvider { |
| 299 public: | 298 public: |
| 300 PRegTestHarness(); | 299 PRegTestHarness(); |
| 301 virtual ~PRegTestHarness(); | 300 virtual ~PRegTestHarness(); |
| 302 | 301 |
| 303 // PolicyProviderTestHarness: | 302 // PolicyProviderTestHarness: |
| 304 virtual void SetUp() OVERRIDE; | 303 virtual void SetUp() OVERRIDE; |
| 305 | 304 |
| 306 virtual ConfigurationPolicyProvider* CreateProvider( | 305 virtual ConfigurationPolicyProvider* CreateProvider( |
| 307 SchemaRegistry* registry, | 306 SchemaRegistry* registry, |
| 308 scoped_refptr<base::SequencedTaskRunner> task_runner, | 307 scoped_refptr<base::SequencedTaskRunner> task_runner) OVERRIDE; |
| 309 const PolicyDefinitionList* policy_list) OVERRIDE; | |
| 310 | 308 |
| 311 virtual void InstallEmptyPolicy() OVERRIDE; | 309 virtual void InstallEmptyPolicy() OVERRIDE; |
| 312 virtual void InstallStringPolicy(const std::string& policy_name, | 310 virtual void InstallStringPolicy(const std::string& policy_name, |
| 313 const std::string& policy_value) OVERRIDE; | 311 const std::string& policy_value) OVERRIDE; |
| 314 virtual void InstallIntegerPolicy(const std::string& policy_name, | 312 virtual void InstallIntegerPolicy(const std::string& policy_name, |
| 315 int policy_value) OVERRIDE; | 313 int policy_value) OVERRIDE; |
| 316 virtual void InstallBooleanPolicy(const std::string& policy_name, | 314 virtual void InstallBooleanPolicy(const std::string& policy_name, |
| 317 bool policy_value) OVERRIDE; | 315 bool policy_value) OVERRIDE; |
| 318 virtual void InstallStringListPolicy( | 316 virtual void InstallStringListPolicy( |
| 319 const std::string& policy_name, | 317 const std::string& policy_name, |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 416 | 414 |
| 417 RegistryTestHarness::RegistryTestHarness(HKEY hive, PolicyScope scope) | 415 RegistryTestHarness::RegistryTestHarness(HKEY hive, PolicyScope scope) |
| 418 : PolicyProviderTestHarness(POLICY_LEVEL_MANDATORY, scope), hive_(hive) {} | 416 : PolicyProviderTestHarness(POLICY_LEVEL_MANDATORY, scope), hive_(hive) {} |
| 419 | 417 |
| 420 RegistryTestHarness::~RegistryTestHarness() {} | 418 RegistryTestHarness::~RegistryTestHarness() {} |
| 421 | 419 |
| 422 void RegistryTestHarness::SetUp() {} | 420 void RegistryTestHarness::SetUp() {} |
| 423 | 421 |
| 424 ConfigurationPolicyProvider* RegistryTestHarness::CreateProvider( | 422 ConfigurationPolicyProvider* RegistryTestHarness::CreateProvider( |
| 425 SchemaRegistry* registry, | 423 SchemaRegistry* registry, |
| 426 scoped_refptr<base::SequencedTaskRunner> task_runner, | 424 scoped_refptr<base::SequencedTaskRunner> task_runner) { |
| 427 const PolicyDefinitionList* policy_list) { | 425 scoped_ptr<AsyncPolicyLoader> loader( |
| 428 scoped_ptr<AsyncPolicyLoader> loader(new PolicyLoaderWin( | 426 new PolicyLoaderWin(task_runner, kRegistryChromePolicyKey, this)); |
| 429 task_runner, policy_list, kRegistryChromePolicyKey, this)); | |
| 430 return new AsyncPolicyProvider(registry, loader.Pass()); | 427 return new AsyncPolicyProvider(registry, loader.Pass()); |
| 431 } | 428 } |
| 432 | 429 |
| 433 void RegistryTestHarness::InstallEmptyPolicy() {} | 430 void RegistryTestHarness::InstallEmptyPolicy() {} |
| 434 | 431 |
| 435 void RegistryTestHarness::InstallStringPolicy( | 432 void RegistryTestHarness::InstallStringPolicy( |
| 436 const std::string& policy_name, | 433 const std::string& policy_name, |
| 437 const std::string& policy_value) { | 434 const std::string& policy_value) { |
| 438 RegKey key(hive_, kRegistryChromePolicyKey, KEY_ALL_ACCESS); | 435 RegKey key(hive_, kRegistryChromePolicyKey, KEY_ALL_ACCESS); |
| 439 ASSERT_TRUE(key.Valid()); | 436 ASSERT_TRUE(key.Valid()); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 549 ASSERT_TRUE(file_util::WriteFile(preg_file_path_, | 546 ASSERT_TRUE(file_util::WriteFile(preg_file_path_, |
| 550 preg_parser::kPRegFileHeader, | 547 preg_parser::kPRegFileHeader, |
| 551 arraysize(preg_parser::kPRegFileHeader))); | 548 arraysize(preg_parser::kPRegFileHeader))); |
| 552 | 549 |
| 553 memset(&gpo_, 0, sizeof(GROUP_POLICY_OBJECT)); | 550 memset(&gpo_, 0, sizeof(GROUP_POLICY_OBJECT)); |
| 554 gpo_.lpFileSysPath = const_cast<wchar_t*>(temp_dir_.path().value().c_str()); | 551 gpo_.lpFileSysPath = const_cast<wchar_t*>(temp_dir_.path().value().c_str()); |
| 555 } | 552 } |
| 556 | 553 |
| 557 ConfigurationPolicyProvider* PRegTestHarness::CreateProvider( | 554 ConfigurationPolicyProvider* PRegTestHarness::CreateProvider( |
| 558 SchemaRegistry* registry, | 555 SchemaRegistry* registry, |
| 559 scoped_refptr<base::SequencedTaskRunner> task_runner, | 556 scoped_refptr<base::SequencedTaskRunner> task_runner) { |
| 560 const PolicyDefinitionList* policy_list) { | 557 scoped_ptr<AsyncPolicyLoader> loader( |
| 561 scoped_ptr<AsyncPolicyLoader> loader(new PolicyLoaderWin( | 558 new PolicyLoaderWin(task_runner, kRegistryChromePolicyKey, this)); |
| 562 task_runner, policy_list, kRegistryChromePolicyKey, this)); | |
| 563 return new AsyncPolicyProvider(registry, loader.Pass()); | 559 return new AsyncPolicyProvider(registry, loader.Pass()); |
| 564 } | 560 } |
| 565 | 561 |
| 566 void PRegTestHarness::InstallEmptyPolicy() {} | 562 void PRegTestHarness::InstallEmptyPolicy() {} |
| 567 | 563 |
| 568 void PRegTestHarness::InstallStringPolicy(const std::string& policy_name, | 564 void PRegTestHarness::InstallStringPolicy(const std::string& policy_name, |
| 569 const std::string& policy_value) { | 565 const std::string& policy_value) { |
| 570 AppendStringToPRegFile(kRegistryChromePolicyKey, policy_name, policy_value); | 566 AppendStringToPRegFile(kRegistryChromePolicyKey, policy_name, policy_value); |
| 571 } | 567 } |
| 572 | 568 |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 822 GROUP_POLICY_OBJECT* next, | 818 GROUP_POLICY_OBJECT* next, |
| 823 GROUP_POLICY_OBJECT* prev) { | 819 GROUP_POLICY_OBJECT* prev) { |
| 824 memset(gpo, 0, sizeof(GROUP_POLICY_OBJECT)); | 820 memset(gpo, 0, sizeof(GROUP_POLICY_OBJECT)); |
| 825 gpo->dwOptions = options; | 821 gpo->dwOptions = options; |
| 826 gpo->lpFileSysPath = const_cast<wchar_t*>(path.value().c_str()); | 822 gpo->lpFileSysPath = const_cast<wchar_t*>(path.value().c_str()); |
| 827 gpo->pNext = next; | 823 gpo->pNext = next; |
| 828 gpo->pPrev = prev; | 824 gpo->pPrev = prev; |
| 829 } | 825 } |
| 830 | 826 |
| 831 bool Matches(const PolicyBundle& expected) { | 827 bool Matches(const PolicyBundle& expected) { |
| 832 PolicyLoaderWin loader(loop_.message_loop_proxy(), | 828 PolicyLoaderWin loader(loop_.message_loop_proxy(), kTestPolicyKey, this); |
| 833 &test_policy_definitions::kList, kTestPolicyKey, | |
| 834 this); | |
| 835 scoped_ptr<PolicyBundle> loaded( | 829 scoped_ptr<PolicyBundle> loaded( |
| 836 loader.InitialLoad(schema_registry_.schema_map())); | 830 loader.InitialLoad(schema_registry_.schema_map())); |
| 837 return loaded->Equals(expected); | 831 return loaded->Equals(expected); |
| 838 } | 832 } |
| 839 | 833 |
| 840 void InstallRegistrySentinel() { | 834 void InstallRegistrySentinel() { |
| 841 RegKey hklm_key(HKEY_CURRENT_USER, kTestPolicyKey, KEY_ALL_ACCESS); | 835 RegKey hklm_key(HKEY_CURRENT_USER, kTestPolicyKey, KEY_ALL_ACCESS); |
| 842 ASSERT_TRUE(hklm_key.Valid()); | 836 ASSERT_TRUE(hklm_key.Valid()); |
| 843 hklm_key.WriteValue( | 837 hklm_key.WriteValue( |
| 844 UTF8ToUTF16(test_policy_definitions::kKeyString).c_str(), | 838 UTF8ToUTF16(test_keys::kKeyString).c_str(), |
| 845 UTF8ToUTF16("registry").c_str()); | 839 UTF8ToUTF16("registry").c_str()); |
| 846 } | 840 } |
| 847 | 841 |
| 848 bool MatchesRegistrySentinel() { | 842 bool MatchesRegistrySentinel() { |
| 849 base::DictionaryValue expected_policy; | 843 base::DictionaryValue expected_policy; |
| 850 expected_policy.SetString(test_policy_definitions::kKeyString, "registry"); | 844 expected_policy.SetString(test_keys::kKeyString, "registry"); |
| 851 PolicyBundle expected; | 845 PolicyBundle expected; |
| 852 expected.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | 846 expected.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) |
| 853 .LoadFrom(&expected_policy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER); | 847 .LoadFrom(&expected_policy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER); |
| 854 return Matches(expected); | 848 return Matches(expected); |
| 855 } | 849 } |
| 856 | 850 |
| 857 bool MatchesTestBundle() { | 851 bool MatchesTestBundle() { |
| 858 base::DictionaryValue expected_policy; | 852 base::DictionaryValue expected_policy; |
| 859 expected_policy.SetBoolean(test_policy_definitions::kKeyBoolean, true); | 853 expected_policy.SetBoolean(test_keys::kKeyBoolean, true); |
| 860 expected_policy.SetString(test_policy_definitions::kKeyString, "GPO"); | 854 expected_policy.SetString(test_keys::kKeyString, "GPO"); |
| 861 expected_policy.SetInteger(test_policy_definitions::kKeyInteger, 42); | 855 expected_policy.SetInteger(test_keys::kKeyInteger, 42); |
| 862 scoped_ptr<base::ListValue> list(new base::ListValue()); | 856 scoped_ptr<base::ListValue> list(new base::ListValue()); |
| 863 list->AppendString("GPO 1"); | 857 list->AppendString("GPO 1"); |
| 864 list->AppendString("GPO 2"); | 858 list->AppendString("GPO 2"); |
| 865 expected_policy.Set(test_policy_definitions::kKeyStringList, | 859 expected_policy.Set(test_keys::kKeyStringList, list.release()); |
| 866 list.release()); | |
| 867 PolicyBundle expected; | 860 PolicyBundle expected; |
| 868 expected.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | 861 expected.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) |
| 869 .LoadFrom(&expected_policy, POLICY_LEVEL_MANDATORY, | 862 .LoadFrom(&expected_policy, POLICY_LEVEL_MANDATORY, |
| 870 POLICY_SCOPE_MACHINE); | 863 POLICY_SCOPE_MACHINE); |
| 871 return Matches(expected); | 864 return Matches(expected); |
| 872 } | 865 } |
| 873 | 866 |
| 874 ScopedGroupPolicyRegistrySandbox registry_sandbox_; | 867 ScopedGroupPolicyRegistrySandbox registry_sandbox_; |
| 875 PGROUP_POLICY_OBJECT gpo_list_; | 868 PGROUP_POLICY_OBJECT gpo_list_; |
| 876 DWORD gpo_list_status_; | 869 DWORD gpo_list_status_; |
| 877 base::FilePath test_data_dir_; | 870 base::FilePath test_data_dir_; |
| 878 }; | 871 }; |
| 879 | 872 |
| 880 const char16 PolicyLoaderWinTest::kTestPolicyKey[] = | 873 const char16 PolicyLoaderWinTest::kTestPolicyKey[] = |
| 881 L"SOFTWARE\\Policies\\Chromium"; | 874 L"SOFTWARE\\Policies\\Chromium"; |
| 882 | 875 |
| 883 TEST_F(PolicyLoaderWinTest, HKLMOverHKCU) { | 876 TEST_F(PolicyLoaderWinTest, HKLMOverHKCU) { |
| 884 RegKey hklm_key(HKEY_LOCAL_MACHINE, kTestPolicyKey, KEY_ALL_ACCESS); | 877 RegKey hklm_key(HKEY_LOCAL_MACHINE, kTestPolicyKey, KEY_ALL_ACCESS); |
| 885 ASSERT_TRUE(hklm_key.Valid()); | 878 ASSERT_TRUE(hklm_key.Valid()); |
| 886 hklm_key.WriteValue(UTF8ToUTF16(test_policy_definitions::kKeyString).c_str(), | 879 hklm_key.WriteValue(UTF8ToUTF16(test_keys::kKeyString).c_str(), |
| 887 UTF8ToUTF16("hklm").c_str()); | 880 UTF8ToUTF16("hklm").c_str()); |
| 888 RegKey hkcu_key(HKEY_CURRENT_USER, kTestPolicyKey, KEY_ALL_ACCESS); | 881 RegKey hkcu_key(HKEY_CURRENT_USER, kTestPolicyKey, KEY_ALL_ACCESS); |
| 889 ASSERT_TRUE(hkcu_key.Valid()); | 882 ASSERT_TRUE(hkcu_key.Valid()); |
| 890 hkcu_key.WriteValue(UTF8ToUTF16(test_policy_definitions::kKeyString).c_str(), | 883 hkcu_key.WriteValue(UTF8ToUTF16(test_keys::kKeyString).c_str(), |
| 891 UTF8ToUTF16("hkcu").c_str()); | 884 UTF8ToUTF16("hkcu").c_str()); |
| 892 | 885 |
| 893 PolicyBundle expected; | 886 PolicyBundle expected; |
| 894 expected.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | 887 expected.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) |
| 895 .Set(test_policy_definitions::kKeyString, | 888 .Set(test_keys::kKeyString, |
| 896 POLICY_LEVEL_MANDATORY, | 889 POLICY_LEVEL_MANDATORY, |
| 897 POLICY_SCOPE_MACHINE, | 890 POLICY_SCOPE_MACHINE, |
| 898 base::Value::CreateStringValue("hklm"), NULL); | 891 base::Value::CreateStringValue("hklm"), NULL); |
| 899 EXPECT_TRUE(Matches(expected)); | 892 EXPECT_TRUE(Matches(expected)); |
| 900 } | 893 } |
| 901 | 894 |
| 902 TEST_F(PolicyLoaderWinTest, Load3rdPartyWithoutSchema) { | 895 TEST_F(PolicyLoaderWinTest, Load3rdPartyWithoutSchema) { |
| 903 base::DictionaryValue dict; | 896 base::DictionaryValue dict; |
| 904 dict.SetString("str", "string value"); | 897 dict.SetString("str", "string value"); |
| 905 dict.SetInteger("int", 123); | 898 dict.SetInteger("int", 123); |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1204 .LoadFrom(&expected_a, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE); | 1197 .LoadFrom(&expected_a, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE); |
| 1205 base::DictionaryValue expected_b; | 1198 base::DictionaryValue expected_b; |
| 1206 expected_b.SetInteger("policy 1", 2); | 1199 expected_b.SetInteger("policy 1", 2); |
| 1207 expected.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, | 1200 expected.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, |
| 1208 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")) | 1201 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")) |
| 1209 .LoadFrom(&expected_b, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE); | 1202 .LoadFrom(&expected_b, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE); |
| 1210 EXPECT_TRUE(Matches(expected)); | 1203 EXPECT_TRUE(Matches(expected)); |
| 1211 } | 1204 } |
| 1212 | 1205 |
| 1213 } // namespace policy | 1206 } // namespace policy |
| OLD | NEW |