Skip to content

Commit 4a82156

Browse files
committed
B2B-2024: [AWS S3] [Integration Tests]: Investigate Test Failures in cms module
1 parent b161b9f commit 4a82156

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

app/code/Magento/RemoteStorage/Model/Filesystem/Directory/WriteFactory.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
class WriteFactory extends BaseWriteFactory
2020
{
2121
/**
22-
* Object Manager
23-
*
2422
* @var ObjectManagerInterface
2523
*/
2624
private $objectManager;
@@ -32,19 +30,29 @@ class WriteFactory extends BaseWriteFactory
3230
*/
3331
private $driverPool;
3432

33+
/**
34+
* Deny List Validator
35+
*
36+
* @var DenyListPathValidator
37+
*/
38+
private $denyListPathValidator;
39+
3540
/**
3641
* WriteFactory constructor.
3742
*
3843
* @param ObjectManagerInterface $objectManager
3944
* @param BaseDriverPool $driverPool
45+
* @param DenyListPathValidator|null $denyListPathValidator
4046
*/
4147
public function __construct(
4248
ObjectManagerInterface $objectManager,
43-
BaseDriverPool $driverPool
49+
BaseDriverPool $driverPool,
50+
?DenyListPathValidator $denyListPathValidator = null
4451
) {
4552
$this->objectManager = $objectManager;
4653
$this->driverPool = $driverPool;
47-
parent::__construct($driverPool);
54+
$this->denyListPathValidator = $denyListPathValidator;
55+
parent::__construct($driverPool, $denyListPathValidator);
4856
}
4957

5058
/**
@@ -64,7 +72,7 @@ public function create(
6472

6573
$validators = [
6674
'pathValidator' => new PathValidator($driver),
67-
'denyListPathValidator' => new DenyListPathValidator($driver)
75+
'denyListPathValidator' => $this->denyListPathValidator ?: new DenyListPathValidator($driver)
6876
];
6977

7078
$pathValidator = new CompositePathValidator($validators);
@@ -82,6 +90,5 @@ public function create(
8290
} else {
8391
return parent::create($path, $driverCode, $createPermissions);
8492
}
85-
8693
}
8794
}

dev/tests/integration/testsuite/Magento/Cms/Controller/Adminhtml/Wysiwyg/Images/DeleteFilesTest.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
use Magento\Framework\App\Filesystem\DirectoryList;
1313
use Magento\Framework\Exception\FileSystemException;
1414
use Magento\Framework\Filesystem\Directory\DenyListPathValidator;
15-
use Magento\Framework\Filesystem\Directory\TargetDirectory;
16-
use Magento\Framework\Filesystem\Directory\WriteFactory;
1715
use Magento\Framework\Filesystem\Directory\WriteInterface;
1816
use Magento\Framework\Filesystem\Driver\File;
17+
use Magento\RemoteStorage\Driver\DriverPool;
18+
use Magento\RemoteStorage\Model\Filesystem\Directory\WriteFactory;
1919

2020
/**
2121
* Test for \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images\DeleteFiles class.
@@ -79,11 +79,6 @@ class DeleteFilesTest extends \PHPUnit\Framework\TestCase
7979
*/
8080
private $bypassDenyListWrite;
8181

82-
/**
83-
* @var WriteInterface
84-
*/
85-
private $rootDirectory;
86-
8782
/**
8883
* @inheritdoc
8984
* @throws FileSystemException
@@ -97,8 +92,6 @@ protected function setUp(): void
9792
/** @var \Magento\Cms\Helper\Wysiwyg\Images $imagesHelper */
9893
$this->imagesHelper = $this->objectManager->get(\Magento\Cms\Helper\Wysiwyg\Images::class);
9994
$this->mediaDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA);
100-
$this->rootDirectory = $this->objectManager->get(TargetDirectory::class)
101-
->getDirectoryWrite(DirectoryList::ROOT);
10295
$this->fullDirectoryPath = $this->imagesHelper->getStorageRoot() . $directoryName;
10396
$this->mediaDirectory->create($this->mediaDirectory->getRelativePath($this->fullDirectoryPath));
10497
$filePath = $this->fullDirectoryPath . DIRECTORY_SEPARATOR . $this->fileName;
@@ -190,8 +183,13 @@ public function testDeleteHtaccess()
190183
$bypassDenyListWriteFactory = $this->objectManager->create(WriteFactory::class, [
191184
'denyListPathValidator' => $denyListPathValidator
192185
]);
193-
$this->bypassDenyListWrite = $bypassDenyListWriteFactory
194-
->create($this->directoryList->getPath(DirectoryList::MEDIA));
186+
$this->bypassDenyListWrite = $bypassDenyListWriteFactory->create(
187+
$this->mediaDirectory->getAbsolutePath(),
188+
$this->mediaDirectory->getDriver() instanceof File ? DriverPool::FILE : DriverPool::REMOTE,
189+
null,
190+
DirectoryList::MEDIA
191+
);
192+
195193
if (!$this->bypassDenyListWrite->isFile($path)) {
196194
$this->bypassDenyListWrite->writeFile($path, "Order deny,allow\nDeny from all");
197195
}
@@ -205,6 +203,7 @@ public function testDeleteHtaccess()
205203
$this->bypassDenyListWrite->getRelativePath($testDir . '/' . '.htaccess')
206204
)
207205
);
206+
$this->bypassDenyListWrite->delete($testDir);
208207
}
209208

210209
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function validate(
5555
): void {
5656
$realDirectoryPath = $this->driver->getRealPathSafety($directoryPath);
5757
$fullPath = $this->driver->getAbsolutePath(
58-
$realDirectoryPath . DIRECTORY_SEPARATOR,
58+
rtrim($realDirectoryPath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR,
5959
$path,
6060
$scheme
6161
);

0 commit comments

Comments
 (0)