From 40fec3c5306de9f4fc6489fcf64f373ca43e3b3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Sun, 17 Nov 2024 11:32:34 +0100 Subject: [PATCH] Fix the default firewall in test login Update admin client authentication method Modified `getClientAuthenticatedAsAdmin` to accept an optional firewall parameter and updated dependency to use `chill_in_memory` user provider. This allows more flexible and configurable testing of client authentication against different firewalls. --- src/Bundle/ChillMainBundle/Test/PrepareClientTrait.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Test/PrepareClientTrait.php b/src/Bundle/ChillMainBundle/Test/PrepareClientTrait.php index 619436269..57c87f6bf 100644 --- a/src/Bundle/ChillMainBundle/Test/PrepareClientTrait.php +++ b/src/Bundle/ChillMainBundle/Test/PrepareClientTrait.php @@ -31,6 +31,7 @@ trait PrepareClientTrait public function getClientAuthenticated( $username = 'center a_social', $password = 'password', + $firewall = 'chill_main', ): KernelBrowser { if ('admin' === $username) { return $this->getClientAuthenticatedAsAdmin(); @@ -49,12 +50,12 @@ trait PrepareClientTrait throw new \RuntimeException(sprintf('user with username or email %s not found', $username)); } - $client->loginUser($user); + $client->loginUser($user, $firewall); return $client; } - public function getClientAuthenticatedAsAdmin(): KernelBrowser + public function getClientAuthenticatedAsAdmin(string $firewall = 'chill_main'): KernelBrowser { if (!$this instanceof WebTestCase) { throw new \LogicException(sprintf('The current class does not implements %s', WebTestCase::class)); @@ -63,9 +64,9 @@ trait PrepareClientTrait $client = static::createClient(); /** @var \Symfony\Component\Security\Core\User\InMemoryUserProvider $userProvider */ - $userProvider = static::getContainer()->get('security.user.provider.concrete.in_memory'); + $userProvider = static::getContainer()->get('security.user.provider.concrete.chill_in_memory'); $user = $userProvider->loadUserByIdentifier('admin'); - $client->loginUser($user); + $client->loginUser($user, $firewall); return $client; }