bug #14346 [WebProfilerBundle] Fix resiliency to exceptions thrown by the url generator (nicolas-grekas)
This PR was merged into the 2.6 branch.
Discussion
----------
[WebProfilerBundle] Fix resiliency to exceptions thrown by the url generator
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #14111, #14337, #14342 in conjunction with #14345
| License | MIT
| Doc PR | -
Commits
-------
92e33e4
[WebProfilerBundle] Fix resiliency to exceptions thrown by the url generator
This commit is contained in:
commit
eb2ff793e8
@ -61,10 +61,14 @@ class WebDebugToolbarListener implements EventSubscriberInterface
|
||||
$request = $event->getRequest();
|
||||
|
||||
if ($response->headers->has('X-Debug-Token') && null !== $this->urlGenerator) {
|
||||
try {
|
||||
$response->headers->set(
|
||||
'X-Debug-Token-Link',
|
||||
$this->urlGenerator->generate('_profiler', array('token' => $response->headers->get('X-Debug-Token')))
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
$response->headers->set('X-Debug-Error', get_class($e).': '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
if (!$event->isMasterRequest()) {
|
||||
|
@ -206,6 +206,27 @@ class WebDebugToolbarListenerTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals('/_profiler/xxxxxxxx', $response->headers->get('X-Debug-Token-Link'));
|
||||
}
|
||||
|
||||
public function testThrowingUrlGenerator()
|
||||
{
|
||||
$response = new Response();
|
||||
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
|
||||
|
||||
$urlGenerator = $this->getUrlGeneratorMock();
|
||||
$urlGenerator
|
||||
->expects($this->once())
|
||||
->method('generate')
|
||||
->with('_profiler', array('token' => 'xxxxxxxx'))
|
||||
->will($this->throwException(new \Exception('foo')))
|
||||
;
|
||||
|
||||
$event = new FilterResponseEvent($this->getKernelMock(), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response);
|
||||
|
||||
$listener = new WebDebugToolbarListener($this->getTwigMock(), false, WebDebugToolbarListener::ENABLED, 'bottom', $urlGenerator);
|
||||
$listener->onKernelResponse($event);
|
||||
|
||||
$this->assertEquals('Exception: foo', $response->headers->get('X-Debug-Error'));
|
||||
}
|
||||
|
||||
protected function getRequestMock($isXmlHttpRequest = false, $requestFormat = 'html', $hasSession = true)
|
||||
{
|
||||
$request = $this->getMock(
|
||||
|
Reference in New Issue
Block a user