FirewallMap example

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.');

        

    private const ATTRIBUTE_FIREWALL_CONTEXT = '_firewall_context';

    public function testGetListenersWithEmptyMap()
    {
        $request = new Request();

        $map = [];
        $container = $this->createMock(Container::class);
        $container->expects($this->never())->method('get');

        $firewallMap = new FirewallMap($container$map);

        $this->assertEquals([[], null, null]$firewallMap->getListeners($request));
        $this->assertNull($firewallMap->getFirewallConfig($request));
        $this->assertFalse($request->attributes->has(self::ATTRIBUTE_FIREWALL_CONTEXT));
    }

    public function testGetListenersWithInvalidParameter()
    {
        $request = new Request();
        $request->attributes->set(self::ATTRIBUTE_FIREWALL_CONTEXT, 'foo');

        
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestMatcherInterface;
use Symfony\Component\Security\Http\Firewall\ExceptionListener;
use Symfony\Component\Security\Http\FirewallMap;

class FirewallMapTest extends TestCase
{
    public function testGetListeners()
    {
        $map = new FirewallMap();

        $request = new Request();

        $notMatchingMatcher = $this->createMock(RequestMatcherInterface::class);
        $notMatchingMatcher
            ->expects($this->once())
            ->method('matches')
            ->with($this->equalTo($request))
            ->willReturn(false)
        ;

        
Home | Imprint | This part of the site doesn't use cookies.