Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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/mac/seatbelt_exec.h" | |
| 6 | |
| 7 #include "base/process/kill.h" | |
| 8 #include "base/test/multiprocess_test.h" | |
| 9 #include "base/test/test_timeouts.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | |
| 11 #include "testing/multiprocess_func_list.h" | |
| 12 | |
| 13 namespace sandbox { | |
| 14 | |
| 15 class SeatbeltExecTest : public base::MultiProcessTest {}; | |
| 16 | |
| 17 MULTIPROCESS_TEST_MAIN(ServerTest) { | |
| 18 std::string profile = | |
| 19 "(version 1)\n" | |
| 20 "(deny default (with no-log))\n" | |
| 21 "(define allowed-dir \"ALLOWED_READ_DIR\")\n" | |
| 22 "(define executable-path \"EXECUTABLE_PATH\")\n" | |
| 23 "(allow process-exec* (path (param executable-path)))\n" | |
| 24 "(allow file-read* (path (param executable-path)))\n" | |
| 25 "(allow file-read* (subpath (param allowed-dir)))\n"; | |
| 26 | |
| 27 SeatbeltExecServer exec_server(-1); | |
| 28 std::string exec_path = "/bin/ls"; | |
| 29 exec_server.AllowProcessExec(exec_path); | |
| 30 | |
| 31 std::string allowed_path = "/Applications"; | |
| 32 mac::SandboxParams params; | |
| 33 google::protobuf::MapPair<std::string, std::string> pair("ALLOWED_READ_DIR", | |
| 34 allowed_path); | |
| 35 CHECK(params.mutable_params()->insert(pair).second); | |
| 36 params.set_policy(profile); | |
| 37 | |
| 38 CHECK(exec_server.ApplySandboxProfile(params) == 0); | |
|
Robert Sesek
2017/05/10 15:25:28
CHECK_EQ
Greg K
2017/05/11 17:44:14
Done.
| |
| 39 | |
| 40 // Test that the sandbox profile is actually applied. | |
| 41 struct stat sb; | |
| 42 CHECK(stat(allowed_path.c_str(), &sb) == 0); | |
|
Robert Sesek
2017/05/10 15:25:28
CHECK_EQ, and the two lines below
Greg K
2017/05/11 17:44:14
Done.
| |
| 43 CHECK(stat("/", &sb) == -1); | |
| 44 CHECK(stat(exec_path.c_str(), &sb) == 0); | |
| 45 | |
| 46 return 0; | |
| 47 } | |
| 48 | |
| 49 TEST_F(SeatbeltExecTest, ServerTest) { | |
| 50 base::SpawnChildResult spawn_child = SpawnChild("ServerTest"); | |
| 51 ASSERT_TRUE(spawn_child.process.IsValid()); | |
| 52 int exit_code = 42; | |
| 53 EXPECT_TRUE(spawn_child.process.WaitForExitWithTimeout( | |
| 54 TestTimeouts::action_max_timeout(), &exit_code)); | |
| 55 EXPECT_EQ(exit_code, 0); | |
| 56 } | |
| 57 | |
| 58 MULTIPROCESS_TEST_MAIN(ClientTest) { | |
| 59 SeatbeltExecClient exec_client; | |
| 60 | |
| 61 CHECK(exec_client.SetBooleanParameter("key1", true)); | |
| 62 CHECK(!exec_client.SetBooleanParameter("key1", false)); | |
| 63 CHECK(exec_client.SetBooleanParameter("key2", false)); | |
| 64 CHECK(exec_client.SetParameter("key3", "value")); | |
| 65 CHECK(!exec_client.SetParameter("key3", "value")); | |
| 66 exec_client.SetPolicy("(version 1)(deny default)"); | |
| 67 | |
| 68 sandbox::mac::SandboxParams params = exec_client.GetParamsForTesting(); | |
| 69 CHECK(params.params_size() == 3); | |
| 70 CHECK(!params.policy().empty()); | |
| 71 | |
| 72 return 0; | |
| 73 } | |
| 74 | |
| 75 TEST_F(SeatbeltExecTest, ClientTest) { | |
| 76 base::SpawnChildResult spawn_child = SpawnChild("ClientTest"); | |
| 77 ASSERT_TRUE(spawn_child.process.IsValid()); | |
| 78 int exit_code = 42; | |
| 79 EXPECT_TRUE(spawn_child.process.WaitForExitWithTimeout( | |
| 80 TestTimeouts::action_max_timeout(), &exit_code)); | |
| 81 EXPECT_EQ(exit_code, 0); | |
| 82 } | |
| 83 | |
| 84 } // namespace sandbox | |
| OLD | NEW |