File tree Expand file tree Collapse file tree 2 files changed +27
-2
lines changed
app/code/Magento/Cms/Controller/Adminhtml/Wysiwyg/Images
dev/tests/integration/testsuite/Magento/Cms/Controller/Adminhtml/Wysiwyg/Images Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change 6
6
namespace Magento \Cms \Controller \Adminhtml \Wysiwyg \Images ;
7
7
8
8
use Magento \Framework \App \Filesystem \DirectoryList ;
9
+ use Magento \Framework \App \Action \HttpPostActionInterface ;
9
10
10
11
/**
11
12
* Delete image files.
12
13
*/
13
- class DeleteFiles extends \Magento \Cms \Controller \Adminhtml \Wysiwyg \Images
14
+ class DeleteFiles extends \Magento \Cms \Controller \Adminhtml \Wysiwyg \Images implements HttpPostActionInterface
14
15
{
15
16
/**
16
17
* @var \Magento\Framework\Controller\Result\JsonFactory
@@ -79,7 +80,7 @@ public function execute()
79
80
$ filesystem = $ this ->_objectManager ->get (\Magento \Framework \Filesystem::class);
80
81
$ dir = $ filesystem ->getDirectoryRead (DirectoryList::MEDIA );
81
82
$ 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 ) ) {
83
84
$ this ->getStorage ()->deleteFile ($ filePath );
84
85
}
85
86
}
Original file line number Diff line number Diff line change @@ -64,6 +64,10 @@ protected function setUp()
64
64
$ filePath = $ this ->fullDirectoryPath . DIRECTORY_SEPARATOR . $ this ->fileName ;
65
65
$ fixtureDir = realpath (__DIR__ . '/../../../../../Catalog/_files ' );
66
66
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
+ }
67
71
$ this ->model = $ this ->objectManager ->get (\Magento \Cms \Controller \Adminhtml \Wysiwyg \Images \DeleteFiles::class);
68
72
}
69
73
@@ -87,6 +91,26 @@ public function testExecute()
87
91
);
88
92
}
89
93
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
+
90
114
/**
91
115
* Execute method with traversal file path to check that there is no ability to remove file which is not
92
116
* under media directory.
You can’t perform that action at this time.
0 commit comments