Skip to content

Commit

Permalink
[SecurityBundle] Fixed LogicException message of FirewallAwareTrait
Browse files Browse the repository at this point in the history
  • Loading branch information
fkropfhamer authored and fabpot committed Sep 26, 2021
1 parent aed98f8 commit b755ed5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Security/FirewallAwareTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private function getForFirewall(): object
{
$serviceIdentifier = str_replace('FirewallAware', '', static::class);
if (null === $request = $this->requestStack->getCurrentRequest()) {
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.');
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.');
}

$firewall = $this->firewallMap->getFirewallConfig($request);
Expand Down
34 changes: 34 additions & 0 deletions Tests/Security/UserAuthenticatorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Symfony\Bundle\SecurityBundle\Tests\Security;

use PHPUnit\Framework\TestCase;
use Symfony\Bundle\SecurityBundle\Security\FirewallMap;
use Symfony\Bundle\SecurityBundle\Security\UserAuthenticator;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Security\Core\User\InMemoryUser;
use Symfony\Component\Security\Core\User\InMemoryUserProvider;
use Symfony\Component\Security\Http\Authenticator\HttpBasicAuthenticator;

class UserAuthenticatorTest extends TestCase
{
public function testThrowsLogicExceptionIfCurrentRequestIsNull()
{
$container = new Container();
$firewallMap = new FirewallMap($container, []);
$requestStack = new RequestStack();
$user = new InMemoryUser('username', 'password');
$userProvider = new InMemoryUserProvider();
$authenticator = new HttpBasicAuthenticator('name', $userProvider);
$request = new Request();

$userAuthenticator = new UserAuthenticator($firewallMap, $container, $requestStack);

$this->expectException(\LogicException::class);
$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.');

$userAuthenticator->authenticateUser($user, $authenticator, $request);
}
}

0 comments on commit b755ed5

Please sign in to comment.