| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <fcntl.h> | 5 #include <fcntl.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 #include <sys/stat.h> | 7 #include <sys/stat.h> |
| 8 #include <unistd.h> | 8 #include <unistd.h> |
| 9 | 9 |
| 10 #include "base/process/kill.h" | 10 #include "base/process/kill.h" |
| 11 #include "base/test/multiprocess_test.h" | 11 #include "base/test/multiprocess_test.h" |
| 12 #include "base/test/test_timeouts.h" | 12 #include "base/test/test_timeouts.h" |
| 13 #include "sandbox/mac/sandbox_compiler.h" | 13 #include "sandbox/mac/sandbox_compiler.h" |
| 14 #include "sandbox/mac/seatbelt.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "testing/multiprocess_func_list.h" | 16 #include "testing/multiprocess_func_list.h" |
| 16 | 17 |
| 17 namespace sandbox { | 18 namespace sandbox { |
| 18 | 19 |
| 19 class SandboxMacCompilerTest : public base::MultiProcessTest {}; | 20 class SandboxMacCompilerTest : public base::MultiProcessTest {}; |
| 20 | 21 |
| 21 MULTIPROCESS_TEST_MAIN(BasicProfileProcess) { | 22 MULTIPROCESS_TEST_MAIN(BasicProfileProcess) { |
| 22 std::string profile = | 23 std::string profile = |
| 23 "(version 1)" | 24 "(version 1)" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 TEST_F(SandboxMacCompilerTest, ProfileFunctionalityTestError) { | 156 TEST_F(SandboxMacCompilerTest, ProfileFunctionalityTestError) { |
| 156 base::SpawnChildResult spawn_child = | 157 base::SpawnChildResult spawn_child = |
| 157 SpawnChild("ProfileFunctionalityTestErrorProcess"); | 158 SpawnChild("ProfileFunctionalityTestErrorProcess"); |
| 158 ASSERT_TRUE(spawn_child.process.IsValid()); | 159 ASSERT_TRUE(spawn_child.process.IsValid()); |
| 159 int exit_code = 42; | 160 int exit_code = 42; |
| 160 EXPECT_TRUE(spawn_child.process.WaitForExitWithTimeout( | 161 EXPECT_TRUE(spawn_child.process.WaitForExitWithTimeout( |
| 161 TestTimeouts::action_max_timeout(), &exit_code)); | 162 TestTimeouts::action_max_timeout(), &exit_code)); |
| 162 EXPECT_EQ(exit_code, 0); | 163 EXPECT_EQ(exit_code, 0); |
| 163 } | 164 } |
| 164 | 165 |
| 166 MULTIPROCESS_TEST_MAIN(SandboxCheckTestProcess) { |
| 167 CHECK(!Seatbelt::IsSandboxed()); |
| 168 std::string profile = |
| 169 "(version 1)" |
| 170 "(deny default (with no-log))"; |
| 171 |
| 172 SandboxCompiler compiler(profile); |
| 173 std::string error; |
| 174 CHECK(compiler.CompileAndApplyProfile(&error)); |
| 175 CHECK(Seatbelt::IsSandboxed()); |
| 176 |
| 177 return 0; |
| 178 } |
| 179 |
| 180 TEST_F(SandboxMacCompilerTest, SandboxCheckTest) { |
| 181 base::SpawnChildResult spawn_child = SpawnChild("SandboxCheckTestProcess"); |
| 182 ASSERT_TRUE(spawn_child.process.IsValid()); |
| 183 int exit_code = 42; |
| 184 EXPECT_TRUE(spawn_child.process.WaitForExitWithTimeout( |
| 185 TestTimeouts::action_max_timeout(), &exit_code)); |
| 186 EXPECT_EQ(exit_code, 0); |
| 187 } |
| 188 |
| 165 } // namespace sandbox | 189 } // namespace sandbox |
| OLD | NEW |