| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
| 10 #include "content/common/sandbox_mac.h" | 10 #include "content/common/sandbox_mac.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 bool MacSandboxedFileAccessTestCase::SandboxedTest() { | 89 bool MacSandboxedFileAccessTestCase::SandboxedTest() { |
| 90 int fdes = open("/etc/passwd", O_RDONLY); | 90 int fdes = open("/etc/passwd", O_RDONLY); |
| 91 file_util::ScopedFD file_closer(&fdes); | 91 file_util::ScopedFD file_closer(&fdes); |
| 92 return fdes == -1; | 92 return fdes == -1; |
| 93 } | 93 } |
| 94 | 94 |
| 95 TEST_F(MacSandboxTest, FileAccess) { | 95 TEST_F(MacSandboxTest, FileAccess) { |
| 96 EXPECT_TRUE(RunTestInAllSandboxTypes("MacSandboxedFileAccessTestCase", NULL)); | 96 EXPECT_TRUE(RunTestInAllSandboxTypes("MacSandboxedFileAccessTestCase", NULL)); |
| 97 } | 97 } |
| 98 | 98 |
| 99 //--------------------- /dev/urandom Sandboxing ---------------------- |
| 100 // /dev/urandom is available to ppapi sandbox only. |
| 101 class MacSandboxedUrandomTestCase : public sandboxtest::MacSandboxTestCase { |
| 102 public: |
| 103 virtual bool SandboxedTest(); |
| 104 }; |
| 105 |
| 106 REGISTER_SANDBOX_TEST_CASE(MacSandboxedUrandomTestCase); |
| 107 |
| 108 bool MacSandboxedUrandomTestCase::SandboxedTest() { |
| 109 int fdes = open("/dev/urandom", O_RDONLY); |
| 110 file_util::ScopedFD file_closer(&fdes); |
| 111 |
| 112 // Open succeeds under ppapi sandbox, else it is not permitted. |
| 113 if (test_data_ == "ppapi") { |
| 114 return fdes != -1; |
| 115 } else { |
| 116 return fdes == -1 && errno == EPERM; |
| 117 } |
| 118 } |
| 119 |
| 120 TEST_F(MacSandboxTest, UrandomAccess) { |
| 121 // Similar to RunTestInAllSandboxTypes(), except changing |
| 122 // |test_data| for the ppapi case. Passing "" in the non-ppapi case |
| 123 // to overwrite the test data (NULL means not to change it). |
| 124 for (content::SandboxType i = content::SANDBOX_TYPE_FIRST_TYPE; |
| 125 i < content::SANDBOX_TYPE_AFTER_LAST_TYPE; ++i) { |
| 126 if (i == content::SANDBOX_TYPE_PPAPI) { |
| 127 EXPECT_TRUE(RunTestInSandbox(i, "MacSandboxedUrandomTestCase", "ppapi")); |
| 128 } else { |
| 129 EXPECT_TRUE(RunTestInSandbox(i, "MacSandboxedUrandomTestCase", "")) |
| 130 << "for sandbox type " << i; |
| 131 } |
| 132 } |
| 133 } |
| 134 |
| 99 } // namespace | 135 } // namespace |
| OLD | NEW |