From fead5a497b0728fbceb08e4f915441beac60b813 Mon Sep 17 00:00:00 2001 From: Gregor Becker Date: Mon, 10 May 2021 19:06:52 +0200 Subject: [PATCH 1/2] fix(laravel-soap-126): 400 Bad Request, XML not as expected Added mustUnderstand option for Wsse Header --- src/Middleware/WsseMiddleware.php | 7 ++++++- tests/Unit/SoapClientTest.php | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Middleware/WsseMiddleware.php b/src/Middleware/WsseMiddleware.php index cc67c21..20f4bec 100644 --- a/src/Middleware/WsseMiddleware.php +++ b/src/Middleware/WsseMiddleware.php @@ -62,6 +62,11 @@ class WsseMiddleware extends Middleware */ private $encrypt = false; + /** + * @var bool + */ + private $mustUnderstand = true; + /** * @var bool */ @@ -127,7 +132,7 @@ public function withServerCertificateHasSubjectKeyIdentifier(bool $hasSubjectKey public function beforeRequest(callable $handler, RequestInterface $request): Promise { $xml = SoapXml::fromStream($request->getBody()); - $wsse = new WSSESoap($xml->getXmlDocument()); + $wsse = new WSSESoap($xml->getXmlDocument(), $this->mustUnderstand); // Prepare the WSSE soap class: $wsse->signAllHeaders = $this->signAllHeaders; diff --git a/tests/Unit/SoapClientTest.php b/tests/Unit/SoapClientTest.php index b2be530..194b28b 100644 --- a/tests/Unit/SoapClientTest.php +++ b/tests/Unit/SoapClientTest.php @@ -40,6 +40,21 @@ public function testMagicCallByConfig() self::assertTrue($response->ok()); } + public function testWsseWithWsaCall() + { + Soap::fake(); + $client = Soap::baseWsdl('https://laravel-soap.wsdl')->withWsse([ + 'userTokenName' => 'Test', + 'userTokenPassword' => 'passwordTest', + 'mustUnderstand' => false + ])->withWsa(); + $response = $client->Get_User(); + $lastRequestInfo = $client->getEngine()->collectLastRequestInfo(); + self::assertStringNotContainsString( 'mustUnderstand', $lastRequestInfo->getLastRequest()); +// dd($client->debugLastSoapRequest()); + self::assertTrue($response->ok()); + } + public function testArrayAccessResponse() { Soap::fakeSequence()->push('test'); From 4bb385d2223b964df5400e55198be89656e5d07a Mon Sep 17 00:00:00 2001 From: Gregor Becker Date: Mon, 10 May 2021 21:36:04 +0200 Subject: [PATCH 2/2] Apply fixes from StyleCI (#139) Co-authored-by: Gregor Becker --- tests/Unit/SoapClientTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Unit/SoapClientTest.php b/tests/Unit/SoapClientTest.php index 194b28b..c6c4290 100644 --- a/tests/Unit/SoapClientTest.php +++ b/tests/Unit/SoapClientTest.php @@ -46,11 +46,11 @@ public function testWsseWithWsaCall() $client = Soap::baseWsdl('https://laravel-soap.wsdl')->withWsse([ 'userTokenName' => 'Test', 'userTokenPassword' => 'passwordTest', - 'mustUnderstand' => false + 'mustUnderstand' => false, ])->withWsa(); $response = $client->Get_User(); $lastRequestInfo = $client->getEngine()->collectLastRequestInfo(); - self::assertStringNotContainsString( 'mustUnderstand', $lastRequestInfo->getLastRequest()); + self::assertStringNotContainsString('mustUnderstand', $lastRequestInfo->getLastRequest()); // dd($client->debugLastSoapRequest()); self::assertTrue($response->ok()); }