Skip to content

Commit

Permalink
Account lockout policy - fail if no user id
Browse files Browse the repository at this point in the history
  • Loading branch information
rochamarcelo committed Mar 29, 2024
1 parent 597f25f commit 6240ba8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Identifier/PasswordLockout/LockoutHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public function __construct(array $config = [])
*/
public function isUnlocked(\ArrayAccess|array $identity): bool
{
if (!isset($identity['id'])) {
return false;
}
$lockoutField = $this->getConfig('userLockoutField');
$userLockoutTime = $identity[$lockoutField] ?? null;
if ($userLockoutTime) {
Expand Down
3 changes: 3 additions & 0 deletions src/Identifier/PasswordLockoutIdentifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public function __construct(array $config = [])
*/
protected function _checkPassword(ArrayAccess|array|null $identity, ?string $password): bool
{
if (!isset($identity['id'])) {
return false;
}
$check = parent::_checkPassword($identity, $password);
$handler = $this->getLockoutHandler();
if (!$check) {
Expand Down
24 changes: 24 additions & 0 deletions tests/TestCase/Identifier/PasswordLockout/LockoutHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,28 @@ public function testIsUnlockedSaveLockoutAndNotCompleted()
$this->assertInstanceOf(DateTime::class, $userAfter->lockout_time);
$this->assertEquals($userBefore->lockout_time, $userAfter->lockout_time);
}

/**
* @return void
*/
public function testIsUnlockedWithoutIdButNotEmpty()
{
$handler = new LockoutHandler();
$user = [
'username' => 'user-2',
'email' => '[email protected]'
];
$actual = $handler->isUnlocked($user);
$this->assertFalse($actual);
}

/**
* @return void
*/
public function testIsUnlockedWithoutIdAndEmpty()
{
$handler = new LockoutHandler();
$actual = $handler->isUnlocked([]);
$this->assertFalse($actual);
}
}

0 comments on commit 6240ba8

Please sign in to comment.