Greg Kerr | 9e96523 | 2017-07-24 22:44:22 | [diff] [blame] | 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 | #import <Foundation/Foundation.h> |
| 6 | #import <IOSurface/IOSurface.h> |
| 7 | |
| 8 | #include <ifaddrs.h> |
| 9 | #include <servers/bootstrap.h> |
| 10 | #include <sys/socket.h> |
| 11 | #include <sys/stat.h> |
| 12 | #include <sys/sysctl.h> |
| 13 | #include <sys/types.h> |
| 14 | #include <unistd.h> |
| 15 | |
| 16 | #include "base/files/file_util.h" |
| 17 | #include "base/files/scoped_temp_dir.h" |
| 18 | #include "base/mac/bundle_locations.h" |
| 19 | #include "base/mac/mac_util.h" |
| 20 | #include "base/process/kill.h" |
| 21 | #include "base/sys_info.h" |
| 22 | #include "base/test/multiprocess_test.h" |
| 23 | #include "base/test/test_timeouts.h" |
Greg Kerr | 9e96523 | 2017-07-24 22:44:22 | [diff] [blame] | 24 | #include "content/test/test_content_client.h" |
| 25 | #include "sandbox/mac/sandbox_compiler.h" |
| 26 | #include "sandbox/mac/seatbelt_exec.h" |
Tom Sepez | 614d933 | 2017-10-03 00:06:27 | [diff] [blame] | 27 | #include "services/service_manager/sandbox/mac/renderer_v2.sb.h" |
Tom Sepez | e2923d5 | 2017-10-12 01:23:55 | [diff] [blame] | 28 | #include "services/service_manager/sandbox/mac/sandbox_mac.h" |
Greg Kerr | 9e96523 | 2017-07-24 22:44:22 | [diff] [blame] | 29 | #include "testing/gtest/include/gtest/gtest.h" |
| 30 | #include "testing/multiprocess_func_list.h" |
| 31 | |
| 32 | namespace content { |
| 33 | |
| 34 | namespace { |
| 35 | |
| 36 | void SetParametersForTest(sandbox::SandboxCompiler* compiler, |
| 37 | const base::FilePath& logging_path, |
| 38 | const base::FilePath& executable_path) { |
| 39 | bool enable_logging = true; |
Tom Sepez | e2923d5 | 2017-10-12 01:23:55 | [diff] [blame] | 40 | CHECK(compiler->InsertBooleanParam( |
| 41 | service_manager::Sandbox::kSandboxEnableLogging, enable_logging)); |
| 42 | CHECK(compiler->InsertBooleanParam( |
| 43 | service_manager::Sandbox::kSandboxDisableDenialLogging, !enable_logging)); |
Greg Kerr | 9e96523 | 2017-07-24 22:44:22 | [diff] [blame] | 44 | |
| 45 | std::string homedir = |
Tom Sepez | e2923d5 | 2017-10-12 01:23:55 | [diff] [blame] | 46 | service_manager::Sandbox::GetCanonicalSandboxPath(base::GetHomeDir()) |
| 47 | .value(); |
| 48 | CHECK(compiler->InsertStringParam( |
| 49 | service_manager::Sandbox::kSandboxHomedirAsLiteral, homedir)); |
Greg Kerr | 9e96523 | 2017-07-24 22:44:22 | [diff] [blame] | 50 | |
| 51 | int32_t major_version, minor_version, bugfix_version; |
| 52 | base::SysInfo::OperatingSystemVersionNumbers(&major_version, &minor_version, |
| 53 | &bugfix_version); |
| 54 | int32_t os_version = (major_version * 100) + minor_version; |
Tom Sepez | e2923d5 | 2017-10-12 01:23:55 | [diff] [blame] | 55 | CHECK(compiler->InsertStringParam(service_manager::Sandbox::kSandboxOSVersion, |
Greg Kerr | 9e96523 | 2017-07-24 22:44:22 | [diff] [blame] | 56 | std::to_string(os_version))); |
| 57 | |
Tom Sepez | e2923d5 | 2017-10-12 01:23:55 | [diff] [blame] | 58 | std::string bundle_path = service_manager::Sandbox::GetCanonicalSandboxPath( |
| 59 | base::mac::MainBundlePath()) |
| 60 | .value(); |
| 61 | CHECK(compiler->InsertStringParam( |
| 62 | service_manager::Sandbox::kSandboxBundlePath, bundle_path)); |
Greg Kerr | 9e96523 | 2017-07-24 22:44:22 | [diff] [blame] | 63 | |
Tom Sepez | e2923d5 | 2017-10-12 01:23:55 | [diff] [blame] | 64 | CHECK(compiler->InsertStringParam( |
| 65 | service_manager::Sandbox::kSandboxChromeBundleId, |
| 66 | "com.google.Chrome.test.sandbox")); |
| 67 | CHECK(compiler->InsertStringParam( |
| 68 | service_manager::Sandbox::kSandboxBrowserPID, std::to_string(getpid()))); |
Greg Kerr | 9e96523 | 2017-07-24 22:44:22 | [diff] [blame] | 69 | |
Tom Sepez | e2923d5 | 2017-10-12 01:23:55 | [diff] [blame] | 70 | CHECK(compiler->InsertStringParam( |
| 71 | service_manager::Sandbox::kSandboxLoggingPathAsLiteral, |
| 72 | logging_path.value())); |
Greg Kerr | 9e96523 | 2017-07-24 22:44:22 | [diff] [blame] | 73 | |
| 74 | // Parameters normally set by the main executable. |
| 75 | CHECK(compiler->InsertStringParam("CURRENT_PID", std::to_string(getpid()))); |
|
|