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

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

Issue 400293002: Write MacSandboxTest.OpenSSLAccess. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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 #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"
11 #include "content/common/sandbox_mac.h" 11 #include "content/common/sandbox_mac.h"
12 #include "content/common/sandbox_mac_unittest_helper.h" 12 #include "content/common/sandbox_mac_unittest_helper.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 #if defined(USE_OPENSSL)
16 #include <openssl/rand.h>
17 #include "crypto/openssl_util.h"
18 #else
13 #include "crypto/nss_util.h" 19 #include "crypto/nss_util.h"
14 #include "testing/gtest/include/gtest/gtest.h" 20 #endif
15 21
16 namespace content { 22 namespace content {
17 23
18 //--------------------- Clipboard Sandboxing ---------------------- 24 //--------------------- Clipboard Sandboxing ----------------------
19 // Test case for checking sandboxing of clipboard access. 25 // Test case for checking sandboxing of clipboard access.
20 class MacSandboxedClipboardTestCase : public MacSandboxTestCase { 26 class MacSandboxedClipboardTestCase : public MacSandboxTestCase {
21 public: 27 public:
22 MacSandboxedClipboardTestCase(); 28 MacSandboxedClipboardTestCase();
23 virtual ~MacSandboxedClipboardTestCase(); 29 virtual ~MacSandboxedClipboardTestCase();
24 30
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 119
114 char buf[16]; 120 char buf[16];
115 int rc = HANDLE_EINTR(read(fdes.get(), buf, sizeof(buf))); 121 int rc = HANDLE_EINTR(read(fdes.get(), buf, sizeof(buf)));
116 return rc == sizeof(buf); 122 return rc == sizeof(buf);
117 } 123 }
118 124
119 TEST_F(MacSandboxTest, UrandomAccess) { 125 TEST_F(MacSandboxTest, UrandomAccess) {
120 EXPECT_TRUE(RunTestInAllSandboxTypes("MacSandboxedUrandomTestCase", NULL)); 126 EXPECT_TRUE(RunTestInAllSandboxTypes("MacSandboxedUrandomTestCase", NULL));
121 } 127 }
122 128
129 #if defined(USE_OPENSSL)
130
131 //--------------------- OpenSSL Sandboxing ----------------------
132 // Test case for checking sandboxing of OpenSSL initialization.
133 class MacSandboxedOpenSSLTestCase : public MacSandboxTestCase {
134 public:
135 virtual bool SandboxedTest() OVERRIDE;
136 };
137
138 REGISTER_SANDBOX_TEST_CASE(MacSandboxedOpenSSLTestCase);
139
140 bool MacSandboxedOpenSSLTestCase::SandboxedTest() {
141 crypto::EnsureOpenSSLInit();
142
143 // Ensure that RAND_bytes is functional within the sandbox.
144 uint8_t byte;
145 return RAND_bytes(&byte, 1) == 1;
146 }
147
148 TEST_F(MacSandboxTest, OpenSSLAccess) {
149 EXPECT_TRUE(RunTestInAllSandboxTypes("MacSandboxedOpenSSLTestCase", NULL));
150 }
151
152 #else // !defined(USE_OPENSSL)
153
123 //--------------------- NSS Sandboxing ---------------------- 154 //--------------------- NSS Sandboxing ----------------------
124 // Test case for checking sandboxing of NSS initialization. 155 // Test case for checking sandboxing of NSS initialization.
125 class MacSandboxedNSSTestCase : public MacSandboxTestCase { 156 class MacSandboxedNSSTestCase : public MacSandboxTestCase {
126 public: 157 public:
127 virtual bool SandboxedTest() OVERRIDE; 158 virtual bool SandboxedTest() OVERRIDE;
128 }; 159 };
129 160
130 REGISTER_SANDBOX_TEST_CASE(MacSandboxedNSSTestCase); 161 REGISTER_SANDBOX_TEST_CASE(MacSandboxedNSSTestCase);
131 162
132 bool MacSandboxedNSSTestCase::SandboxedTest() { 163 bool MacSandboxedNSSTestCase::SandboxedTest() {
133 // If NSS cannot read from /dev/urandom, NSS initialization will call abort(), 164 // If NSS cannot read from /dev/urandom, NSS initialization will call abort(),
134 // which will cause this test case to fail. 165 // which will cause this test case to fail.
135 crypto::ForceNSSNoDBInit(); 166 crypto::ForceNSSNoDBInit();
136 crypto::EnsureNSSInit(); 167 crypto::EnsureNSSInit();
137 return true; 168 return true;
138 } 169 }
139 170
140 TEST_F(MacSandboxTest, NSSAccess) { 171 TEST_F(MacSandboxTest, NSSAccess) {
141 EXPECT_TRUE(RunTestInAllSandboxTypes("MacSandboxedNSSTestCase", NULL)); 172 EXPECT_TRUE(RunTestInAllSandboxTypes("MacSandboxedNSSTestCase", NULL));
142 } 173 }
143 174
175 #endif // defined(USE_OPENSSL)
176
144 } // namespace content 177 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698