From b4c0b188962b364d13f54c4b0e91337938d4e0c7 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 12 Aug 2013 00:52:16 +0200 Subject: [PATCH] Add tests, refs #2017 --- src/Composer/Util/StreamContextFactory.php | 2 +- .../Test/Util/StreamContextFactoryTest.php | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/Composer/Util/StreamContextFactory.php b/src/Composer/Util/StreamContextFactory.php index f9d2deb78..892016674 100644 --- a/src/Composer/Util/StreamContextFactory.php +++ b/src/Composer/Util/StreamContextFactory.php @@ -73,7 +73,7 @@ final class StreamContextFactory } // add request_fulluri and authentication if we still have a proxy to connect to - if (isset($options['http']['proxy'])) { + if (!empty($options['http']['proxy'])) { // enabled request_fulluri unless it is explicitly disabled switch (parse_url($url, PHP_URL_SCHEME)) { case 'http': // default request_fulluri to true diff --git a/tests/Composer/Test/Util/StreamContextFactoryTest.php b/tests/Composer/Test/Util/StreamContextFactoryTest.php index 003cbdad4..a12419afa 100644 --- a/tests/Composer/Test/Util/StreamContextFactoryTest.php +++ b/tests/Composer/Test/Util/StreamContextFactoryTest.php @@ -20,12 +20,14 @@ class StreamContextFactoryTest extends \PHPUnit_Framework_TestCase { unset($_SERVER['HTTP_PROXY']); unset($_SERVER['http_proxy']); + unset($_SERVER['no_proxy']); } protected function tearDown() { unset($_SERVER['HTTP_PROXY']); unset($_SERVER['http_proxy']); + unset($_SERVER['no_proxy']); } /** @@ -73,6 +75,36 @@ class StreamContextFactoryTest extends \PHPUnit_Framework_TestCase )), $options); } + public function testHttpProxyWithNoProxy() + { + $_SERVER['http_proxy'] = 'http://username:password@proxyserver.net:3128/'; + $_SERVER['no_proxy'] = 'foo,example.org'; + + $context = StreamContextFactory::getContext('http://example.org', array('http' => array('method' => 'GET'))); + $options = stream_context_get_options($context); + + $this->assertEquals(array('http' => array( + 'method' => 'GET', + 'max_redirects' => 20, + 'follow_location' => 1, + )), $options); + } + + public function testHttpProxyWithNoProxyWildcard() + { + $_SERVER['http_proxy'] = 'http://username:password@proxyserver.net:3128/'; + $_SERVER['no_proxy'] = '*'; + + $context = StreamContextFactory::getContext('http://example.org', array('http' => array('method' => 'GET'))); + $options = stream_context_get_options($context); + + $this->assertEquals(array('http' => array( + 'method' => 'GET', + 'max_redirects' => 20, + 'follow_location' => 1, + )), $options); + } + public function testOptionsArePreserved() { $_SERVER['http_proxy'] = 'http://username:password@proxyserver.net:3128/';