Skip to content

Commit 5b5cb4c

Browse files
authored
ENGCOM-5852: Fix the false directory path comparison failure, which causes incorrect error message for no writable permission. #24530
2 parents a2760b0 + 811feaa commit 5b5cb4c

File tree

2 files changed

+81
-1
lines changed

2 files changed

+81
-1
lines changed

lib/internal/Magento/Framework/Filesystem/Directory/PathValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function validate(
5858
}
5959

6060
if (mb_strpos($actualPath, $realDirectoryPath) !== 0
61-
&& $path .DIRECTORY_SEPARATOR !== $realDirectoryPath
61+
&& rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR !== $realDirectoryPath
6262
) {
6363
throw new ValidatorException(
6464
new Phrase(
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
/**
3+
* Unit Test for \Magento\Framework\Filesystem\Directory\PathValidator
4+
*
5+
* Copyright © Magento, Inc. All rights reserved.
6+
* See COPYING.txt for license details.
7+
*/
8+
namespace Magento\Framework\Filesystem\Test\Unit\Directory;
9+
10+
use Magento\Framework\Filesystem\Directory\WriteInterface;
11+
use Magento\Framework\Filesystem\DriverInterface;
12+
13+
class PathValidatorTest extends \PHPUnit\Framework\TestCase
14+
{
15+
/**
16+
* \Magento\Framework\Filesystem\Driver
17+
*
18+
* @var \PHPUnit_Framework_MockObject_MockObject
19+
*/
20+
protected $driver;
21+
22+
/**
23+
* @var \Magento\Framework\Filesystem\Directory\PathValidator
24+
*/
25+
protected $pathValidator;
26+
27+
/**
28+
* Set up
29+
*/
30+
protected function setUp()
31+
{
32+
$this->driver = $this->createMock(\Magento\Framework\Filesystem\Driver\File::class);
33+
$this->pathValidator = new \Magento\Framework\Filesystem\Directory\PathValidator(
34+
$this->driver
35+
);
36+
}
37+
38+
/**
39+
* Tear down
40+
*/
41+
protected function tearDown()
42+
{
43+
$this->pathValidator = null;
44+
}
45+
46+
/**
47+
* @param string $directoryPath
48+
* @param string $path
49+
* @param string $scheme
50+
* @param bool $absolutePath
51+
* @param string $prefix
52+
* @dataProvider validateDataProvider
53+
*/
54+
public function testValidate($directoryPath, $path, $scheme, $absolutePath, $prefix)
55+
{
56+
$this->driver->expects($this->exactly(2))
57+
->method('getRealPathSafety')
58+
->willReturnMap(
59+
[
60+
[$directoryPath, $directoryPath],
61+
[null, $prefix . $directoryPath . ltrim($path, '/')],
62+
]
63+
);
64+
65+
$this->assertNull(
66+
$this->pathValidator->validate($directoryPath, $path, $scheme, $absolutePath)
67+
);
68+
}
69+
70+
/**
71+
* @return array
72+
*/
73+
public function validateDataProvider()
74+
{
75+
return [
76+
['/directory/path/', '/directory/path/', '/', false, '/://'],
77+
['/directory/path/', '/var/.regenerate', null, false, ''],
78+
];
79+
}
80+
}

0 commit comments

Comments
 (0)