Added NTLM authentication support to Zend\Soap\Client\DotNet. #3202

Closed
wants to merge 3 commits into
from

Conversation

Projects
None yet
3 participants
Contributor

jessiehernandez commented Dec 11, 2012

This commit adds NTLM authentication support to the DotNet SOAP client, which I needed for a project I'm working on at my job. I'm a newbie to git (I use SVN for the most part), so if I did anything wrong just let me know. I ran the tests successfully locally, though I had to change a $this->once() call in the test to $this->any(), as I was getting a Bus error from PHPUnit (it does not happen on the test suite I have at work).

Comments/suggestions welcome.

@Maks3w Maks3w and 1 other commented on an outdated diff Dec 11, 2012

tests/ZendTest/Soap/Client/DotNetTest.php
@@ -0,0 +1,262 @@
+<?php
+/**
+ * Zend Framework (http://framework.zend.com/)
+ *
+ * @link http://github.com/zendframework/zf2 for the canonical source repository
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @package Zend_Soap
+ */
+
+// @codingStandardsIgnoreStart
+
+namespace Zend\Soap
@Maks3w

Maks3w Dec 11, 2012

Member

Instead of use braces end the statement with a ;

@Maks3w

Maks3w Dec 11, 2012

Member

Use different files for different namespaces

@jessiehernandez

jessiehernandez Dec 11, 2012

Contributor

Not possible, as this trick is needed to "mock" out the call_user_func call
in Zend\Soap\Client. Inside Zend\Soap\Client::_doRequest, a call is made
as call_user_func(array($client,'SoapClient::__doRequest')...). There is
absolutely no way I can mock this out from PHPUnit. I am forced to resort
to defining call_user_func inside the namespace in order to intercept the
call and make sure the base method is called when NTLM authentication is
not used.

Jessie

On Tue, Dec 11, 2012 at 3:10 PM, Maks notifications@github.com wrote:

In tests/ZendTest/Soap/Client/DotNetTest.php:

@@ -0,0 +1,262 @@
+<?php
+/**

Use different files for different namespaces


Reply to this email directly or view it on GitHubhttps://github.com/zendframework/zf2/pull/3202/files#r2383929.

@Maks3w Maks3w commented on an outdated diff Dec 11, 2012

tests/ZendTest/Soap/Client/DotNetTest.php
@@ -0,0 +1,262 @@
+<?php
+/**
+ * Zend Framework (http://framework.zend.com/)
+ *
+ * @link http://github.com/zendframework/zf2 for the canonical source repository
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @package Zend_Soap
+ */
+
+// @codingStandardsIgnoreStart
@Maks3w

Maks3w Dec 11, 2012

Member

Please remove this kind of comments

@weierophinney weierophinney and 1 other commented on an outdated diff Dec 11, 2012

