Skip to content

Commit 81137ea

Browse files
committed
minor #39630 [Security] Add test to ensure all security events are propagated (scheb)
This PR was merged into the 5.1 branch. Discussion ---------- [Security] Add test to ensure all security events are propagated | Q | A | ------------- | --- | Branch? | 5.1 | Bug fix? | no | New feature? | no | Deprecations? | no | License | MIT Follow-up to #39621. As requested by @wouterj I'm adding a dedicated test case to ensure the security events are propagated from global to firewall-level event dispatcher. I'll file another PR to add `AuthenticationTokenCreatedEvent` as soon as this has been merged and copied to the 5.2 branch, that I need to target for the `AuthenticationTokenCreatedEvent` change. Happy holidays! Commits ------- e78adf7604 Add test case to ensure all security events are propagated
2 parents 305edfa + f329c0d commit 81137ea

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

Tests/DependencyInjection/Compiler/RegisterGlobalSecurityEventListenersPassTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@
2020
use Symfony\Component\EventDispatcher\EventDispatcher;
2121
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
2222
use Symfony\Component\Security\Core\AuthenticationEvents;
23+
use Symfony\Component\Security\Core\Event\AuthenticationSuccessEvent;
2324
use Symfony\Component\Security\Http\Event\CheckPassportEvent;
25+
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
26+
use Symfony\Component\Security\Http\Event\LoginFailureEvent;
2427
use Symfony\Component\Security\Http\Event\LoginSuccessEvent;
2528
use Symfony\Component\Security\Http\Event\LogoutEvent;
29+
use Symfony\Component\Security\Http\SecurityEvents;
2630

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

52+
/**
53+
* @dataProvider providePropagatedEvents
54+
*/
55+
public function testEventIsPropagated(string $configuredEvent, string $registeredEvent)
56+
{
57+
$this->container->loadFromExtension('security', [
58+
'enable_authenticator_manager' => true,
59+
'firewalls' => ['main' => ['pattern' => '/', 'http_basic' => true]],
60+
]);
61+
62+
$this->container->register('app.security_listener', \stdClass::class)
63+
->addTag('kernel.event_listener', ['method' => 'onEvent', 'event' => $configuredEvent]);
64+
65+
$this->container->compile();
66+
67+
$this->assertListeners([
68+
[$registeredEvent, ['app.security_listener', 'onEvent'], 0],
69+
]);
70+
}
71+
72+
public function providePropagatedEvents(): array
73+
{
74+
return [
75+
[CheckPassportEvent::class, CheckPassportEvent::class],
76+
[LoginFailureEvent::class, LoginFailureEvent::class],
77+
[LoginSuccessEvent::class, LoginSuccessEvent::class],
78+
[LogoutEvent::class, LogoutEvent::class],
79+
[AuthenticationEvents::AUTHENTICATION_SUCCESS, AuthenticationEvents::AUTHENTICATION_SUCCESS],
80+
[SecurityEvents::INTERACTIVE_LOGIN, SecurityEvents::INTERACTIVE_LOGIN],
81+
82+
// These events are ultimately registered by their event name instead of the FQN
83+
[AuthenticationSuccessEvent::class, AuthenticationEvents::AUTHENTICATION_SUCCESS],
84+
[InteractiveLoginEvent::class, SecurityEvents::INTERACTIVE_LOGIN],
85+
];
86+
}
87+
4888
public function testRegisterCustomListener()
4989
{
5090
$this->container->loadFromExtension('security', [

0 commit comments

Comments
 (0)