From a8516b7184f96ffa497d39eef869f5acda52d979 Mon Sep 17 00:00:00 2001 From: PHAS Developer <110562019+phasdev@users.noreply.github.com> Date: Tue, 28 Jan 2025 19:24:43 +0000 Subject: [PATCH] [Security] Return null instead of empty username to fix deprecation notice --- .../Security/Http/Authenticator/RemoteUserAuthenticator.php | 2 +- .../Http/Tests/Authenticator/RemoteUserAuthenticatorTest.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Security/Http/Authenticator/RemoteUserAuthenticator.php b/src/Symfony/Component/Security/Http/Authenticator/RemoteUserAuthenticator.php index 958eeaeaec227..39649666ccace 100644 --- a/src/Symfony/Component/Security/Http/Authenticator/RemoteUserAuthenticator.php +++ b/src/Symfony/Component/Security/Http/Authenticator/RemoteUserAuthenticator.php @@ -45,6 +45,6 @@ protected function extractUsername(Request $request): ?string throw new BadCredentialsException(sprintf('User key was not found: "%s".', $this->userKey)); } - return $request->server->get($this->userKey); + return $request->server->get($this->userKey) ?: null; } } diff --git a/src/Symfony/Component/Security/Http/Tests/Authenticator/RemoteUserAuthenticatorTest.php b/src/Symfony/Component/Security/Http/Tests/Authenticator/RemoteUserAuthenticatorTest.php index 5119f8ce09e74..b94f90884e2e0 100644 --- a/src/Symfony/Component/Security/Http/Tests/Authenticator/RemoteUserAuthenticatorTest.php +++ b/src/Symfony/Component/Security/Http/Tests/Authenticator/RemoteUserAuthenticatorTest.php @@ -36,6 +36,7 @@ public function testSupportNoUser() $authenticator = new RemoteUserAuthenticator(new InMemoryUserProvider(), new TokenStorage(), 'main'); $this->assertFalse($authenticator->supports($this->createRequest([]))); + $this->assertFalse($authenticator->supports($this->createRequest(['REMOTE_USER' => '']))); } public function testSupportTokenStorageWithToken()