From 8fa667da6133b25bea253113dc7c464cefc29996 Mon Sep 17 00:00:00 2001 From: Johan Kromhout Date: Wed, 27 Nov 2024 09:47:56 +0100 Subject: [PATCH] Ensure correct invite url Prior to this change, the api call to invite would fail because the relative path would collapse. This change ensures the baseUri and call path are absolute/relative when needed so the calls get executed as expected. See https://symfony.com/doc/7.2/reference/configuration/framework.html#reference-http-client-base-uri --- .../Invite/InviteHttpClient.php | 6 +- .../Invite/InviteHttpClientUrlSanitizer.php | 56 ++++++++++++++++ .../InviteHttpClientUrlSanitizerTest.php | 64 +++++++++++++++++++ 3 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 src/Surfnet/ServiceProviderDashboard/Infrastructure/Invite/InviteHttpClientUrlSanitizer.php create mode 100644 tests/unit/Infrastructure/Invite/InviteHttpClientUrlSanitizerTest.php diff --git a/src/Surfnet/ServiceProviderDashboard/Infrastructure/Invite/InviteHttpClient.php b/src/Surfnet/ServiceProviderDashboard/Infrastructure/Invite/InviteHttpClient.php index 45266647e..e7b778d4d 100644 --- a/src/Surfnet/ServiceProviderDashboard/Infrastructure/Invite/InviteHttpClient.php +++ b/src/Surfnet/ServiceProviderDashboard/Infrastructure/Invite/InviteHttpClient.php @@ -43,8 +43,10 @@ public function __construct( ], ]; + $baseUri = InviteHttpClientUrlSanitizer::buildBaseUri($path, $host); + $this->httpClient = HttpClient::createForBaseUri( - $host . $path, + $baseUri, $options ); } @@ -54,6 +56,7 @@ public function __construct( */ public function post(string $path, array $payload): ResponseInterface { + $path = InviteHttpClientUrlSanitizer::ensureRelativePath($path); return $this->httpClient->request( 'POST', $path, @@ -66,6 +69,7 @@ public function post(string $path, array $payload): ResponseInterface */ public function delete(string $path): ResponseInterface { + $path = InviteHttpClientUrlSanitizer::ensureRelativePath($path); return $this->httpClient->request( 'DELETE', $path, diff --git a/src/Surfnet/ServiceProviderDashboard/Infrastructure/Invite/InviteHttpClientUrlSanitizer.php b/src/Surfnet/ServiceProviderDashboard/Infrastructure/Invite/InviteHttpClientUrlSanitizer.php new file mode 100644 index 000000000..92b06aa9e --- /dev/null +++ b/src/Surfnet/ServiceProviderDashboard/Infrastructure/Invite/InviteHttpClientUrlSanitizer.php @@ -0,0 +1,56 @@ +