diff --git a/src/Composer/Repository/Vcs/GitBitbucketDriver.php b/src/Composer/Repository/Vcs/GitBitbucketDriver.php index 950115a79..c9a3c2fdf 100644 --- a/src/Composer/Repository/Vcs/GitBitbucketDriver.php +++ b/src/Composer/Repository/Vcs/GitBitbucketDriver.php @@ -12,6 +12,7 @@ namespace Composer\Repository\Vcs; +use Composer\Config; use Composer\Json\JsonFile; use Composer\IO\IOInterface; @@ -140,7 +141,7 @@ class GitBitbucketDriver extends VcsDriver implements VcsDriverInterface /** * {@inheritDoc} */ - public static function supports(IOInterface $io, $url, $deep = false) + public static function supports(IOInterface $io, $url, Config $config, $deep = false) { if (!preg_match('#^https://bitbucket\.org/([^/]+)/(.+?)\.git$#', $url)) { return false; diff --git a/src/Composer/Repository/Vcs/GitDriver.php b/src/Composer/Repository/Vcs/GitDriver.php index e2a3a9eb0..2bcb79e23 100644 --- a/src/Composer/Repository/Vcs/GitDriver.php +++ b/src/Composer/Repository/Vcs/GitDriver.php @@ -18,6 +18,7 @@ use Composer\Util\Filesystem; use Composer\Util\Git as GitUtil; use Composer\IO\IOInterface; use Composer\Cache; +use Composer\Config; /** * @author Jordi Boggiano @@ -211,7 +212,7 @@ class GitDriver extends VcsDriver /** * {@inheritDoc} */ - public static function supports(IOInterface $io, $url, $deep = false) + public static function supports(IOInterface $io, $url, Config $config, $deep = false) { if (preg_match('#(^git://|\.git$|git(?:olite)?@|//git\.|//github.com/)#i', $url)) { return true; diff --git a/src/Composer/Repository/Vcs/GitHubDriver.php b/src/Composer/Repository/Vcs/GitHubDriver.php index f84eb74ca..e84c1d012 100644 --- a/src/Composer/Repository/Vcs/GitHubDriver.php +++ b/src/Composer/Repository/Vcs/GitHubDriver.php @@ -12,6 +12,7 @@ namespace Composer\Repository\Vcs; +use Composer\Config; use Composer\Downloader\TransportException; use Composer\Json\JsonFile; use Composer\Cache; @@ -231,9 +232,14 @@ class GitHubDriver extends VcsDriver /** * {@inheritDoc} */ - public static function supports(IOInterface $io, $url, $deep = false) + public static function supports(IOInterface $io, $url, Config $config, $deep = false) { - if (!preg_match('#^((?:https?|git)://([^/]+)/|git@([^:]+):)([^/]+)/(.+?)(?:\.git)?$#', $url)) { + if (!preg_match('#^((?:https?|git)://([^/]+)/|git@([^:]+):)([^/]+)/(.+?)(?:\.git)?$#', $url, $matches)) { + return false; + } + + $originUrl = isset($matches[2]) ? $matches[2] : $matches[3]; + if (!in_array($originUrl, $config->get('github-domains'))) { return false; } diff --git a/src/Composer/Repository/Vcs/HgBitbucketDriver.php b/src/Composer/Repository/Vcs/HgBitbucketDriver.php index 80683a465..9c403e71d 100644 --- a/src/Composer/Repository/Vcs/HgBitbucketDriver.php +++ b/src/Composer/Repository/Vcs/HgBitbucketDriver.php @@ -12,6 +12,7 @@ namespace Composer\Repository\Vcs; +use Composer\Config; use Composer\Json\JsonFile; use Composer\IO\IOInterface; @@ -150,7 +151,7 @@ class HgBitbucketDriver extends VcsDriver /** * {@inheritDoc} */ - public static function supports(IOInterface $io, $url, $deep = false) + public static function supports(IOInterface $io, $url, Config $config, $deep = false) { if (!preg_match('#^https://bitbucket\.org/([^/]+)/([^/]+)/?$#', $url)) { return false; diff --git a/src/Composer/Repository/Vcs/HgDriver.php b/src/Composer/Repository/Vcs/HgDriver.php index c3c06e38a..abfd0de51 100644 --- a/src/Composer/Repository/Vcs/HgDriver.php +++ b/src/Composer/Repository/Vcs/HgDriver.php @@ -12,6 +12,7 @@ namespace Composer\Repository\Vcs; +use Composer\Config; use Composer\Json\JsonFile; use Composer\Util\ProcessExecutor; use Composer\Util\Filesystem; @@ -189,7 +190,7 @@ class HgDriver extends VcsDriver /** * {@inheritDoc} */ - public static function supports(IOInterface $io, $url, $deep = false) + public static function supports(IOInterface $io, $url, Config $config, $deep = false) { if (preg_match('#(^(?:https?|ssh)://(?:[^@]@)?bitbucket.org|https://(?:.*?)\.kilnhg.com)#i', $url)) { return true; diff --git a/src/Composer/Repository/Vcs/PerforceDriver.php b/src/Composer/Repository/Vcs/PerforceDriver.php index 54e1d3e7d..6ff51125a 100644 --- a/src/Composer/Repository/Vcs/PerforceDriver.php +++ b/src/Composer/Repository/Vcs/PerforceDriver.php @@ -12,6 +12,7 @@ namespace Composer\Repository\Vcs; +use Composer\Config; use Composer\IO\IOInterface; use Composer\Util\ProcessExecutor; use Composer\Util\Perforce; @@ -158,7 +159,7 @@ class PerforceDriver extends VcsDriver /** * {@inheritDoc} */ - public static function supports(IOInterface $io, $url, $deep = false) + public static function supports(IOInterface $io, $url, Config $config, $deep = false) { if ($deep || preg_match('#\b(perforce|p4)\b#i', $url)) { return Perforce::checkServerExists($url, new ProcessExecutor); diff --git a/src/Composer/Repository/Vcs/SvnDriver.php b/src/Composer/Repository/Vcs/SvnDriver.php index c5a67b455..a2e345b07 100644 --- a/src/Composer/Repository/Vcs/SvnDriver.php +++ b/src/Composer/Repository/Vcs/SvnDriver.php @@ -13,6 +13,7 @@ namespace Composer\Repository\Vcs; use Composer\Cache; +use Composer\Config; use Composer\Json\JsonFile; use Composer\Util\ProcessExecutor; use Composer\Util\Filesystem; @@ -241,7 +242,7 @@ class SvnDriver extends VcsDriver /** * {@inheritDoc} */ - public static function supports(IOInterface $io, $url, $deep = false) + public static function supports(IOInterface $io, $url, Config $config, $deep = false) { $url = self::normalizeUrl($url); if (preg_match('#(^svn://|^svn\+ssh://|svn\.)#i', $url)) { diff --git a/src/Composer/Repository/Vcs/VcsDriverInterface.php b/src/Composer/Repository/Vcs/VcsDriverInterface.php index b29841b68..741cf1dda 100644 --- a/src/Composer/Repository/Vcs/VcsDriverInterface.php +++ b/src/Composer/Repository/Vcs/VcsDriverInterface.php @@ -12,6 +12,7 @@ namespace Composer\Repository\Vcs; +use Composer\Config; use Composer\IO\IOInterface; /** @@ -90,10 +91,11 @@ interface VcsDriverInterface /** * Checks if this driver can handle a given url * - * @param IOInterface $io IO instance - * @param string $url - * @param bool $deep unless true, only shallow checks (url matching typically) should be done + * @param IOInterface $io IO instance + * @param string $url URL to validate/check + * @param Config $config current $config + * @param bool $deep unless true, only shallow checks (url matching typically) should be done * @return bool */ - public static function supports(IOInterface $io, $url, $deep = false); + public static function supports(IOInterface $io, $url, Config $config, $deep = false); } diff --git a/src/Composer/Repository/VcsRepository.php b/src/Composer/Repository/VcsRepository.php index 701db33bb..a18328725 100644 --- a/src/Composer/Repository/VcsRepository.php +++ b/src/Composer/Repository/VcsRepository.php @@ -80,7 +80,7 @@ class VcsRepository extends ArrayRepository } foreach ($this->drivers as $driver) { - if ($driver::supports($this->io, $this->url)) { + if ($driver::supports($this->io, $this->url, $this->config)) { $driver = new $driver($this->repoConfig, $this->io, $this->config); $driver->initialize(); @@ -89,7 +89,7 @@ class VcsRepository extends ArrayRepository } foreach ($this->drivers as $driver) { - if ($driver::supports($this->io, $this->url, true)) { + if ($driver::supports($this->io, $this->url, $this->config, true)) { $driver = new $driver($this->repoConfig, $this->io, $this->config); $driver->initialize(); diff --git a/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php b/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php index d2c8167b9..ba418b2a2 100644 --- a/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php @@ -104,7 +104,6 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase public function testHasComposerFile() { - $this->setUp(); $repoConfig = array( 'url' => 'TEST_PERFORCE_URL', 'depot' => 'TEST_DEPOT_CONFIG', @@ -131,17 +130,17 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase $result = $driver->hasComposerFile($identifier); $this->assertTrue($result); } - + /** * Test that supports() simply return false. - * + * * @covers \Composer\Repository\Vcs\PerforceDriver::supports - * + * * @return void */ public function testSupportsReturnsFalseNoDeepCheck() { $this->expectOutputString(''); - $this->assertFalse(PerforceDriver::supports($this->io, 'existing.url')); + $this->assertFalse(PerforceDriver::supports($this->io, 'existing.url', $this->config)); } } diff --git a/tests/Composer/Test/Repository/Vcs/SvnDriverTest.php b/tests/Composer/Test/Repository/Vcs/SvnDriverTest.php index d9bd53321..1b4437a04 100644 --- a/tests/Composer/Test/Repository/Vcs/SvnDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/SvnDriverTest.php @@ -80,10 +80,8 @@ class SvnDriverTest extends \PHPUnit_Framework_TestCase */ public function testSupport($url, $assertion) { - if ($assertion === true) { - $this->assertTrue(SvnDriver::supports($this->getMock('Composer\IO\IOInterface'), $url)); - } else { - $this->assertFalse(SvnDriver::supports($this->getMock('Composer\IO\IOInterface'), $url)); - } + $config = new Config(); + $result = SvnDriver::supports($this->getMock('Composer\IO\IOInterface'), $url, $config); + $this->assertEquals($assertion, $result); } }