10000 bug #43146 [SecurityBundle] Fixed LogicException message of FirewallA… · symfony/symfony@4a54875 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4a54875

Browse files
committed
bug #43146 [SecurityBundle] Fixed LogicException message of FirewallAwareTrait (fkropfhamer)
This PR was submitted for the 5.4 branch but it was squashed and merged into the 5.3 branch instead. Discussion ---------- [SecurityBundle] Fixed LogicException message of FirewallAwareTrait | Q | A | ------------- | --- | Branch? | 5.4 for features / 4.4 or 5.3 for bug fixes <!-- see below --> | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #43145 <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> <!-- Replace this notice by a short README for your feature/bugfix. This will help people understand your PR and can be used as a start for the documentation. Additionally (see https://symfony.com/releases): - Always add tests and ensure they pass. - Never break backward compatibility (see https://symfony.com/bc). - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too.) - Features and deprecations must be submitted against branch 5.x. - Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry --> Commits ------- d93da59 [SecurityBundle] Fixed LogicException message of FirewallAwareTrait
2 parents a990843 + d93da59 commit 4a54875

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/Symfony/Bundle/SecurityBundle/Security/FirewallAwareTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ private function getForFirewall(): object
2929
{
3030
$serviceIdentifier = str_replace('FirewallAware', '', static::class);
3131
if (null === $request = $this->requestStack->getCurrentRequest()) {
32-
throw new \LogicException('Cannot determine the correct '.$serviceIdentifier.' to use: there is no active Request and so, the firewall cannot be determined. Try using a specific '.$serviceIdentifier().' service.');
32+
throw new \LogicException('Cannot determine the correct '.$serviceIdentifier.' to use: there is no active Request and so, the firewall cannot be determined. Try using a specific '.$serviceIdentifier.' service.');
3333
}
3434

3535
$firewall = $this->firewallMap->getFirewallConfig($request);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Symfony\Bundle\SecurityBundle\Tests\Security;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Symfony\Bundle\SecurityBundle\Security\FirewallMap;
7+
use Symfony\Bundle\SecurityBundle\Security\UserAuthenticator;
8+
use Symfony\Component\DependencyInjection\Container;
9+
use Symfony\Component\HttpFoundation\Request;
10+
use Symfony\Component\HttpFoundation\RequestStack;
11+
use Symfony\Component\Security\Core\User\InMemoryUser;
12+
use Symfony\Component\Security\Core\User\InMemoryUserProvider;
13+
use Symfony\Component\Security\Http\Authenticator\HttpBasicAuthenticator;
14+
15+
class UserAuthenticatorTest extends TestCase
16+
{
17+
public function testThrowsLogicExceptionIfCurrentRequestIsNull()
18+
{
19+
$container = new Container();
20+
$firewallMap = new FirewallMap($container, []);
21+
$requestStack = new RequestStack();
22+
$user = new InMemoryUser('username', 'password');
23+
$userProvider = new InMemoryUserProvider();
24+
$authenticator = new HttpBasicAuthenticator('name', $userProvider);
25+
$request = new Request();
26+
27+
$userAuthenticator = new UserAuthenticator($firewallMap, $container, $requestStack);
28+
29+
$this->expectException(\LogicException::class);
30+
$this->expectExceptionMessage('Cannot determine the correct Symfony\Bundle\SecurityBundle\Security\UserAuthenticator to use: there is no active Request and so, the firewall cannot be determined. Try using a specific Symfony\Bundle\SecurityBundle\Security\UserAuthenticator service.');
31+
32+
$userAuthenticator->authenticateUser($user, $authenticator, $request);
33+
}
34+
}

0 commit comments

Comments
 (0)
0