OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <tuple> | 5 #include <tuple> |
6 #include <windows.h> | 6 #include <windows.h> |
7 #include <versionhelpers.h> // windows.h must be before. | 7 #include <versionhelpers.h> // windows.h must be before. |
8 | 8 |
9 #include "base/test/test_reg_util_win.h" | 9 #include "base/test/test_reg_util_win.h" |
10 #include "base/win/registry.h" | 10 #include "base/win/registry.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 &policy, sizeof(policy))) | 65 &policy, sizeof(policy))) |
66 return false; | 66 return false; |
67 | 67 |
68 return policy.DisableExtensionPoints; | 68 return policy.DisableExtensionPoints; |
69 } | 69 } |
70 | 70 |
71 return true; | 71 return true; |
72 } | 72 } |
73 | 73 |
74 void RegRedirect(nt::ROOT_KEY key, | 74 void RegRedirect(nt::ROOT_KEY key, |
75 registry_util::RegistryOverrideManager& rom) { | 75 registry_util::RegistryOverrideManager* rom) { |
76 ASSERT_TRUE(key != nt::AUTO); | |
grt (UTC plus 2)
2016/09/30 09:32:16
ASSERT_NE(key, nt::AUTO);?
penny
2016/10/01 01:44:25
Better, yes.
| |
76 base::string16 temp; | 77 base::string16 temp; |
77 | 78 |
78 if (key == nt::HKCU) { | 79 if (key == nt::HKCU) { |
79 rom.OverrideRegistry(HKEY_CURRENT_USER, &temp); | 80 rom->OverrideRegistry(HKEY_CURRENT_USER, &temp); |
80 ::wcsncpy(nt::HKCU_override, temp.c_str(), nt::g_kRegMaxPathLen - 1); | 81 ASSERT_TRUE(nt::SetTestingOverride(nt::HKCU, temp)); |
81 } else if (key == nt::HKLM) { | 82 } else { |
82 rom.OverrideRegistry(HKEY_LOCAL_MACHINE, &temp); | 83 rom->OverrideRegistry(HKEY_LOCAL_MACHINE, &temp); |
83 ::wcsncpy(nt::HKLM_override, temp.c_str(), nt::g_kRegMaxPathLen - 1); | 84 ASSERT_TRUE(nt::SetTestingOverride(nt::HKLM, temp)); |
84 } | 85 } |
85 // nt::AUTO should not be passed into this function. | 86 } |
87 | |
88 void CancelRegRedirect(nt::ROOT_KEY key) { | |
89 ASSERT_TRUE(key != nt::AUTO); | |
grt (UTC plus 2)
2016/09/30 09:32:16
ASSERT_NE
penny
2016/10/01 01:44:25
Done.
| |
90 base::string16 temp = L""; | |
grt (UTC plus 2)
2016/09/30 09:32:16
omit assignment
penny
2016/10/01 01:44:25
Done.
| |
91 if (key == nt::HKCU) | |
92 ASSERT_TRUE(nt::SetTestingOverride(nt::HKCU, temp)); | |
93 else | |
94 ASSERT_TRUE(nt::SetTestingOverride(nt::HKLM, temp)); | |
86 } | 95 } |
87 | 96 |
88 TEST(ChromeElfUtilTest, CanaryTest) { | 97 TEST(ChromeElfUtilTest, CanaryTest) { |
89 EXPECT_TRUE(IsSxSChrome(kCanaryExePath)); | 98 EXPECT_TRUE(IsSxSChrome(kCanaryExePath)); |
90 EXPECT_FALSE(IsSxSChrome(kChromeUserExePath)); | 99 EXPECT_FALSE(IsSxSChrome(kChromeUserExePath)); |
91 EXPECT_FALSE(IsSxSChrome(kChromiumExePath)); | 100 EXPECT_FALSE(IsSxSChrome(kChromiumExePath)); |
92 } | 101 } |
93 | 102 |
94 TEST(ChromeElfUtilTest, SystemInstallTest) { | 103 TEST(ChromeElfUtilTest, SystemInstallTest) { |
95 EXPECT_TRUE(IsSystemInstall(kChromeSystemExePath)); | 104 EXPECT_TRUE(IsSystemInstall(kChromeSystemExePath)); |
96 EXPECT_FALSE(IsSystemInstall(kChromeUserExePath)); | 105 EXPECT_FALSE(IsSystemInstall(kChromeUserExePath)); |
97 } | 106 } |
98 | 107 |
99 TEST(ChromeElfUtilTest, BrowserProcessTest) { | 108 TEST(ChromeElfUtilTest, BrowserProcessTest) { |
100 EXPECT_EQ(ProcessType::UNINITIALIZED, g_process_type); | 109 EXPECT_EQ(ProcessType::UNINITIALIZED, g_process_type); |
101 InitializeProcessType(); | 110 InitializeProcessType(); |
102 EXPECT_FALSE(IsNonBrowserProcess()); | 111 EXPECT_FALSE(IsNonBrowserProcess()); |
103 } | 112 } |
104 | 113 |
105 TEST(ChromeElfUtilTest, BrowserProcessSecurityTest) { | 114 TEST(ChromeElfUtilTest, BrowserProcessSecurityTest) { |
106 if (!::IsWindows8OrGreater()) | 115 if (!::IsWindows8OrGreater()) |
107 return; | 116 return; |
108 | 117 |
109 // Set up registry override for this test. | 118 // Set up registry override for this test. |
110 registry_util::RegistryOverrideManager override_manager; | 119 registry_util::RegistryOverrideManager override_manager; |
111 RegRedirect(nt::HKCU, override_manager); | 120 RegRedirect(nt::HKCU, &override_manager); |
112 | 121 |
113 // First, ensure that the emergency-off finch signal works. | 122 // First, ensure that the emergency-off finch signal works. |
114 EXPECT_TRUE(SetSecurityFinchFlag(true)); | 123 EXPECT_TRUE(SetSecurityFinchFlag(true)); |
115 elf_security::EarlyBrowserSecurity(); | 124 elf_security::EarlyBrowserSecurity(); |
116 EXPECT_FALSE(IsSecuritySet()); | 125 EXPECT_FALSE(IsSecuritySet()); |
117 EXPECT_TRUE(SetSecurityFinchFlag(false)); | 126 EXPECT_TRUE(SetSecurityFinchFlag(false)); |
118 | 127 |
119 // Second, test that the process mitigation is set when no finch signal. | 128 // Second, test that the process mitigation is set when no finch signal. |
120 elf_security::EarlyBrowserSecurity(); | 129 elf_security::EarlyBrowserSecurity(); |
121 EXPECT_TRUE(IsSecuritySet()); | 130 EXPECT_TRUE(IsSecuritySet()); |
122 } | |
123 | 131 |
124 //------------------------------------------------------------------------------ | 132 CancelRegRedirect(nt::HKCU); |
125 // NT registry API tests (chrome_elf_reg) | |
126 //------------------------------------------------------------------------------ | |
127 | |
128 TEST(ChromeElfUtilTest, NTRegistry) { | |
129 HANDLE key_handle; | |
130 const wchar_t* dword_val_name = L"DwordTestValue"; | |
131 DWORD dword_val = 1234; | |
132 const wchar_t* sz_val_name = L"SzTestValue"; | |
133 base::string16 sz_val = L"blah de blah de blahhhhh."; | |
134 const wchar_t* sz_val_name2 = L"SzTestValueEmpty"; | |
135 base::string16 sz_val2 = L""; | |
136 const wchar_t* multisz_val_name = L"SzmultiTestValue"; | |
137 std::vector<base::string16> multisz_val; | |
138 base::string16 multi1 = L"one"; | |
139 base::string16 multi2 = L"two"; | |
140 base::string16 multi3 = L"three"; | |
141 const wchar_t* multisz_val_name2 = L"SzmultiTestValueBad"; | |
142 base::string16 multi_empty = L""; | |
143 const wchar_t* sz_new_key_1 = L"test\\new\\subkey"; | |
144 const wchar_t* sz_new_key_2 = L"test\\new\\subkey\\blah\\"; | |
145 const wchar_t* sz_new_key_3 = L"\\test\\new\\subkey\\\\blah2"; | |
146 | |
147 // Set up registry override for this test. | |
148 registry_util::RegistryOverrideManager override_manager; | |
149 RegRedirect(nt::HKCU, override_manager); | |
150 | |
151 // Create a temp key to play under. | |
152 ASSERT_TRUE(nt::CreateRegKey(nt::HKCU, elf_sec::kRegSecurityPath, | |
153 KEY_ALL_ACCESS, &key_handle)); | |
154 | |
155 // Exercise the supported getter & setter functions. | |
156 EXPECT_TRUE(nt::SetRegValueDWORD(key_handle, dword_val_name, dword_val)); | |
157 EXPECT_TRUE(nt::SetRegValueSZ(key_handle, sz_val_name, sz_val)); | |
158 EXPECT_TRUE(nt::SetRegValueSZ(key_handle, sz_val_name2, sz_val2)); | |
159 | |
160 DWORD get_dword = 0; | |
161 base::string16 get_sz; | |
162 EXPECT_TRUE(nt::QueryRegValueDWORD(key_handle, dword_val_name, &get_dword) && | |
163 get_dword == dword_val); | |
164 EXPECT_TRUE(nt::QueryRegValueSZ(key_handle, sz_val_name, &get_sz) && | |
165 get_sz.compare(sz_val) == 0); | |
166 EXPECT_TRUE(nt::QueryRegValueSZ(key_handle, sz_val_name2, &get_sz) && | |
167 get_sz.compare(sz_val2) == 0); | |
168 | |
169 multisz_val.push_back(multi1); | |
170 multisz_val.push_back(multi2); | |
171 multisz_val.push_back(multi3); | |
172 EXPECT_TRUE( | |
173 nt::SetRegValueMULTISZ(key_handle, multisz_val_name, multisz_val)); | |
174 multisz_val.clear(); | |
175 multisz_val.push_back(multi_empty); | |
176 EXPECT_TRUE( | |
177 nt::SetRegValueMULTISZ(key_handle, multisz_val_name2, multisz_val)); | |
178 multisz_val.clear(); | |
179 | |
180 EXPECT_TRUE( | |
181 nt::QueryRegValueMULTISZ(key_handle, multisz_val_name, &multisz_val)); | |
182 if (multisz_val.size() == 3) { | |
183 EXPECT_TRUE(multi1.compare(multisz_val.at(0)) == 0); | |
184 EXPECT_TRUE(multi2.compare(multisz_val.at(1)) == 0); | |
185 EXPECT_TRUE(multi3.compare(multisz_val.at(2)) == 0); | |
186 } else { | |
187 EXPECT_TRUE(false); | |
188 } | |
189 multisz_val.clear(); | |
190 | |
191 EXPECT_TRUE( | |
192 nt::QueryRegValueMULTISZ(key_handle, multisz_val_name2, &multisz_val)); | |
193 if (multisz_val.size() == 1) { | |
194 EXPECT_TRUE(multi_empty.compare(multisz_val.at(0)) == 0); | |
195 } else { | |
196 EXPECT_TRUE(false); | |
197 } | |
198 multisz_val.clear(); | |
199 | |
200 // Clean up | |
201 EXPECT_TRUE(nt::DeleteRegKey(key_handle)); | |
202 nt::CloseRegKey(key_handle); | |
203 | |
204 // More tests for CreateRegKey recursion. | |
205 ASSERT_TRUE( | |
206 nt::CreateRegKey(nt::HKCU, sz_new_key_1, KEY_ALL_ACCESS, nullptr)); | |
207 EXPECT_TRUE(nt::OpenRegKey(nt::HKCU, sz_new_key_1, KEY_ALL_ACCESS, | |
208 &key_handle, nullptr)); | |
209 EXPECT_TRUE(nt::DeleteRegKey(key_handle)); | |
210 nt::CloseRegKey(key_handle); | |
211 | |
212 ASSERT_TRUE( | |
213 nt::CreateRegKey(nt::HKCU, sz_new_key_2, KEY_ALL_ACCESS, nullptr)); | |
214 EXPECT_TRUE(nt::OpenRegKey(nt::HKCU, sz_new_key_2, KEY_ALL_ACCESS, | |
215 &key_handle, nullptr)); | |
216 EXPECT_TRUE(nt::DeleteRegKey(key_handle)); | |
217 nt::CloseRegKey(key_handle); | |
218 | |
219 ASSERT_TRUE( | |
220 nt::CreateRegKey(nt::HKCU, sz_new_key_3, KEY_ALL_ACCESS, nullptr)); | |
221 EXPECT_TRUE(nt::OpenRegKey(nt::HKCU, L"test\\new\\subkey\\blah2", | |
222 KEY_ALL_ACCESS, &key_handle, nullptr)); | |
223 EXPECT_TRUE(nt::DeleteRegKey(key_handle)); | |
224 nt::CloseRegKey(key_handle); | |
225 | |
226 ASSERT_TRUE(nt::CreateRegKey(nt::HKCU, nullptr, KEY_ALL_ACCESS, &key_handle)); | |
227 nt::CloseRegKey(key_handle); | |
228 } | 133 } |
229 | 134 |
230 // Parameterized test with paramters: | 135 // Parameterized test with paramters: |
231 // 1: product: "canary" or "google" | 136 // 1: product: "canary" or "google" |
232 // 2: install level: "user" or "system" | 137 // 2: install level: "user" or "system" |
233 // 3: install mode: "single" or "multi" | 138 // 3: install mode: "single" or "multi" |
234 class ChromeElfUtilTest | 139 class ChromeElfUtilTest |
235 : public testing::TestWithParam< | 140 : public testing::TestWithParam< |
236 std::tuple<const char*, const char*, const char*>> { | 141 std::tuple<const char*, const char*, const char*>> { |
237 protected: | 142 protected: |
238 void SetUp() override { | 143 void SetUp() override { |
239 // Set up registry override for these tests. | 144 // Set up registry override for these tests. |
240 RegRedirect(nt::HKLM, override_manager_); | 145 RegRedirect(nt::HKLM, &override_manager_); |
241 RegRedirect(nt::HKCU, override_manager_); | 146 RegRedirect(nt::HKCU, &override_manager_); |
242 | 147 |
243 const char* app; | 148 const char* app; |
244 const char* level; | 149 const char* level; |
245 const char* mode; | 150 const char* mode; |
246 std::tie(app, level, mode) = GetParam(); | 151 std::tie(app, level, mode) = GetParam(); |
247 is_canary_ = (std::string(app) == "canary"); | 152 is_canary_ = (std::string(app) == "canary"); |
248 system_level_ = (std::string(level) != "user"); | 153 system_level_ = (std::string(level) != "user"); |
249 multi_install_ = (std::string(mode) != "single"); | 154 multi_install_ = (std::string(mode) != "single"); |
250 if (is_canary_) { | 155 if (is_canary_) { |
251 ASSERT_FALSE(system_level_); | 156 ASSERT_FALSE(system_level_); |
252 ASSERT_FALSE(multi_install_); | 157 ASSERT_FALSE(multi_install_); |
253 app_guid_ = kAppGuidCanary; | 158 app_guid_ = kAppGuidCanary; |
254 chrome_path_ = kCanaryExePath; | 159 chrome_path_ = kCanaryExePath; |
255 } else { | 160 } else { |
256 app_guid_ = kAppGuidGoogleChrome; | 161 app_guid_ = kAppGuidGoogleChrome; |
257 chrome_path_ = | 162 chrome_path_ = |
258 (system_level_ ? kChromeSystemExePath : kChromeUserExePath); | 163 (system_level_ ? kChromeSystemExePath : kChromeUserExePath); |
259 } | 164 } |
260 if (multi_install_) { | 165 if (multi_install_) { |
261 SetMultiInstallStateInRegistry(system_level_, true); | 166 SetMultiInstallStateInRegistry(system_level_, true); |
262 app_guid_ = kAppGuidGoogleBinaries; | 167 app_guid_ = kAppGuidGoogleBinaries; |
263 } | 168 } |
264 } | 169 } |
265 | 170 |
171 void TearDown() override { | |
172 CancelRegRedirect(nt::HKCU); | |
173 CancelRegRedirect(nt::HKLM); | |
174 } | |
175 | |
266 base::string16 BuildKey(const wchar_t* path, const wchar_t* guid) { | 176 base::string16 BuildKey(const wchar_t* path, const wchar_t* guid) { |
267 base::string16 full_key_path(path); | 177 base::string16 full_key_path(path); |
268 full_key_path.append(1, L'\\'); | 178 full_key_path.append(1, L'\\'); |
269 full_key_path.append(guid); | 179 full_key_path.append(guid); |
270 return full_key_path; | 180 return full_key_path; |
271 } | 181 } |
272 | 182 |
273 void SetUsageStat(DWORD value, bool state_medium) { | 183 void SetUsageStat(DWORD value, bool state_medium) { |
274 LONG result = base::win::RegKey( | 184 LONG result = base::win::RegKey( |
275 system_level_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, | 185 system_level_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
604 testing::Combine(testing::Values("canary"), | 514 testing::Combine(testing::Values("canary"), |
605 testing::Values("user"), | 515 testing::Values("user"), |
606 testing::Values("single"))); | 516 testing::Values("single"))); |
607 INSTANTIATE_TEST_CASE_P(GoogleChrome, | 517 INSTANTIATE_TEST_CASE_P(GoogleChrome, |
608 ChromeElfUtilTest, | 518 ChromeElfUtilTest, |
609 testing::Combine(testing::Values("google"), | 519 testing::Combine(testing::Values("google"), |
610 testing::Values("user", "system"), | 520 testing::Values("user", "system"), |
611 testing::Values("single", "multi"))); | 521 testing::Values("single", "multi"))); |
612 | 522 |
613 } // namespace | 523 } // namespace |
OLD | NEW |