+
+ public function testCSPHeaderIsRemoved()
+ {
+ $dispatcher = new EventDispatcher();
+ $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
+ $kernel->expects($this->once())->method('handle')->will($this->returnCallback(function (Request $request) {
+ return new Response($request->getRequestFormat());
+ }));
+
+ $listener = new ExceptionListener('foo', $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock(), true);
+
+ $dispatcher->addSubscriber($listener);
+
+ $request = Request::create('/');
+ $event = new GetResponseForExceptionEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, new \Exception('foo'));
+ $dispatcher->dispatch(KernelEvents::EXCEPTION, $event);
+
+ $response = new Response('', 200, array('content-security-policy' => "style-src 'self'"));
+ $this->assertTrue($response->headers->has('content-security-policy'));
+
+ $event = new FilterResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response);
+ $dispatcher->dispatch(KernelEvents::RESPONSE, $event);
+
+ $this->assertFalse($response->headers->has('content-security-policy'), 'CSP header has been removed');
+ $this->assertFalse($dispatcher->hasListeners(KernelEvents::RESPONSE), 'CSP removal listener has been removed');
+ }
+
+ public function testNullController()
+ {
+ $listener = new ExceptionListener(null);
+ $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
+ $kernel->expects($this->once())->method('handle')->will($this->returnCallback(function (Request $request) {
+ $controller = $request->attributes->get('_controller');
+
+ return $controller();
+ }));
+ $request = Request::create('/');
+ $event = new GetResponseForExceptionEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, new \Exception('foo'));
+
+ $listener->onKernelException($event);
+
+ $this->assertContains('Whoops, looks like something went wrong.', $event->getResponse()->getContent());
+ }