Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(564)

Side by Side Diff: sandbox/win/src/policy_target_test.cc

Issue 1814863004: Cleanup/Remove Windows XP/Vista version checks from Windows sandbox code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: revert disabled reparse point check Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sandbox/win/src/policy_broker.cc ('k') | sandbox/win/src/process_mitigations.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/memory/shared_memory.h" 5 #include "base/memory/shared_memory.h"
6 #include "base/strings/string_number_conversions.h" 6 #include "base/strings/string_number_conversions.h"
7 #include "base/strings/string_piece.h" 7 #include "base/strings/string_piece.h"
8 #include "base/win/scoped_process_information.h" 8 #include "base/win/scoped_process_information.h"
9 #include "base/win/windows_version.h" 9 #include "base/win/windows_version.h"
10 #include "sandbox/win/src/sandbox.h" 10 #include "sandbox/win/src/sandbox.h"
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 base::string16 writable_cmdline_str(L"foo.exe"); 163 base::string16 writable_cmdline_str(L"foo.exe");
164 if (!::CreateProcessW(L"foo.exe", &writable_cmdline_str[0], NULL, NULL, FALSE, 164 if (!::CreateProcessW(L"foo.exe", &writable_cmdline_str[0], NULL, NULL, FALSE,
165 0, NULL, NULL, &startup_info, &temp_process_info)) 165 0, NULL, NULL, &startup_info, &temp_process_info))
166 return SBOX_TEST_SUCCEEDED; 166 return SBOX_TEST_SUCCEEDED;
167 base::win::ScopedProcessInformation process_info(temp_process_info); 167 base::win::ScopedProcessInformation process_info(temp_process_info);
168 return SBOX_TEST_FAILED; 168 return SBOX_TEST_FAILED;
169 } 169 }
170 170
171 TEST(PolicyTargetTest, SetInformationThread) { 171 TEST(PolicyTargetTest, SetInformationThread) {
172 TestRunner runner; 172 TestRunner runner;
173 if (base::win::GetVersion() >= base::win::VERSION_XP) { 173 runner.SetTestState(BEFORE_REVERT);
174 runner.SetTestState(BEFORE_REVERT); 174 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"PolicyTargetTest_token"));
175 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"PolicyTargetTest_token"));
176 }
177 175
178 runner.SetTestState(AFTER_REVERT); 176 runner.SetTestState(AFTER_REVERT);
179 EXPECT_EQ(ERROR_NO_TOKEN, runner.RunTest(L"PolicyTargetTest_token")); 177 EXPECT_EQ(ERROR_NO_TOKEN, runner.RunTest(L"PolicyTargetTest_token"));
180 178
181 runner.SetTestState(EVERY_STATE); 179 runner.SetTestState(EVERY_STATE);
182 if (base::win::GetVersion() >= base::win::VERSION_XP) 180 EXPECT_EQ(SBOX_TEST_FAILED, runner.RunTest(L"PolicyTargetTest_steal"));
183 EXPECT_EQ(SBOX_TEST_FAILED, runner.RunTest(L"PolicyTargetTest_steal"));
184 } 181 }
185 182
186 TEST(PolicyTargetTest, OpenThreadToken) { 183 TEST(PolicyTargetTest, OpenThreadToken) {
187 TestRunner runner; 184 TestRunner runner;
188 if (base::win::GetVersion() >= base::win::VERSION_XP) { 185 runner.SetTestState(BEFORE_REVERT);
189 runner.SetTestState(BEFORE_REVERT); 186 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"PolicyTargetTest_token2"));
190 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"PolicyTargetTest_token2"));
191 }
192 187
193 runner.SetTestState(AFTER_REVERT); 188 runner.SetTestState(AFTER_REVERT);
194 EXPECT_EQ(ERROR_NO_TOKEN, runner.RunTest(L"PolicyTargetTest_token2")); 189 EXPECT_EQ(ERROR_NO_TOKEN, runner.RunTest(L"PolicyTargetTest_token2"));
195 } 190 }
196 191
197 TEST(PolicyTargetTest, OpenThreadTokenEx) { 192 TEST(PolicyTargetTest, OpenThreadTokenEx) {
198 TestRunner runner; 193 TestRunner runner;
199 if (base::win::GetVersion() < base::win::VERSION_XP)
200 return;
201 194
202 runner.SetTestState(BEFORE_REVERT); 195 runner.SetTestState(BEFORE_REVERT);
203 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"PolicyTargetTest_token3")); 196 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"PolicyTargetTest_token3"));
204 197
205 runner.SetTestState(AFTER_REVERT); 198 runner.SetTestState(AFTER_REVERT);
206 EXPECT_EQ(ERROR_NO_TOKEN, runner.RunTest(L"PolicyTargetTest_token3")); 199 EXPECT_EQ(ERROR_NO_TOKEN, runner.RunTest(L"PolicyTargetTest_token3"));
207 } 200 }
208 201
209 TEST(PolicyTargetTest, OpenThread) { 202 TEST(PolicyTargetTest, OpenThread) {
210 TestRunner runner; 203 TestRunner runner;
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 342
350 // Close the desktop handle. 343 // Close the desktop handle.
351 temp_policy = broker->CreatePolicy(); 344 temp_policy = broker->CreatePolicy();
352 temp_policy->DestroyAlternateDesktop(); 345 temp_policy->DestroyAlternateDesktop();
353 temp_policy->Release(); 346 temp_policy->Release();
354 } 347 }
355 348
356 // Launches the app in the sandbox and share a handle with it. The app should 349 // Launches the app in the sandbox and share a handle with it. The app should
357 // be able to use the handle. 350 // be able to use the handle.
358 TEST(PolicyTargetTest, ShareHandleTest) { 351 TEST(PolicyTargetTest, ShareHandleTest) {
359 // The way we share handles via STARTUPINFOEX does not work on XP.
360 if (base::win::GetVersion() < base::win::VERSION_VISTA)
361 return;
362 352
363 BrokerServices* broker = GetBroker(); 353 BrokerServices* broker = GetBroker();
364 ASSERT_TRUE(broker != NULL); 354 ASSERT_TRUE(broker != NULL);
365 355
366 base::StringPiece contents = "Hello World"; 356 base::StringPiece contents = "Hello World";
367 std::string name = "TestSharedMemory"; 357 std::string name = "TestSharedMemory";
368 base::SharedMemoryCreateOptions options; 358 base::SharedMemoryCreateOptions options;
369 options.size = contents.size(); 359 options.size = contents.size();
370 options.share_read_only = true; 360 options.share_read_only = true;
371 options.name_deprecated = &name; 361 options.name_deprecated = &name;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 398
409 EXPECT_EQ(static_cast<DWORD>(WAIT_TIMEOUT), 399 EXPECT_EQ(static_cast<DWORD>(WAIT_TIMEOUT),
410 ::WaitForSingleObject(target.process_handle(), 2000)); 400 ::WaitForSingleObject(target.process_handle(), 2000));
411 401
412 EXPECT_TRUE(::TerminateProcess(target.process_handle(), 0)); 402 EXPECT_TRUE(::TerminateProcess(target.process_handle(), 0));
413 403
414 ::WaitForSingleObject(target.process_handle(), INFINITE); 404 ::WaitForSingleObject(target.process_handle(), INFINITE);
415 } 405 }
416 406
417 } // namespace sandbox 407 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/win/src/policy_broker.cc ('k') | sandbox/win/src/process_mitigations.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698