Skip to content

Commit 464ffc2

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-72052' into 2.3-develop-pr4
2 parents 4a832fe + 93d7b57 commit 464ffc2

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

app/code/Magento/ImportExport/Controller/Adminhtml/History/Download.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __construct(
3939
*/
4040
public function execute()
4141
{
42-
$fileName = $this->getRequest()->getParam('filename');
42+
$fileName = basename($this->getRequest()->getParam('filename'));
4343

4444
/** @var \Magento\ImportExport\Helper\Report $reportHelper */
4545
$reportHelper = $this->_objectManager->get(\Magento\ImportExport\Helper\Report::class);

app/code/Magento/ImportExport/Test/Unit/Controller/Adminhtml/History/DownloadTest.php

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ class DownloadTest extends \PHPUnit\Framework\TestCase
7272
*/
7373
protected function setUp()
7474
{
75-
$this->request = $this->createPartialMock(\Magento\Framework\App\Request\Http::class, ['getParam']);
76-
$this->request->expects($this->any())->method('getParam')->with('filename')->willReturn('filename');
75+
$this->request = $this->getMockBuilder(\Magento\Framework\App\Request\Http::class)
76+
->disableOriginalConstructor()
77+
->getMock();
7778
$this->reportHelper = $this->createPartialMock(
7879
\Magento\ImportExport\Helper\Report::class,
7980
['importFileExists', 'getReportSize', 'getReportOutput']
@@ -126,21 +127,44 @@ protected function setUp()
126127
}
127128

128129
/**
129-
* Test execute()
130+
* Tests download controller with different file names in request.
131+
*
132+
* @param string $requestFilename
133+
* @param string $processedFilename
134+
* @dataProvider executeDataProvider
130135
*/
131-
public function testExecute()
136+
public function testExecute($requestFilename, $processedFilename)
132137
{
133-
$this->reportHelper->expects($this->any())->method('importFileExists')->willReturn(true);
138+
$this->request->method('getParam')
139+
->with('filename')
140+
->willReturn($requestFilename);
141+
142+
$this->reportHelper->method('importFileExists')
143+
->with($processedFilename)
144+
->willReturn(true);
134145
$this->resultRaw->expects($this->once())->method('setContents');
135146
$this->downloadController->execute();
136147
}
137148

149+
/**
150+
* @return array
151+
*/
152+
public function executeDataProvider()
153+
{
154+
return [
155+
'Normal file name' => ['filename.csv', 'filename.csv'],
156+
'Relative file name' => ['../../../../../../../../etc/passwd', 'passwd'],
157+
'Empty file name' => ['', ''],
158+
];
159+
}
160+
138161
/**
139162
* Test execute() with not found file
140163
*/
141164
public function testExecuteFileNotFound()
142165
{
143-
$this->reportHelper->expects($this->any())->method('importFileExists')->willReturn(false);
166+
$this->request->method('getParam')->with('filename')->willReturn('filename');
167+
$this->reportHelper->method('importFileExists')->willReturn(false);
144168
$this->resultRaw->expects($this->never())->method('setContents');
145169
$this->downloadController->execute();
146170
}

0 commit comments

Comments
 (0)