8 Commits

13 changed files with 140 additions and 81 deletions

View File

@ -4,7 +4,6 @@ namespace BeSimple\SoapClient\Curl;
use BeSimple\SoapClient\Curl\Http\HttpAuthenticationBasicOptions; use BeSimple\SoapClient\Curl\Http\HttpAuthenticationBasicOptions;
use BeSimple\SoapClient\Curl\Http\HttpAuthenticationDigestOptions; use BeSimple\SoapClient\Curl\Http\HttpAuthenticationDigestOptions;
use BeSimple\SoapClient\Curl\Http\SslCertificateOptions;
use Exception; use Exception;
class Curl class Curl
@ -141,6 +140,11 @@ class Curl
curl_setopt($curlSession, CURLOPT_CAPATH, $sslCertificateOptions->hasCertificateAuthorityPath()); curl_setopt($curlSession, CURLOPT_CAPATH, $sslCertificateOptions->hasCertificateAuthorityPath());
} }
} }
if ($options->hasSslVersion()) {
curl_setopt($curlSession, CURLOPT_SSLVERSION, $options->getSslVersion());
}
$executeSoapCallResponse = $this->executeHttpCall($curlSession, $options); $executeSoapCallResponse = $this->executeHttpCall($curlSession, $options);
$httpRequestHeadersAsString = curl_getinfo($curlSession, CURLINFO_HEADER_OUT); $httpRequestHeadersAsString = curl_getinfo($curlSession, CURLINFO_HEADER_OUT);
@ -159,7 +163,7 @@ class Curl
$httpResponseCode $httpResponseCode
); );
if (!is_integer($httpResponseCode) || $httpResponseCode >= 400 || $httpResponseCode === 0) { if (!is_int($httpResponseCode) || $httpResponseCode >= 400 || $httpResponseCode === 0) {
return new CurlResponse( return new CurlResponse(
$this->normalizeStringOrFalse($httpRequestHeadersAsString), $this->normalizeStringOrFalse($httpRequestHeadersAsString),

View File

@ -2,9 +2,9 @@
namespace BeSimple\SoapClient\Curl; namespace BeSimple\SoapClient\Curl;
use BeSimple\SoapClient\Curl\Http\HttpAuthenticationBasicOptions;
use BeSimple\SoapClient\Curl\Http\HttpAuthenticationDigestOptions; use BeSimple\SoapClient\Curl\Http\HttpAuthenticationDigestOptions;
use BeSimple\SoapClient\Curl\Http\HttpAuthenticationInterface; use BeSimple\SoapClient\Curl\Http\HttpAuthenticationInterface;
use BeSimple\SoapClient\Curl\Http\HttpAuthenticationBasicOptions;
use BeSimple\SoapClient\Curl\Http\SslCertificateOptions; use BeSimple\SoapClient\Curl\Http\SslCertificateOptions;
use BeSimple\SoapClient\SoapServerProxy\SoapServerProxy; use BeSimple\SoapClient\SoapServerProxy\SoapServerProxy;
@ -22,6 +22,7 @@ class CurlOptions
private $proxy; private $proxy;
private $httpAuthentication; private $httpAuthentication;
private $sslCertificateOptions; private $sslCertificateOptions;
private $sslVersion;
/** /**
* @param string $userAgent * @param string $userAgent
@ -31,6 +32,7 @@ class CurlOptions
* @param SoapServerProxy|null $proxy * @param SoapServerProxy|null $proxy
* @param HttpAuthenticationInterface|null $httpAuthentication * @param HttpAuthenticationInterface|null $httpAuthentication
* @param SslCertificateOptions|null $sslCertificateOptions * @param SslCertificateOptions|null $sslCertificateOptions
* @param int $sslVersion
*/ */
public function __construct( public function __construct(
$userAgent, $userAgent,
@ -39,7 +41,8 @@ class CurlOptions
$connectionTimeout, $connectionTimeout,
SoapServerProxy $proxy = null, SoapServerProxy $proxy = null,
HttpAuthenticationInterface $httpAuthentication = null, HttpAuthenticationInterface $httpAuthentication = null,
SslCertificateOptions $sslCertificateOptions = null SslCertificateOptions $sslCertificateOptions = null,
$sslVersion = null
) { ) {
$this->userAgent = $userAgent; $this->userAgent = $userAgent;
$this->followLocationMaxRedirects = $followLocationMaxRedirects; $this->followLocationMaxRedirects = $followLocationMaxRedirects;
@ -48,6 +51,7 @@ class CurlOptions
$this->proxy = $proxy; $this->proxy = $proxy;
$this->httpAuthentication = $httpAuthentication; $this->httpAuthentication = $httpAuthentication;
$this->sslCertificateOptions = $sslCertificateOptions; $this->sslCertificateOptions = $sslCertificateOptions;
$this->sslVersion = $sslVersion;
} }
public function getUserAgent() public function getUserAgent()
@ -123,4 +127,14 @@ class CurlOptions
return false; return false;
} }
public function hasSslVersion()
{
return $this->sslVersion !== null;
}
public function getSslVersion()
{
return $this->sslVersion;
}
} }

