Check connectivity to custom composer repos in diagnose command
parent
8ae6fa1205
commit
3e7b3b26df
|
@ -117,6 +117,25 @@ EOT
|
|||
$io->write('Checking https connectivity to packagist: ', false);
|
||||
$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();
|
||||
$protos = $config->get('disable-tls') === true ? ['http'] : ['http', 'https'];
|
||||
try {
|
||||
|
@ -310,6 +329,45 @@ EOT
|
|||
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
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue