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 #include <set> | 5 #include <set> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/platform_file.h" | 10 #include "base/platform_file.h" |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 p->GrantReadFile(kRendererID, base::FilePath(TEST_PATH("/etc/"))); | 347 p->GrantReadFile(kRendererID, base::FilePath(TEST_PATH("/etc/"))); |
348 EXPECT_TRUE(p->CanReadFile(kRendererID, | 348 EXPECT_TRUE(p->CanReadFile(kRendererID, |
349 base::FilePath(TEST_PATH("/etc/passwd")))); | 349 base::FilePath(TEST_PATH("/etc/passwd")))); |
350 EXPECT_FALSE(p->CanReadDirectory(kRendererID, | 350 EXPECT_FALSE(p->CanReadDirectory(kRendererID, |
351 base::FilePath(TEST_PATH("/etc/")))); | 351 base::FilePath(TEST_PATH("/etc/")))); |
352 | 352 |
353 p->Remove(kRendererID); | 353 p->Remove(kRendererID); |
354 } | 354 } |
355 | 355 |
356 TEST_F(ChildProcessSecurityPolicyTest, FilePermissions) { | 356 TEST_F(ChildProcessSecurityPolicyTest, FilePermissions) { |
357 base::FilePath granted_file = FilePath(TEST_PATH("/home/joe")); | 357 base::FilePath granted_file = base::FilePath(TEST_PATH("/home/joe")); |
358 base::FilePath sibling_file = FilePath(TEST_PATH("/home/bob")); | 358 base::FilePath sibling_file = base::FilePath(TEST_PATH("/home/bob")); |
359 base::FilePath child_file = FilePath(TEST_PATH("/home/joe/file")); | 359 base::FilePath child_file = base::FilePath(TEST_PATH("/home/joe/file")); |
360 base::FilePath parent_file = FilePath(TEST_PATH("/home")); | 360 base::FilePath parent_file = base::FilePath(TEST_PATH("/home")); |
361 base::FilePath parent_slash_file = FilePath(TEST_PATH("/home/")); | 361 base::FilePath parent_slash_file = base::FilePath(TEST_PATH("/home/")); |
362 base::FilePath child_traversal1 = FilePath(TEST_PATH("/home/joe/././file")); | 362 base::FilePath child_traversal1 = |
363 base::FilePath child_traversal2 = FilePath( | 363 base::FilePath(TEST_PATH("/home/joe/././file")); |
| 364 base::FilePath child_traversal2 = base::FilePath( |
364 TEST_PATH("/home/joe/file/../otherfile")); | 365 TEST_PATH("/home/joe/file/../otherfile")); |
365 base::FilePath evil_traversal1 = | 366 base::FilePath evil_traversal1 = |
366 FilePath(TEST_PATH("/home/joe/../../etc/passwd")); | 367 base::FilePath(TEST_PATH("/home/joe/../../etc/passwd")); |
367 base::FilePath evil_traversal2 = FilePath( | 368 base::FilePath evil_traversal2 = base::FilePath( |
368 TEST_PATH("/home/joe/./.././../etc/passwd")); | 369 TEST_PATH("/home/joe/./.././../etc/passwd")); |
369 base::FilePath self_traversal = FilePath(TEST_PATH("/home/joe/../joe/file")); | 370 base::FilePath self_traversal = |
370 base::FilePath relative_file = FilePath(FILE_PATH_LITERAL("home/joe")); | 371 base::FilePath(TEST_PATH("/home/joe/../joe/file")); |
| 372 base::FilePath relative_file = base::FilePath(FILE_PATH_LITERAL("home/joe")); |
371 | 373 |
372 ChildProcessSecurityPolicyImpl* p = | 374 ChildProcessSecurityPolicyImpl* p = |
373 ChildProcessSecurityPolicyImpl::GetInstance(); | 375 ChildProcessSecurityPolicyImpl::GetInstance(); |
374 | 376 |
375 // Grant permissions for a file. | 377 // Grant permissions for a file. |
376 p->Add(kRendererID); | 378 p->Add(kRendererID); |
377 EXPECT_FALSE(p->HasPermissionsForFile(kRendererID, granted_file, | 379 EXPECT_FALSE(p->HasPermissionsForFile(kRendererID, granted_file, |
378 base::PLATFORM_FILE_OPEN)); | 380 base::PLATFORM_FILE_OPEN)); |
379 | 381 |
380 p->GrantPermissionsForFile(kRendererID, granted_file, | 382 p->GrantPermissionsForFile(kRendererID, granted_file, |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 // queried on the IO thread. The ChildProcessSecurityPolicy needs to be | 544 // queried on the IO thread. The ChildProcessSecurityPolicy needs to be |
543 // prepared to answer policy questions about renderers who no longer exist. | 545 // prepared to answer policy questions about renderers who no longer exist. |
544 | 546 |
545 // In this case, we default to secure behavior. | 547 // In this case, we default to secure behavior. |
546 EXPECT_FALSE(p->CanRequestURL(kRendererID, url)); | 548 EXPECT_FALSE(p->CanRequestURL(kRendererID, url)); |
547 EXPECT_FALSE(p->CanReadFile(kRendererID, file)); | 549 EXPECT_FALSE(p->CanReadFile(kRendererID, file)); |
548 EXPECT_FALSE(p->HasWebUIBindings(kRendererID)); | 550 EXPECT_FALSE(p->HasWebUIBindings(kRendererID)); |
549 } | 551 } |
550 | 552 |
551 } // namespace content | 553 } // namespace content |
OLD | NEW |