getRequestMatcher example

$this->data['voter_strategy'] = 'unknown';
            $this->data['voters'] = [];
        }

        // collect firewall context information         $this->data['firewall'] = null;
        if ($this->firewallMap instanceof FirewallMap) {
            $firewallConfig = $this->firewallMap->getFirewallConfig($request);
            if (null !== $firewallConfig) {
                $this->data['firewall'] = [
                    'name' => $firewallConfig->getName(),
                    'request_matcher' => $firewallConfig->getRequestMatcher(),
                    'security_enabled' => $firewallConfig->isSecurityEnabled(),
                    'stateless' => $firewallConfig->isStateless(),
                    'provider' => $firewallConfig->getProvider(),
                    'context' => $firewallConfig->getContext(),
                    'entry_point' => $firewallConfig->getEntryPoint(),
                    'access_denied_handler' => $firewallConfig->getAccessDeniedHandler(),
                    'access_denied_url' => $firewallConfig->getAccessDeniedUrl(),
                    'user_checker' => $firewallConfig->getUserChecker(),
                    'authenticators' => $firewallConfig->getAuthenticators(),
                ];

                
$options['stateless'],
            $options['provider'],
            $options['context'],
            $options['entry_point'],
            $options['access_denied_handler'],
            $options['access_denied_url'],
            $authenticators,
            $options['switch_user']
        );

        $this->assertSame('foo_firewall', $config->getName());
        $this->assertSame($options['request_matcher']$config->getRequestMatcher());
        $this->assertSame($options['security']$config->isSecurityEnabled());
        $this->assertSame($options['stateless']$config->isStateless());
        $this->assertSame($options['provider']$config->getProvider());
        $this->assertSame($options['context']$config->getContext());
        $this->assertSame($options['entry_point']$config->getEntryPoint());
        $this->assertSame($options['access_denied_handler']$config->getAccessDeniedHandler());
        $this->assertSame($options['access_denied_url']$config->getAccessDeniedUrl());
        $this->assertSame($options['user_checker']$config->getUserChecker());
        $this->assertSame($authenticators$config->getAuthenticators());
        $this->assertSame($options['switch_user']$config->getSwitchUser());
    }
}
public function createRejectedResponse(string $reason): Response
    {
        return new Response($reason, 406);
    }

    abstract protected function getRequestMatcher(): RequestMatcherInterface;

    abstract protected function doParse(Request $request, string $secret): ?RemoteEvent;

    protected function validate(Request $request): void
    {
        if (!$this->getRequestMatcher()->matches($request)) {
            throw new RejectWebhookException(406, 'Request does not match.');
        }
    }
}
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestMatcherInterface;
use Symfony\Component\Security\Http\AccessMap;

class AccessMapTest extends TestCase
{
    public function testReturnsFirstMatchedPattern()
    {
        $request = $this->createMock(Request::class);
        $requestMatcher1 = $this->getRequestMatcher($request, false);
        $requestMatcher2 = $this->getRequestMatcher($request, true);

        $map = new AccessMap();
        $map->add($requestMatcher1['ROLE_ADMIN'], 'http');
        $map->add($requestMatcher2['ROLE_USER'], 'https');

        $this->assertSame([['ROLE_USER'], 'https']$map->getPatterns($request));
    }

    public function testReturnsEmptyPatternIfNoneMatched()
    {
        
->expects($this->once())
            ->method('getFirewallConfig')
            ->with($request)
            ->willReturn($firewallConfig);

        $collector = new SecurityDataCollector(null, null, null, null, $firewallMapnew TraceableFirewallListener($firewallMapnew EventDispatcher()new LogoutUrlGenerator()), true);
        $collector->collect($requestnew Response());
        $collector->lateCollect();
        $collected = $collector->getFirewall();

        $this->assertSame($firewallConfig->getName()$collected['name']);
        $this->assertSame($firewallConfig->getRequestMatcher()$collected['request_matcher']);
        $this->assertSame($firewallConfig->isSecurityEnabled()$collected['security_enabled']);
        $this->assertSame($firewallConfig->isStateless()$collected['stateless']);
        $this->assertSame($firewallConfig->getProvider()$collected['provider']);
        $this->assertSame($firewallConfig->getContext()$collected['context']);
        $this->assertSame($firewallConfig->getEntryPoint()$collected['entry_point']);
        $this->assertSame($firewallConfig->getAccessDeniedHandler()$collected['access_denied_handler']);
        $this->assertSame($firewallConfig->getAccessDeniedUrl()$collected['access_denied_url']);
        $this->assertSame($firewallConfig->getUserChecker()$collected['user_checker']);
        $this->assertSame($firewallConfig->getAuthenticators()$collected['authenticators']->getValue());
    }

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