View File

@ -34,7 +34,8 @@ class CurlOptionsBuilder
self::DEFAULT_CONNECTION_TIMEOUT, self::DEFAULT_CONNECTION_TIMEOUT,
$soapClientOptions->getProxy(), $soapClientOptions->getProxy(),
self::getHttpAuthOptions($soapClientOptions), self::getHttpAuthOptions($soapClientOptions),
self::getSslCertificateOptions($soapClientOptions) self::getSslCertificateOptions($soapClientOptions),
$soapClientOptions->getSslVersion()
); );
} }

View File

@ -61,7 +61,7 @@ class SoapClient extends \SoapClient
$this->curl, $this->curl,
$soapOptions->getWsdlFile(), $soapOptions->getWsdlFile(),
$soapOptions->getWsdlCacheType(), $soapOptions->getWsdlCacheType(),
false $soapClientOptions->isResolveRemoteIncludes()
); );
} catch (Exception $e) { } catch (Exception $e) {
throw new SoapFault( throw new SoapFault(

View File

@ -81,4 +81,47 @@ class SoapClientOptionsBuilder
$endpointLocation $endpointLocation
); );
} }
/**
* @param $endpointLocation
* @param SoapServerAuthenticationInterface $authentication
* @return SoapClientOptions
*/
public static function createWithAuthenticationAndEndpointLocationAndSslVersionV3(
$endpointLocation,
SoapServerAuthenticationInterface $authentication
) {
return new SoapClientOptions(
SoapClientOptions::SOAP_CLIENT_TRACE_ON,
SoapClientOptions::SOAP_CLIENT_EXCEPTIONS_ON,
CurlOptions::DEFAULT_USER_AGENT,
SoapClientOptions::SOAP_CLIENT_COMPRESSION_NONE,
$authentication,
SoapClientOptions::SOAP_CLIENT_PROXY_NONE,
$endpointLocation,
false,
CURL_SSLVERSION_SSLv3
);
}
/**
* @param SoapServerAuthenticationInterface $authentication
* @param bool $resolveRemoteIncludes
* @return SoapClientOptions
*/
public static function createWithAuthenticationAndResolveRemoteIncludes(
SoapServerAuthenticationInterface $authentication,
$resolveRemoteIncludes
) {
return new SoapClientOptions(
SoapClientOptions::SOAP_CLIENT_TRACE_ON,
SoapClientOptions::SOAP_CLIENT_EXCEPTIONS_ON,
CurlOptions::DEFAULT_USER_AGENT,
SoapClientOptions::SOAP_CLIENT_COMPRESSION_NONE,
$authentication,
SoapClientOptions::SOAP_CLIENT_PROXY_NONE,
SoapClientOptions::SOAP_CLIENT_ENDPOINT_LOCATION_NONE,
$resolveRemoteIncludes
);
}
} }

View File

