8000 minor #49938 [Security] Improve DX when invalid custom authenticators… · weaverryan/symfony@cf5f103 · GitHub
[go: up one dir, main page]

Skip to content

Commit cf5f103

Browse files
minor symfony#49938 [Security] Improve DX when invalid custom authenticators (alamirault)
This PR was squashed before being merged into the 6.3 branch. Discussion ---------- [Security] Improve DX when invalid custom authenticators | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead --> | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> Before this PR error was ```yaml security: firewalls: main: lazy: true provider: users_in_memory custom_authenticators: - App\Security\FooProvider # Mistake is here, must be an AuthenticatorInterface ``` ![image](https://user-images.githubusercontent.com/9253091/230036405-e6be6a7e-b05d-40ad-8155-113634f7e341.png) Commits ------- 93cc075 [Security] Improve DX when invalid custom authenticators
2 parents 92e213e + 93cc075 commit cf5f103

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/Symfony/Component/Security/Http/Authentication/AuthenticatorManager.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ public function supports(Request $request): ?bool
104104
foreach ($this->authenticators as $authenticator) {
105105
$this->logger?->debug('Checking support on authenticator.', ['firewall_name' => $this->firewallName, 'authenticator' => $authenticator::class]);
106106

107+
if (!$authenticator instanceof AuthenticatorInterface) {
108+
throw new \InvalidArgumentException(sprintf('Authenticator "%s" must implement "%s".', get_debug_type($authenticator), AuthenticatorInterface::class));
109+
}
110+
107111
if (false !== $supports = $authenticator->supports($request)) {
108112
$authenticators[] = $authenticator;
109113
$lazy = $lazy && null === $supports;

src/Symfony/Component/Security/Http/Tests/Authentication/AuthenticatorManagerTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@ public static function provideSupportsData()
7777
yield [[], false];
7878
}
7979

80+
public function testSupportsInvalidAuthenticator()
81+
{
82+
$manager = $this->createManager([new \stdClass()]);
83+
84+
$this->expectExceptionObject(
85+
new \InvalidArgumentException('Authenticator "stdClass" must implement "Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface".')
86+
);
87+
88+
$manager->supports($this->request);
89+
}
90+
8091
public function testSupportCheckedUponRequestAuthentication()
8192
{
8293
// the attribute stores the supported authenticators, returning false now

0 commit comments

Comments
 (0)
0