1
0
Fork 0

allow FileDownloader to use username:password@ info when downloading through https?

pull/2015/head
Jan Prieser 2013-06-17 15:41:48 +02:00
parent d498e73363
commit cc1e10e8ae
2 changed files with 20 additions and 0 deletions

View File

@ -99,7 +99,13 @@ class RemoteFilesystem
$this->progress = $progress; $this->progress = $progress;
$this->lastProgress = null; $this->lastProgress = null;
// capture username/password from URL if there is one
if (preg_match('{^https?://(.+):(.+)@([^/]+)}i', $fileUrl, $match)) {
$this->io->setAuthentication($originUrl, urldecode($match[1]), urldecode($match[2]));
}
$options = $this->getOptionsForUrl($originUrl, $additionalOptions); $options = $this->getOptionsForUrl($originUrl, $additionalOptions);
if ($this->io->isDebug()) { if ($this->io->isDebug()) {
$this->io->write('Downloading '.$fileUrl); $this->io->write('Downloading '.$fileUrl);
} }

View File

@ -13,6 +13,7 @@
namespace Composer\Test\Util; namespace Composer\Test\Util;
use Composer\Util\RemoteFilesystem; use Composer\Util\RemoteFilesystem;
use Installer\Exception;
class RemoteFilesystemTest extends \PHPUnit_Framework_TestCase class RemoteFilesystemTest extends \PHPUnit_Framework_TestCase
{ {
@ -143,6 +144,19 @@ class RemoteFilesystemTest extends \PHPUnit_Framework_TestCase
} }
} }
public function testCaptureAuthenticationParamsFromUrl()
{
$io = $this->getMock('Composer\IO\IOInterface');
$io
->expects($this->once())
->method('setAuthentication')
;
$fs = new RemoteFilesystem($io);
$fs->getContents('example.com', 'http://user:pass@www.example.com/something');
}
public function testGetContents() public function testGetContents()
{ {
$fs = new RemoteFilesystem($this->getMock('Composer\IO\IOInterface')); $fs = new RemoteFilesystem($this->getMock('Composer\IO\IOInterface'));