8000 feature #18656 Updating the error message of an AuthenticationEntryPo… · symfony/symfony@1ab5be7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1ab5be7

Browse files
committed
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
2 parents 2f562c8 + 7b6c56c commit 1ab5be7

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,15 @@ private function startAuthentication(Request $request, AuthenticationException $
203203
}
204204
}
205205

206-
return $this->authenticationEntryPoint->start($request, $authException);
206+
$response = $this->authenticationEntryPoint->start($request, $authException);
207+
208+
if (!$response instanceof Response) {
209+
$given = is_object($response) ? get_class($response) : gettype($response);
210+
211+
throw new \LogicException(sprintf('The %s::start() method must return a Response object (%s returned)', get_class($this->authenticationEntryPoint), $given));
212+
}
213+
214+
return $response;
207215
}
208216

209217
/**

src/Symfony/Component/Security/Http/Tests/Firewall/ExceptionListenerTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,20 @@ public function getAuthenticationExceptionProvider()
6565
);
6666
}
6767

68+
public function testExceptionWhenEntryPointReturnsBadValue()
69+
{
70+
$event = $this->createEvent(new AuthenticationException());
71+
72+
$entryPoint = $this->getMock('Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface');
73+
$entryPoint->expects($this->once())->method('start')->will($this->returnValue('NOT A RESPONSE'));
74+
75+
$listener = $this->createExceptionListener(null, null, null, $entryPoint);
76+
$listener->onKernelException($event);
77+
// the exception has been replaced by our LogicException
78+
$this->assertInstanceOf('LogicException', $event->getException());
79+
$this->assertStringEndsWith('start() method must return a Response object (string returned)', $event->getException()->getMessage());
80+
}
81+
6882
/**
6983
* @dataProvider getAccessDeniedExceptionProvider
7084
*/

0 commit comments

Comments
 (0)
0