فهرست منبع

VcsDrivers now send proper originUrl for authentication

Jordi Boggiano 13 سال پیش
والد
کامیت
7bfe031768

+ 1 - 0
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';
     }
 
     /**

+ 2 - 1
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 (<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:

+ 1 - 0
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';
     }
 
     /**

+ 3 - 1
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)

+ 5 - 5
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