diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ed98af11..d75fba633 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ Changelog ========= +## 2.5.1 +* Bugfix: Prevent error in `EntityUserProvider::refreshUser` when `$userId` is a `Ulid` + ## 2.5.0 (2026-02-19) * Added: PHP 8.5 test coverage, * Added: Support for Symfony 8.0, diff --git a/src/Security/Core/User/EntityUserProvider.php b/src/Security/Core/User/EntityUserProvider.php index 2b1bc52bc..d2a608014 100644 --- a/src/Security/Core/User/EntityUserProvider.php +++ b/src/Security/Core/User/EntityUserProvider.php @@ -94,7 +94,7 @@ public function refreshUser(UserInterface $user): UserInterface $username = $user->getUserIdentifier(); if (null === $user = $this->findUser([$identifier => $userId])) { - throw $this->createUserNotFoundException($username, \sprintf('User with ID "%d" could not be reloaded.', $userId)); + throw $this->createUserNotFoundException($username, \sprintf('User with ID "%s" could not be reloaded.', $userId)); } return $user; diff --git a/tests/Fixtures/StringIDUser.php b/tests/Fixtures/StringIDUser.php new file mode 100644 index 000000000..3875c1dc9 --- /dev/null +++ b/tests/Fixtures/StringIDUser.php @@ -0,0 +1,38 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace HWI\Bundle\OAuthBundle\Tests\Fixtures; + +use Deprecated; +use Symfony\Component\Security\Core\User\UserInterface; + +final class StringIDUser implements UserInterface +{ + public function getId(): string + { + return '6f5f78b2-005d-4eea-96c4-79044aaebb34'; + } + + public function getRoles(): array + { + return []; + } + + public function getUserIdentifier(): string + { + return 'abc'; + } + + #[Deprecated] + public function eraseCredentials(): void + { + } +} diff --git a/tests/Security/Core/User/EntityUserProviderTest.php b/tests/Security/Core/User/EntityUserProviderTest.php index 0a42dfb50..87e63fe66 100644 --- a/tests/Security/Core/User/EntityUserProviderTest.php +++ b/tests/Security/Core/User/EntityUserProviderTest.php @@ -1,5 +1,7 @@ expectException(UserNotFoundException::class); } + + public function testRefreshUserWorksWithUlid(): void + { + // Simulate `framework.php_errors.throw: true` + set_error_handler(static function ( + int $severity, + string $message, + string $file, + int $line + ): never { + throw new ErrorException($message, 0, $severity, $file, $line); + }); + + try { + $this->assertUserNotFoundException(); + $this->expectExceptionMessage('User with ID "6f5f78b2-005d-4eea-96c4-79044aaebb34" could not be reloaded.'); + + $provider = new EntityUserProvider( + $this->createManagerRegistryMock(), + StringIDUser::class, + [] + ); + + $provider->refreshUser(new StringIDUser()); + } finally { + restore_error_handler(); + } + } + }