VcsDrivers now send proper originUrl for authentication

main
Jordi Boggiano 12 years ago
parent c754f96677
commit 7bfe031768

@ -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';
}
/**

@ -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 (<info>'.$this->url.'</info>):');
$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:

@ -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';
}
/**

@ -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)

@ -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

Loading…
Cancel
Save