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

Side by Side Diff: content/common/sandbox_mac_system_access_unittest.mm

Issue 10695185: Allow /dev/urandom from ppapi sandbox. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Make urandom access read-only, and test that it works. Created 8 years, 5 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 | « no previous file | content/ppapi_plugin/ppapi.sb » ('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) 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
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 if (fdes == -1)
115 return false;
116
117 char buf[16];
118 int rc = read(fdes, buf, sizeof(buf));
119 return rc == sizeof(buf);
120 } else {
121 return fdes == -1 && errno == EPERM;
122 }
123 }
124
125 TEST_F(MacSandboxTest, UrandomAccess) {
126 // Similar to RunTestInAllSandboxTypes(), except changing
127 // |test_data| for the ppapi case. Passing "" in the non-ppapi case
128 // to overwrite the test data (NULL means not to change it).
129 for (content::SandboxType i = content::SANDBOX_TYPE_FIRST_TYPE;
130 i < content::SANDBOX_TYPE_AFTER_LAST_TYPE; ++i) {
131 if (i == content::SANDBOX_TYPE_PPAPI) {
132 EXPECT_TRUE(RunTestInSandbox(i, "MacSandboxedUrandomTestCase", "ppapi"));
133 } else {
134 EXPECT_TRUE(RunTestInSandbox(i, "MacSandboxedUrandomTestCase", ""))
135 << "for sandbox type " << i;
136 }
137 }
138 }
139
99 } // namespace 140 } // namespace
OLDNEW
« no previous file with comments | « no previous file | content/ppapi_plugin/ppapi.sb » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698