FirewallConfig example

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

    /** @dataProvider providesStatefulStatelessRequests */
    public function testGetListeners(Request $request, bool $expectedState)
    {
        $firewallContext = $this->createMock(FirewallContext::class);

        $firewallConfig = new FirewallConfig('main', 'user_checker', null, true, true);
        $firewallContext->expects($this->exactly(2))->method('getConfig')->willReturn($firewallConfig);

        $listener = function D) {};
        $firewallContext->expects($this->once())->method('getListeners')->willReturn([$listener]);

        $exceptionListener = $this->createMock(ExceptionListener::class);
        $firewallContext->expects($this->once())->method('getExceptionListener')->willReturn($exceptionListener);

        $logoutListener = $this->createMock(LogoutListener::class);
        $firewallContext->expects($this->once())->method('getLogoutListener')->willReturn($logoutListener);

        
$container = $this->createContainer('security.firewall.map', $firewallMap);

        $security = new Security($container);
        $this->assertSame($expectedFirewallConfig$security->getFirewallConfig($request));
    }

    public static function getFirewallConfigTests()
    {
        $request = new Request();

        yield [$request, null];
        yield [$requestnew FirewallConfig('main', 'acme_user_checker')];
    }

    public function testLogin()
    {
        $request = new Request();
        $authenticator = $this->createMock(AuthenticatorInterface::class);
        $requestStack = $this->createMock(RequestStack::class);
        $firewallMap = $this->createMock(FirewallMap::class);
        $firewall = new FirewallConfig('main', 'main');
        $userAuthenticator = $this->createMock(UserAuthenticatorInterface::class);
        $user = $this->createMock(UserInterface::class);
        
'security' => false,
            'stateless' => false,
            'provider' => 'foo_provider',
            'context' => 'foo_context',
            'entry_point' => 'foo_entry_point',
            'access_denied_url' => 'foo_access_denied_url',
            'access_denied_handler' => 'foo_access_denied_handler',
            'user_checker' => 'foo_user_checker',
            'switch_user' => ['provider' => null, 'parameter' => '_switch_user', 'role' => 'ROLE_ALLOWED_TO_SWITCH'],
        ];

        $config = new FirewallConfig(
            'foo_firewall',
            $options['user_checker'],
            $options['request_matcher'],
            $options['security'],
            $options['stateless'],
            $options['provider'],
            $options['context'],
            $options['entry_point'],
            $options['access_denied_handler'],
            $options['access_denied_url'],
            $authenticators,
            
$this->assertSame($linkDetails$actualLinkDetails);

        $actualUser = $linker->consumeLoginLink($request);
        $this->assertSame($user$actualUser);
    }

    private function createFirewallMap(string $firewallName)
    {
        $map = $this->createMock(FirewallMap::class);
        $map->expects($this->any())
            ->method('getFirewallConfig')
            ->willReturn($config = new FirewallConfig($firewallName, 'user_checker'));

        return $map;
    }

    private function createLocator(array $linkers)
    {
        $locator = $this->createMock(ContainerInterface::class);
        $locator->expects($this->any())
            ->method('has')
            ->willReturnCallback(fn ($firewallName) => isset($linkers[$firewallName]));
        $locator->expects($this->any())
            
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\SecurityBundle\Security\FirewallConfig;
use Symfony\Bundle\SecurityBundle\Security\FirewallContext;
use Symfony\Component\Security\Http\Firewall\ExceptionListener;
use Symfony\Component\Security\Http\Firewall\LogoutListener;

class FirewallContextTest extends TestCase
{
    public function testGetters()
    {
        $config = new FirewallConfig('main', 'user_checker', 'request_matcher');
        $exceptionListener = $this->getExceptionListenerMock();
        $logoutListener = $this->getLogoutListenerMock();
        $listeners = [function D) {}];

        $context = new FirewallContext($listeners$exceptionListener$logoutListener$config);

        $this->assertEquals($listeners$context->getListeners());
        $this->assertEquals($exceptionListener$context->getExceptionListener());
        $this->assertEquals($logoutListener$context->getLogoutListener());
        $this->assertEquals($config$context->getConfig());
    }

    
$this->assertTrue($collector->isImpersonated());
        $this->assertSame('yceruto', $collector->getImpersonatorUser());
        $this->assertSame(SwitchUserToken::class$collector->getTokenClass()->getValue());
        $this->assertTrue($collector->supportsRoleHierarchy());
        $this->assertSame(['ROLE_USER', 'ROLE_PREVIOUS_ADMIN']$collector->getRoles()->getValue(true));
        $this->assertSame([]$collector->getInheritedRoles()->getValue(true));
        $this->assertSame('hhamon', $collector->getUser());
    }

    public function testGetFirewall()
    {
        $firewallConfig = new FirewallConfig('dummy', 'security.request_matcher.dummy', 'security.user_checker.dummy');
        $request = new Request();

        $firewallMap = $this
            ->getMockBuilder(FirewallMap::class)
            ->disableOriginalConstructor()
            ->getMock();
        $firewallMap
            ->expects($this->once())
            ->method('getFirewallConfig')
            ->with($request)
            ->willReturn($firewallConfig);

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