Skip to content
Snippets Groups Projects

Issue #3354095: "Check for existing subdirectory returns false positive when public files directory is a root directory or a symlink to a root directory"

Open Issue #3354095: "Check for existing subdirectory returns false positive when public files directory is a root directory or a symlink to a root directory"
4 unresolved threads
Open Víctor Dorado requested to merge issue/drupal-3354095:3354095-dir-false-positive into 11.x
4 unresolved threads

Merge request reports

Members who can merge are allowed to add commits.
Code Quality is loading
Test summary results are being parsed
Ready to merge by members who can write to the target branch.
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
11 */
12 class StreamWrapperCustomRootDirectoryTest extends FileTestBase {
13
14 /**
15 * Tests that the public stream wrapper can handle a custom root directory.
16 */
17 public function testRealPathHandlesCustomRootDirectory(): void {
18 $this->setSetting('file_public_path', '/custom-dir');
19 $this->assertDirectoryDoesNotExist("public://foo/custom-dir");
20 }
21
22 }
23
24 }
25
26 namespace Drupal\Core\StreamWrapper {
  • Not overly a fan of including these directly in tests. What if another test could use it?

  • But this is totally ad-hoc for this test... it replaces realpath() and stat() functions in a very customized way to make this very test working. Indeed, I don't think it would be safe to add other tests in this class, which would make all Drupal\Core\StreamWrapper namespace code use those fake realpath() and stat() methods.

    Edited by Víctor Dorado
  • Please register or sign in to reply
  • 13
    14 /**
    15 * Tests that the public stream wrapper can handle a custom root directory.
    16 */
    17 public function testRealPathHandlesCustomRootDirectory(): void {
    18 $this->setSetting('file_public_path', '/custom-dir');
    19 $this->assertDirectoryDoesNotExist("public://foo/custom-dir");
    20 }
    21
    22 }
    23
    24 }
    25
    26 namespace Drupal\Core\StreamWrapper {
    27
    28 function realpath(string $path): string|false {
  • 21
    22 }
    23
    24 }
    25
    26 namespace Drupal\Core\StreamWrapper {
    27
    28 function realpath(string $path): string|false {
    29 // Simulate that /custom-dir is an existing directory.
    30 if (preg_match('/^\/custom-dir$/', $path)) {
    31 return $path;
    32 }
    33 return \realpath($path);
    34 }
    35
    36 function stat(string $filename): array|false {
  • Please register or sign in to reply
    Loading