Skip to content

Commit

Permalink
MAGETWO-64902: [GitHub][PR] bug #8277 fixing bug with https downloadi…
Browse files Browse the repository at this point in the history
…ng. #8278
  • Loading branch information
Magento CICD authored Feb 23, 2017
2 parents c5f2c4d + 86fd9ff commit d317435
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
17 changes: 16 additions & 1 deletion app/code/Magento/CatalogImportExport/Model/Import/Uploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Magento\CatalogImportExport\Model\Import;

use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Filesystem\DriverPool;

/**
Expand All @@ -15,6 +16,14 @@
*/
class Uploader extends \Magento\MediaStorage\Model\File\Uploader
{

/**
* HTTP scheme
* used to compare against the filename and select the proper DriverPool adapter
* @var string
*/
private $httpScheme = 'http://';

/**
* Temp directory.
*
Expand Down Expand Up @@ -145,7 +154,13 @@ public function move($fileName, $renameFileOff = false)
}
if (preg_match('/\bhttps?:\/\//i', $fileName, $matches)) {
$url = str_replace($matches[0], '', $fileName);
$read = $this->_readFactory->create($url, DriverPool::HTTP);

if ($matches[0] === $this->httpScheme) {
$read = $this->_readFactory->create($url, DriverPool::HTTP);
} else {
$read = $this->_readFactory->create($url, DriverPool::HTTPS);
}

$fileName = preg_replace('/[^a-z0-9\._-]+/i', '', $fileName);
$this->_directory->writeFile(
$this->_directory->getRelativePath($this->getTmpDir() . '/' . $fileName),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,63 @@ public function testMoveFileName()
$this->assertEquals(['name' => $fileName], $this->uploader->move($fileName));
}

/**
* @dataProvider moveFileUrlDriverPoolDataProvider
*/
public function testMoveFileUrlDrivePool($fileUrl, $expectedHost, $expectedDriverPool, $expectedScheme)
{

$driverPool = $this->getMock(\Magento\Framework\Filesystem\DriverPool::class, ['getDriver']);
$driverMock = $this->getMock($expectedDriverPool, ['readAll']);
$driverMock->expects($this->any())->method('isExists')->willReturn(true);
$driverMock->expects($this->any())->method('readAll')->willReturn(null);
$driverPool->expects($this->any())->method('getDriver')->willReturn($driverMock);

$readFactory = $this->getMockBuilder(\Magento\Framework\Filesystem\File\ReadFactory::class)
->setConstructorArgs(
[
$driverPool,
]
)
->setMethods(['create'])
->getMock();

$readFactory->expects($this->any())->method('create')
->with($expectedHost, $expectedScheme)
->willReturn($driverMock);

$uploaderMock = $this->getMockBuilder(\Magento\CatalogImportExport\Model\Import\Uploader::class)
->setConstructorArgs([
$this->coreFileStorageDb,
$this->coreFileStorage,
$this->imageFactory,
$this->validator,
$this->filesystem,
$readFactory,
])
->getMock();

$uploaderMock->move($fileUrl);
}

public function moveFileUrlDriverPoolDataProvider()
{
return [
[
'$fileUrl' => 'http://test_uploader_file',
'$expectedHost' => 'test_uploader_file',
'$expectedDriverPool' => \Magento\Framework\Filesystem\Driver\Http::class,
'$expectedScheme' => \Magento\Framework\Filesystem\DriverPool::HTTP,
],
[
'$fileUrl' => 'https://!:^&`;file',
'$expectedHost' => '!:^&`;file',
'$expectedDriverPool' => \Magento\Framework\Filesystem\Driver\Https::class,
'$expectedScheme' => \Magento\Framework\Filesystem\DriverPool::HTTPS,
],
];
}

public function moveFileUrlDataProvider()
{
return [
Expand Down

0 comments on commit d317435

Please sign in to comment.