OLD | NEW |
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/services/credentials.h" | 5 #include "sandbox/linux/services/credentials.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <stdio.h> | 9 #include <stdio.h> |
10 #include <sys/stat.h> | 10 #include <sys/stat.h> |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 | 50 |
51 // Give dynamic tools a simple thing to test. | 51 // Give dynamic tools a simple thing to test. |
52 TEST(Credentials, CreateAndDestroy) { | 52 TEST(Credentials, CreateAndDestroy) { |
53 { | 53 { |
54 Credentials cred1; | 54 Credentials cred1; |
55 (void) cred1; | 55 (void) cred1; |
56 } | 56 } |
57 scoped_ptr<Credentials> cred2(new Credentials); | 57 scoped_ptr<Credentials> cred2(new Credentials); |
58 } | 58 } |
59 | 59 |
| 60 TEST(Credentials, CountOpenFds) { |
| 61 base::ScopedFD proc_fd(open("/proc", O_RDONLY | O_DIRECTORY)); |
| 62 ASSERT_TRUE(proc_fd.is_valid()); |
| 63 Credentials creds; |
| 64 int fd_count = creds.CountOpenFds(proc_fd.get()); |
| 65 int fd = open("/dev/null", O_RDONLY); |
| 66 ASSERT_LE(0, fd); |
| 67 EXPECT_EQ(fd_count + 1, creds.CountOpenFds(proc_fd.get())); |
| 68 ASSERT_EQ(0, IGNORE_EINTR(close(fd))); |
| 69 EXPECT_EQ(fd_count, creds.CountOpenFds(proc_fd.get())); |
| 70 } |
| 71 |
60 TEST(Credentials, HasOpenDirectory) { | 72 TEST(Credentials, HasOpenDirectory) { |
61 Credentials creds; | 73 Credentials creds; |
62 // No open directory should exist at startup. | 74 // No open directory should exist at startup. |
63 EXPECT_FALSE(creds.HasOpenDirectory(-1)); | 75 EXPECT_FALSE(creds.HasOpenDirectory(-1)); |
64 { | 76 { |
65 // Have a "/dev" file descriptor around. | 77 // Have a "/dev" file descriptor around. |
66 int dev_fd = open("/dev", O_RDONLY | O_DIRECTORY); | 78 int dev_fd = open("/dev", O_RDONLY | O_DIRECTORY); |
67 base::ScopedFD dev_fd_closer(dev_fd); | 79 base::ScopedFD dev_fd_closer(dev_fd); |
68 EXPECT_TRUE(creds.HasOpenDirectory(-1)); | 80 EXPECT_TRUE(creds.HasOpenDirectory(-1)); |
69 } | 81 } |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 | 227 |
216 // The kernel should now prevent us from regaining capabilities because we | 228 // The kernel should now prevent us from regaining capabilities because we |
217 // are in a chroot. | 229 // are in a chroot. |
218 CHECK(!Credentials::SupportsNewUserNS()); | 230 CHECK(!Credentials::SupportsNewUserNS()); |
219 CHECK(!creds.MoveToNewUserNS()); | 231 CHECK(!creds.MoveToNewUserNS()); |
220 } | 232 } |
221 | 233 |
222 } // namespace. | 234 } // namespace. |
223 | 235 |
224 } // namespace sandbox. | 236 } // namespace sandbox. |
OLD | NEW |