mirror of
https://github.com/composer/composer
synced 2025-05-09 00:22:53 +00:00
Refactor proxy handling to require https_proxy (#11915)
Composer has always allowed a single http_proxy (or CGI_HTTP_PROXY) environment variable to be used for both HTTP and HTTPS requests. But many other tools and libraries require scheme-specific values. The landscape is already complicated by the use of and need for upper and lower case values, so to bring matters inline with current practice https_proxy is now required for HTTPS requests. The new proxy handler incorporates a transition mechanism, which allows http_proxy to be used for all requests when https_proxy is not set and provides a `needsTransitionWarning` method for the main application. Moving to scheme-specific environment variables means that a user may set a single proxy for either HTTP or HTTPS requests. To accomodate this situation during the transition period, an https_proxy value can be set to an empty string which will prevent http_proxy being used for HTTPS requests.
This commit is contained in:
parent
92f641ac3d
commit
3cc490d4c4
13 changed files with 717 additions and 734 deletions
72
tests/Composer/Test/Util/Http/ProxyItemTest.php
Normal file
72
tests/Composer/Test/Util/Http/ProxyItemTest.php
Normal file
|
@ -0,0 +1,72 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of Composer.
|
||||
*
|
||||
* (c) Nils Adermann <naderman@naderman.de>
|
||||
* Jordi Boggiano <j.boggiano@seld.be>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Composer\Test\Util\Http;
|
||||
|
||||
use Composer\Util\Http\ProxyItem;
|
||||
use Composer\Test\TestCase;
|
||||
|
||||
class ProxyItemTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider dataMalformed
|
||||
*/
|
||||
public function testThrowsOnMalformedUrl(string $url): void
|
||||
{
|
||||
self::expectException('RuntimeException');
|
||||
$proxyItem = new ProxyItem($url, 'http_proxy');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<string>>
|
||||
*/
|
||||
public static function dataMalformed(): array
|
||||
{
|
||||
return [
|
||||
'ws-r' => ["http://user\rname@localhost:80"],
|
||||
'ws-n' => ["http://user\nname@localhost:80"],
|
||||
'ws-t' => ["http://user\tname@localhost:80"],
|
||||
'no-host' => ['localhost'],
|
||||
'no-port' => ['scheme://localhost'],
|
||||
'port-0' => ['http://localhost:0'],
|
||||
'port-big' => ['http://localhost:65536'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataFormatting
|
||||
*/
|
||||
public function testUrlFormatting(string $url, string $expected): void
|
||||
{
|
||||
$proxyItem = new ProxyItem($url, 'http_proxy');
|
||||
$proxy = $proxyItem->toRequestProxy('http');
|
||||
|
||||
self::assertSame($expected, $proxy->getStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<string>>
|
||||
*/
|
||||
public static function dataFormatting(): array
|
||||
{
|
||||
// url, expected
|
||||
return [
|
||||
'none' => ['http://proxy.com:8888', 'http://proxy.com:8888'],
|
||||
'lowercases-scheme' => ['HTTP://proxy.com:8888', 'http://proxy.com:8888'],
|
||||
'adds-http-scheme' => ['proxy.com:80', 'http://proxy.com:80'],
|
||||
'adds-http-port' => ['http://proxy.com', 'http://proxy.com:80'],
|
||||
'adds-https-port' => ['https://proxy.com', 'https://proxy.com:443'],
|
||||
'removes-user' => ['http://user@proxy.com:6180', 'http://***@proxy.com:6180'],
|
||||
'removes-user-pass' => ['http://user:p%40ss@proxy.com:6180', 'http://***:***@proxy.com:6180'],
|
||||
];
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue