diff options
author | Ryan Weaver <ryan@thatsquality.com> | 2016-04-27 12:48:29 -0400 |
---|---|---|
committer | Ryan Weaver <ryan@thatsquality.com> | 2016-04-27 12:48:29 -0400 |
commit | b96b7f3b0b23d4ccef0c9dfba1c2064378d6c9fc (patch) | |
tree | 626cc660986797208d3ea6f50f6a589d202125ce | |
parent | b83c13f9631a3ed5ce79975956eb15625c756f80 (diff) | |
download | symfony-security-b96b7f3b0b23d4ccef0c9dfba1c2064378d6c9fc.zip symfony-security-b96b7f3b0b23d4ccef0c9dfba1c2064378d6c9fc.tar.gz symfony-security-b96b7f3b0b23d4ccef0c9dfba1c2064378d6c9fc.tar.bz2 |
Updating the error message of an AuthenticationEntryPointInterface returns a non-Response object
-rw-r--r-- | Http/Firewall/ExceptionListener.php | 10 | ||||
-rw-r--r-- | Http/Tests/Firewall/ExceptionListenerTest.php | 14 |
2 files changed, 23 insertions, 1 deletions
diff --git a/Http/Firewall/ExceptionListener.php b/Http/Firewall/ExceptionListener.php index 2804d0e..98f5ac0 100644 --- a/Http/Firewall/ExceptionListener.php +++ b/Http/Firewall/ExceptionListener.php @@ -203,7 +203,15 @@ class ExceptionListener } } - return $this->authenticationEntryPoint->start($request, $authException); + $response = $this->authenticationEntryPoint->start($request, $authException); + + if (!$response instanceof Response) { + $given = is_object($response) ? get_class($response) : gettype($response); + + throw new \LogicException(sprintf('The %s::start() method must return a Response object (%s returned)', get_class($this->authenticationEntryPoint), $given)); + } + + return $response; } /** diff --git a/Http/Tests/Firewall/ExceptionListenerTest.php b/Http/Tests/Firewall/ExceptionListenerTest.php index 3d409e5..db0a242 100644 --- a/Http/Tests/Firewall/ExceptionListenerTest.php +++ b/Http/Tests/Firewall/ExceptionListenerTest.php @@ -65,6 +65,20 @@ class ExceptionListenerTest extends \PHPUnit_Framework_TestCase ); } + public function testExceptionWhenEntryPointReturnsBadValue() + { + $event = $this->createEvent(new AuthenticationException()); + + $entryPoint = $this->getMock('Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface'); + $entryPoint->expects($this->once())->method('start')->will($this->returnValue('NOT A RESPONSE')); + + $listener = $this->createExceptionListener(null, null, null, $entryPoint); + $listener->onKernelException($event); + // the exception has been replaced by our LogicException + $this->assertInstanceOf('LogicException', $event->getException()); + $this->assertStringEndsWith('start() method must return a Response object (string returned)', $event->getException()->getMessage()); + } + /** * @dataProvider getAccessDeniedExceptionProvider */ |