8000 [Security] Improve `LogoutUrlGenerator` exception message · symfony/symfony@59187f2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 59187f2

Browse files
alamiraultfabpot
authored andcommitted
[Security] Improve LogoutUrlGenerator exception message
1 parent ac88f9a commit 59187f2

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