From 47e6a7d843041ec68622537406a50bb4f5d837f3 Mon Sep 17 00:00:00 2001 From: Joe Dixon Date: Thu, 11 Apr 2024 14:56:57 +0100 Subject: [PATCH] handle stale apps (#143) --- src/Protocols/Pusher/Http/Controllers/Controller.php | 8 ++------ src/Servers/Reverb/Http/Server.php | 3 +++ .../Protocols/Pusher/Reverb/EventsControllerTest.php | 4 ++++ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Protocols/Pusher/Http/Controllers/Controller.php b/src/Protocols/Pusher/Http/Controllers/Controller.php index e14bde10..a583cf53 100644 --- a/src/Protocols/Pusher/Http/Controllers/Controller.php +++ b/src/Protocols/Pusher/Http/Controllers/Controller.php @@ -46,12 +46,8 @@ public function verify(RequestInterface $request, Connection $connection, $appId $this->body = $request->getBody()->getContents(); $this->query = $query; - try { - $this->setApplication($appId); - $this->setChannels(); - } catch (HttpException $e) { - $this->close($connection, $e->getStatusCode(), $e->getMessage()); - } + $this->setApplication($appId); + $this->setChannels(); } /** diff --git a/src/Servers/Reverb/Http/Server.php b/src/Servers/Reverb/Http/Server.php index 51ec0c01..182a849f 100644 --- a/src/Servers/Reverb/Http/Server.php +++ b/src/Servers/Reverb/Http/Server.php @@ -11,6 +11,7 @@ use React\EventLoop\LoopInterface; use React\Socket\ConnectionInterface; use React\Socket\ServerInterface; +use Symfony\Component\HttpKernel\Exception\HttpException; use Throwable; class Server @@ -57,6 +58,8 @@ protected function handleRequest(string $message, Connection $connection): void try { $this->router->dispatch($request, $connection); + } catch (HttpException $e) { + $this->close($connection, $e->getStatusCode(), $e->getMessage()); } catch (Throwable $e) { Log::error($e->getMessage()); $this->close($connection, 500, 'Internal server error.'); diff --git a/tests/Feature/Protocols/Pusher/Reverb/EventsControllerTest.php b/tests/Feature/Protocols/Pusher/Reverb/EventsControllerTest.php index 24dc30d1..f6df3122 100644 --- a/tests/Feature/Protocols/Pusher/Reverb/EventsControllerTest.php +++ b/tests/Feature/Protocols/Pusher/Reverb/EventsControllerTest.php @@ -193,3 +193,7 @@ expect($response->getStatusCode())->toBe(500); })->throws(ResponseException::class, exceptionCode: 500); + +it('fails when app cannot be found', function () { + await($this->signedPostRequest('events', appId: 'invalid-app-id')); +})->throws(ResponseException::class, exceptionCode: 404);