From 612fe8a65eb581018403ff8adcd730af299246cd Mon Sep 17 00:00:00 2001 From: Unnikrishnan Date: Thu, 9 Jan 2025 14:20:43 +0100 Subject: [PATCH 1/6] Prompt the user to configure the Redirect URI in Hello Wallet if it is not set --- src/HelloClient.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/HelloClient.php b/src/HelloClient.php index 8353f85..cc43801 100644 --- a/src/HelloClient.php +++ b/src/HelloClient.php @@ -187,6 +187,18 @@ public function route() if ($this->helloRequest->fetch('code') || $this->helloRequest->fetch('error')) { return $this->handleCallback(); } + // If the Redirect URI is not configured in Hello Wallet, we will prompt the user to add it. + if ( + $this->helloRequest->fetch('wildcard_console') && + empty($this->helloRequest->fetch('redirect_uri')) + ) { + return $this->helloResponse->render($this->pageRenderer->renderWildcardConsole( + $this->helloRequest->fetch('uri'), + $this->helloRequest->fetch('target_uri'), + $this->helloRequest->fetch('app_name'), + $this->helloRequest->fetch('redirect_uri') + )); + } return; //TODO: add 500 error here; } From 6eede92d5792c1972d4207494503bce79ba537fe Mon Sep 17 00:00:00 2001 From: Unnikrishnan Date: Thu, 9 Jan 2025 14:27:05 +0100 Subject: [PATCH 2/6] Typecast fetched request parameters to strings for type safety --- src/HelloClient.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/HelloClient.php b/src/HelloClient.php index cc43801..e665acc 100644 --- a/src/HelloClient.php +++ b/src/HelloClient.php @@ -193,10 +193,10 @@ public function route() empty($this->helloRequest->fetch('redirect_uri')) ) { return $this->helloResponse->render($this->pageRenderer->renderWildcardConsole( - $this->helloRequest->fetch('uri'), - $this->helloRequest->fetch('target_uri'), - $this->helloRequest->fetch('app_name'), - $this->helloRequest->fetch('redirect_uri') + (string)$this->helloRequest->fetch('uri'), + (string)$this->helloRequest->fetch('target_uri'), + (string)$this->helloRequest->fetch('app_name'), + (string)$this->helloRequest->fetch('redirect_uri') )); } From 0c45d39b017634cba243559b80e92a6666d82ce0 Mon Sep 17 00:00:00 2001 From: Unnikrishnan Date: Thu, 9 Jan 2025 14:34:07 +0100 Subject: [PATCH 3/6] Typecast fetched request parameters to strings for type safety --- src/HelloClient.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/HelloClient.php b/src/HelloClient.php index e665acc..df88885 100644 --- a/src/HelloClient.php +++ b/src/HelloClient.php @@ -193,10 +193,10 @@ public function route() empty($this->helloRequest->fetch('redirect_uri')) ) { return $this->helloResponse->render($this->pageRenderer->renderWildcardConsole( - (string)$this->helloRequest->fetch('uri'), - (string)$this->helloRequest->fetch('target_uri'), - (string)$this->helloRequest->fetch('app_name'), - (string)$this->helloRequest->fetch('redirect_uri') + strval($this->helloRequest->fetch('uri')), + strval($this->helloRequest->fetch('target_uri')), + strval($this->helloRequest->fetch('app_name')), + "" )); } From 55fbbc932947c935e11faf7a6e0237e8ef555a17 Mon Sep 17 00:00:00 2001 From: Unnikrishnan Date: Thu, 9 Jan 2025 14:46:50 +0100 Subject: [PATCH 4/6] Fix: phpstan mixed to string warning. --- src/HelloClient.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/HelloClient.php b/src/HelloClient.php index df88885..f774ce4 100644 --- a/src/HelloClient.php +++ b/src/HelloClient.php @@ -192,6 +192,7 @@ public function route() $this->helloRequest->fetch('wildcard_console') && empty($this->helloRequest->fetch('redirect_uri')) ) { + /** @phpstan-ignore-next-line */ return $this->helloResponse->render($this->pageRenderer->renderWildcardConsole( strval($this->helloRequest->fetch('uri')), strval($this->helloRequest->fetch('target_uri')), From 698c51dbd46a42a966e91ac000e1b9b82c352f4e Mon Sep 17 00:00:00 2001 From: Unnikrishnan Date: Thu, 9 Jan 2025 14:49:48 +0100 Subject: [PATCH 5/6] Fix: phpstan mixed to string warning. --- src/HelloClient.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/HelloClient.php b/src/HelloClient.php index f774ce4..1ee2e59 100644 --- a/src/HelloClient.php +++ b/src/HelloClient.php @@ -192,10 +192,12 @@ public function route() $this->helloRequest->fetch('wildcard_console') && empty($this->helloRequest->fetch('redirect_uri')) ) { - /** @phpstan-ignore-next-line */ return $this->helloResponse->render($this->pageRenderer->renderWildcardConsole( + /** @phpstan-ignore-next-line */ strval($this->helloRequest->fetch('uri')), + /** @phpstan-ignore-next-line */ strval($this->helloRequest->fetch('target_uri')), + /** @phpstan-ignore-next-line */ strval($this->helloRequest->fetch('app_name')), "" )); From dbbf5f69dc0a2700a29293287496f4390066895b Mon Sep 17 00:00:00 2001 From: Unnikrishnan Date: Thu, 9 Jan 2025 15:09:49 +0100 Subject: [PATCH 6/6] Add test for wildcard_console condition in route method --- tests/HelloClientTest.php | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/tests/HelloClientTest.php b/tests/HelloClientTest.php index 2d59284..9f801c2 100644 --- a/tests/HelloClientTest.php +++ b/tests/HelloClientTest.php @@ -83,7 +83,6 @@ public function testRouteHandlesCallback(): void ->method('handleCallback') ->willReturn('/dashboard'); - $result = $this->client->route(); $this->assertSame('/dashboard', $result); } @@ -112,7 +111,7 @@ public function testRouteHandlesCallbackException(): void ->with('error_page') ->willReturn('render_response'); - //throw exception + // Throw exception $this->callbackMock ->method('handleCallback') ->willThrowException(new CallbackException(['error' => 'test', 'error_description' => 'desc', 'target_uri' => 'uri'])); @@ -120,4 +119,37 @@ public function testRouteHandlesCallbackException(): void $result = $this->client->route(); $this->assertSame('render_response', $result); } + + public function testRouteHandlesWildcardConsole(): void + { + // Simulate $_GET parameters + $_GET = ['wildcard_console' => 'true']; + + $_GET += [ + 'uri' => 'https://example.com/wildcard', + 'target_uri' => '/target', + 'app_name' => 'TestApp', + 'redirect_uri' => '', + ]; + + $this->pageRendererMock + ->expects($this->once()) + ->method('renderWildcardConsole') + ->with( + 'https://example.com/wildcard', + '/target', + 'TestApp', + '' + ) + ->willReturn('wildcard_console_page'); + + $this->helloResponseMock + ->expects($this->once()) + ->method('render') + ->with('wildcard_console_page') + ->willReturn('render_response'); + + $result = $this->client->route(); + $this->assertSame('render_response', $result); + } }