From 7bfe0317689983d5775314f9b570a1597d64e19f Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 6 May 2012 17:18:26 +0200 Subject: [PATCH] VcsDrivers now send proper originUrl for authentication --- src/Composer/Repository/Vcs/GitBitbucketDriver.php | 1 + src/Composer/Repository/Vcs/GitHubDriver.php | 3 ++- src/Composer/Repository/Vcs/HgBitbucketDriver.php | 1 + src/Composer/Repository/Vcs/VcsDriver.php | 4 +++- .../Composer/Test/Repository/Vcs/GitHubDriverTest.php | 10 +++++----- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Composer/Repository/Vcs/GitBitbucketDriver.php b/src/Composer/Repository/Vcs/GitBitbucketDriver.php index b5cb8960d..28eb66631 100644 --- a/src/Composer/Repository/Vcs/GitBitbucketDriver.php +++ b/src/Composer/Repository/Vcs/GitBitbucketDriver.php @@ -35,6 +35,7 @@ class GitBitbucketDriver extends VcsDriver implements VcsDriverInterface preg_match('#^https://bitbucket\.org/([^/]+)/(.+?)\.git$#', $this->url, $match); $this->owner = $match[1]; $this->repository = $match[2]; + $this->originUrl = 'bitbucket.org'; } /** diff --git a/src/Composer/Repository/Vcs/GitHubDriver.php b/src/Composer/Repository/Vcs/GitHubDriver.php index 9091d0c6f..f1e507235 100644 --- a/src/Composer/Repository/Vcs/GitHubDriver.php +++ b/src/Composer/Repository/Vcs/GitHubDriver.php @@ -46,6 +46,7 @@ class GitHubDriver extends VcsDriver preg_match('#^(?:https?|git)://github\.com/([^/]+)/(.+?)(?:\.git)?$#', $this->url, $match); $this->owner = $match[1]; $this->repository = $match[2]; + $this->originUrl = 'github.com'; $this->fetchRootIdentifier(); } @@ -245,7 +246,7 @@ class GitHubDriver extends VcsDriver $this->io->write('Authentication required ('.$this->url.'):'); $username = $this->io->ask('Username: '); $password = $this->io->askAndHideAnswer('Password: '); - $this->io->setAuthorization($this->url, $username, $password); + $this->io->setAuthorization($this->originUrl, $username, $password); break; default: diff --git a/src/Composer/Repository/Vcs/HgBitbucketDriver.php b/src/Composer/Repository/Vcs/HgBitbucketDriver.php index 43fff9aba..dfdf033f5 100644 --- a/src/Composer/Repository/Vcs/HgBitbucketDriver.php +++ b/src/Composer/Repository/Vcs/HgBitbucketDriver.php @@ -35,6 +35,7 @@ class HgBitbucketDriver extends VcsDriver preg_match('#^https://bitbucket\.org/([^/]+)/([^/]+)/?$#', $this->url, $match); $this->owner = $match[1]; $this->repository = $match[2]; + $this->originUrl = 'bitbucket.org'; } /** diff --git a/src/Composer/Repository/Vcs/VcsDriver.php b/src/Composer/Repository/Vcs/VcsDriver.php index d13b4b4a1..785d53548 100644 --- a/src/Composer/Repository/Vcs/VcsDriver.php +++ b/src/Composer/Repository/Vcs/VcsDriver.php @@ -26,6 +26,7 @@ use Composer\Util\RemoteFilesystem; abstract class VcsDriver implements VcsDriverInterface { protected $url; + protected $originUrl; protected $io; protected $config; protected $process; @@ -43,6 +44,7 @@ abstract class VcsDriver implements VcsDriverInterface final public function __construct($url, IOInterface $io, Config $config, ProcessExecutor $process = null, $remoteFilesystem = null) { $this->url = $url; + $this->originUrl = $url; $this->io = $io; $this->config = $config; $this->process = $process ?: new ProcessExecutor; @@ -86,7 +88,7 @@ abstract class VcsDriver implements VcsDriverInterface */ protected function getContents($url) { - return $this->remoteFilesystem->getContents($this->url, $url, false); + return $this->remoteFilesystem->getContents($this->originUrl, $url, false); } protected static function isLocalUrl($url) diff --git a/tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php b/tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php index 064e870f9..bbd2d3896 100644 --- a/tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php @@ -40,7 +40,7 @@ class GitHubDriverTest extends \PHPUnit_Framework_TestCase $remoteFilesystem->expects($this->at(0)) ->method('getContents') - ->with($this->equalTo($repoUrl), $this->equalTo($repoApiUrl), $this->equalTo(false)) + ->with($this->equalTo('github.com'), $this->equalTo($repoApiUrl), $this->equalTo(false)) ->will($this->throwException(new TransportException('HTTP/1.1 404 Not Found', 404))); $io->expects($this->once()) @@ -55,11 +55,11 @@ class GitHubDriverTest extends \PHPUnit_Framework_TestCase $io->expects($this->once()) ->method('setAuthorization') - ->with($this->equalTo($repoUrl), 'someuser', 'somepassword'); + ->with($this->equalTo('github.com'), 'someuser', 'somepassword'); $remoteFilesystem->expects($this->at(1)) ->method('getContents') - ->with($this->equalTo($repoUrl), $this->equalTo($repoApiUrl), $this->equalTo(false)) + ->with($this->equalTo('github.com'), $this->equalTo($repoApiUrl), $this->equalTo(false)) ->will($this->returnValue('{"master_branch": "test_master"}')); $gitHubDriver = new GitHubDriver($repoUrl, $io, new Config(), null, $remoteFilesystem); @@ -109,7 +109,7 @@ class GitHubDriverTest extends \PHPUnit_Framework_TestCase $remoteFilesystem->expects($this->at(0)) ->method('getContents') - ->with($this->equalTo($repoUrl), $this->equalTo($repoApiUrl), $this->equalTo(false)) + ->with($this->equalTo('github.com'), $this->equalTo($repoApiUrl), $this->equalTo(false)) ->will($this->returnValue('{"master_branch": "test_master"}')); $gitHubDriver = new GitHubDriver($repoUrl, $io, new Config(), null, $remoteFilesystem); @@ -164,7 +164,7 @@ class GitHubDriverTest extends \PHPUnit_Framework_TestCase $remoteFilesystem->expects($this->at(0)) ->method('getContents') - ->with($this->equalTo($repoUrl), $this->equalTo($repoApiUrl), $this->equalTo(false)) + ->with($this->equalTo('github.com'), $this->equalTo($repoApiUrl), $this->equalTo(false)) ->will($this->throwException(new TransportException('HTTP/1.1 404 Not Found', 404))); // clean local clone if present