Skip to content

Commit b8daea7

Browse files
committed
MAGETWO-95550: Adding restriction for controller
1 parent 2d9c1e6 commit b8daea7

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-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
@@ -82,7 +82,7 @@ public function execute()
8282
$filesystem = $this->_objectManager->get(\Magento\Framework\Filesystem::class);
8383
$dir = $filesystem->getDirectoryRead(DirectoryList::MEDIA);
8484
$filePath = $path . '/' . \Magento\Framework\File\Uploader::getCorrectFileName($file);
85-
if ($dir->isFile($dir->getRelativePath($filePath))) {
85+
if ($dir->isFile($dir->getRelativePath($filePath)) && !preg_match('#.htaccess#', $file)) {
8686
$this->getStorage()->deleteFile($filePath);
8787
}
8888
}

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ protected function setUp()
5454
$filePath = $this->fullDirectoryPath . DIRECTORY_SEPARATOR . $this->fileName;
5555
$fixtureDir = realpath(__DIR__ . '/../../../../../Catalog/_files');
5656
copy($fixtureDir . '/' . $this->fileName, $filePath);
57+
$path = '/.htaccess';
58+
if (!$this->mediaDirectory->isFile($path)) {
59+
$this->mediaDirectory->writeFile($path, "Order deny,allow\nDeny from all");
60+
}
5761
$this->model = $objectManager->get(\Magento\Cms\Controller\Adminhtml\Wysiwyg\Images\DeleteFiles::class);
5862
}
5963

@@ -89,4 +93,24 @@ public static function tearDownAfterClass()
8993
$directory->delete('wysiwyg');
9094
}
9195
}
96+
97+
/**
98+
* Check that htaccess file couldn't be removed via
99+
* \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images\DeleteFiles::execute method
100+
*
101+
* @return void
102+
*/
103+
public function testDeleteHtaccess()
104+
{
105+
$this->model->getRequest()->setMethod('POST')
106+
->setPostValue('files', [$this->imagesHelper->idEncode('.htaccess')]);
107+
$this->model->getStorage()->getSession()->setCurrentPath($this->fullDirectoryPath);
108+
$this->model->execute();
109+
110+
$this->assertTrue(
111+
$this->mediaDirectory->isExist(
112+
$this->mediaDirectory->getRelativePath('/' . '.htaccess')
113+
)
114+
);
115+
}
92116
}

0 commit comments

Comments
 (0)