@ -19,6 +19,9 @@ class SoapClientOptions
const SOAP_CLIENT_COMPRESSION_DEFLATE = CurlOptions::SOAP_COMPRESSION_DEFLATE; const SOAP_CLIENT_COMPRESSION_DEFLATE = CurlOptions::SOAP_COMPRESSION_DEFLATE;
const SOAP_CLIENT_AUTHENTICATION_NONE = null; const SOAP_CLIENT_AUTHENTICATION_NONE = null;
const SOAP_CLIENT_PROXY_NONE = null; const SOAP_CLIENT_PROXY_NONE = null;
const SOAP_CLIENT_ENDPOINT_LOCATION_NONE = null;
const SOAP_CLIENT_RESOLVE_REMOTE_INCLUDES_ON = true;
const SOAP_CLIENT_RESOLVE_REMOTE_INCLUDES_OFF = false;
private $trace; private $trace;
private $exceptions; private $exceptions;
@ -27,15 +30,19 @@ class SoapClientOptions
private $authentication; private $authentication;
private $proxy; private $proxy;
private $location; private $location;
private $resolveRemoteIncludes;
private $sslVersion;
/** /**
* @param bool $trace = SoapClientOptions::SOAP_CLIENT_TRACE_ON|SoapClientOptions::SOAP_CLIENT_TRACE_OFF * @param bool $trace = self::SOAP_CLIENT_TRACE_ON|self::SOAP_CLIENT_TRACE_OFF
* @param bool $exceptions = SoapClientOptions::SOAP_CLIENT_EXCEPTIONS_ON|SoapClientOptions::SOAP_CLIENT_EXCEPTIONS_OFF * @param bool $exceptions = self::SOAP_CLIENT_EXCEPTIONS_ON|self::SOAP_CLIENT_EXCEPTIONS_OFF
* @param string $userAgent * @param string $userAgent
* @param int|null $compression = SoapClientOptions::SOAP_CLIENT_COMPRESSION_NONE|SoapClientOptions::SOAP_CLIENT_COMPRESSION_GZIP|SoapClientOptions::SOAP_CLIENT_COMPRESSION_DEFLATE * @param int|null $compression = self::SOAP_CLIENT_COMPRESSION_NONE|self::SOAP_CLIENT_COMPRESSION_GZIP|self::SOAP_CLIENT_COMPRESSION_DEFLATE
* @param SoapServerAuthenticationInterface|null $authentication * @param SoapServerAuthenticationInterface|null $authentication
* @param SoapServerProxy|null $proxy * @param SoapServerProxy|null $proxy
* @param string|null $location * @param string|null $location
* @param bool $resolveRemoteIncludes = self::SOAP_CLIENT_RESOLVE_REMOTE_INCLUDES_ON|self::SOAP_CLIENT_RESOLVE_REMOTE_INCLUDES_OFF
* @param int $sslVersion
*/ */
public function __construct( public function __construct(
$trace, $trace,
@ -44,7 +51,9 @@ class SoapClientOptions
$compression = null, $compression = null,
SoapServerAuthenticationInterface $authentication = null, SoapServerAuthenticationInterface $authentication = null,
SoapServerProxy $proxy = null, SoapServerProxy $proxy = null,
$location = null $location = null,
$resolveRemoteIncludes = false,
$sslVersion = null
) { ) {
$this->trace = $trace; $this->trace = $trace;
$this->exceptions = $exceptions; $this->exceptions = $exceptions;
@ -53,6 +62,8 @@ class SoapClientOptions
$this->authentication = $authentication; $this->authentication = $authentication;
$this->proxy = $proxy; $this->proxy = $proxy;
$this->location = $location; $this->location = $location;
$this->resolveRemoteIncludes = $resolveRemoteIncludes;
$this->sslVersion = $sslVersion;
} }
public function getTrace() public function getTrace()
@ -120,6 +131,11 @@ class SoapClientOptions
return $this->location; return $this->location;
} }
public function isResolveRemoteIncludes()
{
return $this->resolveRemoteIncludes;
}
public function toArray() public function toArray()
{ {
$optionsAsArray = [ $optionsAsArray = [
@ -142,4 +158,9 @@ class SoapClientOptions
return $optionsAsArray; return $optionsAsArray;
} }
public function getSslVersion()
{
return $this->sslVersion;
}
} }

View File

