Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 97fe54d

Browse files
committed
[SecurityBundle] Fix authenticator existence check in Security::login()
1 parent 1663784 commit 97fe54d

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/Symfony/Bundle/SecurityBundle/Security.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public function logout(bool $validateCsrfToken = true): ?Response
116116

117117
private function getAuthenticator(?string $authenticatorName, string $firewallName): AuthenticatorInterface
118118
{
119-
if (!\array_key_exists($firewallName, $this->authenticators)) {
119+
if (!isset($this->authenticators[$firewallName])) {
120120
throw new LogicException(sprintf('No authenticators found for firewall "%s".', $firewallName));
121121
}
122122

src/Symfony/Bundle/SecurityBundle/Tests/SecurityTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,38 @@ public function testLogin()
169169
$security->login($user);
170170
}
171171

172+
public function testLoginWithoutAuthenticatorThrows()
173+
{
174+
$request = new Request();
175+
$authenticator = $this->createMock(AuthenticatorInterface::class);
176+
$requestStack = $this->createMock(RequestStack::class);
177+
$firewallMap = $this->createMock(FirewallMap::class);
178+
$firewall = new FirewallConfig('main', 'main');
179+
$user = $this->createMock(UserInterface::class);
180+
$userChecker = $this->createMock(UserCheckerInterface::class);
181+
182+
$container = $this->createMock(ContainerInterface::class);
183+
$container
184+
->expects($this->atLeastOnce())
185+
->method('get')
186+
->willReturnMap([
187+
['request_stack', $requestStack],
188+
['security.firewall.map', $firewallMap],
189+
['security.user_checker', $userChecker],
190+
])
191+
;
192+
193+
$requestStack->expects($this->once())->method('getCurrentRequest')->willReturn($request);
194+
$firewallMap->expects($this->once())->method('getFirewallConfig')->willReturn($firewall);
195+
196+
$security = new Security($container, ['main' => null]);
197+
198+
$this->expectException(\LogicException::class);
199+
$this->expectExceptionMessage('No authenticators found for firewall "main".');
200+
201+
$security->login($user);
202+
}
203+
172204
public function testLogout()
173205
{
174206
$request = new Request();

0 commit comments

Comments
 (0)