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 "base/strings/stringprintf.h" | 5 #include "base/strings/stringprintf.h" |
6 #include "sandbox/win/src/handle_policy.h" | 6 #include "sandbox/win/src/handle_policy.h" |
7 #include "sandbox/win/src/nt_internals.h" | 7 #include "sandbox/win/src/nt_internals.h" |
8 #include "sandbox/win/src/sandbox.h" | 8 #include "sandbox/win/src/sandbox.h" |
9 #include "sandbox/win/src/sandbox_factory.h" | 9 #include "sandbox/win/src/sandbox_factory.h" |
10 #include "sandbox/win/src/sandbox_policy.h" | 10 #include "sandbox/win/src/sandbox_policy.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 // Tests that duplicating an object works only when the policy allows it. | 47 // Tests that duplicating an object works only when the policy allows it. |
48 TEST(HandlePolicyTest, DuplicateHandle) { | 48 TEST(HandlePolicyTest, DuplicateHandle) { |
49 TestRunner target; | 49 TestRunner target; |
50 TestRunner runner; | 50 TestRunner runner; |
51 | 51 |
52 // Kick off an asynchronous target process for testing. | 52 // Kick off an asynchronous target process for testing. |
53 target.SetAsynchronous(true); | 53 target.SetAsynchronous(true); |
54 EXPECT_EQ(SBOX_TEST_SUCCEEDED, target.RunTest(L"Handle_WaitProcess 30000")); | 54 EXPECT_EQ(SBOX_TEST_SUCCEEDED, target.RunTest(L"Handle_WaitProcess 30000")); |
55 | 55 |
56 // First test that we fail to open the event. | 56 // First test that we fail to open the event. |
57 std::wstring cmd_line = base::StringPrintf(L"Handle_DuplicateEvent %d", | 57 base::string16 cmd_line = base::StringPrintf(L"Handle_DuplicateEvent %d", |
58 target.process_id()); | 58 target.process_id()); |
59 EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(cmd_line.c_str())); | 59 EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(cmd_line.c_str())); |
60 | 60 |
61 // Now successfully open the event after adding a duplicate handle rule. | 61 // Now successfully open the event after adding a duplicate handle rule. |
62 EXPECT_TRUE(runner.AddRule(TargetPolicy::SUBSYS_HANDLES, | 62 EXPECT_TRUE(runner.AddRule(TargetPolicy::SUBSYS_HANDLES, |
63 TargetPolicy::HANDLES_DUP_ANY, | 63 TargetPolicy::HANDLES_DUP_ANY, |
64 L"Event")); | 64 L"Event")); |
65 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(cmd_line.c_str())); | 65 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(cmd_line.c_str())); |
66 } | 66 } |
67 | 67 |
68 // Tests that duplicating an object works only when the policy allows it. | 68 // Tests that duplicating an object works only when the policy allows it. |
69 TEST(HandlePolicyTest, DuplicatePeerHandle) { | 69 TEST(HandlePolicyTest, DuplicatePeerHandle) { |
70 TestRunner target; | 70 TestRunner target; |
71 TestRunner runner; | 71 TestRunner runner; |
72 | 72 |
73 // Kick off an asynchronous target process for testing. | 73 // Kick off an asynchronous target process for testing. |
74 target.SetAsynchronous(true); | 74 target.SetAsynchronous(true); |
75 target.SetUnsandboxed(true); | 75 target.SetUnsandboxed(true); |
76 EXPECT_EQ(SBOX_TEST_SUCCEEDED, target.RunTest(L"Handle_WaitProcess 30000")); | 76 EXPECT_EQ(SBOX_TEST_SUCCEEDED, target.RunTest(L"Handle_WaitProcess 30000")); |
77 | 77 |
78 // First test that we fail to open the event. | 78 // First test that we fail to open the event. |
79 std::wstring cmd_line = base::StringPrintf(L"Handle_DuplicateEvent %d", | 79 base::string16 cmd_line = base::StringPrintf(L"Handle_DuplicateEvent %d", |
80 target.process_id()); | 80 target.process_id()); |
81 EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(cmd_line.c_str())); | 81 EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(cmd_line.c_str())); |
82 | 82 |
83 // Now successfully open the event after adding a duplicate handle rule. | 83 // Now successfully open the event after adding a duplicate handle rule. |
84 EXPECT_TRUE(runner.AddRule(TargetPolicy::SUBSYS_HANDLES, | 84 EXPECT_TRUE(runner.AddRule(TargetPolicy::SUBSYS_HANDLES, |
85 TargetPolicy::HANDLES_DUP_ANY, | 85 TargetPolicy::HANDLES_DUP_ANY, |
86 L"Event")); | 86 L"Event")); |
87 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(cmd_line.c_str())); | 87 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(cmd_line.c_str())); |
88 } | 88 } |
89 | 89 |
90 // Tests that duplicating an object works only when the policy allows it. | 90 // Tests that duplicating an object works only when the policy allows it. |
91 TEST(HandlePolicyTest, DuplicateBrokerHandle) { | 91 TEST(HandlePolicyTest, DuplicateBrokerHandle) { |
92 TestRunner runner; | 92 TestRunner runner; |
93 | 93 |
94 // First test that we fail to open the event. | 94 // First test that we fail to open the event. |
95 std::wstring cmd_line = base::StringPrintf(L"Handle_DuplicateEvent %d", | 95 base::string16 cmd_line = base::StringPrintf(L"Handle_DuplicateEvent %d", |
96 ::GetCurrentProcessId()); | 96 ::GetCurrentProcessId()); |
97 EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(cmd_line.c_str())); | 97 EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(cmd_line.c_str())); |
98 | 98 |
99 // Add the peer rule and make sure we fail again. | 99 // Add the peer rule and make sure we fail again. |
100 EXPECT_TRUE(runner.AddRule(TargetPolicy::SUBSYS_HANDLES, | 100 EXPECT_TRUE(runner.AddRule(TargetPolicy::SUBSYS_HANDLES, |
101 TargetPolicy::HANDLES_DUP_ANY, | 101 TargetPolicy::HANDLES_DUP_ANY, |
102 L"Event")); | 102 L"Event")); |
103 EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(cmd_line.c_str())); | 103 EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(cmd_line.c_str())); |
104 | 104 |
105 | 105 |
106 // Now successfully open the event after adding a broker handle rule. | 106 // Now successfully open the event after adding a broker handle rule. |
107 EXPECT_TRUE(runner.AddRule(TargetPolicy::SUBSYS_HANDLES, | 107 EXPECT_TRUE(runner.AddRule(TargetPolicy::SUBSYS_HANDLES, |
108 TargetPolicy::HANDLES_DUP_BROKER, | 108 TargetPolicy::HANDLES_DUP_BROKER, |
109 L"Event")); | 109 L"Event")); |
110 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(cmd_line.c_str())); | 110 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(cmd_line.c_str())); |
111 } | 111 } |
112 | 112 |
113 } // namespace sandbox | 113 } // namespace sandbox |
114 | 114 |
OLD | NEW |