8000 minor #48212 [Security] Improve `LogoutUrlGenerator` exception messag… · symfony/symfony@631673c · GitHub
[go: up one dir, main page]

Skip to content

Commit 631673c

Browse files
committed
minor #48212 [Security] Improve LogoutUrlGenerator exception message (alamirault)
This PR was squashed before being merged into the 6.2 branch. Discussion ---------- [Security] Improve `LogoutUrlGenerator` exception message | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | yes <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #45913 <!-- 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 --> With this PR, exception message is different when request is under firewall or not, as suggested in #45913 (comment) Commits ------- 59187f2 [Security] Improve `LogoutUrlGenerator` exception message
2 parents ececb2a + 59187f2 commit 631673c

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/Symfony/Component/Security/Http/Logout/LogoutUrlGenerator.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ private function getListener(?string $key): array
151151
}
152152
}
153153

154-
throw new \InvalidArgumentException('Unable to find the current firewall LogoutListener, please provide the provider key manually.');
154+
if (null === $this->currentFirewallName) {
155+
throw new \InvalidArgumentException('This request is not behind a firewall, pass the firewall name manually to generate a logout URL.');
156+
}
157+
158+
throw new \InvalidArgumentException('Unable to find logout in the current firewall, pass the firewall name manually to generate a logout URL.');
155159
}
156160
}

src/Symfony/Component/Security/Http/Tests/Logout/LogoutUrlGeneratorTest.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,22 @@ public function testGuessFromTokenWithoutFirewallNameFallbacksToCurrentFirewall(
8888
$this->assertSame('/logout', $this->generator->getLogoutPath());
8989
}
9090

91-
public function testUnableToGuessThrowsException()
91+
public function testUnableToGuessWithoutCurrentFirewallThrowsException()
9292
{
9393
$this->expectException(\InvalidArgumentException::class);
94-
$this->expectExceptionMessage('Unable to find the current firewall LogoutListener, please provide the provider key manually');
94+
$this->expectExceptionMessage('This request is not behind a firewall, pass the firewall name manually to generate a logout URL.');
9595
$this->generator->registerListener('secured_area', '/logout', null, null);
9696

9797
$this->generator->getLogoutPath();
9898
}
99+
100+
public function testUnableToGuessWithCurrentFirewallThrowsException()
101+
{
102+
$this->expectException(\InvalidArgumentException::class);
103+
$this->expectExceptionMessage('Unable to find logout in the current firewall, pass the firewall name manually to generate a logout URL.');
104+
$this->generator->registerListener('secured_area', '/logout', null, null);
105+
$this->generator->setCurrentFirewall('admin');
106+
107+
$this->generator->getLogoutPath();
108+
}
99109
}

0 commit comments

Comments
 (0)
0