Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug #8277 fixing bug with https downloading. #8278

Merged
merged 4 commits into from
Feb 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 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,19 @@
*/
class Uploader extends \Magento\MediaStorage\Model\File\Uploader
{

/**
* HTTP scheme
* used to compare against the filename and select the proper DriverPool adapter
*/
const HTTP_SCHEME = 'http://';

/**
* HTTPS scheme
* used to compare against the filename and select the proper DriverPool adapter
*/
const HTTPS_SCHEME = 'https://';

/**
* Temp directory.
*
Expand Down Expand Up @@ -145,7 +159,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] === self::HTTP_SCHEME) {
$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