|
22 | 22 | use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
23 | 23 | use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
|
24 | 24 | use Symfony\Component\Security\Core\Exception\BadCredentialsException;
|
| 25 | +use Symfony\Component\Security\Core\Exception\LockedException; |
25 | 26 | use Symfony\Component\Security\Core\Exception\UserNotFoundException;
|
26 | 27 | use Symfony\Component\Security\Core\User\InMemoryUser;
|
27 | 28 | use Symfony\Component\Security\Http\Authentication\AuthenticatorManager;
|
@@ -322,6 +323,42 @@ public function testAuthenticateRequestHidesInvalidUserExceptions()
|
322 | 323 | $this->assertSame($this->response, $response);
|
323 | 324 | }
|
324 | 325 |
|
| 326 | + public function testAuthenticateRequestShowsAccountStatusException() |
| 327 | + { |
| 328 | + $invalidUserException = new LockedException(); |
| 329 | + $authenticator = $this->createMock(TestInteractiveAuthenticator::class); |
| 330 | + $this->request->attributes->set('_security_authenticators', [$authenticator]); |
| 331 | + |
| 332 | + $authenticator->expects($this->any())->method('authenticate')->willThrowException($invalidUserException); |
| 333 | + |
| 334 | + $authenticator->expects($this->any()) |
| 335 | + ->method('onAuthenticationFailure') |
| 336 | + ->with($this->equalTo($this->request), $this->callback(fn ($e) => $e === $invalidUserException)) |
| 337 | + ->willReturn($this->response); |
| 338 | + |
| 339 | + $manager = $this->createManager([$authenticator], showAccountStatusExceptions: true); |
| 340 | + $response = $manager->authenticateRequest($this->request); |
| 341 | + $this->assertSame($this->response, $response); |
| 342 | + } |
| 343 | + |
| 344 | + public function testAuthenticateRequestHidesInvalidAccountStatusExceptiot() |
| 345 | + { |
| 346 | + $invalidUserException = new LockedException(); |
| 347 | + $authenticator = $this->createMock(TestInteractiveAuthenticator::class); |
| 348 | + $this->request->attributes->set('_security_authenticators', [$authenticator]); |
| 349 | + |
| 350 | + $authenticator->expects($this->any())->method('authenticate')->willThrowException($invalidUserException); |
| 351 | + |
| 352 | + $authenticator->expects($this->any()) |
| 353 | + ->method('onAuthenticationFailure') |
| 354 | + ->with($this->equalTo($this->request), $this->callback(fn ($e) => $e instanceof BadCredentialsException && $invalidUserException === $e->getPrevious())) |
| 355 | + ->willReturn($this->response); |
| 356 | + |
| 357 | + $manager = $this->createManager([$authenticator]); |
| 358 | + $response = $manager->authenticateRequest($this->request); |
| 359 | + $this->assertSame($this->response, $response); |
| 360 | + } |
| 361 | + |
325 | 362 | public function testLogsUseTheDecoratedAuthenticatorWhenItIsTraceable()
|
326 | 363 | {
|
327 | 364 | $authenticator = $this->createMock(TestInteractiveAuthenticator::class);
|
@@ -373,9 +410,9 @@ private static function createDummySupportsAuthenticator(?bool $supports = true)
|
373 | 410 | return new DummySupportsAuthenticator($supports);
|
374 | 411 | }
|
375 | 412 |
|
376 |
| - private function createManager($authenticators, $firewallName = 'main', $eraseCredentials = true, array $requiredBadges = [], ?LoggerInterface $logger = null) |
| 413 | + private function createManager($authenticators, $firewallName = 'main', $eraseCredentials = true, array $requiredBadges = [], ?LoggerInterface $logger = null, bool $showAccountStatusExceptions = false) |
377 | 414 | {
|
378 |
| - return new AuthenticatorManager($authenticators, $this->tokenStorage, $this->eventDispatcher, $firewallName, $logger, $eraseCredentials, true, $requiredBadges); |
| 415 | + return new AuthenticatorManager($authenticators, $this->tokenStorage, $this->eventDispatcher, $firewallName, $logger, $eraseCredentials, true, $requiredBadges, showAccountStatusExceptions: $showAccountStatusExceptions); |
379 | 416 | }
|
380 | 417 | }
|
381 | 418 |
|
|
0 commit comments