From c5fa3bdde0e042b64e32102c21edb2e12e474746 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 24 Jul 2018 09:30:06 +0200 Subject: [PATCH] Migrate to repo.packagist.org for package metadata --- doc/05-repositories.md | 2 +- src/Composer/Command/DiagnoseCommand.php | 10 +++++----- src/Composer/Command/InitCommand.php | 2 +- src/Composer/Config.php | 2 +- src/Composer/Repository/ComposerRepository.php | 14 ++++++++++---- src/Composer/Util/RemoteFilesystem.php | 6 +++--- tests/Composer/Test/ConfigTest.php | 8 ++++---- .../Package/Loader/ValidatingArrayLoaderTest.php | 2 +- 8 files changed, 26 insertions(+), 20 deletions(-) diff --git a/doc/05-repositories.md b/doc/05-repositories.md index db54a4fb1..9706a07e0 100644 --- a/doc/05-repositories.md +++ b/doc/05-repositories.md @@ -59,7 +59,7 @@ The main repository type is the `composer` repository. It uses a single This is also the repository type that packagist uses. To reference a `composer` repository, supply the path before the `packages.json` file. In the case of packagist, that file is located at `/packages.json`, so the URL of -the repository would be `packagist.org`. For `example.org/packages.json` the +the repository would be `repo.packagist.org`. For `example.org/packages.json` the repository URL would be `example.org`. #### packages diff --git a/src/Composer/Command/DiagnoseCommand.php b/src/Composer/Command/DiagnoseCommand.php index 3fecf52c4..b15cd35b1 100644 --- a/src/Composer/Command/DiagnoseCommand.php +++ b/src/Composer/Command/DiagnoseCommand.php @@ -81,7 +81,7 @@ EOT } $config->merge(array('config' => array('secure-http' => false))); - $config->prohibitUrlByConfig('http://packagist.org', new NullIO); + $config->prohibitUrlByConfig('http://repo.packagist.org', new NullIO); $this->rfs = Factory::createRemoteFilesystem($io, $config); $this->process = new ProcessExecutor($io); @@ -208,7 +208,7 @@ EOT } try { - $this->rfs->getContents('packagist.org', $proto . '://packagist.org/packages.json', false); + $this->rfs->getContents('packagist.org', $proto . '://repo.packagist.org/packages.json', false); } catch (TransportException $e) { if (false !== strpos($e->getMessage(), 'cafile')) { $result[] = '[' . get_class($e) . '] ' . $e->getMessage() . ''; @@ -230,11 +230,11 @@ EOT { $protocol = extension_loaded('openssl') ? 'https' : 'http'; try { - $json = json_decode($this->rfs->getContents('packagist.org', $protocol . '://packagist.org/packages.json', false), true); + $json = json_decode($this->rfs->getContents('packagist.org', $protocol . '://repo.packagist.org/packages.json', false), true); $hash = reset($json['provider-includes']); $hash = $hash['sha256']; $path = str_replace('%hash%', $hash, key($json['provider-includes'])); - $provider = $this->rfs->getContents('packagist.org', $protocol . '://packagist.org/'.$path, false); + $provider = $this->rfs->getContents('packagist.org', $protocol . '://repo.packagist.org/'.$path, false); if (hash('sha256', $provider) !== $hash) { return 'It seems that your proxy is modifying http traffic on the fly'; @@ -255,7 +255,7 @@ EOT */ private function checkHttpProxyFullUriRequestParam() { - $url = 'http://packagist.org/packages.json'; + $url = 'http://repo.packagist.org/packages.json'; try { $this->rfs->getContents('packagist.org', $url, false); } catch (TransportException $e) { diff --git a/src/Composer/Command/InitCommand.php b/src/Composer/Command/InitCommand.php index 802c65218..7fabb62f1 100644 --- a/src/Composer/Command/InitCommand.php +++ b/src/Composer/Command/InitCommand.php @@ -165,7 +165,7 @@ EOT } $repos[] = RepositoryFactory::createRepo($io, $config, array( 'type' => 'composer', - 'url' => 'https://packagist.org', + 'url' => 'https://repo.packagist.org', )); $this->repos = new CompositeRepository($repos); diff --git a/src/Composer/Config.php b/src/Composer/Config.php index a7fca2988..8ce429d31 100644 --- a/src/Composer/Config.php +++ b/src/Composer/Config.php @@ -72,7 +72,7 @@ class Config public static $defaultRepositories = array( 'packagist.org' => array( 'type' => 'composer', - 'url' => 'https?://packagist.org', + 'url' => 'https?://repo.packagist.org', 'allow_ssl_downgrade' => true, ), ); diff --git a/src/Composer/Repository/ComposerRepository.php b/src/Composer/Repository/ComposerRepository.php index 53c16129f..403b31cd9 100644 --- a/src/Composer/Repository/ComposerRepository.php +++ b/src/Composer/Repository/ComposerRepository.php @@ -90,6 +90,12 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito $this->config = $config; $this->options = $repoConfig['options']; $this->url = $repoConfig['url']; + + // force url for packagist.org to repo.packagist.org + if (preg_match('{^(?Phttps?)://packagist.org/?$}i', $this->url, $match)) { + $this->url = $match['proto'].'://repo.packagist.org'; + } + $this->baseUrl = rtrim(preg_replace('{(?:/[^/\\\\]+\.json)?(?:[?#].*)?$}', '', $this->url), '/'); $this->io = $io; $this->cache = new Cache($io, $config->get('cache-repo-dir').'/'.preg_replace('{[^a-z0-9.]}i', '-', $this->url), 'a-z0-9.$'); @@ -539,10 +545,10 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito } // force values for packagist - if (preg_match('{^https?://packagist.org/?$}i', $this->url) && !empty($this->repoConfig['force-lazy-providers'])) { - $this->url = 'https://packagist.org'; - $this->baseUrl = 'https://packagist.org'; - $this->lazyProvidersUrl = $this->canonicalizeUrl('https://packagist.org/p/%package%.json'); + if (preg_match('{^https?://repo\.packagist\.org/?$}i', $this->url) && !empty($this->repoConfig['force-lazy-providers'])) { + $this->url = 'https://repo.packagist.org'; + $this->baseUrl = 'https://repo.packagist.org'; + $this->lazyProvidersUrl = $this->canonicalizeUrl('https://repo.packagist.org/p/%package%.json'); $this->providersUrl = null; } elseif (!empty($this->repoConfig['force-lazy-providers'])) { $this->lazyProvidersUrl = $this->canonicalizeUrl('/p/%package%.json'); diff --git a/src/Composer/Util/RemoteFilesystem.php b/src/Composer/Util/RemoteFilesystem.php index a12efe774..39ed36107 100644 --- a/src/Composer/Util/RemoteFilesystem.php +++ b/src/Composer/Util/RemoteFilesystem.php @@ -283,9 +283,9 @@ class RemoteFilesystem $options['http']['ignore_errors'] = true; } - if ($this->degradedMode && substr($fileUrl, 0, 21) === 'http://packagist.org/') { + if ($this->degradedMode && substr($fileUrl, 0, 26) === 'http://repo.packagist.org/') { // access packagist using the resolved IPv4 instead of the hostname to force IPv4 protocol - $fileUrl = 'http://' . gethostbyname('packagist.org') . substr($fileUrl, 20); + $fileUrl = 'http://' . gethostbyname('repo.packagist.org') . substr($fileUrl, 20); $degradedPackagist = true; } @@ -297,7 +297,7 @@ class RemoteFilesystem unset($origFileUrl, $actualContextOptions); // Check for secure HTTP, but allow insecure Packagist calls to $hashed providers as file integrity is verified with sha256 - if ((substr($fileUrl, 0, 23) !== 'http://packagist.org/p/' || (false === strpos($fileUrl, '$') && false === strpos($fileUrl, '%24'))) && empty($degradedPackagist) && $this->config) { + if ((!preg_match('{^http://(repo\.)?packagist.org/p/}', $fileUrl) || (false === strpos($fileUrl, '$') && false === strpos($fileUrl, '%24'))) && empty($degradedPackagist) && $this->config) { $this->config->prohibitUrlByConfig($fileUrl, $this->io); } diff --git a/tests/Composer/Test/ConfigTest.php b/tests/Composer/Test/ConfigTest.php index 49700c80a..f84d5d35f 100644 --- a/tests/Composer/Test/ConfigTest.php +++ b/tests/Composer/Test/ConfigTest.php @@ -36,7 +36,7 @@ class ConfigTest extends TestCase $data = array(); $data['local config inherits system defaults'] = array( array( - 'packagist.org' => array('type' => 'composer', 'url' => 'https?://packagist.org', 'allow_ssl_downgrade' => true), + 'packagist.org' => array('type' => 'composer', 'url' => 'https?://repo.packagist.org', 'allow_ssl_downgrade' => true), ), array(), ); @@ -59,7 +59,7 @@ class ConfigTest extends TestCase array( 1 => array('type' => 'vcs', 'url' => 'git://github.com/composer/composer.git'), 0 => array('type' => 'pear', 'url' => 'http://pear.composer.org'), - 'packagist.org' => array('type' => 'composer', 'url' => 'https?://packagist.org', 'allow_ssl_downgrade' => true), + 'packagist.org' => array('type' => 'composer', 'url' => 'https?://repo.packagist.org', 'allow_ssl_downgrade' => true), ), array( array('type' => 'vcs', 'url' => 'git://github.com/composer/composer.git'), @@ -70,7 +70,7 @@ class ConfigTest extends TestCase $data['system config adds above core defaults'] = array( array( 'example.com' => array('type' => 'composer', 'url' => 'http://example.com'), - 'packagist.org' => array('type' => 'composer', 'url' => 'https?://packagist.org', 'allow_ssl_downgrade' => true), + 'packagist.org' => array('type' => 'composer', 'url' => 'https?://repo.packagist.org', 'allow_ssl_downgrade' => true), ), array(), array( @@ -107,7 +107,7 @@ class ConfigTest extends TestCase $data['incorrect local config does not cause ErrorException'] = array( array( - 'packagist.org' => array('type' => 'composer', 'url' => 'https?://packagist.org', 'allow_ssl_downgrade' => true), + 'packagist.org' => array('type' => 'composer', 'url' => 'https?://repo.packagist.org', 'allow_ssl_downgrade' => true), 'type' => 'vcs', 'url' => 'http://example.com', ), diff --git a/tests/Composer/Test/Package/Loader/ValidatingArrayLoaderTest.php b/tests/Composer/Test/Package/Loader/ValidatingArrayLoaderTest.php index 8896f81af..cc66ab399 100644 --- a/tests/Composer/Test/Package/Loader/ValidatingArrayLoaderTest.php +++ b/tests/Composer/Test/Package/Loader/ValidatingArrayLoaderTest.php @@ -119,7 +119,7 @@ class ValidatingArrayLoaderTest extends TestCase 'repositories' => array( array( 'type' => 'composer', - 'url' => 'https://packagist.org/', + 'url' => 'https://repo.packagist.org/', ), ), 'config' => array(