diff --git a/Curl.php b/Curl.php index d33efed..e777fc8 100644 --- a/Curl.php +++ b/Curl.php @@ -80,6 +80,7 @@ public function __construct(array $options = array(), $followLocationMaxRedirect if (isset($options['connection_timeout'])) { curl_setopt($this->ch, CURLOPT_CONNECTTIMEOUT, $options['connection_timeout']); } + if (isset($options['proxy_host'])) { if (false !== $options['proxy_host']) { $proxyHost = $options['proxy_host'].(isset($options['proxy_port']) ? $options['proxy_port'] : 8080); @@ -88,10 +89,16 @@ public function __construct(array $options = array(), $followLocationMaxRedirect } curl_setopt($this->ch, CURLOPT_PROXY, $proxyHost); + + if (false !== $proxyHost && isset($options['proxy_login'])) { + curl_setopt($this->ch, CURLOPT_PROXYUSERPWD, $options['proxy_login'].':'.$options['proxy_password']); + + if (isset($options['proxy_auth'])) { + curl_setopt($this->ch, CURLOPT_PROXYAUTH, $options['proxy_auth']); + } + } } - if (isset($options['proxy_user'])) { - curl_setopt($this->ch, CURLOPT_PROXYUSERPWD, $options['proxy_user'] . ':' . $options['proxy_password']); - } + if (isset($options['login'])) { curl_setopt($this->ch, CURLOPT_HTTPAUTH, isset($options['extra_options']['http_auth']) ? $options['extra_options']['http_auth'] : CURLAUTH_ANY); curl_setopt($this->ch, CURLOPT_USERPWD, $options['login'].':'.$options['password']); diff --git a/SoapClientBuilder.php b/SoapClientBuilder.php index cce4a9a..59b5bba 100644 --- a/SoapClientBuilder.php +++ b/SoapClientBuilder.php @@ -175,19 +175,28 @@ public function withDigestAuthentication($certificate, $passphrase = null) * * @param string $host Host * @param int $port Port - * @param string $username Username + * @param string $login Login * @param string $password Password + * @param int $auth Authentication method * * @return \BeSimple\SoapClient\SoapClientBuilder */ - public function withProxy($host, $port, $username = null, $password = null) + public function withProxy($host, $port, $login = null, $password = null, $auth = null) { $this->soapOptions['proxy_host'] = $host; $this->soapOptions['proxy_port'] = $port; - if ($username) { - $this->soapOptions['proxy_login'] = $username; + if ($login) { + $this->soapOptions['proxy_login'] = $login; $this->soapOptions['proxy_password'] = $password; + + if ($auth) { + if (!in_array($auth, array(\CURLAUTH_BASIC, \CURLAUTH_NTLM), true)) { + throw new \InvalidArgumentException('Invalid authentication method: CURLAUTH_BASIC or CURLAUTH_NTLM constants are availables.'); + } + + $this->soapOptions['proxy_auth'] = $auth; + } } return $this; @@ -236,4 +245,4 @@ protected function validateOptions() { $this->validateWsdl(); } -} \ No newline at end of file +} diff --git a/Tests/AxisInterop/MtomAxisInteropTest.php b/Tests/AxisInterop/MtomAxisInteropTest.php index 27d9e20..f16f8c4 100644 --- a/Tests/AxisInterop/MtomAxisInteropTest.php +++ b/Tests/AxisInterop/MtomAxisInteropTest.php @@ -28,6 +28,7 @@ class MtomAxisInteropTest extends TestCase 'base64Binary' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\base64Binary', 'AttachmentRequest' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\AttachmentRequest', ), + 'proxy_host' => false, ); public function testAttachment() @@ -48,4 +49,4 @@ public function testAttachment() // $this->assertEquals($b64->_, file_get_contents($fileCreatedByServer)); // unlink($fileCreatedByServer); } -} \ No newline at end of file +} diff --git a/Tests/AxisInterop/SwaAxisInteropTest.php b/Tests/AxisInterop/SwaAxisInteropTest.php index 4b9921f..d964aa3 100644 --- a/Tests/AxisInterop/SwaAxisInteropTest.php +++ b/Tests/AxisInterop/SwaAxisInteropTest.php @@ -37,6 +37,7 @@ class SwaAxisInteropTest extends TestCase 'uploadFile' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\uploadFile', 'uploadFileResponse' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\uploadFileResponse', ), + 'proxy_host' => false, ); public function testUploadDownloadText() @@ -74,4 +75,4 @@ public function testUploadDownloadImage() $this->assertEquals($upload->data, $result->data); } -} \ No newline at end of file +} diff --git a/Tests/AxisInterop/WsAddressingAxisInteropTest.php b/Tests/AxisInterop/WsAddressingAxisInteropTest.php index cf7308a..2310476 100644 --- a/Tests/AxisInterop/WsAddressingAxisInteropTest.php +++ b/Tests/AxisInterop/WsAddressingAxisInteropTest.php @@ -32,6 +32,7 @@ class WsAddressingAxisInteropTest extends TestCase private $options = array( 'soap_version' => SOAP_1_2, 'features' => SOAP_SINGLE_ELEMENT_ARRAYS, // make sure that result is array for size=1 + 'proxy_host' => false, ); public function testSession() @@ -56,4 +57,4 @@ public function testSession() $this->assertEquals($soapSessionId1, $soapSessionId2); } -} \ No newline at end of file +} diff --git a/Tests/AxisInterop/WsSecuritySigEncAxisInteropTest.php b/Tests/AxisInterop/WsSecuritySigEncAxisInteropTest.php index 6e4f0d9..2d7070e 100644 --- a/Tests/AxisInterop/WsSecuritySigEncAxisInteropTest.php +++ b/Tests/AxisInterop/WsSecuritySigEncAxisInteropTest.php @@ -64,6 +64,7 @@ class WsSecuritySigEncAxisInteropTest extends TestCase 'addBookResponse' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\addBookResponse', 'BookInformation' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\BookInformation', ), + 'proxy_host' => false, ); public function testSigEnc() @@ -103,4 +104,4 @@ public function testSigEnc() // getBooksByType("scifi"); } -} \ No newline at end of file +} diff --git a/Tests/AxisInterop/WsSecurityUserPassAxisInteropTest.php b/Tests/AxisInterop/WsSecurityUserPassAxisInteropTest.php index 6ab2824..2ee71d6 100644 --- a/Tests/AxisInterop/WsSecurityUserPassAxisInteropTest.php +++ b/Tests/AxisInterop/WsSecurityUserPassAxisInteropTest.php @@ -40,6 +40,7 @@ class WsSecurityUserPassAxisInteropTest extends TestCase 'addBookResponse' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\addBookResponse', 'BookInformation' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\BookInformation', ), + 'proxy_host' => false, ); public function testUserPassText() @@ -93,4 +94,4 @@ public function testUserPassDigest() // getBooksByType("scifi"); } -} \ No newline at end of file +} diff --git a/Tests/CurlTest.php b/Tests/CurlTest.php index c80b992..28b6311 100644 --- a/Tests/CurlTest.php +++ b/Tests/CurlTest.php @@ -74,7 +74,9 @@ public function testGetResponse() public function testGetResponseBody() { - $curl = new Curl(); + $curl = new Curl(array( + 'proxy_host' => false, + )); $curl->exec(sprintf('http://localhost:%d/curl.txt', WEBSERVER_PORT)); $this->assertEquals('This is a testfile for cURL.', $curl->getResponseBody()); @@ -82,7 +84,9 @@ public function testGetResponseBody() public function testGetResponseContentType() { - $curl = new Curl(); + $curl = new Curl(array( + 'proxy_host' => false, + )); $curl->exec(sprintf('http://localhost:%d/curl.txt', WEBSERVER_PORT)); $this->assertEquals('text/plain; charset=UTF-8', $curl->getResponseContentType()); @@ -93,7 +97,9 @@ public function testGetResponseContentType() public function testGetResponseHeaders() { - $curl = new Curl(); + $curl = new Curl(array( + 'proxy_host' => false, + )); $curl->exec(sprintf('http://localhost:%d/curl.txt', WEBSERVER_PORT)); $this->assertEquals(117 + self::$websererPortLength, strlen($curl->getResponseHeaders())); @@ -104,7 +110,9 @@ public function testGetResponseHeaders() public function testGetResponseStatusCode() { - $curl = new Curl(); + $curl = new Curl(array( + 'proxy_host' => false, + )); $curl->exec(sprintf('http://localhost:%d/curl.txt', WEBSERVER_PORT)); $this->assertEquals(200, $curl->getResponseStatusCode()); diff --git a/Tests/ServerInterop/MtomServerInteropTest.php b/Tests/ServerInterop/MtomServerInteropTest.php index 779313f..07d7b48 100644 --- a/Tests/ServerInterop/MtomServerInteropTest.php +++ b/Tests/ServerInterop/MtomServerInteropTest.php @@ -20,6 +20,7 @@ class MtomServerInteropTest extends TestCase 'base64Binary' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\base64Binary', 'AttachmentRequest' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\AttachmentRequest', ), + 'proxy_host' => false, ); public function testAttachment() @@ -40,4 +41,4 @@ public function testAttachment() $this->assertEquals($b64->_, file_get_contents($fileCreatedByServer)); unlink($fileCreatedByServer); } -} \ No newline at end of file +} diff --git a/Tests/ServerInterop/SwaServerInteropTest.php b/Tests/ServerInterop/SwaServerInteropTest.php index 5f3e6f3..01eaeae 100644 --- a/Tests/ServerInterop/SwaServerInteropTest.php +++ b/Tests/ServerInterop/SwaServerInteropTest.php @@ -23,6 +23,7 @@ class SwaServerInteropTest extends TestCase 'uploadFile' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\uploadFile', 'uploadFileResponse' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\uploadFileResponse', ), + 'proxy_host' => false, ); public function testUploadDownloadText() diff --git a/Tests/ServerInterop/WsSecuritySigEncServerInteropTest.php b/Tests/ServerInterop/WsSecuritySigEncServerInteropTest.php index 0ff0142..8978fd6 100644 --- a/Tests/ServerInterop/WsSecuritySigEncServerInteropTest.php +++ b/Tests/ServerInterop/WsSecuritySigEncServerInteropTest.php @@ -30,6 +30,7 @@ class WsSecuritySigEncServerInteropTest extends TestCase 'addBookResponse' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\addBookResponse', 'BookInformation' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\BookInformation', ), + 'proxy_host' => false, ); public function testSigEnc() @@ -69,4 +70,4 @@ public function testSigEnc() // getBooksByType("scifi"); } -} \ No newline at end of file +} diff --git a/Tests/ServerInterop/WsSecurityUserPassServerInteropTest.php b/Tests/ServerInterop/WsSecurityUserPassServerInteropTest.php index 1df839c..efe86b5 100644 --- a/Tests/ServerInterop/WsSecurityUserPassServerInteropTest.php +++ b/Tests/ServerInterop/WsSecurityUserPassServerInteropTest.php @@ -29,6 +29,7 @@ class WsSecurityUserPassServerInteropTest extends TestCase 'addBookResponse' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\addBookResponse', 'BookInformation' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\BookInformation', ), + 'proxy_host' => false, ); public function testUserPassText() @@ -82,4 +83,4 @@ public function testUserPassDigest() // getBooksByType("scifi"); } -} \ No newline at end of file +} diff --git a/Tests/SoapClientBuilderTest.php b/Tests/SoapClientBuilderTest.php index a0ebfeb..e9aecfb 100644 --- a/Tests/SoapClientBuilderTest.php +++ b/Tests/SoapClientBuilderTest.php @@ -96,6 +96,20 @@ public function testWithProxy() $builder->withProxy('127.0.0.1', 8585, 'foo', 'bar'); $this->assertEquals($this->mergeOptions(array('proxy_host' => '127.0.0.1', 'proxy_port' => 8585, 'proxy_login' => 'foo', 'proxy_password' => 'bar')), $builder->getSoapOptions()); + + $builder->withProxy('127.0.0.1', 8585, 'foo', 'bar', \CURLAUTH_BASIC); + $this->assertEquals($this->mergeOptions(array('proxy_host' => '127.0.0.1', 'proxy_port' => 8585, 'proxy_login' => 'foo', 'proxy_password' => 'bar', 'proxy_auth' => \CURLAUTH_BASIC)), $builder->getSoapOptions()); + + $builder->withProxy('127.0.0.1', 8585, 'foo', 'bar', \CURLAUTH_NTLM); + $this->assertEquals($this->mergeOptions(array('proxy_host' => '127.0.0.1', 'proxy_port' => 8585, 'proxy_login' => 'foo', 'proxy_password' => 'bar', 'proxy_auth' => \CURLAUTH_NTLM)), $builder->getSoapOptions()); + + try { + $builder->withProxy('127.0.0.1', 8585, 'foo', 'bar', -100); + + $this->fail('An expected exception has not been raised.'); + } catch (\Exception $e) { + $this->assertInstanceOf('InvalidArgumentException', $e); + } } public function testCreateWithDefaults() diff --git a/Tests/WsdlDownloaderTest.php b/Tests/WsdlDownloaderTest.php index 9597ca6..a5e4595 100644 --- a/Tests/WsdlDownloaderTest.php +++ b/Tests/WsdlDownloaderTest.php @@ -115,7 +115,9 @@ public function testResolveWsdlIncludes($source, $cacheFile, $remoteParentUrl, $ Cache::setDirectory($wsdlCacheUrl); $cacheDirForRegExp = preg_quote($wsdlCacheUrl, '#'); - $wsdlDownloader = new WsdlDownloader(new Curl()); + $wsdlDownloader = new WsdlDownloader(new Curl(array( + 'proxy_host' => false, + ))); $r = new \ReflectionClass($wsdlDownloader); $m = $r->getMethod('resolveRemoteIncludes'); $m->setAccessible(true); @@ -178,7 +180,9 @@ public function testResolveXsdIncludes($source, $cacheFile, $remoteParentUrl, $r Cache::setDirectory($wsdlCacheUrl); $cacheDirForRegExp = preg_quote($wsdlCacheUrl, '#'); - $wsdlDownloader = new WsdlDownloader(new Curl()); + $wsdlDownloader = new WsdlDownloader(new Curl(array( + 'proxy_host' => false, + ))); $r = new \ReflectionClass($wsdlDownloader); $m = $r->getMethod('resolveRemoteIncludes'); $m->setAccessible(true);