1
0
Fork 0

Improve proxy reporting in Diagnose command (#11932)

pull/11943/head
John Stevenson 2024-04-19 13:18:55 +01:00 committed by GitHub
parent 3cc490d4c4
commit 41fb6146b0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 29 additions and 11 deletions

View File

@ -44,6 +44,8 @@ use Composer\XdebugHandler\XdebugHandler;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\ExecutableFinder; use Symfony\Component\Process\ExecutableFinder;
use Composer\Util\Http\ProxyManager;
use Composer\Util\Http\RequestProxy;
/** /**
* @author Jordi Boggiano <j.boggiano@seld.be> * @author Jordi Boggiano <j.boggiano@seld.be>
@ -115,10 +117,21 @@ 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));
$opts = stream_context_get_options(StreamContextFactory::getContext('http://example.org')); $proxyManager = ProxyManager::getInstance();
if (!empty($opts['http']['proxy'])) { $protos = $config->get('disable-tls') === true ? ['http'] : ['http', 'https'];
try {
foreach ($protos as $proto) {
$proxy = $proxyManager->getProxyForRequest($proto.'://repo.packagist.org');
if ($proxy->getStatus() !== '') {
$type = $proxy->isSecure() ? 'HTTPS' : 'HTTP';
$io->write('Checking '.$type.' proxy with '.$proto.': ', false);
$this->outputResult($this->checkHttpProxy($proxy, $proto));
}
}
} catch (TransportException $e) {
$io->write('Checking HTTP proxy: ', false); $io->write('Checking HTTP proxy: ', false);
$this->outputResult($this->checkHttpProxy()); $status = $this->checkConnectivityAndComposerNetworkHttpEnablement();
$this->outputResult(is_string($status) ? $status : $e);
} }
if (count($oauth = $config->get('github-oauth')) > 0) { if (count($oauth = $config->get('github-oauth')) > 0) {
@ -298,17 +311,22 @@ EOT
} }
/** /**
* @return string|true|\Exception * @return string|\Exception
*/ */
private function checkHttpProxy() private function checkHttpProxy(RequestProxy $proxy, string $protocol)
{ {
$result = $this->checkConnectivityAndComposerNetworkHttpEnablement(); $result = $this->checkConnectivityAndComposerNetworkHttpEnablement();
if ($result !== true) { if ($result !== true) {
return $result; return $result;
} }
$protocol = extension_loaded('openssl') ? 'https' : 'http';
try { try {
$proxyStatus = $proxy->getStatus();
if ($proxy->isExcludedByNoProxy()) {
return '<info>SKIP</> <comment>Because repo.packagist.org is '.$proxyStatus.'</>';
}
$json = $this->httpDownloader->get($protocol.'://repo.packagist.org/packages.json')->decodeJson(); $json = $this->httpDownloader->get($protocol.'://repo.packagist.org/packages.json')->decodeJson();
$hash = reset($json['provider-includes']); $hash = reset($json['provider-includes']);
$hash = $hash['sha256']; $hash = $hash['sha256'];
@ -316,13 +334,13 @@ EOT
$provider = $this->httpDownloader->get($protocol.'://repo.packagist.org/'.$path)->getBody(); $provider = $this->httpDownloader->get($protocol.'://repo.packagist.org/'.$path)->getBody();
if (hash('sha256', $provider) !== $hash) { if (hash('sha256', $provider) !== $hash) {
return 'It seems that your proxy is modifying http traffic on the fly'; return '<warning>It seems that your proxy ('.$proxyStatus.') is modifying '.$protocol.' traffic on the fly</>';
} }
return '<info>OK</> <comment>'.$proxyStatus.'</>';
} catch (\Exception $e) { } catch (\Exception $e) {
return $e; return $e;
} }
return true;
} }
/** /**