summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabien Potencier <fabien.potencier@gmail.com>2016-04-28 16:41:32 +0200
committerFabien Potencier <fabien.potencier@gmail.com>2016-04-28 16:41:32 +0200
commit76ff659b146558af0a17c9c08511dc0edfd79def (patch)
tree67e7f91fac713db78f3fe01afc206c20a0df540d
parentd74a6d51327ca44da913e226ae3b1b44c7bc270d (diff)
parentb96b7f3b0b23d4ccef0c9dfba1c2064378d6c9fc (diff)
downloadsymfony-security-76ff659b146558af0a17c9c08511dc0edfd79def.zip
symfony-security-76ff659b146558af0a17c9c08511dc0edfd79def.tar.gz
symfony-security-76ff659b146558af0a17c9c08511dc0edfd79def.tar.bz2
feature #18656 Updating the error message of an AuthenticationEntryPointInterface (weaverryan)
This PR was merged into the 3.1-dev branch. Discussion ---------- Updating the error message of an AuthenticationEntryPointInterface | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | not necessary During a training, we forgot to fill in the `start()` method for an entry point and got a *horrible* error message. Now, if you mess up `start()`, you get: ![screen shot 2016-04-27 at 12 49 50 pm](https://cloud.githubusercontent.com/assets/121003/14860378/92578e68-0c76-11e6-9fe5-45141fe2ce43.png) Thanks! Commits ------- 7b6c56c Updating the error message of an AuthenticationEntryPointInterface returns a non-Response object
-rw-r--r--Http/Firewall/ExceptionListener.php10
-rw-r--r--Http/Tests/Firewall/ExceptionListenerTest.php14
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
*/