@ -19,16 +19,16 @@ class RelativePathResolver
public function resolveRelativePathInUrl($base, $relative) public function resolveRelativePathInUrl($base, $relative)
{ {
$urlParts = parse_url($base); $urlParts = parse_url($base);
$isRelativePathAbsolute = 0 === strpos($relative, '/') || 0 === strpos($relative, '..'); $pathIsSet = true === isset($urlParts['path']);
// combine base path with relative path // combine base path with relative path
if (isset($urlParts['path']) && mb_strlen($relative) > 0 && $isRelativePathAbsolute) { if (true === $pathIsSet && 0 < mb_strlen($relative) && 0 === strpos($relative, '/')) {
// $relative is absolute path from domain (starts with /) // $relative is absolute path from domain (starts with /)
$path = $relative; $path = $relative;
} elseif (isset($urlParts['path']) && strrpos($urlParts['path'], '/') === (strlen($urlParts['path']) )) { } elseif (true === $pathIsSet && strrpos($urlParts['path'], '/') === strlen($urlParts['path'])) {
// base path is directory // base path is directory
$path = $urlParts['path'].$relative; $path = $urlParts['path'].$relative;
} elseif (isset($urlParts['path'])) { } elseif (true === $pathIsSet) {
// strip filename from base path // strip filename from base path
$path = substr($urlParts['path'], 0, strrpos($urlParts['path'], '/')).'/'.$relative; $path = substr($urlParts['path'], 0, strrpos($urlParts['path'], '/')).'/'.$relative;
} else { } else {

View File

@ -4,6 +4,7 @@ namespace BeSimple\SoapClient\Xml;
use BeSimple\SoapClient\Curl\Curl; use BeSimple\SoapClient\Curl\Curl;
use BeSimple\SoapClient\WsdlDownloader; use BeSimple\SoapClient\WsdlDownloader;
use BeSimple\SoapClient\Xml\Path\RelativePathResolver;
use DOMElement; use DOMElement;
use DOMXPath; use DOMXPath;
@ -45,7 +46,8 @@ class XmlDomDocumentImportReplacer
$locationAttributeName, $locationAttributeName,
WsdlDownloader::instantiateDownloader()->getWsdlPath( WsdlDownloader::instantiateDownloader()->getWsdlPath(
$curl, $curl,
self::resolveRelativePathInUrl($parentFilePath, $locationPath), RelativePathResolver::instantiateResolver()
->resolveRelativePathInUrl($parentFilePath, $locationPath),
$cacheType, $cacheType,
true true
) )
@ -55,68 +57,4 @@ class XmlDomDocumentImportReplacer
} }
} }
} }
/**
* Resolves the relative path to base into an absolute.
*
* @param string $base Base path
* @param string $relative Relative path
*
* @return string
*/
private static function resolveRelativePathInUrl($base, $relative)
{
$urlParts = parse_url($base);
$isRelativePathAbsolute = 0 === strpos($relative, '/') || 0 === strpos($relative, '..');
// combine base path with relative path
if (isset($urlParts['path']) && mb_strlen($relative) > 0 && $isRelativePathAbsolute) {
// $relative is absolute path from domain (starts with /)
$path = $relative;
} elseif (isset($urlParts['path']) && strrpos($urlParts['path'], '/') === (strlen($urlParts['path']) )) {
// base path is directory
$path = $urlParts['path'].$relative;
} elseif (isset($urlParts['path'])) {
// strip filename from base path
$path = substr($urlParts['path'], 0, strrpos($urlParts['path'], '/')).'/'.$relative;
} else {
// no base path
$path = '/'.$relative;
}
// foo/./bar ==> foo/bar
// remove double slashes
$path = preg_replace(array('#/\./#', '#/+#'), '/', $path);
// split path by '/'
$parts = explode('/', $path);
// resolve /../
foreach ($parts as $key => $part) {
if ($part === '..') {
$keyToDelete = $key - 1;
while ($keyToDelete > 0) {
if (isset($parts[$keyToDelete])) {
unset($parts[$keyToDelete]);
break;
}
$keyToDelete--;
}
unset($parts[$key]);
}
}
$hostname = $urlParts['scheme'].'://'.$urlParts['host'];
if (isset($urlParts['port'])) {
$hostname .= ':'.$urlParts['port'];
}
if (substr($hostname, -1) !== '/') {
$hostname .= '/';
}
return $hostname.implode('/', $parts);
}
} }

View File

