blob: 647bb130c434ebcf152d3432d7483b6067f45fe9 [file] [log] [blame]
Greg Kerr9e965232017-07-24 22:44:221// 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 Kerr9e965232017-07-24 22:44:2224#include "content/test/test_content_client.h"
25#include "sandbox/mac/sandbox_compiler.h"
26#include "sandbox/mac/seatbelt_exec.h"
Tom Sepez614d9332017-10-03 00:06:2727#include "services/service_manager/sandbox/mac/renderer_v2.sb.h"
Tom Sepeze2923d52017-10-12 01:23:5528#include "services/service_manager/sandbox/mac/sandbox_mac.h"
Greg Kerr9e965232017-07-24 22:44:2229#include "testing/gtest/include/gtest/gtest.h"
30#include "testing/multiprocess_func_list.h"
31
32namespace content {
33
34namespace {
35
36void SetParametersForTest(sandbox::SandboxCompiler* compiler,
37 const base::FilePath& logging_path,
38 const base::FilePath& executable_path) {
39 bool enable_logging = true;
Tom Sepeze2923d52017-10-12 01:23:5540 CHECK(compiler->InsertBooleanParam(
41 service_manager::Sandbox::kSandboxEnableLogging, enable_logging));
42 CHECK(compiler->InsertBooleanParam(
43 service_manager::Sandbox::kSandboxDisableDenialLogging, !enable_logging));
Greg Kerr9e965232017-07-24 22:44:2244
45 std::string homedir =
Tom Sepeze2923d52017-10-12 01:23:5546 service_manager::Sandbox::GetCanonicalSandboxPath(base::GetHomeDir())
47 .value();
48 CHECK(compiler->InsertStringParam(
49 service_manager::Sandbox::kSandboxHomedirAsLiteral, homedir));
Greg Kerr9e965232017-07-24 22:44:2250
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 Sepeze2923d52017-10-12 01:23:5555 CHECK(compiler->InsertStringParam(service_manager::Sandbox::kSandboxOSVersion,
Greg Kerr9e965232017-07-24 22:44:2256 std::to_string(os_version)));
57
Tom Sepeze2923d52017-10-12 01:23:5558 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 Kerr9e965232017-07-24 22:44:2263
Tom Sepeze2923d52017-10-12 01:23:5564 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 Kerr9e965232017-07-24 22:44:2269
Tom Sepeze2923d52017-10-12 01:23:5570 CHECK(compiler->InsertStringParam(
71 service_manager::Sandbox::kSandboxLoggingPathAsLiteral,
72 logging_path.value()));
Greg Kerr9e965232017-07-24 22:44:2273
74 // Parameters normally set by the main executable.
75 CHECK(compiler->InsertStringParam("CURRENT_PID", std::to_string(getpid())));