Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/Security/Core/User/EntityUserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
38 changes: 38 additions & 0 deletions tests/Fixtures/StringIDUser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/*
* This file is part of the HWIOAuthBundle package.
*
* (c) Hardware Info <opensource@hardware.info>
*
* 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
{
}
}
33 changes: 33 additions & 0 deletions tests/Security/Core/User/EntityUserProviderTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of the HWIOAuthBundle package.
*
Expand All @@ -15,9 +17,11 @@
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\Persistence\ObjectManager;
use Doctrine\Persistence\ObjectRepository;
use ErrorException;
use HWI\Bundle\OAuthBundle\OAuth\ResourceOwnerInterface;
use HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface;
use HWI\Bundle\OAuthBundle\Security\Core\User\EntityUserProvider;
use HWI\Bundle\OAuthBundle\Tests\Fixtures\StringIDUser;
use HWI\Bundle\OAuthBundle\Tests\Fixtures\User;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
Expand Down Expand Up @@ -184,4 +188,33 @@ private function assertUserNotFoundException(): void
{
$this->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();
}
}

}
Loading