diff --git a/src/Composer/Util/RemoteFilesystem.php b/src/Composer/Util/RemoteFilesystem.php index 25ef08a61..42eff8421 100644 --- a/src/Composer/Util/RemoteFilesystem.php +++ b/src/Composer/Util/RemoteFilesystem.php @@ -99,7 +99,13 @@ class RemoteFilesystem $this->progress = $progress; $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); + if ($this->io->isDebug()) { $this->io->write('Downloading '.$fileUrl); } diff --git a/tests/Composer/Test/Util/RemoteFilesystemTest.php b/tests/Composer/Test/Util/RemoteFilesystemTest.php index f9c1d398b..4c841555c 100644 --- a/tests/Composer/Test/Util/RemoteFilesystemTest.php +++ b/tests/Composer/Test/Util/RemoteFilesystemTest.php @@ -13,6 +13,7 @@ namespace Composer\Test\Util; use Composer\Util\RemoteFilesystem; +use Installer\Exception; 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() { $fs = new RemoteFilesystem($this->getMock('Composer\IO\IOInterface'));