Skip to content

Commit d021c8e

Browse files
ioigoumetvdijen
authored andcommitted
refactor(SOAPClient): use XMLSchema AnyURIValue for SOAP destination URI
1 parent 03c0b23 commit d021c8e

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

src/SOAPClient.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use RobRichards\XMLSecLibs\XMLSecurityKey;
1010
use SimpleSAML\Configuration;
1111
use SimpleSAML\SAML2\Compat\ContainerSingleton;
12-
use SimpleSAML\SAML2\Type\SAMLAnyURIValue;
1312
use SimpleSAML\SAML2\XML\samlp\AbstractMessage;
1413
use SimpleSAML\SAML2\XML\samlp\MessageFactory;
1514
use SimpleSAML\SOAP11\Utils\XPath;
@@ -20,6 +19,7 @@
2019
use SimpleSAML\Utils\Crypto;
2120
use SimpleSAML\XML\Chunk;
2221
use SimpleSAML\XML\DOMDocumentFactory;
22+
use SimpleSAML\XMLSchema\Type\AnyURIValue;
2323
use SoapClient as BuiltinSoapClient;
2424

2525
use function chunk_split;
@@ -201,21 +201,24 @@ protected function createSoapClient(array $options): BuiltinSoapClient
201201
/**
202202
* Wrapper around __doRequest(), overridable for testing.
203203
*
204+
* NOTE: $destination is a generic xs:anyURI value (XMLSchema), since the SOAP endpoint URI
205+
* is transport-level and not necessarily subject to SAML-layer URI restrictions.
206+
*
204207
* @param \SoapClient $client
205208
* @param string|null $request
206-
* @param \SimpleSAML\SAML2\Type\SAMLAnyURIValue $destination
209+
* @param \SimpleSAML\XMLSchema\Type\AnyURIValue $destination
207210
* @param string $action
208211
* @return string
209212
*/
210213
protected function doSoapRequest(
211214
BuiltinSoapClient $client,
212215
?string $request,
213-
SAMLAnyURIValue $destination,
216+
AnyURIValue $destination,
214217
string $action,
215218
): string {
216219
return (string) $client->__doRequest(
217220
$request,
218-
(string)$destination,
221+
(string) $destination,
219222
$action,
220223
SOAP_1_1,
221224
);

tests/SAML2/SOAPClientTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use SimpleSAML\SAML2\SOAPClient;
1515
use SimpleSAML\SAML2\Type\SAMLAnyURIValue;
1616
use SimpleSAML\SAML2\XML\samlp\AbstractMessage;
17+
use SimpleSAML\XMLSchema\Type\AnyURIValue;
1718
use SimpleSAML\XMLSecurity\TestUtils\PEMCertificatesMock;
1819

1920
/**
@@ -134,7 +135,7 @@ protected function createSoapClient(array $options): \SoapClient
134135
protected function doSoapRequest(
135136
\SoapClient $client,
136137
?string $request,
137-
SAMLAnyURIValue $destination,
138+
AnyURIValue $destination,
138139
string $action,
139140
): string {
140141
throw new \LogicException('doSoapRequest() should not be called when destination is missing.');
@@ -159,6 +160,11 @@ protected function doSoapRequest(
159160
#[DataProvider('provideBadSoapResponses')]
160161
public function testSendThrowsOnEmptySoapResponseOrSoapFault(string $soapResponse, string $expectedMessage): void
161162
{
163+
/**
164+
* Use SAMLAnyURIValue here because AbstractMessage::getDestination() is typed to return it, and PHPUnit
165+
* enforces return-type compatibility on stubs. SAMLAnyURIValue still works for SOAP transport because
166+
* it extends AnyURIValue.
167+
*/
162168
$destination = SAMLAnyURIValue::fromString('https://example.org/soap-endpoint');
163169

164170
$client = new class ($soapResponse) extends SOAPClient {
@@ -182,7 +188,7 @@ protected function createSoapClient(array $options): \SoapClient
182188
protected function doSoapRequest(
183189
\SoapClient $client,
184190
?string $request,
185-
SAMLAnyURIValue $destination,
191+
AnyURIValue $destination,
186192
string $action,
187193
): string {
188194
return $this->soapResponse;

0 commit comments

Comments
 (0)