8000 [Security] json login listener: ensure a json response is sent on bad request by ogizanagi · Pull Request #22585 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Security] json login listener: ensure a json response is sent on bad request #22585

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,15 @@ public function testCustomJsonLoginFailure()
$this->assertSame(500, $response->getStatusCode());
$this->assertSame(array('message' => 'Something went wrong'), json_decode($response->getContent(), true));
}

public function testDefaultJsonLoginBadRequest()
{
$client = $this->createClient(array('test_case' => 'JsonLogin', 'root_config' => 'config.yml'));
$client->request('POST', '/chk', array(), array(), array('CONTENT_TYPE' => 'application/json'), 'Not a json content');
$response = $client->getResponse();

$this->assertSame(400, $response->getStatusCode());
$this->assertSame('application/json', $response->headers->get('Content-Type'));
$this->assertArraySubset(array('error' => array('code' => 400, 'message' => 'Bad Request')), json_decode($response->getContent(), true));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
return array(
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\JsonLoginBundle\JsonLoginBundle(),
);
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ public function handle(GetResponseEvent $event)
$response = $this->onSuccess($request, $authenticatedToken);
} catch (AuthenticationException $e) {
$response = $this->onFailure($request, $e);
} catch (BadRequestHttpException $e) {
$request->setRequestFormat('json');

throw $e;
}

if (null === $response) {
Expand Down
0