Skip to content
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
4 changes: 2 additions & 2 deletions src/Auth/Guard.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public function __construct(LdapInterface $connection, DomainConfiguration $conf
public function attempt(string $username, string $password, bool $stayBound = false): bool
{
switch (true) {
case empty($username):
case $username === '':
throw new UsernameRequiredException('A username must be specified.');
case empty($password):
case $password === '':
throw new PasswordRequiredException('A password must be specified.');
}

Expand Down
28 changes: 28 additions & 0 deletions tests/Unit/Auth/GuardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,34 @@ public function test_attempt_throws_exception_with_an_empty_password()
$guard->attempt('username', '');
}

public function test_attempt_allows_zero_string_password()
{
$ldap = (new LdapFake)
->expect(LdapFake::operation('bind')->once()->with('user', '0')->andReturnResponse())
->expect(LdapFake::operation('bind')->once()->with('foo', 'bar')->andReturnResponse());

$guard = new Guard($ldap, new DomainConfiguration([
'username' => 'foo',
'password' => 'bar',
]));

$this->assertTrue($guard->attempt('user', '0'));
}

public function test_attempt_allows_zero_string_username()
{
$ldap = (new LdapFake)
->expect(LdapFake::operation('bind')->once()->with('0', 'password')->andReturnResponse())
->expect(LdapFake::operation('bind')->once()->with('foo', 'bar')->andReturnResponse());

$guard = new Guard($ldap, new DomainConfiguration([
'username' => 'foo',
'password' => 'bar',
]));

$this->assertTrue($guard->attempt('0', 'password'));
}

public function test_attempt_binds_the_given_credentials_and_rebinds_with_configured_user()
{
$ldap = (new LdapFake)
Expand Down