Skip to content

Commit 0ec4896

Browse files
authored
Merge pull request #85 from ltb-project/84-islocked-function-does-not-verify-if-lockout-duration-is-not-set
Manage empty lockoutDate in isLocked function
2 parents d909107 + 9592788 commit 0ec4896

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/Ltb/Directory/OpenLDAP.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ public function isLocked($entry, $pwdPolicyConfiguration) : bool {
3535

3636
$unlockDate = $this->getUnlockDate($entry, $pwdPolicyConfiguration);
3737

38+
if (!$unlockDate) {
39+
return true;
40+
}
41+
3842
if ( $unlockDate and time() <= $unlockDate->getTimestamp() ) {
3943
return true;
4044
}

tests/Ltb/DirectoryTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,32 @@ public function test_openldap_islocked_no_more_locked(): void
5858
$this->assertFalse($isLocked, "Account should no more be locked");
5959
}
6060

61+
public function test_openldap_islocked_lockout_duration_zero(): void
62+
{
63+
$entry = [
64+
'pwdaccountlockedtime' => [
65+
'count' => 1,
66+
0 => (new DateTime)->modify("-10 days")->format("Ymdhis\Z")
67+
]
68+
];
69+
70+
$isLocked = (new Ltb\Directory\OpenLDAP)->isLocked($entry, array('lockout_duration' => 0));
71+
$this->assertTrue($isLocked, "Account should be locked");
72+
}
73+
74+
public function test_openldap_islocked_no_lockout_duration(): void
75+
{
76+
$entry = [
77+
'pwdaccountlockedtime' => [
78+
'count' => 1,
79+
0 => (new DateTime)->modify("-10 days")->format("Ymdhis\Z")
80+
]
81+
];
82+
83+
$isLocked = (new Ltb\Directory\OpenLDAP)->isLocked($entry, array('lockout_duration' => null));
84+
$this->assertTrue($isLocked, "Account should be locked");
85+
}
86+
6187
public function test_openldap_getlockdate_empty(): void
6288
{
6389
$entry = [

0 commit comments

Comments
 (0)