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

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

Issue 1851213002: Remove sandbox on Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix nacl compile issues Created 4 years, 8 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/sync_policy_test.h ('k') | sandbox/win/src/target_interceptions.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "sandbox/win/src/sync_policy_test.h"
6
7 #include "base/win/scoped_handle.h"
8 #include "sandbox/win/src/sandbox.h"
9 #include "sandbox/win/src/sandbox_policy.h"
10 #include "sandbox/win/src/sandbox_factory.h"
11 #include "sandbox/win/src/nt_internals.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 namespace sandbox {
15
16 SBOX_TESTS_COMMAND int Event_Open(int argc, wchar_t **argv) {
17 if (argc != 2)
18 return SBOX_TEST_FAILED_TO_EXECUTE_COMMAND;
19
20 DWORD desired_access = SYNCHRONIZE;
21 if (L'f' == argv[0][0])
22 desired_access = EVENT_ALL_ACCESS;
23
24 base::win::ScopedHandle event_open(::OpenEvent(
25 desired_access, FALSE, argv[1]));
26 DWORD error_open = ::GetLastError();
27
28 if (event_open.IsValid())
29 return SBOX_TEST_SUCCEEDED;
30
31 if (ERROR_ACCESS_DENIED == error_open ||
32 ERROR_BAD_PATHNAME == error_open ||
33 ERROR_FILE_NOT_FOUND == error_open)
34 return SBOX_TEST_DENIED;
35
36 return SBOX_TEST_FAILED;
37 }
38
39 SBOX_TESTS_COMMAND int Event_CreateOpen(int argc, wchar_t **argv) {
40 if (argc < 2 || argc > 3)
41 return SBOX_TEST_FAILED_TO_EXECUTE_COMMAND;
42
43 wchar_t *event_name = NULL;
44 if (3 == argc)
45 event_name = argv[2];
46
47 BOOL manual_reset = FALSE;
48 BOOL initial_state = FALSE;
49 if (L't' == argv[0][0])
50 manual_reset = TRUE;
51 if (L't' == argv[1][0])
52 initial_state = TRUE;
53
54 base::win::ScopedHandle event_create(::CreateEvent(
55 NULL, manual_reset, initial_state, event_name));
56 DWORD error_create = ::GetLastError();
57 base::win::ScopedHandle event_open;
58 if (event_name)
59 event_open.Set(::OpenEvent(EVENT_ALL_ACCESS, FALSE, event_name));
60
61 if (event_create.IsValid()) {
62 DWORD wait = ::WaitForSingleObject(event_create.Get(), 0);
63 if (initial_state && WAIT_OBJECT_0 != wait)
64 return SBOX_TEST_FAILED;
65
66 if (!initial_state && WAIT_TIMEOUT != wait)
67 return SBOX_TEST_FAILED;
68 }
69
70 if (event_name) {
71 // Both event_open and event_create have to be valid.
72 if (event_open.IsValid() && event_create.IsValid())
73 return SBOX_TEST_SUCCEEDED;
74
75 if ((event_open.IsValid() && !event_create.IsValid()) ||
76 (!event_open.IsValid() && event_create.IsValid())) {
77 return SBOX_TEST_FAILED;
78 }
79 } else {
80 // Only event_create has to be valid.
81 if (event_create.Get())
82 return SBOX_TEST_SUCCEEDED;
83 }
84
85 if (ERROR_ACCESS_DENIED == error_create ||
86 ERROR_BAD_PATHNAME == error_create)
87 return SBOX_TEST_DENIED;
88
89 return SBOX_TEST_FAILED;
90 }
91
92 // Tests the creation of events using all the possible combinations.
93 TEST(SyncPolicyTest, TestEvent) {
94 TestRunner runner;
95 EXPECT_TRUE(runner.AddRule(TargetPolicy::SUBSYS_SYNC,
96 TargetPolicy::EVENTS_ALLOW_ANY,
97 L"test1"));
98 EXPECT_TRUE(runner.AddRule(TargetPolicy::SUBSYS_SYNC,
99 TargetPolicy::EVENTS_ALLOW_ANY,
100 L"test2"));
101
102 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"Event_CreateOpen f f"));
103 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"Event_CreateOpen t f"));
104 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"Event_CreateOpen f t"));
105 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"Event_CreateOpen t t"));
106 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"Event_CreateOpen f f test1"));
107 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"Event_CreateOpen t f test2"));
108 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"Event_CreateOpen f t test1"));
109 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"Event_CreateOpen t t test2"));
110 EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(L"Event_CreateOpen f f test3"));
111 EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(L"Event_CreateOpen t f test4"));
112 EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(L"Event_CreateOpen f t test3"));
113 EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(L"Event_CreateOpen t t test4"));
114 }
115
116 // Tests opening events with read only access.
117 TEST(SyncPolicyTest, TestEventReadOnly) {
118 TestRunner runner;
119 EXPECT_TRUE(runner.AddRule(TargetPolicy::SUBSYS_SYNC,
120 TargetPolicy::EVENTS_ALLOW_READONLY,
121 L"test1"));
122 EXPECT_TRUE(runner.AddRule(TargetPolicy::SUBSYS_SYNC,
123 TargetPolicy::EVENTS_ALLOW_READONLY,
124 L"test2"));
125 EXPECT_TRUE(runner.AddRule(TargetPolicy::SUBSYS_SYNC,
126 TargetPolicy::EVENTS_ALLOW_READONLY,
127 L"test5"));
128 EXPECT_TRUE(runner.AddRule(TargetPolicy::SUBSYS_SYNC,
129 TargetPolicy::EVENTS_ALLOW_READONLY,
130 L"test6"));
131
132 base::win::ScopedHandle handle1(::CreateEvent(NULL, FALSE, FALSE, L"test1"));
133 base::win::ScopedHandle handle2(::CreateEvent(NULL, FALSE, FALSE, L"test2"));
134 base::win::ScopedHandle handle3(::CreateEvent(NULL, FALSE, FALSE, L"test3"));
135 base::win::ScopedHandle handle4(::CreateEvent(NULL, FALSE, FALSE, L"test4"));
136
137 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"Event_CreateOpen f f"));
138 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"Event_CreateOpen t f"));
139 EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(L"Event_Open f test1"));
140 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"Event_Open s test2"));
141 EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(L"Event_Open f test3"));
142 EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(L"Event_Open s test4"));
143 EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(L"Event_CreateOpen f f test5"));
144 EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(L"Event_CreateOpen t f test6"));
145 EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(L"Event_CreateOpen f t test5"));
146 EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(L"Event_CreateOpen t t test6"));
147 }
148
149 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/win/src/sync_policy_test.h ('k') | sandbox/win/src/target_interceptions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698