8000 Updating the error message of an AuthenticationEntryPointInterface re… · symfony/symfony@7b6c56c · GitHub
[go: up one dir, main page]

Skip to content

Commit 7b6c56c

Browse files
committed
Updating the error message of an AuthenticationEntryPointInterface returns a non-Response object
1 parent b26ff03 commit 7b6c56c

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