1
0
Fork 0
mirror of https://github.com/composer/composer synced 2025-05-09 00:22:53 +00:00

Add default http(s) ports to proxy configuration if they are missing.

This commit is contained in:
Danny Berger 2012-04-26 21:38:12 -04:00
parent 762f469cd9
commit e7ba0c38a8
2 changed files with 36 additions and 7 deletions

View file

@ -57,7 +57,7 @@ class StreamContextFactoryTest extends \PHPUnit_Framework_TestCase
public function testHttpProxy()
{
$_SERVER['http_proxy'] = 'http://username:password@proxyserver.net:port/';
$_SERVER['http_proxy'] = 'http://username:password@proxyserver.net:3128/';
$_SERVER['HTTP_PROXY'] = 'http://proxyserver/';
$context = StreamContextFactory::getContext(array('http' => array('method' => 'GET')));
@ -66,22 +66,39 @@ class StreamContextFactoryTest extends \PHPUnit_Framework_TestCase
$this->assertSame('http://proxyserver/', $_SERVER['HTTP_PROXY']);
$this->assertEquals(array('http' => array(
'proxy' => 'tcp://username:password@proxyserver.net:port/',
'proxy' => 'tcp://username:password@proxyserver.net:3128',
'request_fulluri' => true,
'method' => 'GET',
)), $options);
}
public function testSSLProxy()
public function testHttpProxyWithoutPort()
{
$_SERVER['http_proxy'] = 'https://proxyserver/';
$_SERVER['http_proxy'] = 'http://username:password@proxyserver.net';
$context = StreamContextFactory::getContext(array('http' => array('method' => 'GET')));
$options = stream_context_get_options($context);
$this->assertEquals(array('http' => array(
'proxy' => 'tcp://username:password@proxyserver.net:80',
'request_fulluri' => true,
'method' => 'GET',
)), $options);
}
/**
* @dataProvider dataSSLProxy
*/
public function testSSLProxy($expected, $proxy)
{
$_SERVER['http_proxy'] = $proxy;
if (extension_loaded('openssl')) {
$context = StreamContextFactory::getContext();
$options = stream_context_get_options($context);
$this->assertSame(array('http' => array(
'proxy' => 'ssl://proxyserver/',
$this->assertEquals(array('http' => array(
'proxy' => $expected,
'request_fulluri' => true,
)), $options);
} else {
@ -93,4 +110,12 @@ class StreamContextFactoryTest extends \PHPUnit_Framework_TestCase
}
}
}
public function dataSSLProxy()
{
return array(
array('ssl://proxyserver:443', 'https://proxyserver/'),
array('ssl://proxyserver:8443', 'https://proxyserver:8443'),
);
}
}