| 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 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/files/scoped_file.h" | 8 #include "base/files/scoped_file.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 //--------------------- File Access Sandboxing ---------------------- | 80 //--------------------- File Access Sandboxing ---------------------- |
| 81 // Test case for checking sandboxing of filesystem apis. | 81 // Test case for checking sandboxing of filesystem apis. |
| 82 class MacSandboxedFileAccessTestCase : public MacSandboxTestCase { | 82 class MacSandboxedFileAccessTestCase : public MacSandboxTestCase { |
| 83 public: | 83 public: |
| 84 virtual bool SandboxedTest() OVERRIDE; | 84 virtual bool SandboxedTest() OVERRIDE; |
| 85 }; | 85 }; |
| 86 | 86 |
| 87 REGISTER_SANDBOX_TEST_CASE(MacSandboxedFileAccessTestCase); | 87 REGISTER_SANDBOX_TEST_CASE(MacSandboxedFileAccessTestCase); |
| 88 | 88 |
| 89 bool MacSandboxedFileAccessTestCase::SandboxedTest() { | 89 bool MacSandboxedFileAccessTestCase::SandboxedTest() { |
| 90 base::ScopedFD fdes(open("/etc/passwd", O_RDONLY)); | 90 base::ScopedFD fdes(HANDLE_EINTR(open("/etc/passwd", O_RDONLY))); |
| 91 return !fdes.is_valid(); | 91 return !fdes.is_valid(); |
| 92 } | 92 } |
| 93 | 93 |
| 94 TEST_F(MacSandboxTest, FileAccess) { | 94 TEST_F(MacSandboxTest, FileAccess) { |
| 95 EXPECT_TRUE(RunTestInAllSandboxTypes("MacSandboxedFileAccessTestCase", NULL)); | 95 EXPECT_TRUE(RunTestInAllSandboxTypes("MacSandboxedFileAccessTestCase", NULL)); |
| 96 } | 96 } |
| 97 | 97 |
| 98 //--------------------- /dev/urandom Sandboxing ---------------------- | 98 //--------------------- /dev/urandom Sandboxing ---------------------- |
| 99 // /dev/urandom is available to any sandboxed process. | 99 // /dev/urandom is available to any sandboxed process. |
| 100 class MacSandboxedUrandomTestCase : public MacSandboxTestCase { | 100 class MacSandboxedUrandomTestCase : public MacSandboxTestCase { |
| 101 public: | 101 public: |
| 102 virtual bool SandboxedTest() OVERRIDE; | 102 virtual bool SandboxedTest() OVERRIDE; |
| 103 }; | 103 }; |
| 104 | 104 |
| 105 REGISTER_SANDBOX_TEST_CASE(MacSandboxedUrandomTestCase); | 105 REGISTER_SANDBOX_TEST_CASE(MacSandboxedUrandomTestCase); |
| 106 | 106 |
| 107 bool MacSandboxedUrandomTestCase::SandboxedTest() { | 107 bool MacSandboxedUrandomTestCase::SandboxedTest() { |
| 108 base::ScopedFD fdes(open("/dev/urandom", O_RDONLY)); | 108 base::ScopedFD fdes(HANDLE_EINTR(open("/dev/urandom", O_RDONLY))); |
| 109 | 109 |
| 110 // Opening /dev/urandom succeeds under the sandbox. | 110 // Opening /dev/urandom succeeds under the sandbox. |
| 111 if (!fdes.is_valid()) | 111 if (!fdes.is_valid()) |
| 112 return false; | 112 return false; |
| 113 | 113 |
| 114 char buf[16]; | 114 char buf[16]; |
| 115 int rc = read(fdes.get(), buf, sizeof(buf)); | 115 int rc = HANDLE_EINTR(read(fdes.get(), buf, sizeof(buf))); |
| 116 return rc == sizeof(buf); | 116 return rc == sizeof(buf); |
| 117 } | 117 } |
| 118 | 118 |
| 119 TEST_F(MacSandboxTest, UrandomAccess) { | 119 TEST_F(MacSandboxTest, UrandomAccess) { |
| 120 EXPECT_TRUE(RunTestInAllSandboxTypes("MacSandboxedUrandomTestCase", NULL)); | 120 EXPECT_TRUE(RunTestInAllSandboxTypes("MacSandboxedUrandomTestCase", NULL)); |
| 121 } | 121 } |
| 122 | 122 |
| 123 //--------------------- NSS Sandboxing ---------------------- | 123 //--------------------- NSS Sandboxing ---------------------- |
| 124 // Test case for checking sandboxing of NSS initialization. | 124 // Test case for checking sandboxing of NSS initialization. |
| 125 class MacSandboxedNSSTestCase : public MacSandboxTestCase { | 125 class MacSandboxedNSSTestCase : public MacSandboxTestCase { |
| 126 public: | 126 public: |
| 127 virtual bool SandboxedTest() OVERRIDE; | 127 virtual bool SandboxedTest() OVERRIDE; |
| 128 }; | 128 }; |
| 129 | 129 |
| 130 REGISTER_SANDBOX_TEST_CASE(MacSandboxedNSSTestCase); | 130 REGISTER_SANDBOX_TEST_CASE(MacSandboxedNSSTestCase); |
| 131 | 131 |
| 132 bool MacSandboxedNSSTestCase::SandboxedTest() { | 132 bool MacSandboxedNSSTestCase::SandboxedTest() { |
| 133 // If NSS cannot read from /dev/urandom, NSS initialization will call abort(), | 133 // If NSS cannot read from /dev/urandom, NSS initialization will call abort(), |
| 134 // which will cause this test case to fail. | 134 // which will cause this test case to fail. |
| 135 crypto::ForceNSSNoDBInit(); | 135 crypto::ForceNSSNoDBInit(); |
| 136 crypto::EnsureNSSInit(); | 136 crypto::EnsureNSSInit(); |
| 137 return true; | 137 return true; |
| 138 } | 138 } |
| 139 | 139 |
| 140 TEST_F(MacSandboxTest, NSSAccess) { | 140 TEST_F(MacSandboxTest, NSSAccess) { |
| 141 EXPECT_TRUE(RunTestInAllSandboxTypes("MacSandboxedNSSTestCase", NULL)); | 141 EXPECT_TRUE(RunTestInAllSandboxTypes("MacSandboxedNSSTestCase", NULL)); |
| 142 } | 142 } |
| 143 | 143 |
| 144 } // namespace content | 144 } // namespace content |
| OLD | NEW |