Skip to content

Commit 4198b96

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-95550' into 2.1.16-develop-pr60
2 parents f92ce39 + 4846d01 commit 4198b96

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-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: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,64 @@ public static function tearDownAfterClass()
8888
if ($directory->isExist('wysiwyg')) {
8989
$directory->delete('wysiwyg');
9090
}
91+
if ($directory->isExist('.htaccess')) {
92+
$directory->delete('.htaccess');
93+
}
94+
if ($directory->isExist('thtaccess')) {
95+
$directory->delete('thtaccess');
96+
}
97+
}
98+
99+
/**
100+
* Creates file and tries to delete it via
101+
* \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images\DeleteFiles::execute method
102+
*
103+
* @param string $fileName
104+
* @return void
105+
*/
106+
private function createFileAndExecuteDelete($fileName)
107+
{
108+
$path = '/' . $fileName;
109+
if (!$this->mediaDirectory->isFile($path)) {
110+
$this->mediaDirectory->writeFile($path, "Order deny,allow\nDeny from all");
111+
}
112+
$this->model->getRequest()->setMethod('POST')
113+
->setPostValue('files', [$this->imagesHelper->idEncode($fileName)]);
114+
$this->model->getStorage()->getSession()->setCurrentPath($this->mediaDirectory->getAbsolutePath());
115+
$this->model->execute();
116+
}
117+
118+
/**
119+
* Check that htaccess file couldn't be removed via
120+
* \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images\DeleteFiles::execute method
121+
*
122+
* @return void
123+
*/
124+
public function testCouldNotDeleteHtaccess()
125+
{
126+
$fileName = '.htaccess';
127+
$this->createFileAndExecuteDelete($fileName);
128+
$this->assertTrue(
129+
$this->mediaDirectory->isExist(
130+
$this->mediaDirectory->getRelativePath($fileName)
131+
)
132+
);
133+
}
134+
135+
/**
136+
* Check that random file could be removed via
137+
* \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images\DeleteFiles::execute method
138+
*
139+
* @return void
140+
*/
141+
public function testDeleteAnyFile()
142+
{
143+
$fileName = 'thtaccess';
144+
$this->createFileAndExecuteDelete($fileName);
145+
$this->assertFalse(
146+
$this->mediaDirectory->isExist(
147+
$this->mediaDirectory->getRelativePath($fileName)
148+
)
149+
);
91150
}
92151
}

0 commit comments

Comments
 (0)