Skip to content

Commit a2270eb

Browse files
committed
Merge remote-tracking branch 'trigger/MAGETWO-95549' into 2.3.0-qwerty-bugs
2 parents ee41f1b + a3ba91f commit a2270eb

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
namespace Magento\Cms\Controller\Adminhtml\Wysiwyg\Images;
77

88
use Magento\Framework\App\Filesystem\DirectoryList;
9+
use Magento\Framework\App\Action\HttpPostActionInterface;
910

1011
/**
1112
* Delete image files.
1213
*/
13-
class DeleteFiles extends \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images
14+
class DeleteFiles extends \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images implements HttpPostActionInterface
1415
{
1516
/**
1617
* @var \Magento\Framework\Controller\Result\JsonFactory
@@ -79,7 +80,7 @@ public function execute()
7980
$filesystem = $this->_objectManager->get(\Magento\Framework\Filesystem::class);
8081
$dir = $filesystem->getDirectoryRead(DirectoryList::MEDIA);
8182
$filePath = $path . '/' . \Magento\Framework\File\Uploader::getCorrectFileName($file);
82-
if ($dir->isFile($dir->getRelativePath($filePath))) {
83+
if ($dir->isFile($dir->getRelativePath($filePath)) && !preg_match('#.htaccess#', $file)) {
8384
$this->getStorage()->deleteFile($filePath);
8485
}
8586
}

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
@@ -64,6 +64,10 @@ protected function setUp()
6464
$filePath = $this->fullDirectoryPath . DIRECTORY_SEPARATOR . $this->fileName;
6565
$fixtureDir = realpath(__DIR__ . '/../../../../../Catalog/_files');
6666
copy($fixtureDir . '/' . $this->fileName, $filePath);
67+
$path = $this->fullDirectoryPath . '/.htaccess';
68+
if (!$this->mediaDirectory->isFile($path)) {
69+
$this->mediaDirectory->writeFile($path, "Order deny,allow\nDeny from all");
70+
}
6771
$this->model = $this->objectManager->get(\Magento\Cms\Controller\Adminhtml\Wysiwyg\Images\DeleteFiles::class);
6872
}
6973

@@ -87,6 +91,26 @@ public function testExecute()
8791
);
8892
}
8993

94+
/**
95+
* Check that htaccess file couldn't be removed via
96+
* \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images\DeleteFiles::execute method
97+
*
98+
* @return void
99+
*/
100+
public function testDeleteHtaccess()
101+
{
102+
$this->model->getRequest()->setMethod('POST')
103+
->setPostValue('files', [$this->imagesHelper->idEncode('.htaccess')]);
104+
$this->model->getStorage()->getSession()->setCurrentPath($this->fullDirectoryPath);
105+
$this->model->execute();
106+
107+
$this->assertTrue(
108+
$this->mediaDirectory->isExist(
109+
$this->mediaDirectory->getRelativePath($this->fullDirectoryPath . '/' . '.htaccess')
110+
)
111+
);
112+
}
113+
90114
/**
91115
* Execute method with traversal file path to check that there is no ability to remove file which is not
92116
* under media directory.

0 commit comments

Comments
 (0)