From 29092b277bf2ecd7372f2b598139f08cffa604fb Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Mon, 4 May 2026 16:22:54 +0530 Subject: [PATCH] Update AuthenticationHandler to make session parameter optional and add validation for empty session tokens. Update error message in PresenceRealtimeClientTest for clarity. --- .../Realtime/Message/Handlers/AuthenticationHandler.php | 6 +++++- tests/e2e/Services/Presence/PresenceRealtimeClientTest.php | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/Realtime/Message/Handlers/AuthenticationHandler.php b/src/Appwrite/Realtime/Message/Handlers/AuthenticationHandler.php index b6d8616f0b..b17c672d91 100644 --- a/src/Appwrite/Realtime/Message/Handlers/AuthenticationHandler.php +++ b/src/Appwrite/Realtime/Message/Handlers/AuthenticationHandler.php @@ -24,7 +24,7 @@ class AuthenticationHandler extends Action $this ->desc('Authenticate the connection with a session token') ->label(Dispatcher::LABEL_MESSAGE_TYPE, 'authentication') - ->param('session', '', new Text(2048), 'Encoded session token') + ->param('session', '', new Text(2048), 'Encoded session token', optional: true) ->inject('connection') ->inject('realtime') ->inject('database') @@ -44,6 +44,10 @@ class AuthenticationHandler extends Action Registry $register, Response $response, ): array { + if ($session === '') { + throw new Exception(Exception::REALTIME_MESSAGE_FORMAT_INVALID, 'Payload is not valid.'); + } + $store = new Store(); $store->decode($session); diff --git a/tests/e2e/Services/Presence/PresenceRealtimeClientTest.php b/tests/e2e/Services/Presence/PresenceRealtimeClientTest.php index e03dba110d..26a28d9387 100644 --- a/tests/e2e/Services/Presence/PresenceRealtimeClientTest.php +++ b/tests/e2e/Services/Presence/PresenceRealtimeClientTest.php @@ -382,7 +382,7 @@ class PresenceRealtimeClientTest extends Scope ], ])); $missingStatus = $this->receiveErrorMessage($client); - $this->assertStringContainsString('status must be provided', $missingStatus['data']['message'] ?? ''); + $this->assertStringContainsString('status is required', $missingStatus['data']['message'] ?? ''); $this->assertQuietFor( $client, fn (array $frame): bool => ($frame['type'] ?? null) === 'event'