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.
This commit is contained in:
Julien Fastré 2024-11-17 11:32:34 +01:00
parent 3e0731f06e
commit 40fec3c530
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB

View File

@ -31,6 +31,7 @@ trait PrepareClientTrait
public function getClientAuthenticated( public function getClientAuthenticated(
$username = 'center a_social', $username = 'center a_social',
$password = 'password', $password = 'password',
$firewall = 'chill_main',
): KernelBrowser { ): KernelBrowser {
if ('admin' === $username) { if ('admin' === $username) {
return $this->getClientAuthenticatedAsAdmin(); return $this->getClientAuthenticatedAsAdmin();
@ -49,12 +50,12 @@ trait PrepareClientTrait
throw new \RuntimeException(sprintf('user with username or email %s not found', $username)); throw new \RuntimeException(sprintf('user with username or email %s not found', $username));
} }
$client->loginUser($user); $client->loginUser($user, $firewall);
return $client; return $client;
} }
public function getClientAuthenticatedAsAdmin(): KernelBrowser public function getClientAuthenticatedAsAdmin(string $firewall = 'chill_main'): KernelBrowser
{ {
if (!$this instanceof WebTestCase) { if (!$this instanceof WebTestCase) {
throw new \LogicException(sprintf('The current class does not implements %s', WebTestCase::class)); throw new \LogicException(sprintf('The current class does not implements %s', WebTestCase::class));
@ -63,9 +64,9 @@ trait PrepareClientTrait
$client = static::createClient(); $client = static::createClient();
/** @var \Symfony\Component\Security\Core\User\InMemoryUserProvider $userProvider */ /** @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'); $user = $userProvider->loadUserByIdentifier('admin');
$client->loginUser($user); $client->loginUser($user, $firewall);
return $client; return $client;
} }