Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: sandbox/linux/syscall_broker/broker_process_unittest.cc

Issue 1849323003: Convert //sandbox to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixup nonsfi_sandbox_unittest.cc Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sandbox/linux/syscall_broker/broker_process.cc ('k') | sandbox/mac/bootstrap_sandbox.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "sandbox/linux/syscall_broker/broker_process.h" 5 #include "sandbox/linux/syscall_broker/broker_process.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <poll.h> 9 #include <poll.h>
10 #include <stddef.h> 10 #include <stddef.h>
11 #include <sys/resource.h> 11 #include <sys/resource.h>
12 #include <sys/stat.h> 12 #include <sys/stat.h>
13 #include <sys/types.h> 13 #include <sys/types.h>
14 #include <sys/wait.h> 14 #include <sys/wait.h>
15 #include <unistd.h> 15 #include <unistd.h>
16 16
17 #include <algorithm> 17 #include <algorithm>
18 #include <memory>
18 #include <string> 19 #include <string>
19 #include <vector> 20 #include <vector>
20 21
21 #include "base/bind.h" 22 #include "base/bind.h"
22 #include "base/files/file_util.h" 23 #include "base/files/file_util.h"
23 #include "base/files/scoped_file.h" 24 #include "base/files/scoped_file.h"
24 #include "base/logging.h" 25 #include "base/logging.h"
25 #include "base/macros.h" 26 #include "base/macros.h"
26 #include "base/memory/scoped_ptr.h"
27 #include "base/posix/eintr_wrapper.h" 27 #include "base/posix/eintr_wrapper.h"
28 #include "base/posix/unix_domain_socket_linux.h" 28 #include "base/posix/unix_domain_socket_linux.h"
29 #include "sandbox/linux/syscall_broker/broker_client.h" 29 #include "sandbox/linux/syscall_broker/broker_client.h"
30 #include "sandbox/linux/tests/scoped_temporary_file.h" 30 #include "sandbox/linux/tests/scoped_temporary_file.h"
31 #include "sandbox/linux/tests/test_utils.h" 31 #include "sandbox/linux/tests/test_utils.h"
32 #include "sandbox/linux/tests/unit_tests.h" 32 #include "sandbox/linux/tests/unit_tests.h"
33 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
34 34
35 namespace sandbox { 35 namespace sandbox {
36 36
(...skipping 14 matching lines...) Expand all
51 bool NoOpCallback() { 51 bool NoOpCallback() {
52 return true; 52 return true;
53 } 53 }
54 54
55 } // namespace 55 } // namespace
56 56
57 TEST(BrokerProcess, CreateAndDestroy) { 57 TEST(BrokerProcess, CreateAndDestroy) {
58 std::vector<BrokerFilePermission> permissions; 58 std::vector<BrokerFilePermission> permissions;
59 permissions.push_back(BrokerFilePermission::ReadOnly("/proc/cpuinfo")); 59 permissions.push_back(BrokerFilePermission::ReadOnly("/proc/cpuinfo"));
60 60
61 scoped_ptr<BrokerProcess> open_broker(new BrokerProcess(EPERM, permissions)); 61 std::unique_ptr<BrokerProcess> open_broker(
62 new BrokerProcess(EPERM, permissions));
62 ASSERT_TRUE(open_broker->Init(base::Bind(&NoOpCallback))); 63 ASSERT_TRUE(open_broker->Init(base::Bind(&NoOpCallback)));
63 64
64 ASSERT_TRUE(TestUtils::CurrentProcessHasChildren()); 65 ASSERT_TRUE(TestUtils::CurrentProcessHasChildren());
65 // Destroy the broker and check it has exited properly. 66 // Destroy the broker and check it has exited properly.
66 open_broker.reset(); 67 open_broker.reset();
67 ASSERT_FALSE(TestUtils::CurrentProcessHasChildren()); 68 ASSERT_FALSE(TestUtils::CurrentProcessHasChildren());
68 } 69 }
69 70
70 TEST(BrokerProcess, TestOpenAccessNull) { 71 TEST(BrokerProcess, TestOpenAccessNull) {
71 std::vector<BrokerFilePermission> empty; 72 std::vector<BrokerFilePermission> empty;
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 const char kFileCpuInfo[] = "/proc/cpuinfo"; 245 const char kFileCpuInfo[] = "/proc/cpuinfo";
245 const char kNotAbsPath[] = "proc/cpuinfo"; 246 const char kNotAbsPath[] = "proc/cpuinfo";
246 const char kDotDotStart[] = "/../proc/cpuinfo"; 247 const char kDotDotStart[] = "/../proc/cpuinfo";
247 const char kDotDotMiddle[] = "/proc/self/../cpuinfo"; 248 const char kDotDotMiddle[] = "/proc/self/../cpuinfo";
248 const char kDotDotEnd[] = "/proc/.."; 249 const char kDotDotEnd[] = "/proc/..";
249 const char kTrailingSlash[] = "/proc/"; 250 const char kTrailingSlash[] = "/proc/";
250 251
251 std::vector<BrokerFilePermission> permissions; 252 std::vector<BrokerFilePermission> permissions;
252 253
253 permissions.push_back(BrokerFilePermission::ReadOnlyRecursive("/proc/")); 254 permissions.push_back(BrokerFilePermission::ReadOnlyRecursive("/proc/"));
254 scoped_ptr<BrokerProcess> open_broker( 255 std::unique_ptr<BrokerProcess> open_broker(
255 new BrokerProcess(EPERM, permissions, fast_check_in_client)); 256 new BrokerProcess(EPERM, permissions, fast_check_in_client));
256 ASSERT_TRUE(open_broker->Init(base::Bind(&NoOpCallback))); 257 ASSERT_TRUE(open_broker->Init(base::Bind(&NoOpCallback)));
257 // Open cpuinfo via the broker. 258 // Open cpuinfo via the broker.
258 int cpuinfo_fd = open_broker->Open(kFileCpuInfo, O_RDONLY); 259 int cpuinfo_fd = open_broker->Open(kFileCpuInfo, O_RDONLY);
259 base::ScopedFD cpuinfo_fd_closer(cpuinfo_fd); 260 base::ScopedFD cpuinfo_fd_closer(cpuinfo_fd);
260 ASSERT_GE(cpuinfo_fd, 0); 261 ASSERT_GE(cpuinfo_fd, 0);
261 262
262 int fd = -1; 263 int fd = -1;
263 int can_access; 264 int can_access;
264 265
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 void TestOpenCpuinfo(bool fast_check_in_client, bool recursive) { 304 void TestOpenCpuinfo(bool fast_check_in_client, bool recursive) {
304 const char kFileCpuInfo[] = "/proc/cpuinfo"; 305 const char kFileCpuInfo[] = "/proc/cpuinfo";
305 const char kDirProc[] = "/proc/"; 306 const char kDirProc[] = "/proc/";
306 307
307 std::vector<BrokerFilePermission> permissions; 308 std::vector<BrokerFilePermission> permissions;
308 if (recursive) 309 if (recursive)
309 permissions.push_back(BrokerFilePermission::ReadOnlyRecursive(kDirProc)); 310 permissions.push_back(BrokerFilePermission::ReadOnlyRecursive(kDirProc));
310 else 311 else
311 permissions.push_back(BrokerFilePermission::ReadOnly(kFileCpuInfo)); 312 permissions.push_back(BrokerFilePermission::ReadOnly(kFileCpuInfo));
312 313
313 scoped_ptr<BrokerProcess> open_broker( 314 std::unique_ptr<BrokerProcess> open_broker(
314 new BrokerProcess(EPERM, permissions, fast_check_in_client)); 315 new BrokerProcess(EPERM, permissions, fast_check_in_client));
315 ASSERT_TRUE(open_broker->Init(base::Bind(&NoOpCallback))); 316 ASSERT_TRUE(open_broker->Init(base::Bind(&NoOpCallback)));
316 317
317 int fd = -1; 318 int fd = -1;
318 fd = open_broker->Open(kFileCpuInfo, O_RDWR); 319 fd = open_broker->Open(kFileCpuInfo, O_RDWR);
319 base::ScopedFD fd_closer(fd); 320 base::ScopedFD fd_closer(fd);
320 ASSERT_EQ(fd, -EPERM); 321 ASSERT_EQ(fd, -EPERM);
321 322
322 // Check we can read /proc/cpuinfo. 323 // Check we can read /proc/cpuinfo.
323 int can_access = open_broker->Access(kFileCpuInfo, R_OK); 324 int can_access = open_broker->Access(kFileCpuInfo, R_OK);
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 ssize_t len = HANDLE_EINTR(read(fd_check, buf, sizeof(buf))); 657 ssize_t len = HANDLE_EINTR(read(fd_check, buf, sizeof(buf)));
657 658
658 ASSERT_EQ(len, static_cast<ssize_t>(sizeof(kTestText))); 659 ASSERT_EQ(len, static_cast<ssize_t>(sizeof(kTestText)));
659 ASSERT_EQ(memcmp(kTestText, buf, sizeof(kTestText)), 0); 660 ASSERT_EQ(memcmp(kTestText, buf, sizeof(kTestText)), 0);
660 } 661 }
661 } 662 }
662 663
663 } // namespace syscall_broker 664 } // namespace syscall_broker
664 665
665 } // namespace sandbox 666 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/linux/syscall_broker/broker_process.cc ('k') | sandbox/mac/bootstrap_sandbox.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698