1
0
Fork 0

Check connectivity to custom composer repos in diagnose command

pull/12119/head
Jordi Boggiano 2024-09-19 10:23:54 +02:00
parent 8ae6fa1205
commit 3e7b3b26df
No known key found for this signature in database
1 changed files with 58 additions and 0 deletions

View File

@ -117,6 +117,25 @@ EOT
$io->write('Checking https connectivity to packagist: ', false); $io->write('Checking https connectivity to packagist: ', false);
$this->outputResult($this->checkHttp('https', $config)); $this->outputResult($this->checkHttp('https', $config));
foreach ($config->getRepositories() as $repo) {
if (($repo['type'] ?? null) === 'composer' && isset($repo['url'])) {
$composerRepo = new ComposerRepository($repo, $this->getIO(), $config, $this->httpDownloader);
$reflMethod = new \ReflectionMethod($composerRepo, 'getPackagesJsonUrl');
if (PHP_VERSION_ID < 80100) {
$reflMethod->setAccessible(true);
}
$url = $reflMethod->invoke($composerRepo);
if (!str_starts_with($url, 'http')) {
continue;
}
if (str_starts_with($url, 'https://repo.packagist.org')) {
continue;
}
$io->write('Checking connectivity to ' . $repo['url'].': ', false);
$this->outputResult($this->checkComposerRepo($url, $config));
}
}
$proxyManager = ProxyManager::getInstance(); $proxyManager = ProxyManager::getInstance();
$protos = $config->get('disable-tls') === true ? ['http'] : ['http', 'https']; $protos = $config->get('disable-tls') === true ? ['http'] : ['http', 'https'];
try { try {
@ -310,6 +329,45 @@ EOT
return true; return true;
} }
/**
* @return string|string[]|true
*/
private function checkComposerRepo(string $url, Config $config)
{
$result = $this->checkConnectivityAndComposerNetworkHttpEnablement();
if ($result !== true) {
return $result;
}
$result = [];
if (str_starts_with($url, 'https://') && $config->get('disable-tls') === true) {
$tlsWarning = '<warning>Composer is configured to disable SSL/TLS protection. This will leave remote HTTPS requests vulnerable to Man-In-The-Middle attacks.</warning>';
}
try {
$this->httpDownloader->get($url);
} catch (TransportException $e) {
$hints = HttpDownloader::getExceptionHints($e);
if (null !== $hints && count($hints) > 0) {
foreach ($hints as $hint) {
$result[] = $hint;
}
}
$result[] = '<error>[' . get_class($e) . '] ' . $e->getMessage() . '</error>';
}
if (isset($tlsWarning)) {
$result[] = $tlsWarning;
}
if (count($result) > 0) {
return $result;
}
return true;
}
/** /**
* @return string|\Exception * @return string|\Exception
*/ */