| 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 16 matching lines...) Expand all Loading... |
| 27 #include "base/strings/stringprintf.h" | 27 #include "base/strings/stringprintf.h" |
| 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 "chrome/browser/policy/schema_map.h" |
| 37 #include "components/json_schema/json_schema_constants.h" | 38 #include "components/json_schema/json_schema_constants.h" |
| 38 #include "policy/policy_constants.h" | 39 #include "policy/policy_constants.h" |
| 39 #include "testing/gtest/include/gtest/gtest.h" | 40 #include "testing/gtest/include/gtest/gtest.h" |
| 40 | 41 |
| 41 namespace schema = json_schema_constants; | 42 namespace schema = json_schema_constants; |
| 42 | 43 |
| 43 using base::win::RegKey; | 44 using base::win::RegKey; |
| 44 | 45 |
| 45 namespace policy { | 46 namespace policy { |
| 46 | 47 |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 class RegistryTestHarness : public PolicyProviderTestHarness, | 246 class RegistryTestHarness : public PolicyProviderTestHarness, |
| 246 public AppliedGPOListProvider { | 247 public AppliedGPOListProvider { |
| 247 public: | 248 public: |
| 248 RegistryTestHarness(HKEY hive, PolicyScope scope); | 249 RegistryTestHarness(HKEY hive, PolicyScope scope); |
| 249 virtual ~RegistryTestHarness(); | 250 virtual ~RegistryTestHarness(); |
| 250 | 251 |
| 251 // PolicyProviderTestHarness: | 252 // PolicyProviderTestHarness: |
| 252 virtual void SetUp() OVERRIDE; | 253 virtual void SetUp() OVERRIDE; |
| 253 | 254 |
| 254 virtual ConfigurationPolicyProvider* CreateProvider( | 255 virtual ConfigurationPolicyProvider* CreateProvider( |
| 256 SchemaRegistry* registry, |
| 255 scoped_refptr<base::SequencedTaskRunner> task_runner, | 257 scoped_refptr<base::SequencedTaskRunner> task_runner, |
| 256 const PolicyDefinitionList* policy_list) OVERRIDE; | 258 const PolicyDefinitionList* policy_list) OVERRIDE; |
| 257 | 259 |
| 258 virtual void InstallEmptyPolicy() OVERRIDE; | 260 virtual void InstallEmptyPolicy() OVERRIDE; |
| 259 virtual void InstallStringPolicy(const std::string& policy_name, | 261 virtual void InstallStringPolicy(const std::string& policy_name, |
| 260 const std::string& policy_value) OVERRIDE; | 262 const std::string& policy_value) OVERRIDE; |
| 261 virtual void InstallIntegerPolicy(const std::string& policy_name, | 263 virtual void InstallIntegerPolicy(const std::string& policy_name, |
| 262 int policy_value) OVERRIDE; | 264 int policy_value) OVERRIDE; |
| 263 virtual void InstallBooleanPolicy(const std::string& policy_name, | 265 virtual void InstallBooleanPolicy(const std::string& policy_name, |
| 264 bool policy_value) OVERRIDE; | 266 bool policy_value) OVERRIDE; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 class PRegTestHarness : public PolicyProviderTestHarness, | 298 class PRegTestHarness : public PolicyProviderTestHarness, |
| 297 public AppliedGPOListProvider { | 299 public AppliedGPOListProvider { |
| 298 public: | 300 public: |
| 299 PRegTestHarness(); | 301 PRegTestHarness(); |
| 300 virtual ~PRegTestHarness(); | 302 virtual ~PRegTestHarness(); |
| 301 | 303 |
| 302 // PolicyProviderTestHarness: | 304 // PolicyProviderTestHarness: |
| 303 virtual void SetUp() OVERRIDE; | 305 virtual void SetUp() OVERRIDE; |
| 304 | 306 |
| 305 virtual ConfigurationPolicyProvider* CreateProvider( | 307 virtual ConfigurationPolicyProvider* CreateProvider( |
| 308 SchemaRegistry* registry, |
| 306 scoped_refptr<base::SequencedTaskRunner> task_runner, | 309 scoped_refptr<base::SequencedTaskRunner> task_runner, |
| 307 const PolicyDefinitionList* policy_list) OVERRIDE; | 310 const PolicyDefinitionList* policy_list) OVERRIDE; |
| 308 | 311 |
| 309 virtual void InstallEmptyPolicy() OVERRIDE; | 312 virtual void InstallEmptyPolicy() OVERRIDE; |
| 310 virtual void InstallStringPolicy(const std::string& policy_name, | 313 virtual void InstallStringPolicy(const std::string& policy_name, |
| 311 const std::string& policy_value) OVERRIDE; | 314 const std::string& policy_value) OVERRIDE; |
| 312 virtual void InstallIntegerPolicy(const std::string& policy_name, | 315 virtual void InstallIntegerPolicy(const std::string& policy_name, |
| 313 int policy_value) OVERRIDE; | 316 int policy_value) OVERRIDE; |
| 314 virtual void InstallBooleanPolicy(const std::string& policy_name, | 317 virtual void InstallBooleanPolicy(const std::string& policy_name, |
| 315 bool policy_value) OVERRIDE; | 318 bool policy_value) OVERRIDE; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 } | 416 } |
| 414 | 417 |
| 415 RegistryTestHarness::RegistryTestHarness(HKEY hive, PolicyScope scope) | 418 RegistryTestHarness::RegistryTestHarness(HKEY hive, PolicyScope scope) |
| 416 : PolicyProviderTestHarness(POLICY_LEVEL_MANDATORY, scope), hive_(hive) {} | 419 : PolicyProviderTestHarness(POLICY_LEVEL_MANDATORY, scope), hive_(hive) {} |
| 417 | 420 |
| 418 RegistryTestHarness::~RegistryTestHarness() {} | 421 RegistryTestHarness::~RegistryTestHarness() {} |
| 419 | 422 |
| 420 void RegistryTestHarness::SetUp() {} | 423 void RegistryTestHarness::SetUp() {} |
| 421 | 424 |
| 422 ConfigurationPolicyProvider* RegistryTestHarness::CreateProvider( | 425 ConfigurationPolicyProvider* RegistryTestHarness::CreateProvider( |
| 426 SchemaRegistry* registry, |
| 423 scoped_refptr<base::SequencedTaskRunner> task_runner, | 427 scoped_refptr<base::SequencedTaskRunner> task_runner, |
| 424 const PolicyDefinitionList* policy_list) { | 428 const PolicyDefinitionList* policy_list) { |
| 425 scoped_ptr<AsyncPolicyLoader> loader(new PolicyLoaderWin( | 429 scoped_ptr<AsyncPolicyLoader> loader(new PolicyLoaderWin( |
| 426 task_runner, policy_list, kRegistryChromePolicyKey, this)); | 430 task_runner, policy_list, kRegistryChromePolicyKey, this)); |
| 427 return new AsyncPolicyProvider(loader.Pass()); | 431 return new AsyncPolicyProvider(registry, loader.Pass()); |
| 428 } | 432 } |
| 429 | 433 |
| 430 void RegistryTestHarness::InstallEmptyPolicy() {} | 434 void RegistryTestHarness::InstallEmptyPolicy() {} |
| 431 | 435 |
| 432 void RegistryTestHarness::InstallStringPolicy( | 436 void RegistryTestHarness::InstallStringPolicy( |
| 433 const std::string& policy_name, | 437 const std::string& policy_name, |
| 434 const std::string& policy_value) { | 438 const std::string& policy_value) { |
| 435 RegKey key(hive_, kRegistryChromePolicyKey, KEY_ALL_ACCESS); | 439 RegKey key(hive_, kRegistryChromePolicyKey, KEY_ALL_ACCESS); |
| 436 ASSERT_TRUE(key.Valid()); | 440 ASSERT_TRUE(key.Valid()); |
| 437 ASSERT_HRESULT_SUCCEEDED(key.WriteValue(UTF8ToUTF16(policy_name).c_str(), | 441 ASSERT_HRESULT_SUCCEEDED(key.WriteValue(UTF8ToUTF16(policy_name).c_str(), |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 preg_file_path_ = temp_dir_.path().Append(PolicyLoaderWin::kPRegFileName); | 549 preg_file_path_ = temp_dir_.path().Append(PolicyLoaderWin::kPRegFileName); |
| 546 ASSERT_TRUE(file_util::WriteFile(preg_file_path_, | 550 ASSERT_TRUE(file_util::WriteFile(preg_file_path_, |
| 547 preg_parser::kPRegFileHeader, | 551 preg_parser::kPRegFileHeader, |
| 548 arraysize(preg_parser::kPRegFileHeader))); | 552 arraysize(preg_parser::kPRegFileHeader))); |
| 549 | 553 |
| 550 memset(&gpo_, 0, sizeof(GROUP_POLICY_OBJECT)); | 554 memset(&gpo_, 0, sizeof(GROUP_POLICY_OBJECT)); |
| 551 gpo_.lpFileSysPath = const_cast<wchar_t*>(temp_dir_.path().value().c_str()); | 555 gpo_.lpFileSysPath = const_cast<wchar_t*>(temp_dir_.path().value().c_str()); |
| 552 } | 556 } |
| 553 | 557 |
| 554 ConfigurationPolicyProvider* PRegTestHarness::CreateProvider( | 558 ConfigurationPolicyProvider* PRegTestHarness::CreateProvider( |
| 559 SchemaRegistry* registry, |
| 555 scoped_refptr<base::SequencedTaskRunner> task_runner, | 560 scoped_refptr<base::SequencedTaskRunner> task_runner, |
| 556 const PolicyDefinitionList* policy_list) { | 561 const PolicyDefinitionList* policy_list) { |
| 557 scoped_ptr<AsyncPolicyLoader> loader(new PolicyLoaderWin( | 562 scoped_ptr<AsyncPolicyLoader> loader(new PolicyLoaderWin( |
| 558 task_runner, policy_list, kRegistryChromePolicyKey, this)); | 563 task_runner, policy_list, kRegistryChromePolicyKey, this)); |
| 559 return new AsyncPolicyProvider(loader.Pass()); | 564 return new AsyncPolicyProvider(registry, loader.Pass()); |
| 560 } | 565 } |
| 561 | 566 |
| 562 void PRegTestHarness::InstallEmptyPolicy() {} | 567 void PRegTestHarness::InstallEmptyPolicy() {} |
| 563 | 568 |
| 564 void PRegTestHarness::InstallStringPolicy(const std::string& policy_name, | 569 void PRegTestHarness::InstallStringPolicy(const std::string& policy_name, |
| 565 const std::string& policy_value) { | 570 const std::string& policy_value) { |
| 566 AppendStringToPRegFile(kRegistryChromePolicyKey, policy_name, policy_value); | 571 AppendStringToPRegFile(kRegistryChromePolicyKey, policy_name, policy_value); |
| 567 } | 572 } |
| 568 | 573 |
| 569 void PRegTestHarness::InstallIntegerPolicy(const std::string& policy_name, | 574 void PRegTestHarness::InstallIntegerPolicy(const std::string& policy_name, |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 782 // The policy key this tests places data under. This must match the data | 787 // The policy key this tests places data under. This must match the data |
| 783 // files in chrome/test/data/policy/gpo. | 788 // files in chrome/test/data/policy/gpo. |
| 784 static const char16 kTestPolicyKey[]; | 789 static const char16 kTestPolicyKey[]; |
| 785 | 790 |
| 786 PolicyLoaderWinTest() | 791 PolicyLoaderWinTest() |
| 787 : gpo_list_(NULL), | 792 : gpo_list_(NULL), |
| 788 gpo_list_status_(ERROR_ACCESS_DENIED) {} | 793 gpo_list_status_(ERROR_ACCESS_DENIED) {} |
| 789 virtual ~PolicyLoaderWinTest() {} | 794 virtual ~PolicyLoaderWinTest() {} |
| 790 | 795 |
| 791 virtual void SetUp() OVERRIDE { | 796 virtual void SetUp() OVERRIDE { |
| 797 PolicyTestBase::SetUp(); |
| 798 |
| 792 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &test_data_dir_)); | 799 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &test_data_dir_)); |
| 793 test_data_dir_ = test_data_dir_.AppendASCII("chrome") | 800 test_data_dir_ = test_data_dir_.AppendASCII("chrome") |
| 794 .AppendASCII("test") | 801 .AppendASCII("test") |
| 795 .AppendASCII("data") | 802 .AppendASCII("data") |
| 796 .AppendASCII("policy") | 803 .AppendASCII("policy") |
| 797 .AppendASCII("gpo"); | 804 .AppendASCII("gpo"); |
| 805 |
| 806 // Unknown components will be filtered out. Register their names with an |
| 807 // invalid schema to avoid that. |
| 808 ComponentMap components; |
| 809 components["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"] = Schema(); |
| 810 components["bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"] = Schema(); |
| 811 components["int"] = Schema(); |
| 812 components["merge"] = Schema(); |
| 813 components["string"] = Schema(); |
| 814 components["test"] = Schema(); |
| 815 schema_registry_.RegisterComponents(POLICY_DOMAIN_EXTENSIONS, components); |
| 798 } | 816 } |
| 799 | 817 |
| 800 // AppliedGPOListProvider: | 818 // AppliedGPOListProvider: |
| 801 virtual DWORD GetAppliedGPOList(DWORD flags, | 819 virtual DWORD GetAppliedGPOList(DWORD flags, |
| 802 LPCTSTR machine_name, | 820 LPCTSTR machine_name, |
| 803 PSID sid_user, | 821 PSID sid_user, |
| 804 GUID* extension_guid, | 822 GUID* extension_guid, |
| 805 PGROUP_POLICY_OBJECT* gpo_list) OVERRIDE { | 823 PGROUP_POLICY_OBJECT* gpo_list) OVERRIDE { |
| 806 *gpo_list = gpo_list_; | 824 *gpo_list = gpo_list_; |
| 807 return gpo_list_status_; | 825 return gpo_list_status_; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 819 gpo->dwOptions = options; | 837 gpo->dwOptions = options; |
| 820 gpo->lpFileSysPath = const_cast<wchar_t*>(path.value().c_str()); | 838 gpo->lpFileSysPath = const_cast<wchar_t*>(path.value().c_str()); |
| 821 gpo->pNext = next; | 839 gpo->pNext = next; |
| 822 gpo->pPrev = prev; | 840 gpo->pPrev = prev; |
| 823 } | 841 } |
| 824 | 842 |
| 825 bool Matches(const PolicyBundle& expected) { | 843 bool Matches(const PolicyBundle& expected) { |
| 826 PolicyLoaderWin loader(loop_.message_loop_proxy(), | 844 PolicyLoaderWin loader(loop_.message_loop_proxy(), |
| 827 &test_policy_definitions::kList, kTestPolicyKey, | 845 &test_policy_definitions::kList, kTestPolicyKey, |
| 828 this); | 846 this); |
| 829 scoped_ptr<PolicyBundle> loaded(loader.Load()); | 847 scoped_ptr<PolicyBundle> loaded( |
| 848 loader.InitialLoad(schema_registry_.schema_map())); |
| 830 return loaded->Equals(expected); | 849 return loaded->Equals(expected); |
| 831 } | 850 } |
| 832 | 851 |
| 833 void InstallRegistrySentinel() { | 852 void InstallRegistrySentinel() { |
| 834 RegKey hklm_key(HKEY_CURRENT_USER, kTestPolicyKey, KEY_ALL_ACCESS); | 853 RegKey hklm_key(HKEY_CURRENT_USER, kTestPolicyKey, KEY_ALL_ACCESS); |
| 835 ASSERT_TRUE(hklm_key.Valid()); | 854 ASSERT_TRUE(hklm_key.Valid()); |
| 836 hklm_key.WriteValue( | 855 hklm_key.WriteValue( |
| 837 UTF8ToUTF16(test_policy_definitions::kKeyString).c_str(), | 856 UTF8ToUTF16(test_policy_definitions::kKeyString).c_str(), |
| 838 UTF8ToUTF16("registry").c_str()); | 857 UTF8ToUTF16("registry").c_str()); |
| 839 } | 858 } |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1197 .LoadFrom(&expected_a, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE); | 1216 .LoadFrom(&expected_a, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE); |
| 1198 base::DictionaryValue expected_b; | 1217 base::DictionaryValue expected_b; |
| 1199 expected_b.SetInteger("policy 1", 2); | 1218 expected_b.SetInteger("policy 1", 2); |
| 1200 expected.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, | 1219 expected.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, |
| 1201 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")) | 1220 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")) |
| 1202 .LoadFrom(&expected_b, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE); | 1221 .LoadFrom(&expected_b, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE); |
| 1203 EXPECT_TRUE(Matches(expected)); | 1222 EXPECT_TRUE(Matches(expected)); |
| 1204 } | 1223 } |
| 1205 | 1224 |
| 1206 } // namespace policy | 1225 } // namespace policy |
| OLD | NEW |