From 7c77c49f9084f3046113a8f23f3df8375224d933 Mon Sep 17 00:00:00 2001 From: butschster Date: Tue, 9 Apr 2024 23:35:55 +0400 Subject: [PATCH] Bugfixes 1. SMTP message duplications 2. Auth headers via WS RPC 3. Proxy FE bg --- app/modules/Smtp/Interfaces/TCP/Service.php | 13 +++++++++++++ app/src/Application/OAuth/ActorProvider.php | 6 ------ app/src/Interfaces/Centrifugo/RPCService.php | 12 +++++++++--- app/src/Interfaces/Http/Handler/FrontendRequest.php | 5 ++++- docker/Dockerfile | 2 ++ 5 files changed, 28 insertions(+), 10 deletions(-) diff --git a/app/modules/Smtp/Interfaces/TCP/Service.php b/app/modules/Smtp/Interfaces/TCP/Service.php index 9cce4d26..2d5f52ab 100644 --- a/app/modules/Smtp/Interfaces/TCP/Service.php +++ b/app/modules/Smtp/Interfaces/TCP/Service.php @@ -12,6 +12,7 @@ use Spiral\Cqrs\CommandBusInterface; use Spiral\RoadRunner\Tcp\Request; use Spiral\RoadRunner\Tcp\TcpEvent; +use Spiral\RoadRunner\Tcp\TcpResponse; use Spiral\RoadRunnerBridge\Tcp\Response\CloseConnection; use Spiral\RoadRunnerBridge\Tcp\Response\RespondMessage; use Spiral\RoadRunnerBridge\Tcp\Response\ResponseInterface; @@ -45,6 +46,7 @@ public function handle(Request $request): ResponseInterface $message = $this->cache->get($cacheKey, []); $response = new CloseConnection(); + $dispatched = false; if ($request->event === TcpEvent::Close) { $this->cache->delete($cacheKey); @@ -71,15 +73,26 @@ public function handle(Request $request): ResponseInterface if (\count($messages) === 1) { $this->dispatchMessage($content); $this->cache->delete($cacheKey); + $dispatched = true; } elseif (!empty($messages[1])) { $this->dispatchMessage($messages[0]); $this->cache->delete($cacheKey); + $dispatched = true; } } $message['content'] = $content; } + if ( + $response instanceof CloseConnection || + $response->getAction() === TcpResponse::RespondClose || + $dispatched + ) { + $this->cache->delete($cacheKey); + return $response; + } + $this->cache->set( $cacheKey, $message, diff --git a/app/src/Application/OAuth/ActorProvider.php b/app/src/Application/OAuth/ActorProvider.php index f0e63fd4..c61fd3eb 100644 --- a/app/src/Application/OAuth/ActorProvider.php +++ b/app/src/Application/OAuth/ActorProvider.php @@ -4,17 +4,11 @@ namespace App\Application\OAuth; -use Auth0\SDK\Auth0; use Spiral\Auth\ActorProviderInterface; use Spiral\Auth\TokenInterface; final class ActorProvider implements ActorProviderInterface { - public function __construct( - private readonly Auth0 $auth, - ) { - } - public function getActor(TokenInterface $token): ?User { $payload = $token->getPayload(); diff --git a/app/src/Interfaces/Centrifugo/RPCService.php b/app/src/Interfaces/Centrifugo/RPCService.php index 96bd1f32..bb6b2a54 100644 --- a/app/src/Interfaces/Centrifugo/RPCService.php +++ b/app/src/Interfaces/Centrifugo/RPCService.php @@ -65,10 +65,16 @@ public function createHttpRequest(Request\RPC $request): ServerRequestInterface $token = $data['token'] ?? null; unset($data['token']); - return match ($method) { - 'GET', 'HEAD' => $httpRequest->withQueryParams($data)->withHeader('X-Auth-Token', $token), - 'POST', 'PUT', 'DELETE' => $httpRequest->withParsedBody($data)->withHeader('X-Auth-Token', $token), + $httpRequest = match ($method) { + 'GET', 'HEAD' => $httpRequest->withQueryParams($data), + 'POST', 'PUT', 'DELETE' => $httpRequest->withParsedBody($data), default => throw new \InvalidArgumentException('Unsupported method'), }; + + if (!empty($token)) { + $httpRequest = $httpRequest->withHeader('X-Auth-Token', $token); + } + + return $httpRequest; } } diff --git a/app/src/Interfaces/Http/Handler/FrontendRequest.php b/app/src/Interfaces/Http/Handler/FrontendRequest.php index 607e902b..f2a75d15 100644 --- a/app/src/Interfaces/Http/Handler/FrontendRequest.php +++ b/app/src/Interfaces/Http/Handler/FrontendRequest.php @@ -73,6 +73,9 @@ private function isValidRequest(ServerRequestInterface $request): bool { $path = $request->getUri()->getPath(); - return $path === '/' || \str_starts_with($path, '/_nuxt/') || $path === '/favicon/favicon.ico'; + return $path === '/' + || \str_starts_with($path, '/_nuxt/') + || $path === '/favicon/favicon.ico' + || $path === '/bg.jpg'; } } diff --git a/docker/Dockerfile b/docker/Dockerfile index d35298e0..3b348c61 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -69,6 +69,8 @@ ENV APP_ENV=production ENV DEBUG=false ENV ENCRYPTER_KEY=def00000232ae92c8e8ec0699093fa06ce014cd48d39c3c62c279dd947db084e56ee48b5c91cebc1c5abe53f7755021d09043757561c244c1c0c765cfeb5db33eb45a903 ENV TOKENIZER_CACHE_TARGETS=true +ENV AUTH_TOKEN_STORAGE=jwt +ENV AUTH_TOKEN_TRANSPORT=header LABEL org.opencontainers.image.source=$REPOSITORY LABEL org.opencontainers.image.description="Buggregator"