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 10 matching lines...) Expand all Loading... |
21 #include "base/json/json_writer.h" | 21 #include "base/json/json_writer.h" |
22 #include "base/path_service.h" | 22 #include "base/path_service.h" |
23 #include "base/process/process.h" | 23 #include "base/process/process.h" |
24 #include "base/strings/string16.h" | 24 #include "base/strings/string16.h" |
25 #include "base/strings/string_number_conversions.h" | 25 #include "base/strings/string_number_conversions.h" |
26 #include "base/strings/string_util.h" | 26 #include "base/strings/string_util.h" |
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 "base/win/win_util.h" |
31 #include "components/policy/core/common/async_policy_provider.h" | 32 #include "components/policy/core/common/async_policy_provider.h" |
32 #include "components/policy/core/common/configuration_policy_provider_test.h" | 33 #include "components/policy/core/common/configuration_policy_provider_test.h" |
33 #include "components/policy/core/common/external_data_fetcher.h" | 34 #include "components/policy/core/common/external_data_fetcher.h" |
34 #include "components/policy/core/common/policy_bundle.h" | 35 #include "components/policy/core/common/policy_bundle.h" |
35 #include "components/policy/core/common/policy_map.h" | 36 #include "components/policy/core/common/policy_map.h" |
36 #include "components/policy/core/common/preg_parser_win.h" | 37 #include "components/policy/core/common/preg_parser_win.h" |
37 #include "components/policy/core/common/schema_map.h" | 38 #include "components/policy/core/common/schema_map.h" |
38 #include "testing/gtest/include/gtest/gtest.h" | 39 #include "testing/gtest/include/gtest/gtest.h" |
39 | 40 |
40 using base::UTF8ToUTF16; | 41 using base::UTF8ToUTF16; |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 RegistryTestHarness::RegistryTestHarness(HKEY hive, PolicyScope scope) | 340 RegistryTestHarness::RegistryTestHarness(HKEY hive, PolicyScope scope) |
340 : PolicyProviderTestHarness(POLICY_LEVEL_MANDATORY, scope), hive_(hive) {} | 341 : PolicyProviderTestHarness(POLICY_LEVEL_MANDATORY, scope), hive_(hive) {} |
341 | 342 |
342 RegistryTestHarness::~RegistryTestHarness() {} | 343 RegistryTestHarness::~RegistryTestHarness() {} |
343 | 344 |
344 void RegistryTestHarness::SetUp() {} | 345 void RegistryTestHarness::SetUp() {} |
345 | 346 |
346 ConfigurationPolicyProvider* RegistryTestHarness::CreateProvider( | 347 ConfigurationPolicyProvider* RegistryTestHarness::CreateProvider( |
347 SchemaRegistry* registry, | 348 SchemaRegistry* registry, |
348 scoped_refptr<base::SequencedTaskRunner> task_runner) { | 349 scoped_refptr<base::SequencedTaskRunner> task_runner) { |
| 350 base::win::SetDomainStateForTesting(true); |
349 scoped_ptr<AsyncPolicyLoader> loader( | 351 scoped_ptr<AsyncPolicyLoader> loader( |
350 new PolicyLoaderWin(task_runner, kTestPolicyKey, this)); | 352 new PolicyLoaderWin(task_runner, kTestPolicyKey, this)); |
351 return new AsyncPolicyProvider(registry, loader.Pass()); | 353 return new AsyncPolicyProvider(registry, loader.Pass()); |
352 } | 354 } |
353 | 355 |
354 void RegistryTestHarness::InstallEmptyPolicy() {} | 356 void RegistryTestHarness::InstallEmptyPolicy() {} |
355 | 357 |
356 void RegistryTestHarness::InstallStringPolicy( | 358 void RegistryTestHarness::InstallStringPolicy( |
357 const std::string& policy_name, | 359 const std::string& policy_name, |
358 const std::string& policy_value) { | 360 const std::string& policy_value) { |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 PolicyProviderTestHarness* RegistryTestHarness::CreateHKLM() { | 458 PolicyProviderTestHarness* RegistryTestHarness::CreateHKLM() { |
457 return new RegistryTestHarness(HKEY_LOCAL_MACHINE, POLICY_SCOPE_MACHINE); | 459 return new RegistryTestHarness(HKEY_LOCAL_MACHINE, POLICY_SCOPE_MACHINE); |
458 } | 460 } |
459 | 461 |
460 PRegTestHarness::PRegTestHarness() | 462 PRegTestHarness::PRegTestHarness() |
461 : PolicyProviderTestHarness(POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE) {} | 463 : PolicyProviderTestHarness(POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE) {} |
462 | 464 |
463 PRegTestHarness::~PRegTestHarness() {} | 465 PRegTestHarness::~PRegTestHarness() {} |
464 | 466 |
465 void PRegTestHarness::SetUp() { | 467 void PRegTestHarness::SetUp() { |
| 468 base::win::SetDomainStateForTesting(false); |
466 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 469 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
467 preg_file_path_ = temp_dir_.path().Append(PolicyLoaderWin::kPRegFileName); | 470 preg_file_path_ = temp_dir_.path().Append(PolicyLoaderWin::kPRegFileName); |
468 ASSERT_TRUE(file_util::WriteFile(preg_file_path_, | 471 ASSERT_TRUE(file_util::WriteFile(preg_file_path_, |
469 preg_parser::kPRegFileHeader, | 472 preg_parser::kPRegFileHeader, |
470 arraysize(preg_parser::kPRegFileHeader))); | 473 arraysize(preg_parser::kPRegFileHeader))); |
471 | 474 |
472 memset(&gpo_, 0, sizeof(GROUP_POLICY_OBJECT)); | 475 memset(&gpo_, 0, sizeof(GROUP_POLICY_OBJECT)); |
473 gpo_.lpFileSysPath = const_cast<wchar_t*>(temp_dir_.path().value().c_str()); | 476 gpo_.lpFileSysPath = const_cast<wchar_t*>(temp_dir_.path().value().c_str()); |
474 } | 477 } |
475 | 478 |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
695 // 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 |
696 // files in chrome/test/data/policy/gpo. | 699 // files in chrome/test/data/policy/gpo. |
697 static const base::char16 kTestPolicyKey[]; | 700 static const base::char16 kTestPolicyKey[]; |
698 | 701 |
699 PolicyLoaderWinTest() | 702 PolicyLoaderWinTest() |
700 : gpo_list_(NULL), | 703 : gpo_list_(NULL), |
701 gpo_list_status_(ERROR_ACCESS_DENIED) {} | 704 gpo_list_status_(ERROR_ACCESS_DENIED) {} |
702 virtual ~PolicyLoaderWinTest() {} | 705 virtual ~PolicyLoaderWinTest() {} |
703 | 706 |
704 virtual void SetUp() OVERRIDE { | 707 virtual void SetUp() OVERRIDE { |
| 708 base::win::SetDomainStateForTesting(false); |
705 PolicyTestBase::SetUp(); | 709 PolicyTestBase::SetUp(); |
706 | 710 |
707 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &test_data_dir_)); | 711 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &test_data_dir_)); |
708 test_data_dir_ = test_data_dir_.AppendASCII("chrome") | 712 test_data_dir_ = test_data_dir_.AppendASCII("chrome") |
709 .AppendASCII("test") | 713 .AppendASCII("test") |
710 .AppendASCII("data") | 714 .AppendASCII("data") |
711 .AppendASCII("policy") | 715 .AppendASCII("policy") |
712 .AppendASCII("gpo"); | 716 .AppendASCII("gpo"); |
713 } | 717 } |
714 | 718 |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1017 base::FilePath gpo_dir(test_data_dir_.AppendASCII("empty")); | 1021 base::FilePath gpo_dir(test_data_dir_.AppendASCII("empty")); |
1018 GROUP_POLICY_OBJECT gpo; | 1022 GROUP_POLICY_OBJECT gpo; |
1019 InitGPO(&gpo, 0, gpo_dir, NULL, NULL); | 1023 InitGPO(&gpo, 0, gpo_dir, NULL, NULL); |
1020 gpo_list_ = &gpo; | 1024 gpo_list_ = &gpo; |
1021 gpo_list_status_ = ERROR_SUCCESS; | 1025 gpo_list_status_ = ERROR_SUCCESS; |
1022 | 1026 |
1023 PolicyBundle empty; | 1027 PolicyBundle empty; |
1024 EXPECT_TRUE(Matches(empty)); | 1028 EXPECT_TRUE(Matches(empty)); |
1025 } | 1029 } |
1026 | 1030 |
| 1031 TEST_F(PolicyLoaderWinTest, AppliedPolicyInDomain) { |
| 1032 base::win::SetDomainStateForTesting(true); |
| 1033 InstallRegistrySentinel(); |
| 1034 base::FilePath gpo_dir(test_data_dir_.AppendASCII("empty")); |
| 1035 GROUP_POLICY_OBJECT gpo; |
| 1036 InitGPO(&gpo, 0, gpo_dir, NULL, NULL); |
| 1037 gpo_list_ = &gpo; |
| 1038 gpo_list_status_ = ERROR_SUCCESS; |
| 1039 |
| 1040 PolicyBundle empty; |
| 1041 EXPECT_TRUE(MatchesRegistrySentinel()); |
| 1042 } |
| 1043 |
1027 TEST_F(PolicyLoaderWinTest, AppliedPolicyNonExistingFile) { | 1044 TEST_F(PolicyLoaderWinTest, AppliedPolicyNonExistingFile) { |
1028 InstallRegistrySentinel(); | 1045 InstallRegistrySentinel(); |
1029 GROUP_POLICY_OBJECT gpo; | 1046 GROUP_POLICY_OBJECT gpo; |
1030 InitGPO(&gpo, 0, test_data_dir_, NULL, NULL); | 1047 InitGPO(&gpo, 0, test_data_dir_, NULL, NULL); |
1031 gpo_list_ = &gpo; | 1048 gpo_list_ = &gpo; |
1032 gpo_list_status_ = ERROR_SUCCESS; | 1049 gpo_list_status_ = ERROR_SUCCESS; |
1033 | 1050 |
1034 EXPECT_TRUE(MatchesRegistrySentinel()); | 1051 EXPECT_TRUE(MatchesRegistrySentinel()); |
1035 } | 1052 } |
1036 | 1053 |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1180 PolicyMap& expected_policy = expected.Get(ns); | 1197 PolicyMap& expected_policy = expected.Get(ns); |
1181 expected_policy.Set("alternative_browser_path", | 1198 expected_policy.Set("alternative_browser_path", |
1182 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, | 1199 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, |
1183 new base::StringValue("c:\\legacy\\browser.exe"), NULL); | 1200 new base::StringValue("c:\\legacy\\browser.exe"), NULL); |
1184 expected_policy.Set("url_list", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, | 1201 expected_policy.Set("url_list", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, |
1185 list.DeepCopy(), NULL); | 1202 list.DeepCopy(), NULL); |
1186 EXPECT_TRUE(Matches(expected)); | 1203 EXPECT_TRUE(Matches(expected)); |
1187 } | 1204 } |
1188 | 1205 |
1189 } // namespace policy | 1206 } // namespace policy |
OLD | NEW |