10000 [Ldap] cast to string when checking empty passwords · symfony/symfony@f276989 · GitHub
[go: up one dir, main page]

Skip to content

Commit f276989

Browse files
ismail1432nicolas-grekas
authored andcommitted
[Ldap] cast to string when checking empty passwords
1 parent 677d9aa commit f276989

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
@@ -71,7 +71,7 @@ protected function checkAuthentication(UserInterface $user, UsernamePasswordToke
7171
$username = $token->getUsername();
7272
$password = $token->getCredentials();
7373

74-
if ('' === $password) {
74+
if ('' === (string) $password) {
7575
throw new BadCredentialsException('The presented password must not be empty.');
7676
}
7777

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

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

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

0 commit comments

Comments
 (0)
0