Skip to content

Commit

Permalink
bug #650 Fixed AuthenticaionFailureHandler to utilize messages from c…
Browse files Browse the repository at this point in the history
…ustom exceptions (EresDev)

This PR was squashed before being merged into the 2.x-dev branch (closes #650).

Discussion
----------

Fixed AuthenticaionFailureHandler to utilize messages from custom exceptions

Fixed #588

Commits
-------

9414427 Fixed AuthenticaionFailureHandler to utilize messages from custom exceptions
  • Loading branch information
chalasr committed May 5, 2019
2 parents eb304ae + 9414427 commit 14262e8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ public function __construct(EventDispatcherInterface $dispatcher)
*/
public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
{
$event = new AuthenticationFailureEvent($exception, new JWTAuthenticationFailureResponse());
$event = new AuthenticationFailureEvent(
$exception,
new JWTAuthenticationFailureResponse($exception->getMessage())
);

if ($this->dispatcher instanceof ContractsEventDispatcherInterface) {
$this->dispatcher->dispatch($event, Events::AUTHENTICATION_FAILURE);
Expand Down
2 changes: 1 addition & 1 deletion Tests/Functional/GetTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function testGetTokenFromInvalidCredentials()
$this->assertArrayHasKey('message', $body, 'The response should have a "message" key containing the failure reason.');
$this->assertArrayHasKey('code', $body, 'The response should have a "code" key containing the response status code.');

$this->assertSame('Bad credentials', $body['message']);
$this->assertSame('Bad credentials.', $body['message']);
$this->assertSame(401, $body['code']);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@ public function testOnAuthenticationFailure()
->disableOriginalConstructor()
->getMock();

$authenticationException = $this->getAuthenticationException();

$handler = new AuthenticationFailureHandler($dispatcher);
$response = $handler->onAuthenticationFailure($this->getRequest(), $this->getAuthenticationException());
$response = $handler->onAuthenticationFailure($this->getRequest(), $authenticationException);
$content = json_decode($response->getContent(), true);

$this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response);
$this->assertEquals(401, $response->getStatusCode());
$this->assertEquals(401, $content['code']);
$this->assertEquals('Bad credentials', $content['message']);
$this->assertEquals($authenticationException->getMessage(), $content['message']);
}

/**
Expand Down

0 comments on commit 14262e8

Please sign in to comment.