From 33d641de4e78a39fb080752c788f9e00de403d83 Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Mon, 18 Aug 2014 10:29:49 +0200 Subject: [PATCH 1/5] [SoapClient] Fixed tests if proxy exists in environment variables --- .../Tests/AxisInterop/MtomAxisInteropTest.php | 3 ++- .../Tests/AxisInterop/SwaAxisInteropTest.php | 3 ++- .../AxisInterop/WsAddressingAxisInteropTest.php | 3 ++- .../WsSecuritySigEncAxisInteropTest.php | 3 ++- .../WsSecurityUserPassAxisInteropTest.php | 3 ++- src/BeSimple/SoapClient/Tests/CurlTest.php | 16 ++++++++++++---- .../ServerInterop/MtomServerInteropTest.php | 3 ++- .../Tests/ServerInterop/SwaServerInteropTest.php | 1 + .../WsSecuritySigEncServerInteropTest.php | 3 ++- .../WsSecurityUserPassServerInteropTest.php | 3 ++- .../SoapClient/Tests/WsdlDownloaderTest.php | 8 ++++++-- 11 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/BeSimple/SoapClient/Tests/AxisInterop/MtomAxisInteropTest.php b/src/BeSimple/SoapClient/Tests/AxisInterop/MtomAxisInteropTest.php index 27d9e20..f16f8c4 100644 --- a/src/BeSimple/SoapClient/Tests/AxisInterop/MtomAxisInteropTest.php +++ b/src/BeSimple/SoapClient/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 @@ class MtomAxisInteropTest extends TestCase // $this->assertEquals($b64->_, file_get_contents($fileCreatedByServer)); // unlink($fileCreatedByServer); } -} \ No newline at end of file +} diff --git a/src/BeSimple/SoapClient/Tests/AxisInterop/SwaAxisInteropTest.php b/src/BeSimple/SoapClient/Tests/AxisInterop/SwaAxisInteropTest.php index 4b9921f..d964aa3 100644 --- a/src/BeSimple/SoapClient/Tests/AxisInterop/SwaAxisInteropTest.php +++ b/src/BeSimple/SoapClient/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 @@ class SwaAxisInteropTest extends TestCase $this->assertEquals($upload->data, $result->data); } -} \ No newline at end of file +} diff --git a/src/BeSimple/SoapClient/Tests/AxisInterop/WsAddressingAxisInteropTest.php b/src/BeSimple/SoapClient/Tests/AxisInterop/WsAddressingAxisInteropTest.php index cf7308a..2310476 100644 --- a/src/BeSimple/SoapClient/Tests/AxisInterop/WsAddressingAxisInteropTest.php +++ b/src/BeSimple/SoapClient/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 @@ class WsAddressingAxisInteropTest extends TestCase $this->assertEquals($soapSessionId1, $soapSessionId2); } -} \ No newline at end of file +} diff --git a/src/BeSimple/SoapClient/Tests/AxisInterop/WsSecuritySigEncAxisInteropTest.php b/src/BeSimple/SoapClient/Tests/AxisInterop/WsSecuritySigEncAxisInteropTest.php index 6e4f0d9..2d7070e 100644 --- a/src/BeSimple/SoapClient/Tests/AxisInterop/WsSecuritySigEncAxisInteropTest.php +++ b/src/BeSimple/SoapClient/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 @@ class WsSecuritySigEncAxisInteropTest extends TestCase // getBooksByType("scifi"); } -} \ No newline at end of file +} diff --git a/src/BeSimple/SoapClient/Tests/AxisInterop/WsSecurityUserPassAxisInteropTest.php b/src/BeSimple/SoapClient/Tests/AxisInterop/WsSecurityUserPassAxisInteropTest.php index 6ab2824..2ee71d6 100644 --- a/src/BeSimple/SoapClient/Tests/AxisInterop/WsSecurityUserPassAxisInteropTest.php +++ b/src/BeSimple/SoapClient/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 @@ class WsSecurityUserPassAxisInteropTest extends TestCase // getBooksByType("scifi"); } -} \ No newline at end of file +} diff --git a/src/BeSimple/SoapClient/Tests/CurlTest.php b/src/BeSimple/SoapClient/Tests/CurlTest.php index c80b992..28b6311 100644 --- a/src/BeSimple/SoapClient/Tests/CurlTest.php +++ b/src/BeSimple/SoapClient/Tests/CurlTest.php @@ -74,7 +74,9 @@ class CurlTest extends AbstractWebserverTest 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 @@ class CurlTest extends AbstractWebserverTest 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 @@ class CurlTest extends AbstractWebserverTest 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 @@ class CurlTest extends AbstractWebserverTest 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/src/BeSimple/SoapClient/Tests/ServerInterop/MtomServerInteropTest.php b/src/BeSimple/SoapClient/Tests/ServerInterop/MtomServerInteropTest.php index 779313f..07d7b48 100644 --- a/src/BeSimple/SoapClient/Tests/ServerInterop/MtomServerInteropTest.php +++ b/src/BeSimple/SoapClient/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 @@ class MtomServerInteropTest extends TestCase $this->assertEquals($b64->_, file_get_contents($fileCreatedByServer)); unlink($fileCreatedByServer); } -} \ No newline at end of file +} diff --git a/src/BeSimple/SoapClient/Tests/ServerInterop/SwaServerInteropTest.php b/src/BeSimple/SoapClient/Tests/ServerInterop/SwaServerInteropTest.php index 5f3e6f3..01eaeae 100644 --- a/src/BeSimple/SoapClient/Tests/ServerInterop/SwaServerInteropTest.php +++ b/src/BeSimple/SoapClient/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/src/BeSimple/SoapClient/Tests/ServerInterop/WsSecuritySigEncServerInteropTest.php b/src/BeSimple/SoapClient/Tests/ServerInterop/WsSecuritySigEncServerInteropTest.php index 0ff0142..8978fd6 100644 --- a/src/BeSimple/SoapClient/Tests/ServerInterop/WsSecuritySigEncServerInteropTest.php +++ b/src/BeSimple/SoapClient/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 @@ class WsSecuritySigEncServerInteropTest extends TestCase // getBooksByType("scifi"); } -} \ No newline at end of file +} diff --git a/src/BeSimple/SoapClient/Tests/ServerInterop/WsSecurityUserPassServerInteropTest.php b/src/BeSimple/SoapClient/Tests/ServerInterop/WsSecurityUserPassServerInteropTest.php index 1df839c..efe86b5 100644 --- a/src/BeSimple/SoapClient/Tests/ServerInterop/WsSecurityUserPassServerInteropTest.php +++ b/src/BeSimple/SoapClient/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 @@ class WsSecurityUserPassServerInteropTest extends TestCase // getBooksByType("scifi"); } -} \ No newline at end of file +} diff --git a/src/BeSimple/SoapClient/Tests/WsdlDownloaderTest.php b/src/BeSimple/SoapClient/Tests/WsdlDownloaderTest.php index 2027b2d..38905b5 100644 --- a/src/BeSimple/SoapClient/Tests/WsdlDownloaderTest.php +++ b/src/BeSimple/SoapClient/Tests/WsdlDownloaderTest.php @@ -115,7 +115,9 @@ class WsdlDownloaderTest extends AbstractWebserverTest 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 @@ class WsdlDownloaderTest extends AbstractWebserverTest 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); From 960c9f557a9086cda468a4531f6785f8f91155b6 Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Mon, 18 Aug 2014 10:31:20 +0200 Subject: [PATCH 2/5] [SoapClient] Fixed typo for proxy options Fixed #46 --- src/BeSimple/SoapClient/Curl.php | 9 ++++++--- src/BeSimple/SoapClient/SoapClientBuilder.php | 10 +++++----- .../SoapClient/Tests/SoapClientBuilderTest.php | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/BeSimple/SoapClient/Curl.php b/src/BeSimple/SoapClient/Curl.php index d33efed..8bc814b 100644 --- a/src/BeSimple/SoapClient/Curl.php +++ b/src/BeSimple/SoapClient/Curl.php @@ -80,6 +80,7 @@ class Curl 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,12 @@ class Curl } curl_setopt($this->ch, CURLOPT_PROXY, $proxyHost); + + if ($proxyHost && isset($options['proxy_user'])) { + curl_setopt($this->ch, CURLOPT_PROXYUSERPWD, $options['proxy_user'].':'.$options['proxy_pass']); + } } - 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/src/BeSimple/SoapClient/SoapClientBuilder.php b/src/BeSimple/SoapClient/SoapClientBuilder.php index cce4a9a..a01463f 100644 --- a/src/BeSimple/SoapClient/SoapClientBuilder.php +++ b/src/BeSimple/SoapClient/SoapClientBuilder.php @@ -180,14 +180,14 @@ class SoapClientBuilder extends AbstractSoapBuilder * * @return \BeSimple\SoapClient\SoapClientBuilder */ - public function withProxy($host, $port, $username = null, $password = null) + public function withProxy($host, $port, $user = null, $pass = null) { $this->soapOptions['proxy_host'] = $host; $this->soapOptions['proxy_port'] = $port; - if ($username) { - $this->soapOptions['proxy_login'] = $username; - $this->soapOptions['proxy_password'] = $password; + if ($user) { + $this->soapOptions['proxy_user'] = $user; + $this->soapOptions['proxy_pass'] = $pass; } return $this; @@ -236,4 +236,4 @@ class SoapClientBuilder extends AbstractSoapBuilder { $this->validateWsdl(); } -} \ No newline at end of file +} diff --git a/src/BeSimple/SoapClient/Tests/SoapClientBuilderTest.php b/src/BeSimple/SoapClient/Tests/SoapClientBuilderTest.php index a0ebfeb..271f390 100644 --- a/src/BeSimple/SoapClient/Tests/SoapClientBuilderTest.php +++ b/src/BeSimple/SoapClient/Tests/SoapClientBuilderTest.php @@ -95,7 +95,7 @@ class SoapClientBuilderTest extends \PHPUnit_Framework_TestCase $this->assertEquals($this->mergeOptions(array('proxy_host' => 'localhost', 'proxy_port' => 8080)), $builder->getSoapOptions()); $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()); + $this->assertEquals($this->mergeOptions(array('proxy_host' => '127.0.0.1', 'proxy_port' => 8585, 'proxy_user' => 'foo', 'proxy_pass' => 'bar')), $builder->getSoapOptions()); } public function testCreateWithDefaults() From 70db0c42fd38d3c5ccb698119d65c32f821968fa Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Mon, 18 Aug 2014 10:58:40 +0200 Subject: [PATCH 3/5] [SoapClient] Renamed proxy_user to proxy_login option to keep compatibility with SoapClient of PHP --- src/BeSimple/SoapClient/Curl.php | 4 ++-- src/BeSimple/SoapClient/SoapClientBuilder.php | 10 +++++----- .../SoapClient/Tests/SoapClientBuilderTest.php | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/BeSimple/SoapClient/Curl.php b/src/BeSimple/SoapClient/Curl.php index 8bc814b..272f717 100644 --- a/src/BeSimple/SoapClient/Curl.php +++ b/src/BeSimple/SoapClient/Curl.php @@ -90,8 +90,8 @@ class Curl curl_setopt($this->ch, CURLOPT_PROXY, $proxyHost); - if ($proxyHost && isset($options['proxy_user'])) { - curl_setopt($this->ch, CURLOPT_PROXYUSERPWD, $options['proxy_user'].':'.$options['proxy_pass']); + if (false !== $proxyHost && isset($options['proxy_login'])) { + curl_setopt($this->ch, CURLOPT_PROXYUSERPWD, $options['proxy_login'].':'.$options['proxy_password']); } } diff --git a/src/BeSimple/SoapClient/SoapClientBuilder.php b/src/BeSimple/SoapClient/SoapClientBuilder.php index a01463f..910d718 100644 --- a/src/BeSimple/SoapClient/SoapClientBuilder.php +++ b/src/BeSimple/SoapClient/SoapClientBuilder.php @@ -175,19 +175,19 @@ class SoapClientBuilder extends AbstractSoapBuilder * * @param string $host Host * @param int $port Port - * @param string $username Username + * @param string $login Login * @param string $password Password * * @return \BeSimple\SoapClient\SoapClientBuilder */ - public function withProxy($host, $port, $user = null, $pass = null) + public function withProxy($host, $port, $login = null, $password = null) { $this->soapOptions['proxy_host'] = $host; $this->soapOptions['proxy_port'] = $port; - if ($user) { - $this->soapOptions['proxy_user'] = $user; - $this->soapOptions['proxy_pass'] = $pass; + if ($login) { + $this->soapOptions['proxy_login'] = $login; + $this->soapOptions['proxy_password'] = $password; } return $this; diff --git a/src/BeSimple/SoapClient/Tests/SoapClientBuilderTest.php b/src/BeSimple/SoapClient/Tests/SoapClientBuilderTest.php index 271f390..a0ebfeb 100644 --- a/src/BeSimple/SoapClient/Tests/SoapClientBuilderTest.php +++ b/src/BeSimple/SoapClient/Tests/SoapClientBuilderTest.php @@ -95,7 +95,7 @@ class SoapClientBuilderTest extends \PHPUnit_Framework_TestCase $this->assertEquals($this->mergeOptions(array('proxy_host' => 'localhost', 'proxy_port' => 8080)), $builder->getSoapOptions()); $builder->withProxy('127.0.0.1', 8585, 'foo', 'bar'); - $this->assertEquals($this->mergeOptions(array('proxy_host' => '127.0.0.1', 'proxy_port' => 8585, 'proxy_user' => 'foo', 'proxy_pass' => 'bar')), $builder->getSoapOptions()); + $this->assertEquals($this->mergeOptions(array('proxy_host' => '127.0.0.1', 'proxy_port' => 8585, 'proxy_login' => 'foo', 'proxy_password' => 'bar')), $builder->getSoapOptions()); } public function testCreateWithDefaults() From 1a7f60b679afbea96d57a45e9eb7389422ee8247 Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Mon, 18 Aug 2014 11:45:53 +0200 Subject: [PATCH 4/5] [SoapClient] Added proxy authentication option in SoapClientBuilder Fixed #47 --- src/BeSimple/SoapClient/Curl.php | 4 ++++ src/BeSimple/SoapClient/SoapClientBuilder.php | 11 ++++++++++- .../SoapClient/Tests/SoapClientBuilderTest.php | 14 ++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/BeSimple/SoapClient/Curl.php b/src/BeSimple/SoapClient/Curl.php index 272f717..e777fc8 100644 --- a/src/BeSimple/SoapClient/Curl.php +++ b/src/BeSimple/SoapClient/Curl.php @@ -92,6 +92,10 @@ class Curl 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']); + } } } diff --git a/src/BeSimple/SoapClient/SoapClientBuilder.php b/src/BeSimple/SoapClient/SoapClientBuilder.php index 910d718..59b5bba 100644 --- a/src/BeSimple/SoapClient/SoapClientBuilder.php +++ b/src/BeSimple/SoapClient/SoapClientBuilder.php @@ -177,10 +177,11 @@ class SoapClientBuilder extends AbstractSoapBuilder * @param int $port Port * @param string $login Login * @param string $password Password + * @param int $auth Authentication method * * @return \BeSimple\SoapClient\SoapClientBuilder */ - public function withProxy($host, $port, $login = null, $password = null) + public function withProxy($host, $port, $login = null, $password = null, $auth = null) { $this->soapOptions['proxy_host'] = $host; $this->soapOptions['proxy_port'] = $port; @@ -188,6 +189,14 @@ class SoapClientBuilder extends AbstractSoapBuilder 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; diff --git a/src/BeSimple/SoapClient/Tests/SoapClientBuilderTest.php b/src/BeSimple/SoapClient/Tests/SoapClientBuilderTest.php index a0ebfeb..e9aecfb 100644 --- a/src/BeSimple/SoapClient/Tests/SoapClientBuilderTest.php +++ b/src/BeSimple/SoapClient/Tests/SoapClientBuilderTest.php @@ -96,6 +96,20 @@ class SoapClientBuilderTest extends \PHPUnit_Framework_TestCase $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() From 7a9119cef107345824785bf5fadcf8342f436917 Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Mon, 18 Aug 2014 13:54:19 +0200 Subject: [PATCH 5/5] [SoapBundle] Added configuration to configure client proxy --- .../BeSimpleSoapExtension.php | 17 +++++++++++++ .../DependencyInjection/Configuration.php | 24 ++++++++++++++++++- .../doc/soapclient/configuration.rst | 18 +++++++++++--- 3 files changed, 55 insertions(+), 4 deletions(-) diff --git a/src/BeSimple/SoapBundle/DependencyInjection/BeSimpleSoapExtension.php b/src/BeSimple/SoapBundle/DependencyInjection/BeSimpleSoapExtension.php index 5de74a3..a0b8c51 100644 --- a/src/BeSimple/SoapBundle/DependencyInjection/BeSimpleSoapExtension.php +++ b/src/BeSimple/SoapBundle/DependencyInjection/BeSimpleSoapExtension.php @@ -98,6 +98,23 @@ class BeSimpleSoapExtension extends Extension } } + $proxy = $options['proxy']; + if (false !== $proxy['host']) { + if (null !== $proxy['auth']) { + if ('basic' === $proxy['auth']) { + $proxy['auth'] = \CURLAUTH_BASIC; + } elseif ('ntlm' === $proxy['auth']) { + $proxy['auth'] = \CURLAUTH_NTLM; + } + } + + $definition->addMethodCall('withProxy', array( + $proxy['host'], $proxy['port'], + $proxy['login'], $proxy['password'], + $proxy['auth'] + )); + } + if (isset($defOptions['cache_type'])) { $defOptions['cache_type'] = $this->getCacheType($defOptions['cache_type']); } diff --git a/src/BeSimple/SoapBundle/DependencyInjection/Configuration.php b/src/BeSimple/SoapBundle/DependencyInjection/Configuration.php index 1cba9ff..9374bff 100644 --- a/src/BeSimple/SoapBundle/DependencyInjection/Configuration.php +++ b/src/BeSimple/SoapBundle/DependencyInjection/Configuration.php @@ -24,6 +24,7 @@ use Symfony\Component\Config\Definition\Builder\TreeBuilder; class Configuration { private $cacheTypes = array('none', 'disk', 'memory', 'disk_memory'); + private $proxyAuth = array('basic', 'ntlm'); /** * Generates the configuration tree. @@ -85,12 +86,33 @@ class Configuration ->scalarNode('cache_type') ->validate() ->ifNotInArray($this->cacheTypes) - ->thenInvalid(sprintf('The cache type has to be either %s', implode(', ', $this->cacheTypes))) + ->thenInvalid(sprintf('The cache type has to be either: %s', implode(', ', $this->cacheTypes))) ->end() ->end() ->arrayNode('classmap') ->useAttributeAsKey('name')->prototype('scalar')->end() ->end() + ->arrayNode('proxy') + ->info('proxy configuration') + ->addDefaultsIfNotSet() + ->beforeNormalization() + ->ifTrue(function ($v) { return !is_array($v); }) + ->then(function ($v) { return array('host' => null === $v ? false : $v); }) + ->end() + ->children() + ->scalarNode('host')->defaultFalse()->end() + ->scalarNode('port')->defaultValue(3128)->end() + ->scalarNode('login')->defaultNull()->end() + ->scalarNode('password')->defaultNull()->end() + ->scalarNode('auth') + ->defaultNull() + ->validate() + ->ifNotInArray($this->proxyAuth) + ->thenInvalid(sprintf('The proxy auth has to be either: %s', implode(', ', $this->proxyAuth))) + ->end() + ->end() + ->end() + ->end() ->end() ->end() ->end() diff --git a/src/BeSimple/SoapBundle/Resources/doc/soapclient/configuration.rst b/src/BeSimple/SoapBundle/Resources/doc/soapclient/configuration.rst index bd715a4..59088cc 100644 --- a/src/BeSimple/SoapBundle/Resources/doc/soapclient/configuration.rst +++ b/src/BeSimple/SoapBundle/Resources/doc/soapclient/configuration.rst @@ -1,8 +1,8 @@ Configuration ============= -Minimal client configuration ----------------------------- +Client configuration +-------------------- Configure your first client in your config file: @@ -12,8 +12,20 @@ Configure your first client in your config file: be_simple_soap: clients: DemoApi: - wsdl: http://localhost:8086/app_dev.php/ws/DemoApi?wsdl + # required + wsdl: http://localhost/app_dev.php/ws/DemoApi?wsdl + # classmap (optional) + classmap: + type_name: "Full\Class\Name" + + # proxy (optional) + proxy: + host: proxy.domain.name # required to enable proxy configuration + port: 3128 + login: ~ + password: ~ + auth: ~ # can be 'basic' or 'ntlm' Using client ------------