Skip to content
This repository was archived by the owner on May 31, 2024. It is now read-only.

Commit bf5d835

Browse files
committed
Merge branch '4.0'
* 4.0: fix merge Env var maps to undefined constant. [SecurityBundle] Backport test [Security] fix merge of 2.7 into 2.8 + add test case backport regression test from 3.4 do not mock the container builder or definitions fixed CS [TwigBundle] Register TwigBridge extensions first [WebProfilerBundle] Fix sub request link PhpDocExtractor::getTypes() throws fatal error when type omitted Fix misspelling variable use libsodium to run Argon2i related tests [DI] minor: use a strict comparision in setDecoratedService [HttpKernel] fix FC Follow-on to #25825: Fix edge case in getParameterOption. keep the context when validating forms
2 parents 51c268d + 2068d96 commit bf5d835

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

Http/Firewall/UsernamePasswordFormAuthenticationListener.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,13 @@ protected function attemptAuthentication(Request $request)
7777
}
7878
}
7979

80-
$requestBag = $this->options['post_only'] ? $request->request : $request;
81-
$username = ParameterBagUtils::getParameterBagValue($requestBag, $this->options['username_parameter']);
82-
$password = ParameterBagUtils::getParameterBagValue($requestBag, $this->options['password_parameter']);
80+
if ($this->options['post_only']) {
81+
$username = ParameterBagUtils::getParameterBagValue($request->request, $this->options['username_parameter']);
82+
$password = ParameterBagUtils::getParameterBagValue($request->request, $this->options['password_parameter']);
83+
} else {
84+
$username = ParameterBagUtils::getRequestParameterValue($request, $this->options['username_parameter']);
85+
$password = ParameterBagUtils::getRequestParameterValue($request, $this->options['password_parameter']);
86+
}
8387

8488
if (!\is_string($username) || (\is_object($username) && !\method_exists($username, '__toString'))) {
8589
throw new BadRequestHttpException(sprintf('The key "%s" must be a string, "%s" given.', $this->options['username_parameter'], \gettype($username)));

Http/Tests/Firewall/UsernamePasswordFormAuthenticationListenerTest.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ public function testHandleWhenUsernameLength($username, $ok)
7777
}
7878

7979
/**
80+
* @dataProvider postOnlyDataProvider
8081
* @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
8182
* @expectedExceptionMessage The key "_username" must be a string, "array" given.
8283
*/
83-
public function testHandleNonStringUsername()
84+
public function testHandleNonStringUsername($postOnly)
8485
{
8586
$request = Request::create('/login_check', 'POST', array('_username' => array()));
8687
$request->setSession($this->getMockBuilder('Symfony\Component\HttpFoundation\Session\SessionInterface')->getMock());
87-
8888
$listener = new UsernamePasswordFormAuthenticationListener(
8989
new TokenStorage(),
9090
$this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')->getMock(),
@@ -93,14 +93,20 @@ public function testHandleNonStringUsername()
9393
'foo',
9494
new DefaultAuthenticationSuccessHandler($httpUtils),
9595
new DefaultAuthenticationFailureHandler($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $httpUtils),
96-
array('require_previous_session' => false)
96+
array('require_previous_session' => false, 'post_only' => $postOnly)
9797
);
98-
9998
$event = new GetResponseEvent($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $request, HttpKernelInterface::MASTER_REQUEST);
100-
10199
$listener->handle($event);
102100
}
103101

102+
public function postOnlyDataProvider()
103+
{
104+
return array(
105+
array(true),
106+
array(false),
107+
);
108+
}
109+
104110
public function getUsernameForLength()
105111
{
106112
return array(

0 commit comments

Comments
 (0)