feature #36666 [Security] Renamed VerifyAuthenticatorCredentialsEvent to CheckPassportEvent (wouterj)

This PR was merged into the 5.1-dev branch.

Discussion
----------

[Security] Renamed VerifyAuthenticatorCredentialsEvent to CheckPassportEvent

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #36608
| License       | MIT
| Doc PR        | -

This event was named long before we introduced the concept of passports. Listeners on this event check the user, the credentials and any badges of the Security passport. I think `CheckPassportEvent` makes the most sense (more than `CheckCredentialsEvent`).

Also, I managed to break fabbot in the large PR. Just checked all new classes and added license headers in case they were missing (fabbot complained about most of them in this PR already).

Commits
-------

5ba4d1de86 Renamed VerifyAuthenticatorCredentialsEvent to CheckPassportEvent
This commit is contained in:
Fabien Potencier 2020-05-03 08:34:00 +02:00
commit 1308dd5553
12 changed files with 79 additions and 45 deletions

View File

@ -12,10 +12,10 @@
namespace Symfony\Bundle\SecurityBundle\EventListener; namespace Symfony\Bundle\SecurityBundle\EventListener;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Http\Event\CheckPassportEvent;
use Symfony\Component\Security\Http\Event\LoginFailureEvent; use Symfony\Component\Security\Http\Event\LoginFailureEvent;
use Symfony\Component\Security\Http\Event\LoginSuccessEvent; use Symfony\Component\Security\Http\Event\LoginSuccessEvent;
use Symfony\Component\Security\Http\Event\LogoutEvent; use Symfony\Component\Security\Http\Event\LogoutEvent;
use Symfony\Component\Security\Http\Event\VerifyAuthenticatorCredentialsEvent;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
/** /**
@ -39,7 +39,7 @@ class FirewallEventBubblingListener implements EventSubscriberInterface
LogoutEvent::class => 'bubbleEvent', LogoutEvent::class => 'bubbleEvent',
LoginFailureEvent::class => 'bubbleEvent', LoginFailureEvent::class => 'bubbleEvent',
LoginSuccessEvent::class => 'bubbleEvent', LoginSuccessEvent::class => 'bubbleEvent',
VerifyAuthenticatorCredentialsEvent::class => 'bubbleEvent', CheckPassportEvent::class => 'bubbleEvent',
]; ];
} }

View File

@ -44,7 +44,7 @@
<!-- Listeners --> <!-- Listeners -->
<service id="security.listener.verify_authenticator_credentials" class="Symfony\Component\Security\Http\EventListener\VerifyAuthenticatorCredentialsListener"> <service id="security.listener.check_authenticator_credentials" class="Symfony\Component\Security\Http\EventListener\CheckCredentialsListener">
<tag name="kernel.event_subscriber" /> <tag name="kernel.event_subscriber" />
<argument type="service" id="security.encoder_factory" /> <argument type="service" id="security.encoder_factory" />
</service> </service>

View File

@ -26,10 +26,10 @@ use Symfony\Component\Security\Http\Authenticator\Passport\AnonymousPassport;
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\BadgeInterface; use Symfony\Component\Security\Http\Authenticator\Passport\Badge\BadgeInterface;
use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface; use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface;
use Symfony\Component\Security\Http\Authenticator\Passport\SelfValidatingPassport; use Symfony\Component\Security\Http\Authenticator\Passport\SelfValidatingPassport;
use Symfony\Component\Security\Http\Event\CheckPassportEvent;
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent; use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
use Symfony\Component\Security\Http\Event\LoginFailureEvent; use Symfony\Component\Security\Http\Event\LoginFailureEvent;
use Symfony\Component\Security\Http\Event\LoginSuccessEvent; use Symfony\Component\Security\Http\Event\LoginSuccessEvent;
use Symfony\Component\Security\Http\Event\VerifyAuthenticatorCredentialsEvent;
use Symfony\Component\Security\Http\SecurityEvents; use Symfony\Component\Security\Http\SecurityEvents;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
@ -159,7 +159,7 @@ class AuthenticatorManager implements AuthenticatorManagerInterface, UserAuthent
$passport = $authenticator->authenticate($request); $passport = $authenticator->authenticate($request);
// check the passport (e.g. password checking) // check the passport (e.g. password checking)
$event = new VerifyAuthenticatorCredentialsEvent($authenticator, $passport); $event = new CheckPassportEvent($authenticator, $passport);
$this->eventDispatcher->dispatch($event); $this->eventDispatcher->dispatch($event);
// check if all badges are resolved // check if all badges are resolved

View File

@ -1,5 +1,14 @@
<?php <?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Security\Http\Authenticator\Token; namespace Symfony\Component\Security\Http\Authenticator\Token;
use Symfony\Component\Security\Core\Authentication\Token\AbstractToken; use Symfony\Component\Security\Core\Authentication\Token\AbstractToken;

View File

@ -1,9 +1,16 @@
<?php <?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Security\Http\Event; namespace Symfony\Component\Security\Http\Event;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface; use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface;
use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface; use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface;
use Symfony\Contracts\EventDispatcher\Event; use Symfony\Contracts\EventDispatcher\Event;
@ -17,7 +24,7 @@ use Symfony\Contracts\EventDispatcher\Event;
* *
* @author Wouter de Jong <wouter@wouterj.nl> * @author Wouter de Jong <wouter@wouterj.nl>
*/ */
class VerifyAuthenticatorCredentialsEvent extends Event class CheckPassportEvent extends Event
{ {
private $authenticator; private $authenticator;
private $passport; private $passport;

View File

@ -1,5 +1,14 @@
<?php <?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Security\Http\EventListener; namespace Symfony\Component\Security\Http\EventListener;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@ -8,7 +17,7 @@ use Symfony\Component\Security\Core\Exception\BadCredentialsException;
use Symfony\Component\Security\Http\Authenticator\Passport\Credentials\CustomCredentials; use Symfony\Component\Security\Http\Authenticator\Passport\Credentials\CustomCredentials;
use Symfony\Component\Security\Http\Authenticator\Passport\Credentials\PasswordCredentials; use Symfony\Component\Security\Http\Authenticator\Passport\Credentials\PasswordCredentials;
use Symfony\Component\Security\Http\Authenticator\Passport\UserPassportInterface; use Symfony\Component\Security\Http\Authenticator\Passport\UserPassportInterface;
use Symfony\Component\Security\Http\Event\VerifyAuthenticatorCredentialsEvent; use Symfony\Component\Security\Http\Event\CheckPassportEvent;
/** /**
* This listeners uses the interfaces of authenticators to * This listeners uses the interfaces of authenticators to
@ -19,7 +28,7 @@ use Symfony\Component\Security\Http\Event\VerifyAuthenticatorCredentialsEvent;
* @final * @final
* @experimental in 5.1 * @experimental in 5.1
*/ */
class VerifyAuthenticatorCredentialsListener implements EventSubscriberInterface class CheckCredentialsListener implements EventSubscriberInterface
{ {
private $encoderFactory; private $encoderFactory;
@ -28,7 +37,7 @@ class VerifyAuthenticatorCredentialsListener implements EventSubscriberInterface
$this->encoderFactory = $encoderFactory; $this->encoderFactory = $encoderFactory;
} }
public function onAuthenticating(VerifyAuthenticatorCredentialsEvent $event): void public function checkPassport(CheckPassportEvent $event): void
{ {
$passport = $event->getPassport(); $passport = $event->getPassport();
if ($passport instanceof UserPassportInterface && $passport->hasBadge(PasswordCredentials::class)) { if ($passport instanceof UserPassportInterface && $passport->hasBadge(PasswordCredentials::class)) {
@ -74,6 +83,6 @@ class VerifyAuthenticatorCredentialsListener implements EventSubscriberInterface
public static function getSubscribedEvents(): array public static function getSubscribedEvents(): array
{ {
return [VerifyAuthenticatorCredentialsEvent::class => ['onAuthenticating', 128]]; return [CheckPassportEvent::class => 'checkPassport'];
} }
} }

View File

@ -16,7 +16,7 @@ use Symfony\Component\Security\Core\Exception\InvalidCsrfTokenException;
use Symfony\Component\Security\Csrf\CsrfToken; use Symfony\Component\Security\Csrf\CsrfToken;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface; use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\CsrfTokenBadge; use Symfony\Component\Security\Http\Authenticator\Passport\Badge\CsrfTokenBadge;
use Symfony\Component\Security\Http\Event\VerifyAuthenticatorCredentialsEvent; use Symfony\Component\Security\Http\Event\CheckPassportEvent;
/** /**
* @author Wouter de Jong <wouter@wouterj.nl> * @author Wouter de Jong <wouter@wouterj.nl>
@ -33,7 +33,7 @@ class CsrfProtectionListener implements EventSubscriberInterface
$this->csrfTokenManager = $csrfTokenManager; $this->csrfTokenManager = $csrfTokenManager;
} }
public function verifyCredentials(VerifyAuthenticatorCredentialsEvent $event): void public function checkPassport(CheckPassportEvent $event): void
{ {
$passport = $event->getPassport(); $passport = $event->getPassport();
if (!$passport->hasBadge(CsrfTokenBadge::class)) { if (!$passport->hasBadge(CsrfTokenBadge::class)) {
@ -57,6 +57,6 @@ class CsrfProtectionListener implements EventSubscriberInterface
public static function getSubscribedEvents(): array public static function getSubscribedEvents(): array
{ {
return [VerifyAuthenticatorCredentialsEvent::class => ['verifyCredentials', 256]]; return [CheckPassportEvent::class => ['checkPassport', 128]];
} }
} }

View File

@ -1,13 +1,22 @@
<?php <?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Security\Http\EventListener; namespace Symfony\Component\Security\Http\EventListener;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Core\User\UserCheckerInterface; use Symfony\Component\Security\Core\User\UserCheckerInterface;
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\PreAuthenticatedUserBadge; use Symfony\Component\Security\Http\Authenticator\Passport\Badge\PreAuthenticatedUserBadge;
use Symfony\Component\Security\Http\Authenticator\Passport\UserPassportInterface; use Symfony\Component\Security\Http\Authenticator\Passport\UserPassportInterface;
use Symfony\Component\Security\Http\Event\CheckPassportEvent;
use Symfony\Component\Security\Http\Event\LoginSuccessEvent; use Symfony\Component\Security\Http\Event\LoginSuccessEvent;
use Symfony\Component\Security\Http\Event\VerifyAuthenticatorCredentialsEvent;
/** /**
* @author Wouter de Jong <wouter@wouterj.nl> * @author Wouter de Jong <wouter@wouterj.nl>
@ -24,7 +33,7 @@ class UserCheckerListener implements EventSubscriberInterface
$this->userChecker = $userChecker; $this->userChecker = $userChecker;
} }
public function preCredentialsVerification(VerifyAuthenticatorCredentialsEvent $event): void public function preCheckCredentials(CheckPassportEvent $event): void
{ {
$passport = $event->getPassport(); $passport = $event->getPassport();
if (!$passport instanceof UserPassportInterface || $passport->hasBadge(PreAuthenticatedUserBadge::class)) { if (!$passport instanceof UserPassportInterface || $passport->hasBadge(PreAuthenticatedUserBadge::class)) {
@ -34,7 +43,7 @@ class UserCheckerListener implements EventSubscriberInterface
$this->userChecker->checkPreAuth($passport->getUser()); $this->userChecker->checkPreAuth($passport->getUser());
} }
public function postCredentialsVerification(LoginSuccessEvent $event): void public function postCheckCredentials(LoginSuccessEvent $event): void
{ {
$passport = $event->getPassport(); $passport = $event->getPassport();
if (!$passport instanceof UserPassportInterface || null === $passport->getUser()) { if (!$passport instanceof UserPassportInterface || null === $passport->getUser()) {
@ -47,8 +56,8 @@ class UserCheckerListener implements EventSubscriberInterface
public static function getSubscribedEvents(): array public static function getSubscribedEvents(): array
{ {
return [ return [
VerifyAuthenticatorCredentialsEvent::class => [['preCredentialsVerification', 256]], CheckPassportEvent::class => ['preCheckCredentials', 256],
LoginSuccessEvent::class => ['postCredentialsVerification', 256], LoginSuccessEvent::class => ['postCheckCredentials', 256],
]; ];
} }
} }

View File

@ -24,7 +24,7 @@ use Symfony\Component\Security\Http\Authenticator\InteractiveAuthenticatorInterf
use Symfony\Component\Security\Http\Authenticator\Passport\Credentials\PasswordCredentials; use Symfony\Component\Security\Http\Authenticator\Passport\Credentials\PasswordCredentials;
use Symfony\Component\Security\Http\Authenticator\Passport\Passport; use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
use Symfony\Component\Security\Http\Authenticator\Passport\SelfValidatingPassport; use Symfony\Component\Security\Http\Authenticator\Passport\SelfValidatingPassport;
use Symfony\Component\Security\Http\Event\VerifyAuthenticatorCredentialsEvent; use Symfony\Component\Security\Http\Event\CheckPassportEvent;
class AuthenticatorManagerTest extends TestCase class AuthenticatorManagerTest extends TestCase
{ {
@ -95,7 +95,7 @@ class AuthenticatorManagerTest extends TestCase
$matchingAuthenticator->expects($this->any())->method('authenticate')->willReturn(new SelfValidatingPassport($this->user)); $matchingAuthenticator->expects($this->any())->method('authenticate')->willReturn(new SelfValidatingPassport($this->user));
$listenerCalled = false; $listenerCalled = false;
$this->eventDispatcher->addListener(VerifyAuthenticatorCredentialsEvent::class, function (VerifyAuthenticatorCredentialsEvent $event) use (&$listenerCalled, $matchingAuthenticator) { $this->eventDispatcher->addListener(CheckPassportEvent::class, function (CheckPassportEvent $event) use (&$listenerCalled, $matchingAuthenticator) {
if ($event->getAuthenticator() === $matchingAuthenticator && $event->getPassport()->getUser() === $this->user) { if ($event->getAuthenticator() === $matchingAuthenticator && $event->getPassport()->getUser() === $this->user) {
$listenerCalled = true; $listenerCalled = true;
} }
@ -106,7 +106,7 @@ class AuthenticatorManagerTest extends TestCase
$manager = $this->createManager($authenticators); $manager = $this->createManager($authenticators);
$this->assertNull($manager->authenticateRequest($this->request)); $this->assertNull($manager->authenticateRequest($this->request));
$this->assertTrue($listenerCalled, 'The VerifyAuthenticatorCredentialsEvent listener is not called'); $this->assertTrue($listenerCalled, 'The CheckPassportEvent listener is not called');
} }
public function provideMatchingAuthenticatorIndex() public function provideMatchingAuthenticatorIndex()

View File

@ -21,10 +21,10 @@ use Symfony\Component\Security\Http\Authenticator\Passport\Credentials\CustomCre
use Symfony\Component\Security\Http\Authenticator\Passport\Credentials\PasswordCredentials; use Symfony\Component\Security\Http\Authenticator\Passport\Credentials\PasswordCredentials;
use Symfony\Component\Security\Http\Authenticator\Passport\Passport; use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
use Symfony\Component\Security\Http\Authenticator\Passport\SelfValidatingPassport; use Symfony\Component\Security\Http\Authenticator\Passport\SelfValidatingPassport;
use Symfony\Component\Security\Http\Event\VerifyAuthenticatorCredentialsEvent; use Symfony\Component\Security\Http\Event\CheckPassportEvent;
use Symfony\Component\Security\Http\EventListener\VerifyAuthenticatorCredentialsListener; use Symfony\Component\Security\Http\EventListener\CheckCredentialsListener;
class VerifyAuthenticatorCredentialsListenerTest extends TestCase class CheckCredentialsListenerTest extends TestCase
{ {
private $encoderFactory; private $encoderFactory;
private $listener; private $listener;
@ -33,7 +33,7 @@ class VerifyAuthenticatorCredentialsListenerTest extends TestCase
protected function setUp(): void protected function setUp(): void
{ {
$this->encoderFactory = $this->createMock(EncoderFactoryInterface::class); $this->encoderFactory = $this->createMock(EncoderFactoryInterface::class);
$this->listener = new VerifyAuthenticatorCredentialsListener($this->encoderFactory); $this->listener = new CheckCredentialsListener($this->encoderFactory);
$this->user = new User('wouter', 'encoded-password'); $this->user = new User('wouter', 'encoded-password');
} }
@ -53,7 +53,7 @@ class VerifyAuthenticatorCredentialsListenerTest extends TestCase
} }
$credentials = new PasswordCredentials($password); $credentials = new PasswordCredentials($password);
$this->listener->onAuthenticating($this->createEvent(new Passport($this->user, $credentials))); $this->listener->checkPassport($this->createEvent(new Passport($this->user, $credentials)));
if (true === $result) { if (true === $result) {
$this->assertTrue($credentials->isResolved()); $this->assertTrue($credentials->isResolved());
@ -74,7 +74,7 @@ class VerifyAuthenticatorCredentialsListenerTest extends TestCase
$this->encoderFactory->expects($this->never())->method('getEncoder'); $this->encoderFactory->expects($this->never())->method('getEncoder');
$event = $this->createEvent(new Passport($this->user, new PasswordCredentials(''))); $event = $this->createEvent(new Passport($this->user, new PasswordCredentials('')));
$this->listener->onAuthenticating($event); $this->listener->checkPassport($event);
} }
/** /**
@ -91,7 +91,7 @@ class VerifyAuthenticatorCredentialsListenerTest extends TestCase
$credentials = new CustomCredentials(function () use ($result) { $credentials = new CustomCredentials(function () use ($result) {
return $result; return $result;
}, ['password' => 'foo']); }, ['password' => 'foo']);
$this->listener->onAuthenticating($this->createEvent(new Passport($this->user, $credentials))); $this->listener->checkPassport($this->createEvent(new Passport($this->user, $credentials)));
if (true === $result) { if (true === $result) {
$this->assertTrue($credentials->isResolved()); $this->assertTrue($credentials->isResolved());
@ -109,11 +109,11 @@ class VerifyAuthenticatorCredentialsListenerTest extends TestCase
$this->encoderFactory->expects($this->never())->method('getEncoder'); $this->encoderFactory->expects($this->never())->method('getEncoder');
$event = $this->createEvent(new SelfValidatingPassport($this->user)); $event = $this->createEvent(new SelfValidatingPassport($this->user));
$this->listener->onAuthenticating($event); $this->listener->checkPassport($event);
} }
private function createEvent($passport) private function createEvent($passport)
{ {
return new VerifyAuthenticatorCredentialsEvent($this->createMock(AuthenticatorInterface::class), $passport); return new CheckPassportEvent($this->createMock(AuthenticatorInterface::class), $passport);
} }
} }

View File

@ -19,7 +19,7 @@ use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface; use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface;
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\CsrfTokenBadge; use Symfony\Component\Security\Http\Authenticator\Passport\Badge\CsrfTokenBadge;
use Symfony\Component\Security\Http\Authenticator\Passport\SelfValidatingPassport; use Symfony\Component\Security\Http\Authenticator\Passport\SelfValidatingPassport;
use Symfony\Component\Security\Http\Event\VerifyAuthenticatorCredentialsEvent; use Symfony\Component\Security\Http\Event\CheckPassportEvent;
use Symfony\Component\Security\Http\EventListener\CsrfProtectionListener; use Symfony\Component\Security\Http\EventListener\CsrfProtectionListener;
class CsrfProtectionListenerTest extends TestCase class CsrfProtectionListenerTest extends TestCase
@ -38,7 +38,7 @@ class CsrfProtectionListenerTest extends TestCase
$this->csrfTokenManager->expects($this->never())->method('isTokenValid'); $this->csrfTokenManager->expects($this->never())->method('isTokenValid');
$event = $this->createEvent($this->createPassport(null)); $event = $this->createEvent($this->createPassport(null));
$this->listener->verifyCredentials($event); $this->listener->checkPassport($event);
} }
public function testValidCsrfToken() public function testValidCsrfToken()
@ -49,7 +49,7 @@ class CsrfProtectionListenerTest extends TestCase
->willReturn(true); ->willReturn(true);
$event = $this->createEvent($this->createPassport(new CsrfTokenBadge('authenticator_token_id', 'abc123'))); $event = $this->createEvent($this->createPassport(new CsrfTokenBadge('authenticator_token_id', 'abc123')));
$this->listener->verifyCredentials($event); $this->listener->checkPassport($event);
$this->expectNotToPerformAssertions(); $this->expectNotToPerformAssertions();
} }
@ -65,12 +65,12 @@ class CsrfProtectionListenerTest extends TestCase
->willReturn(false); ->willReturn(false);
$event = $this->createEvent($this->createPassport(new CsrfTokenBadge('authenticator_token_id', 'abc123'))); $event = $this->createEvent($this->createPassport(new CsrfTokenBadge('authenticator_token_id', 'abc123')));
$this->listener->verifyCredentials($event); $this->listener->checkPassport($event);
} }
private function createEvent($passport) private function createEvent($passport)
{ {
return new VerifyAuthenticatorCredentialsEvent($this->createMock(AuthenticatorInterface::class), $passport); return new CheckPassportEvent($this->createMock(AuthenticatorInterface::class), $passport);
} }
private function createPassport(?CsrfTokenBadge $badge) private function createPassport(?CsrfTokenBadge $badge)

View File

@ -20,8 +20,8 @@ use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface;
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\PreAuthenticatedUserBadge; use Symfony\Component\Security\Http\Authenticator\Passport\Badge\PreAuthenticatedUserBadge;
use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface; use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface;
use Symfony\Component\Security\Http\Authenticator\Passport\SelfValidatingPassport; use Symfony\Component\Security\Http\Authenticator\Passport\SelfValidatingPassport;
use Symfony\Component\Security\Http\Event\CheckPassportEvent;
use Symfony\Component\Security\Http\Event\LoginSuccessEvent; use Symfony\Component\Security\Http\Event\LoginSuccessEvent;
use Symfony\Component\Security\Http\Event\VerifyAuthenticatorCredentialsEvent;
use Symfony\Component\Security\Http\EventListener\UserCheckerListener; use Symfony\Component\Security\Http\EventListener\UserCheckerListener;
class UserCheckerListenerTest extends TestCase class UserCheckerListenerTest extends TestCase
@ -41,44 +41,44 @@ class UserCheckerListenerTest extends TestCase
{ {
$this->userChecker->expects($this->once())->method('checkPreAuth')->with($this->user); $this->userChecker->expects($this->once())->method('checkPreAuth')->with($this->user);
$this->listener->preCredentialsVerification($this->createVerifyAuthenticatorCredentialsEvent()); $this->listener->preCheckCredentials($this->createCheckPassportEvent());
} }
public function testPreAuthNoUser() public function testPreAuthNoUser()
{ {
$this->userChecker->expects($this->never())->method('checkPreAuth'); $this->userChecker->expects($this->never())->method('checkPreAuth');
$this->listener->preCredentialsVerification($this->createVerifyAuthenticatorCredentialsEvent($this->createMock(PassportInterface::class))); $this->listener->preCheckCredentials($this->createCheckPassportEvent($this->createMock(PassportInterface::class)));
} }
public function testPreAuthenticatedBadge() public function testPreAuthenticatedBadge()
{ {
$this->userChecker->expects($this->never())->method('checkPreAuth'); $this->userChecker->expects($this->never())->method('checkPreAuth');
$this->listener->preCredentialsVerification($this->createVerifyAuthenticatorCredentialsEvent(new SelfValidatingPassport($this->user, [new PreAuthenticatedUserBadge()]))); $this->listener->preCheckCredentials($this->createCheckPassportEvent(new SelfValidatingPassport($this->user, [new PreAuthenticatedUserBadge()])));
} }
public function testPostAuthValidCredentials() public function testPostAuthValidCredentials()
{ {
$this->userChecker->expects($this->once())->method('checkPostAuth')->with($this->user); $this->userChecker->expects($this->once())->method('checkPostAuth')->with($this->user);
$this->listener->postCredentialsVerification($this->createLoginSuccessEvent()); $this->listener->postCheckCredentials($this->createLoginSuccessEvent());
} }
public function testPostAuthNoUser() public function testPostAuthNoUser()
{ {
$this->userChecker->expects($this->never())->method('checkPostAuth'); $this->userChecker->expects($this->never())->method('checkPostAuth');
$this->listener->postCredentialsVerification($this->createLoginSuccessEvent($this->createMock(PassportInterface::class))); $this->listener->postCheckCredentials($this->createLoginSuccessEvent($this->createMock(PassportInterface::class)));
} }
private function createVerifyAuthenticatorCredentialsEvent($passport = null) private function createCheckPassportEvent($passport = null)
{ {
if (null === $passport) { if (null === $passport) {
$passport = new SelfValidatingPassport($this->user); $passport = new SelfValidatingPassport($this->user);
} }
return new VerifyAuthenticatorCredentialsEvent($this->createMock(AuthenticatorInterface::class), $passport); return new CheckPassportEvent($this->createMock(AuthenticatorInterface::class), $passport);
} }
private function createLoginSuccessEvent($passport = null) private function createLoginSuccessEvent($passport = null)