Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1ebe203

Browse files
ismail1432fabpot
authored andcommitted
[Ldap] cast to string when checking empty passwords
1 parent e1f817f commit 1ebe203

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/Symfony/Component/Security/Core/Authentication/Provider/LdapBindAuthenticationProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ protected function checkAuthentication(UserInterface $user, UsernamePasswordToke
8282
$username = $token->getUsername();
8383
$password = $token->getCredentials();
8484

85-
if ('' === $password) {
85+
if ('' === (string) $password) {
8686
throw new BadCredentialsException('The presented password must not be empty.');
8787
}
8888

src/Symfony/Component/Security/Core/Tests/Authentication/Provider/LdapBindAuthenticationProviderTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,23 @@ public function testEmptyPasswordShouldThrowAnException()
4545
$reflection->invoke($provider, new User('foo', null), new UsernamePasswordToken('foo', '', 'key'));
4646
}
4747

48+
/**
49+
* @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException
50+
* @expectedExceptionMessage The presented password must not be empty.
51+
*/
52+
public function testNullPasswordShouldThrowAnException()
53+
{
54+
$userProvider = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserProviderInterface')->getMock();
55+
$ldap = $this->getMockBuilder('Symfony\Component\Ldap\LdapClientInterface')->getMock();
56+
$userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock();
57+
58+
$provider = new LdapBindAuthenticationProvider($userProvider, $userChecker, 'key', $ldap);
59+
$reflection = new \ReflectionMethod($provider, 'checkAuthentication');
60+
$reflection->setAccessible(true);
61+
62+
$reflection->invoke($provider, new User('foo', null), new UsernamePasswordToken('foo', null, 'key'));
63+
}
64+
4865
/**
4966
* @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException
5067
* @expectedExceptionMessage The presented password is invalid.

0 commit comments

Comments
 (0)