| 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 #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 } |
| 11 | 11 |
| 12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 13 #include "base/file_path.h" | 13 #include "base/file_path.h" |
| 14 #include "base/test/multiprocess_test.h" | 14 #include "base/test/multiprocess_test.h" |
| 15 #include "base/sys_string_conversions.h" | 15 #include "base/sys_string_conversions.h" |
| 16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 17 #include "content/common/sandbox_mac.h" | 17 #include "content/common/sandbox_mac.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "testing/multiprocess_func_list.h" | 19 #include "testing/multiprocess_func_list.h" |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 static const char* kSandboxAccessPathKey = "sandbox_dir"; | 23 static const char* kSandboxAccessPathKey = "sandbox_dir"; |
| 24 static const char* kDeniedSuffix = "_denied"; | 24 static const char* kDeniedSuffix = "_denied"; |
| 25 | 25 |
| 26 } // namespace | 26 } // namespace |
| 27 | 27 |
| 28 // Tests need to be in the same namespace as the sandbox::Sandbox class to be | 28 // Tests need to be in the same namespace as the Sandbox class to be useable |
| 29 // useable with FRIEND_TEST() declaration. | 29 // with FRIEND_TEST() declaration. |
| 30 namespace sandbox { | 30 namespace content { |
| 31 | 31 |
| 32 class MacDirAccessSandboxTest : public base::MultiProcessTest { | 32 class MacDirAccessSandboxTest : public base::MultiProcessTest { |
| 33 public: | 33 public: |
| 34 bool CheckSandbox(const std::string& directory_to_try) { | 34 bool CheckSandbox(const std::string& directory_to_try) { |
| 35 setenv(kSandboxAccessPathKey, directory_to_try.c_str(), 1); | 35 setenv(kSandboxAccessPathKey, directory_to_try.c_str(), 1); |
| 36 base::ProcessHandle child_process = SpawnChild("mac_sandbox_path_access", | 36 base::ProcessHandle child_process = SpawnChild("mac_sandbox_path_access", |
| 37 false); | 37 false); |
| 38 if (child_process == base::kNullProcessHandle) { | 38 if (child_process == base::kNullProcessHandle) { |
| 39 LOG(WARNING) << "SpawnChild failed"; | 39 LOG(WARNING) << "SpawnChild failed"; |
| 40 return false; | 40 return false; |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 if (open(denied_file2.value().c_str(), O_WRONLY | O_CREAT) > 0) { | 298 if (open(denied_file2.value().c_str(), O_WRONLY | O_CREAT) > 0) { |
| 299 PLOG(ERROR) << "Sandbox breach: was able to write (" | 299 PLOG(ERROR) << "Sandbox breach: was able to write (" |
| 300 << denied_file2.value() | 300 << denied_file2.value() |
| 301 << ")"; | 301 << ")"; |
| 302 return -1; | 302 return -1; |
| 303 } | 303 } |
| 304 | 304 |
| 305 return 0; | 305 return 0; |
| 306 } | 306 } |
| 307 | 307 |
| 308 } // namespace sandbox | 308 } // namespace content |
| OLD | NEW |