@ -27,7 +27,7 @@ class MimeBoundaryAnalyser
*/ */
public static function isMessageLineBoundary($mimeMessageLine) public static function isMessageLineBoundary($mimeMessageLine)
{ {
return strlen($mimeMessageLine) > 0 && $mimeMessageLine[0] === "-"; return preg_match('/^--[0-9A-Za-z\s\'\/\+\_\,\-\.\:\=\?]+/', $mimeMessageLine) === 1;
} }
/** /**

View File

@ -4,6 +4,7 @@ namespace BeSimple\SoapClient;
use BeSimple\SoapClient\Curl\CurlOptions; use BeSimple\SoapClient\Curl\CurlOptions;
use BeSimple\SoapClient\SoapOptions\SoapClientOptions; use BeSimple\SoapClient\SoapOptions\SoapClientOptions;
use BeSimple\SoapClient\SoapServerAuthentication\SoapServerAuthenticationBasic;
use BeSimple\SoapCommon\ClassMap; use BeSimple\SoapCommon\ClassMap;
use BeSimple\SoapCommon\SoapOptions\SoapOptions; use BeSimple\SoapCommon\SoapOptions\SoapOptions;
use BeSimple\SoapCommon\SoapOptionsBuilder; use BeSimple\SoapCommon\SoapOptionsBuilder;
@ -87,6 +88,27 @@ class SoapClientBuilderTest extends PHPUnit_Framework_TestCase
self::assertInstanceOf(SoapClient::class, $soapClient); self::assertInstanceOf(SoapClient::class, $soapClient);
} }
public function testCreateOptionsWithAuthenticationAndEndpointLocationAndSslVersionV3()
{
$authentication = new SoapServerAuthenticationBasic('', '');
$soapClientOptions = SoapClientOptionsBuilder::createWithAuthenticationAndEndpointLocationAndSslVersionV3('', $authentication);
self::assertSame(CURL_SSLVERSION_SSLv3, $soapClientOptions->getSslVersion());
}
public function testConstructSoapClientWithAuthenticationAndEndpointLocationAndSslVersionV3()
{
$authentication = new SoapServerAuthenticationBasic('', '');
$soapOptions = SoapOptionsBuilder::createWithDefaults(self::TEST_LOCAL_WSDL_UK);
$soapClient = $this->getSoapBuilder()->build(
SoapClientOptionsBuilder::createWithAuthenticationAndEndpointLocationAndSslVersionV3('', $authentication),
$soapOptions
);
self::assertInstanceOf(SoapClient::class, $soapClient);
}
private function getSoapBuilder() private function getSoapBuilder()
{ {
return new SoapClientBuilder(); return new SoapClientBuilder();

View File

@ -30,6 +30,11 @@ class RelativePathResolverTest extends PHPUnit_Framework_TestCase
public function providePathInfo() public function providePathInfo()
{ {
return [ return [
[
'http://anyendpoint.tld:9999/path/to/endpoint.wsdl',
'../Schemas/Common/SoapHeader.xsd',
'http://anyendpoint.tld:9999/path/Schemas/Common/SoapHeader.xsd',
],
[ [
'http://endpoint-location.ltd/', 'http://endpoint-location.ltd/',
'Document1.xsd', 'Document1.xsd',

View File

@ -97,9 +97,18 @@ class XmlDomDocumentImportReplacerTest extends PHPUnit_Framework_TestCase
Helper::PFX_XML_SCHEMA, Helper::PFX_XML_SCHEMA,
Helper::NS_XML_SCHEMA, Helper::NS_XML_SCHEMA,
'schemaLocation', 'schemaLocation',
'http://endpoint-location.ltd:8080/endpoint/', 'http://endpoint-location.ltd:8080/endpoint/wsdl.wsdl',
'<xs:include schemaLocation="http://endpoint-location.ltd:8080/Schemas/Common/Document1.xsd"></xs:include>' '<xs:include schemaLocation="http://endpoint-location.ltd:8080/Schemas/Common/Document1.xsd"></xs:include>'
], ],
'schemaWithParentPathAndSubDir' => [
file_get_contents(__DIR__.'/testUpdateXmlDocument.wsdl'),
new Curl(CurlOptionsBuilder::buildDefault()),
Helper::PFX_XML_SCHEMA,
Helper::NS_XML_SCHEMA,
'schemaLocation',
'http://endpoint-location.ltd:8080/endpoint/subdir/wsdl.wsdl',
'<xs:include schemaLocation="http://endpoint-location.ltd:8080/endpoint/Schemas/Common/Document1.xsd"></xs:include>'
],
]; ];
} }
} }

View File

@ -67,6 +67,8 @@ class MimeBoundaryAnalyserTest extends PHPUnit_Framework_TestCase
{ {
return [ return [
['-- this line is boundary', self::EXPECTED_IS_BOUNDARY], ['-- this line is boundary', self::EXPECTED_IS_BOUNDARY],
['--this line is boundary', self::EXPECTED_IS_BOUNDARY],
['--@ this line is not boundary', self::EXPECTED_IS_NOT_BOUNDARY],
['-- this line is also a boundary --', self::EXPECTED_IS_BOUNDARY], ['-- this line is also a boundary --', self::EXPECTED_IS_BOUNDARY],
['mesage line -- is not boundary', self::EXPECTED_IS_NOT_BOUNDARY], ['mesage line -- is not boundary', self::EXPECTED_IS_NOT_BOUNDARY],
[' -- mesage line -- is not boundary', self::EXPECTED_IS_NOT_BOUNDARY], [' -- mesage line -- is not boundary', self::EXPECTED_IS_NOT_BOUNDARY],