| 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 #include <dirent.h> | 6 #include <dirent.h> |
| 7 | 7 |
| 8 extern "C" { | 8 extern "C" { |
| 9 #include <sandbox.h> | 9 #include <sandbox.h> |
| 10 } | 10 } |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 } | 123 } |
| 124 expected.append(kSandboxEscapeSuffix); | 124 expected.append(kSandboxEscapeSuffix); |
| 125 | 125 |
| 126 std::string out; | 126 std::string out; |
| 127 EXPECT_TRUE(Sandbox::QuoteStringForRegex(in_utf8, &out)); | 127 EXPECT_TRUE(Sandbox::QuoteStringForRegex(in_utf8, &out)); |
| 128 EXPECT_EQ(expected, out); | 128 EXPECT_EQ(expected, out); |
| 129 | 129 |
| 130 } | 130 } |
| 131 } | 131 } |
| 132 | 132 |
| 133 // A class to handle auto-deleting a directory. | |
| 134 class ScopedDirectoryDelete { | |
| 135 public: | |
| 136 inline void operator()(FilePath* x) const { | |
| 137 if (x) { | |
| 138 file_util::Delete(*x, true); | |
| 139 } | |
| 140 } | |
| 141 }; | |
| 142 | |
| 143 typedef scoped_ptr_malloc<FilePath, ScopedDirectoryDelete> ScopedDirectory; | |
| 144 | |
| 145 // Disabled as times out, taking out remaining tests: 89170. | 133 // Disabled as times out, taking out remaining tests: 89170. |
| 146 TEST_F(MacDirAccessSandboxTest, DISABLED_SandboxAccess) { | 134 TEST_F(MacDirAccessSandboxTest, DISABLED_SandboxAccess) { |
| 147 using file_util::CreateDirectory; | 135 using file_util::CreateDirectory; |
| 148 | 136 |
| 149 FilePath tmp_dir; | 137 FilePath tmp_dir; |
| 150 ASSERT_TRUE(file_util::CreateNewTempDirectory("", &tmp_dir)); | 138 ASSERT_TRUE(file_util::CreateNewTempDirectory("", &tmp_dir)); |
| 151 // This step is important on OS X since the sandbox only understands "real" | 139 // This step is important on OS X since the sandbox only understands "real" |
| 152 // paths and the paths CreateNewTempDirectory() returns are empirically in | 140 // paths and the paths CreateNewTempDirectory() returns are empirically in |
| 153 // /var which is a symlink to /private/var . | 141 // /var which is a symlink to /private/var . |
| 154 Sandbox::GetCanonicalSandboxPath(&tmp_dir); | 142 Sandbox::GetCanonicalSandboxPath(&tmp_dir); |
| 155 ScopedDirectory cleanup(&tmp_dir); | 143 file_util::ScopedDirectory cleanup(&tmp_dir); |
| 156 | 144 |
| 157 const char* sandbox_dir_cases[] = { | 145 const char* sandbox_dir_cases[] = { |
| 158 "simple_dir_name", | 146 "simple_dir_name", |
| 159 "^hello++ $", // Regex. | 147 "^hello++ $", // Regex. |
| 160 "\\^.$|()[]*+?{}", // All regex characters. | 148 "\\^.$|()[]*+?{}", // All regex characters. |
| 161 }; | 149 }; |
| 162 | 150 |
| 163 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(sandbox_dir_cases); ++i) { | 151 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(sandbox_dir_cases); ++i) { |
| 164 const char* sandbox_dir_name = sandbox_dir_cases[i]; | 152 const char* sandbox_dir_name = sandbox_dir_cases[i]; |
| 165 FilePath sandbox_dir = tmp_dir.Append(sandbox_dir_name); | 153 FilePath sandbox_dir = tmp_dir.Append(sandbox_dir_name); |
| 166 ASSERT_TRUE(CreateDirectory(sandbox_dir)); | 154 ASSERT_TRUE(CreateDirectory(sandbox_dir)); |
| 167 ScopedDirectory cleanup_sandbox(&sandbox_dir); | 155 file_util::ScopedDirectory cleanup_sandbox(&sandbox_dir); |
| 168 | 156 |
| 169 // Create a sibling directory of the sandbox dir, whose name has sandbox dir | 157 // Create a sibling directory of the sandbox dir, whose name has sandbox dir |
| 170 // as a substring but to which access is denied. | 158 // as a substring but to which access is denied. |
| 171 std::string sibling_sandbox_dir_name_denied = | 159 std::string sibling_sandbox_dir_name_denied = |
| 172 std::string(sandbox_dir_cases[i]) + kDeniedSuffix; | 160 std::string(sandbox_dir_cases[i]) + kDeniedSuffix; |
| 173 FilePath sibling_sandbox_dir = tmp_dir.Append( | 161 FilePath sibling_sandbox_dir = tmp_dir.Append( |
| 174 sibling_sandbox_dir_name_denied.c_str()); | 162 sibling_sandbox_dir_name_denied.c_str()); |
| 175 ASSERT_TRUE(CreateDirectory(sibling_sandbox_dir)); | 163 ASSERT_TRUE(CreateDirectory(sibling_sandbox_dir)); |
| 176 ScopedDirectory cleanup_sandbox_sibling(&sibling_sandbox_dir); | 164 file_util::ScopedDirectory cleanup_sandbox_sibling(&sibling_sandbox_dir); |
| 177 | 165 |
| 178 EXPECT_TRUE(CheckSandbox(sandbox_dir.value())); | 166 EXPECT_TRUE(CheckSandbox(sandbox_dir.value())); |
| 179 } | 167 } |
| 180 } | 168 } |
| 181 | 169 |
| 182 MULTIPROCESS_TEST_MAIN(mac_sandbox_path_access) { | 170 MULTIPROCESS_TEST_MAIN(mac_sandbox_path_access) { |
| 183 char *sandbox_allowed_dir = getenv(kSandboxAccessPathKey); | 171 char *sandbox_allowed_dir = getenv(kSandboxAccessPathKey); |
| 184 if (!sandbox_allowed_dir) | 172 if (!sandbox_allowed_dir) |
| 185 return -1; | 173 return -1; |
| 186 | 174 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 PLOG(ERROR) << "Sandbox breach: was able to write (" | 288 PLOG(ERROR) << "Sandbox breach: was able to write (" |
| 301 << denied_file2.value() | 289 << denied_file2.value() |
| 302 << ")"; | 290 << ")"; |
| 303 return -1; | 291 return -1; |
| 304 } | 292 } |
| 305 | 293 |
| 306 return 0; | 294 return 0; |
| 307 } | 295 } |
| 308 | 296 |
| 309 } // namespace sandbox | 297 } // namespace sandbox |
| OLD | NEW |