Skip to content

Commit 8a309e8

Browse files
author
OlgaVasyltsun
committed
MC-18100: Changes in Downloadable product upload controller
1 parent 4b3b814 commit 8a309e8

File tree

3 files changed

+26
-16
lines changed

3 files changed

+26
-16
lines changed

dev/tests/integration/testsuite/Magento/Downloadable/Controller/Adminhtml/Downloadable/File/UploadTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Downloadable\Controller\Adminhtml\Downloadable\File;
89

@@ -47,6 +48,9 @@ public function testUploadWrongUploadType($postData): void
4748
$this->assertEquals(0, $result['errorcode']);
4849
}
4950

51+
/**
52+
* @return array
53+
*/
5054
public function uploadWrongUploadTypeDataProvider(): array
5155
{
5256
return [

dev/tests/integration/testsuite/Magento/Framework/File/UploaderTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ protected function setUp()
3939
/**
4040
* @return void
4141
*/
42-
public function testUploadFileFromAllowedFolder(): void
42+
public function testUploadFileFromAllowedFolder()
4343
{
4444
$mediaDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA);
4545
$tmpDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::SYS_TMP);
@@ -67,7 +67,7 @@ public function testUploadFileFromAllowedFolder(): void
6767
*
6868
* @return void
6969
*/
70-
public function testUploadFileFromNotAllowedFolder(): void
70+
public function testUploadFileFromNotAllowedFolder()
7171
{
7272
$fileName = 'text.txt';
7373
$tmpDir = 'tmp';
@@ -89,8 +89,6 @@ public function testUploadFileFromNotAllowedFolder(): void
8989
*/
9090
protected function tearDown()
9191
{
92-
parent::tearDown();
93-
9492
$tmpDir = 'tmp';
9593
$mediaDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA);
9694
$mediaDirectory->delete($tmpDir);

lib/internal/Magento/Framework/File/Uploader.php

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -173,17 +173,12 @@ class Uploader
173173
*
174174
* @param string|array $fileId
175175
* @param \Magento\Framework\File\Mime|null $fileMime
176-
* @param DirectoryList|null $directoryList
177176
* @throws \DomainException
178177
*/
179178
public function __construct(
180179
$fileId,
181-
Mime $fileMime = null,
182-
DirectoryList $directoryList = null
180+
Mime $fileMime = null
183181
) {
184-
$this->directoryList= $directoryList ?: \Magento\Framework\App\ObjectManager::getInstance()
185-
->get(DirectoryList::class);
186-
187182
$this->_setUploadFileId($fileId);
188183
if (!file_exists($this->_file['tmp_name'])) {
189184
$code = empty($this->_file['tmp_name']) ? self::TMP_NAME_EMPTY : 0;
@@ -606,7 +601,7 @@ private function _setUploadFileId($fileId)
606601
* @return void
607602
* @throws \InvalidArgumentException
608603
*/
609-
private function validateFileId(array $fileId): void
604+
private function validateFileId(array $fileId)
610605
{
611606
$isValid = false;
612607
if (isset($fileId['tmp_name'])) {
@@ -615,14 +610,14 @@ private function validateFileId(array $fileId): void
615610
if (preg_match('/\.\.(\\\|\/)/', $tmpName) !== 1) {
616611
$allowedFolders = [
617612
sys_get_temp_dir(),
618-
$this->directoryList->getPath(DirectoryList::MEDIA),
619-
$this->directoryList->getPath(DirectoryList::VAR_DIR),
620-
$this->directoryList->getPath(DirectoryList::TMP),
621-
$this->directoryList->getPath(DirectoryList::UPLOAD),
613+
$this->getDirectoryList()->getPath(DirectoryList::MEDIA),
614+
$this->getDirectoryList()->getPath(DirectoryList::VAR_DIR),
615+
$this->getDirectoryList()->getPath(DirectoryList::TMP),
616+
$this->getDirectoryList()->getPath(DirectoryList::UPLOAD),
622617
];
623618

624619
$disallowedFolders = [
625-
$this->directoryList->getPath(DirectoryList::LOG),
620+
$this->getDirectoryList()->getPath(DirectoryList::LOG),
626621
];
627622

628623
foreach ($allowedFolders as $allowedFolder) {
@@ -648,6 +643,19 @@ private function validateFileId(array $fileId): void
648643
}
649644
}
650645

646+
/**
647+
* @return DirectoryList
648+
*/
649+
private function getDirectoryList(): DirectoryList
650+
{
651+
if ($this->directoryList === null) {
652+
$this->directoryList = \Magento\Framework\App\ObjectManager::getInstance()
653+
->get(DirectoryList::class);
654+
}
655+
656+
return $this->directoryList;
657+
}
658+
651659
/**
652660
* Create destination folder
653661
*

0 commit comments

Comments
 (0)