| 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 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 virtual void SetUp() override { | 705 virtual void SetUp() override { |
| 706 base::win::SetDomainStateForTesting(false); | 706 base::win::SetDomainStateForTesting(false); |
| 707 PolicyTestBase::SetUp(); | 707 PolicyTestBase::SetUp(); |
| 708 | 708 |
| 709 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &test_data_dir_)); | 709 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &test_data_dir_)); |
| 710 test_data_dir_ = test_data_dir_.AppendASCII("chrome") | 710 test_data_dir_ = test_data_dir_.AppendASCII("chrome") |
| 711 .AppendASCII("test") | 711 .AppendASCII("test") |
| 712 .AppendASCII("data") | 712 .AppendASCII("data") |
| 713 .AppendASCII("policy") | 713 .AppendASCII("policy") |
| 714 .AppendASCII("gpo"); | 714 .AppendASCII("gpo"); |
| 715 |
| 716 gpo_list_provider_ = this; |
| 715 } | 717 } |
| 716 | 718 |
| 717 // AppliedGPOListProvider: | 719 // AppliedGPOListProvider: |
| 718 virtual DWORD GetAppliedGPOList(DWORD flags, | 720 virtual DWORD GetAppliedGPOList(DWORD flags, |
| 719 LPCTSTR machine_name, | 721 LPCTSTR machine_name, |
| 720 PSID sid_user, | 722 PSID sid_user, |
| 721 GUID* extension_guid, | 723 GUID* extension_guid, |
| 722 PGROUP_POLICY_OBJECT* gpo_list) override { | 724 PGROUP_POLICY_OBJECT* gpo_list) override { |
| 723 *gpo_list = gpo_list_; | 725 *gpo_list = gpo_list_; |
| 724 return gpo_list_status_; | 726 return gpo_list_status_; |
| 725 } | 727 } |
| 726 virtual BOOL FreeGPOList(PGROUP_POLICY_OBJECT gpo_list) override { | 728 virtual BOOL FreeGPOList(PGROUP_POLICY_OBJECT gpo_list) override { |
| 727 return TRUE; | 729 return TRUE; |
| 728 } | 730 } |
| 729 | 731 |
| 730 void InitGPO(GROUP_POLICY_OBJECT* gpo, | 732 void InitGPO(GROUP_POLICY_OBJECT* gpo, |
| 731 DWORD options, | 733 DWORD options, |
| 732 const base::FilePath& path, | 734 const base::FilePath& path, |
| 733 GROUP_POLICY_OBJECT* next, | 735 GROUP_POLICY_OBJECT* next, |
| 734 GROUP_POLICY_OBJECT* prev) { | 736 GROUP_POLICY_OBJECT* prev) { |
| 735 memset(gpo, 0, sizeof(GROUP_POLICY_OBJECT)); | 737 memset(gpo, 0, sizeof(GROUP_POLICY_OBJECT)); |
| 736 gpo->dwOptions = options; | 738 gpo->dwOptions = options; |
| 737 gpo->lpFileSysPath = const_cast<wchar_t*>(path.value().c_str()); | 739 gpo->lpFileSysPath = const_cast<wchar_t*>(path.value().c_str()); |
| 738 gpo->pNext = next; | 740 gpo->pNext = next; |
| 739 gpo->pPrev = prev; | 741 gpo->pPrev = prev; |
| 740 } | 742 } |
| 741 | 743 |
| 742 bool Matches(const PolicyBundle& expected) { | 744 bool Matches(const PolicyBundle& expected) { |
| 743 PolicyLoaderWin loader(loop_.message_loop_proxy(), kTestPolicyKey, this); | 745 PolicyLoaderWin loader(loop_.message_loop_proxy(), kTestPolicyKey, |
| 746 gpo_list_provider_); |
| 744 scoped_ptr<PolicyBundle> loaded( | 747 scoped_ptr<PolicyBundle> loaded( |
| 745 loader.InitialLoad(schema_registry_.schema_map())); | 748 loader.InitialLoad(schema_registry_.schema_map())); |
| 746 return loaded->Equals(expected); | 749 return loaded->Equals(expected); |
| 747 } | 750 } |
| 748 | 751 |
| 749 void InstallRegistrySentinel() { | 752 void InstallRegistrySentinel() { |
| 750 RegKey hklm_key(HKEY_CURRENT_USER, kTestPolicyKey, KEY_ALL_ACCESS); | 753 RegKey hklm_key(HKEY_CURRENT_USER, kTestPolicyKey, KEY_ALL_ACCESS); |
| 751 ASSERT_TRUE(hklm_key.Valid()); | 754 ASSERT_TRUE(hklm_key.Valid()); |
| 752 hklm_key.WriteValue( | 755 hklm_key.WriteValue( |
| 753 UTF8ToUTF16(test_keys::kKeyString).c_str(), | 756 UTF8ToUTF16(test_keys::kKeyString).c_str(), |
| (...skipping 22 matching lines...) Expand all Loading... |
| 776 expected.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | 779 expected.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) |
| 777 .LoadFrom(&expected_policy, POLICY_LEVEL_MANDATORY, | 780 .LoadFrom(&expected_policy, POLICY_LEVEL_MANDATORY, |
| 778 POLICY_SCOPE_MACHINE); | 781 POLICY_SCOPE_MACHINE); |
| 779 return Matches(expected); | 782 return Matches(expected); |
| 780 } | 783 } |
| 781 | 784 |
| 782 ScopedGroupPolicyRegistrySandbox registry_sandbox_; | 785 ScopedGroupPolicyRegistrySandbox registry_sandbox_; |
| 783 PGROUP_POLICY_OBJECT gpo_list_; | 786 PGROUP_POLICY_OBJECT gpo_list_; |
| 784 DWORD gpo_list_status_; | 787 DWORD gpo_list_status_; |
| 785 base::FilePath test_data_dir_; | 788 base::FilePath test_data_dir_; |
| 789 AppliedGPOListProvider* gpo_list_provider_; |
| 786 }; | 790 }; |
| 787 | 791 |
| 788 const base::char16 PolicyLoaderWinTest::kTestPolicyKey[] = | 792 const base::char16 PolicyLoaderWinTest::kTestPolicyKey[] = |
| 789 L"SOFTWARE\\Policies\\Chromium"; | 793 L"SOFTWARE\\Policies\\Chromium"; |
| 790 | 794 |
| 791 TEST_F(PolicyLoaderWinTest, HKLMOverHKCU) { | 795 TEST_F(PolicyLoaderWinTest, HKLMOverHKCU) { |
| 792 RegKey hklm_key(HKEY_LOCAL_MACHINE, kTestPolicyKey, KEY_ALL_ACCESS); | 796 RegKey hklm_key(HKEY_LOCAL_MACHINE, kTestPolicyKey, KEY_ALL_ACCESS); |
| 793 ASSERT_TRUE(hklm_key.Valid()); | 797 ASSERT_TRUE(hklm_key.Valid()); |
| 794 hklm_key.WriteValue(UTF8ToUTF16(test_keys::kKeyString).c_str(), | 798 hklm_key.WriteValue(UTF8ToUTF16(test_keys::kKeyString).c_str(), |
| 795 UTF8ToUTF16("hklm").c_str()); | 799 UTF8ToUTF16("hklm").c_str()); |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1040 | 1044 |
| 1041 TEST_F(PolicyLoaderWinTest, AppliedPolicyInDomain) { | 1045 TEST_F(PolicyLoaderWinTest, AppliedPolicyInDomain) { |
| 1042 base::win::SetDomainStateForTesting(true); | 1046 base::win::SetDomainStateForTesting(true); |
| 1043 InstallRegistrySentinel(); | 1047 InstallRegistrySentinel(); |
| 1044 base::FilePath gpo_dir(test_data_dir_.AppendASCII("empty")); | 1048 base::FilePath gpo_dir(test_data_dir_.AppendASCII("empty")); |
| 1045 GROUP_POLICY_OBJECT gpo; | 1049 GROUP_POLICY_OBJECT gpo; |
| 1046 InitGPO(&gpo, 0, gpo_dir, NULL, NULL); | 1050 InitGPO(&gpo, 0, gpo_dir, NULL, NULL); |
| 1047 gpo_list_ = &gpo; | 1051 gpo_list_ = &gpo; |
| 1048 gpo_list_status_ = ERROR_SUCCESS; | 1052 gpo_list_status_ = ERROR_SUCCESS; |
| 1049 | 1053 |
| 1050 PolicyBundle empty; | |
| 1051 EXPECT_TRUE(MatchesRegistrySentinel()); | 1054 EXPECT_TRUE(MatchesRegistrySentinel()); |
| 1052 } | 1055 } |
| 1053 | 1056 |
| 1057 TEST_F(PolicyLoaderWinTest, GpoProviderNotSpecified) { |
| 1058 base::win::SetDomainStateForTesting(false); |
| 1059 InstallRegistrySentinel(); |
| 1060 base::FilePath gpo_dir(test_data_dir_.AppendASCII("empty")); |
| 1061 GROUP_POLICY_OBJECT gpo; |
| 1062 InitGPO(&gpo, 0, gpo_dir, NULL, NULL); |
| 1063 gpo_list_ = &gpo; |
| 1064 gpo_list_status_ = ERROR_SUCCESS; |
| 1065 gpo_list_provider_ = nullptr; |
| 1066 |
| 1067 EXPECT_TRUE(MatchesRegistrySentinel()); |
| 1068 } |
| 1069 |
| 1054 TEST_F(PolicyLoaderWinTest, AppliedPolicyNonExistingFile) { | 1070 TEST_F(PolicyLoaderWinTest, AppliedPolicyNonExistingFile) { |
| 1055 InstallRegistrySentinel(); | 1071 InstallRegistrySentinel(); |
| 1056 GROUP_POLICY_OBJECT gpo; | 1072 GROUP_POLICY_OBJECT gpo; |
| 1057 InitGPO(&gpo, 0, test_data_dir_, NULL, NULL); | 1073 InitGPO(&gpo, 0, test_data_dir_, NULL, NULL); |
| 1058 gpo_list_ = &gpo; | 1074 gpo_list_ = &gpo; |
| 1059 gpo_list_status_ = ERROR_SUCCESS; | 1075 gpo_list_status_ = ERROR_SUCCESS; |
| 1060 | 1076 |
| 1061 EXPECT_TRUE(MatchesRegistrySentinel()); | 1077 EXPECT_TRUE(MatchesRegistrySentinel()); |
| 1062 } | 1078 } |
| 1063 | 1079 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1207 PolicyMap& expected_policy = expected.Get(ns); | 1223 PolicyMap& expected_policy = expected.Get(ns); |
| 1208 expected_policy.Set("alternative_browser_path", | 1224 expected_policy.Set("alternative_browser_path", |
| 1209 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, | 1225 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, |
| 1210 new base::StringValue("c:\\legacy\\browser.exe"), NULL); | 1226 new base::StringValue("c:\\legacy\\browser.exe"), NULL); |
| 1211 expected_policy.Set("url_list", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, | 1227 expected_policy.Set("url_list", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, |
| 1212 list.DeepCopy(), NULL); | 1228 list.DeepCopy(), NULL); |
| 1213 EXPECT_TRUE(Matches(expected)); | 1229 EXPECT_TRUE(Matches(expected)); |
| 1214 } | 1230 } |
| 1215 | 1231 |
| 1216 } // namespace policy | 1232 } // namespace policy |
| OLD | NEW |