library/Zend/Soap/Client/DotNet.php
+ $curlClient->write('POST', $uri, 1.1, $headers, $request);
+ $response = HttpResponse::fromString($curlClient->read());
+ $curlClient->close();
+
+ // Save headers
+ $this->lastRequestHeaders = $this->flattenHeaders($headers);
+ $this->lastResponseHeaders = $response->getHeaders()->toString();
+
+ // Return only the XML body
+ return $response->getBody();
+ }
+
+ /**
+ * Returns the cURL client that is being used.
+ *
+ * @return \Zend\Http\Client\Adapter\Curl The cURL client.
@weierophinney

weierophinney Dec 11, 2012

Owner

annotation value can be simply "CurlClient"; they're resolved based on imports and/or current namespace.

@jessiehernandez

jessiehernandez Dec 11, 2012

Contributor

Perfect, wasn't sure on the coding standard requirement in this area.
Thanks, Matthew!

Jessie Hernandez

On Tue, Dec 11, 2012 at 3:28 PM, weierophinney notifications@github.comwrote:

In library/Zend/Soap/Client/DotNet.php:

  •    $curlClient->write('POST', $uri, 1.1, $headers, $request);
    
  •    $response = HttpResponse::fromString($curlClient->read());
    
  •    $curlClient->close();
    
  •    // Save headers
    
  •    $this->lastRequestHeaders  = $this->flattenHeaders($headers);
    
  •    $this->lastResponseHeaders = $response->getHeaders()->toString();
    
  •    // Return only the XML body
    
  •    return $response->getBody();
    
  • }
  • /**
  • \* Returns the cURL client that is being used.
    
  • *
    
  • \* @return \Zend\Http\Client\Adapter\Curl The cURL client.
    

annotation value can be simply "CurlClient"; they're resolved based on
imports and/or current namespace.


Reply to this email directly or view it on GitHubhttps://github.com/zendframework/zf2/pull/3202/files#r2384187.

NOTE: This trick is needed to "mock" out the call_user_func call in Zend\Soap\Client. Inside Zend\Soap\Client::_doRequest, a call is made as call_user_func(array($client,'SoapClient::__doRequest')...). There is absolutely no way I can mock this out from PHPUnit. I am forced to resort to defining call_user_func inside the namespace in order to intercept the call and make sure the base method is called when NTLM authentication is not used.

Of course, I would much rather prefer for the Client class to be refactored in this case so I can simply just use a mock object.

@weierophinney weierophinney added a commit that referenced this pull request Dec 11, 2012

@weierophinney weierophinney [#3202] CS
- Moved call_user_func override into separate file
- Moved MockCallUserFunc class into separate class file
- Passes php-cs-fixer, and tests run
3434dae
Member

Maks3w commented Dec 13, 2012

Seems this has broken Travis Tests

PHP 5.4.8 (cli) (built: Nov 22 2012 13:07:18)

ZendTest/Soap:
PHPUnit 3.7.10 by Sebastian Bergmann.

Configuration read from /home/travis/builds/zendframework/zf2/tests/phpunit.xml.dist

Segmentation fault
SS.....................

Contributor

jessiehernandez commented Dec 13, 2012

Works fine under PHPUnit 3.7.10 using Zend Server CE's current PHP version (5.3.14). I'm going to compile 5.4.8 and see if that is the culprit.

$ ~/projects/phpunit/usr/local/zend/bin/phpunit ZendTest/Soap
PHPUnit 3.7.10 by Sebastian Bergmann.

Configuration read from /Users/jessie/projects/zf2/tests/phpunit.xml.dist

SS................................I............................ 63 / 165 ( 38%)
..................................I............................ 126 / 165 ( 76%)
.......................................

Time: 2 seconds, Memory: 10.00Mb

OK, but incomplete or skipped tests!
Tests: 165, Assertions: 330, Incomplete: 2, Skipped: 2.

Contributor

jessiehernandez commented Dec 13, 2012

I'm happy to report that the segfault has nothing to do with my changes. I removed all three files (DotNet.php, calc_user_func.php and MockCallUserFunc.php) and I still get the segfault (this was using PHP 5.4.9). Here's the output:

jessie-hernandezs-macbook-pro:tests jessie$ find ZendTest/Soap
ZendTest/Soap
ZendTest/Soap/_files
ZendTest/Soap/_files/cert_file
ZendTest/Soap/_files/commontypes.php
ZendTest/Soap/_files/fulltests
ZendTest/Soap/_files/fulltests/server1.php
ZendTest/Soap/_files/fulltests/server2.php
ZendTest/Soap/_files/wsdl_documentation.wsdl
ZendTest/Soap/_files/wsdl_example.wsdl
ZendTest/Soap/AutoDiscover
ZendTest/Soap/AutoDiscover/OnlineTest.php
ZendTest/Soap/AutoDiscoverTest.php
ZendTest/Soap/Client
ZendTest/Soap/ClientTest.php
ZendTest/Soap/schemas
ZendTest/Soap/schemas/wsdl.xsd
ZendTest/Soap/Server
ZendTest/Soap/Server/_files
ZendTest/Soap/Server/_files/calculator.wsdl
ZendTest/Soap/Server/DocumentLiteralWrapperTest.php
ZendTest/Soap/ServerTest.php
ZendTest/Soap/TestAsset
ZendTest/Soap/TestAsset/cert_file
ZendTest/Soap/TestAsset/commontypes.php
ZendTest/Soap/TestAsset/fulltests
ZendTest/Soap/TestAsset/fulltests/server1.php
ZendTest/Soap/TestAsset/fulltests/server2.php
ZendTest/Soap/TestAsset/MyCalculatorService.php
ZendTest/Soap/TestAsset/wsdl_documentation.wsdl
ZendTest/Soap/TestAsset/wsdl_example.wsdl
ZendTest/Soap/TestAsset/WsdlTestClass.php
ZendTest/Soap/Wsdl
ZendTest/Soap/Wsdl/ArrayOfTypeComplexStrategyTest.php
ZendTest/Soap/Wsdl/ArrayOfTypeSequenceStrategyTest.php
ZendTest/Soap/Wsdl/CompositeStrategyTest.php
ZendTest/Soap/Wsdl/DefaultComplexTypeTest.php
ZendTest/Soap/WsdlTest.php

$ phpunit ZendTest/Soap
PHPUnit 3.7.10 by Sebastian Bergmann.

Configuration read from /Users/jessie/projects/zf2/tests/phpunit.xml.dist

SS.........................Segmentation fault: 11

Contributor

jessiehernandez commented Dec 13, 2012

After adding the --stderr option to PHPUnit and increasing the ulimit, it all worked (I stopped getting the segfault on the codebase before my changes and after them):

$ find ZendTest/Soap
ZendTest/Soap
ZendTest/Soap/.DS_Store
ZendTest/Soap/_files
ZendTest/Soap/_files/cert_file
ZendTest/Soap/_files/commontypes.php
ZendTest/Soap/_files/fulltests
ZendTest/Soap/_files/fulltests/server1.php
ZendTest/Soap/_files/fulltests/server2.php
ZendTest/Soap/_files/wsdl_documentation.wsdl
ZendTest/Soap/_files/wsdl_example.wsdl
ZendTest/Soap/AutoDiscover
ZendTest/Soap/AutoDiscover/OnlineTest.php
ZendTest/Soap/AutoDiscoverTest.php
ZendTest/Soap/Client
ZendTest/Soap/Client/DotNetTest.php
ZendTest/Soap/ClientTest.php
ZendTest/Soap/schemas
ZendTest/Soap/schemas/wsdl.xsd
ZendTest/Soap/Server
ZendTest/Soap/Server/_files
ZendTest/Soap/Server/_files/calculator.wsdl
ZendTest/Soap/Server/DocumentLiteralWrapperTest.php
ZendTest/Soap/ServerTest.php
ZendTest/Soap/TestAsset
ZendTest/Soap/TestAsset/call_user_func.php
ZendTest/Soap/TestAsset/cert_file
ZendTest/Soap/TestAsset/commontypes.php
ZendTest/Soap/TestAsset/fulltests
ZendTest/Soap/TestAsset/fulltests/server1.php
ZendTest/Soap/TestAsset/fulltests/server2.php
ZendTest/Soap/TestAsset/MockCallUserFunc.php
ZendTest/Soap/TestAsset/MyCalculatorService.php
ZendTest/Soap/TestAsset/wsdl_documentation.wsdl
ZendTest/Soap/TestAsset/wsdl_example.wsdl
ZendTest/Soap/TestAsset/WsdlTestClass.php
ZendTest/Soap/Wsdl
ZendTest/Soap/Wsdl/ArrayOfTypeComplexStrategyTest.php
ZendTest/Soap/Wsdl/ArrayOfTypeSequenceStrategyTest.php
ZendTest/Soap/Wsdl/CompositeStrategyTest.php
ZendTest/Soap/Wsdl/DefaultComplexTypeTest.php
ZendTest/Soap/WsdlTest.php

$ phpunit --stderr ZendTest/Soap
PHPUnit 3.7.10 by Sebastian Bergmann.

Configuration read from /Users/jessie/projects/zf2/tests/phpunit.xml.dist

SS................................I............................ 63 / 165 ( 38%)
..................................I............................ 126 / 165 ( 76%)
.......................................

Time: 0 seconds, Memory: 8.50Mb

OK, but incomplete or skipped tests!
Tests: 165, Assertions: 329, Incomplete: 2, Skipped: 2.

@weierophinney weierophinney added a commit to zendframework/zend-soap that referenced this pull request May 15, 2015

@weierophinney weierophinney [zendframework/zendframework#3202] CS
- Moved call_user_func override into separate file
- Moved MockCallUserFunc class into separate class file
- Passes php-cs-fixer, and tests run
4b85372

@weierophinney weierophinney added a commit to zendframework/zend-soap that referenced this pull request May 15, 2015

@weierophinney weierophinney Merge branch 'feature/soap-ntlm-auth' into develop a73949e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment