Skip to content

Commit ed27a7a

Browse files
committed
MAGETWO-95551: Adding restriction for controller
1 parent 991d785 commit ed27a7a

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

app/code/Magento/Cms/Controller/Adminhtml/Wysiwyg/Images/DeleteFiles.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function execute()
7979
$filesystem = $this->_objectManager->get(\Magento\Framework\Filesystem::class);
8080
$dir = $filesystem->getDirectoryRead(DirectoryList::MEDIA);
8181
$filePath = $path . '/' . \Magento\Framework\File\Uploader::getCorrectFileName($file);
82-
if ($dir->isFile($dir->getRelativePath($filePath))) {
82+
if ($dir->isFile($dir->getRelativePath($filePath)) && !preg_match('#^\.htaccess$#', $file)) {
8383
$this->getStorage()->deleteFile($filePath);
8484
}
8585
}

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ class DeleteFilesTest extends \PHPUnit\Framework\TestCase
4343
*/
4444
private $objectManager;
4545

46+
/**
47+
* @var string
48+
*/
49+
private $fullDirectoryPath;
50+
4651
/**
4752
* @inheritdoc
4853
*/
@@ -54,6 +59,11 @@ protected function setUp()
5459
$this->imagesHelper = $this->objectManager->get(\Magento\Cms\Helper\Wysiwyg\Images::class);
5560
$this->mediaDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA);
5661
$this->model = $this->objectManager->get(\Magento\Cms\Controller\Adminhtml\Wysiwyg\Images\DeleteFiles::class);
62+
$this->fullDirectoryPath = $this->imagesHelper->getStorageRoot() . '/directory1';
63+
$path = $this->fullDirectoryPath . '/.htaccess';
64+
if (!$this->mediaDirectory->isFile($path)) {
65+
$this->mediaDirectory->writeFile($path, "Order deny,allow\nDeny from all");
66+
}
5767
}
5868

5969
/**
@@ -106,6 +116,26 @@ public function testExecuteWithLinkedMedia()
106116
$this->assertFalse(is_file($fullDirectoryPath . DIRECTORY_SEPARATOR . $this->fileName));
107117
}
108118

119+
/**
120+
* Check that htaccess file couldn't be removed via
121+
* \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images\DeleteFiles::execute method
122+
*
123+
* @return void
124+
*/
125+
public function testDeleteHtaccess()
126+
{
127+
$this->model->getRequest()->setMethod('POST')
128+
->setPostValue('files', [$this->imagesHelper->idEncode('.htaccess')]);
129+
$this->model->getStorage()->getSession()->setCurrentPath($this->fullDirectoryPath);
130+
$this->model->execute();
131+
132+
$this->assertTrue(
133+
$this->mediaDirectory->isExist(
134+
$this->mediaDirectory->getRelativePath($this->fullDirectoryPath . '/' . '.htaccess')
135+
)
136+
);
137+
}
138+
109139
/**
110140
* @inheritdoc
111141
*/

0 commit comments

Comments
 (0)