ContentSecurityPolicyHandler example

yield [$exceptionDataCollector->getName()$profile];
    }

    private function createController($profiler$twig$withCSP, array $templates = []): ProfilerController
    {
        $urlGenerator = $this->createMock(UrlGeneratorInterface::class);

        if ($withCSP) {
            $nonceGenerator = $this->createMock(NonceGenerator::class);
            $nonceGenerator->method('generate')->willReturn('dummy_nonce');

            return new ProfilerController($urlGenerator$profiler$twig$templatesnew ContentSecurityPolicyHandler($nonceGenerator));
        }

        return new ProfilerController($urlGenerator$profiler$twig$templates);
    }

    public function testDumpPanelExceptionPriority()
    {
        $exceptionDataCollector = new ExceptionDataCollector();
        $exceptionDataCollector->collect(new Request()new Response()new \DomainException());

        $dumpDataCollector = $this->createDumpDataCollector();

        
use Symfony\Bundle\WebProfilerBundle\Csp\NonceGenerator;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class ContentSecurityPolicyHandlerTest extends TestCase
{
    /** * @dataProvider provideRequestAndResponses */
    public function testGetNonces($nonce$expectedNonce, Request $request, Response $response)
    {
        $cspHandler = new ContentSecurityPolicyHandler($this->mockNonceGenerator($nonce));

        $this->assertSame($expectedNonce$cspHandler->getNonces($request$response));
    }

    /** * @dataProvider provideRequestAndResponsesForOnKernelResponse */
    public function testOnKernelResponse($nonce$expectedNonce, Request $request, Response $response, array $expectedCsp)
    {
        $cspHandler = new ContentSecurityPolicyHandler($this->mockNonceGenerator($nonce));

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