Skip to content

[Security] Add test to ensure all security events are propagated #39630

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Core\AuthenticationEvents;
use Symfony\Component\Security\Core\Event\AuthenticationSuccessEvent;
use Symfony\Component\Security\Http\Event\CheckPassportEvent;
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
use Symfony\Component\Security\Http\Event\LoginFailureEvent;
use Symfony\Component\Security\Http\Event\LoginSuccessEvent;
use Symfony\Component\Security\Http\Event\LogoutEvent;
use Symfony\Component\Security\Http\SecurityEvents;

class RegisterGlobalSecurityEventListenersPassTest extends TestCase
{
Expand All @@ -45,6 +49,42 @@ protected function setUp(): void
$securityBundle->build($this->container);
}

/**
* @dataProvider providePropagatedEvents
*/
public function testEventIsPropagated(string $configuredEvent, string $registeredEvent)
{
$this->container->loadFromExtension('security', [
'enable_authenticator_manager' => true,
'firewalls' => ['main' => ['pattern' => '/', 'http_basic' => true]],
]);

$this->container->register('app.security_listener', \stdClass::class)
->addTag('kernel.event_listener', ['method' => 'onEvent', 'event' => $configuredEvent]);

$this->container->compile();

$this->assertListeners([
[$registeredEvent, ['app.security_listener', 'onEvent'], 0],
]);
}

public function providePropagatedEvents(): array
{
return [
[CheckPassportEvent::class, CheckPassportEvent::class],
[LoginFailureEvent::class, LoginFailureEvent::class],
[LoginSuccessEvent::class, LoginSuccessEvent::class],
[LogoutEvent::class, LogoutEvent::class],
[AuthenticationEvents::AUTHENTICATION_SUCCESS, AuthenticationEvents::AUTHENTICATION_SUCCESS],
[SecurityEvents::INTERACTIVE_LOGIN, SecurityEvents::INTERACTIVE_LOGIN],

// These events are ultimately registered by their event name instead of the FQN
[AuthenticationSuccessEvent::class, AuthenticationEvents::AUTHENTICATION_SUCCESS],
[InteractiveLoginEvent::class, SecurityEvents::INTERACTIVE_LOGIN],
];
}

public function testRegisterCustomListener()
{
$this->container->loadFromExtension('security', [
Expand Down