Skip to content

Commit

Permalink
Tests on getUnlockDate
Browse files Browse the repository at this point in the history
  • Loading branch information
coudot committed Aug 29, 2024
1 parent 334db8a commit 4837d12
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions tests/Ltb/DirectoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,51 @@ public function test_openldap_getlockdate_notempty(): void
$this->assertEquals($dt->format("Y/m/d - h:i:s"), $getLockDate->format("Y/m/d - h:i:s"), "Lock date is correct");
}

public function test_openldap_getunlockdate_noduration(): void
{
$dt = new DateTime;
$phpLDAPMock = Mockery::mock('overload:Ltb\PhpLDAP');
$phpLDAPMock->shouldreceive([
'ldap_read' => null,
'ldap_errno' => 0,
'ldap_get_entries' => [
'count' => 1,
0 => [
'pwdaccountlockedtime' => [
'count' => 1,
0 => $dt->format("Ymdhis\Z"),
]
]
]
]);

$unlockDate = (new Ltb\Directory\OpenLDAP)->getUnlockDate(null, null, array('lockout_duration' => 0));
$this->assertNull($unlockDate, "Unkock date should be null");
}

public function test_openldap_getunlockdate_duration(): void
{
$dt = new DateTime;
$phpLDAPMock = Mockery::mock('overload:Ltb\PhpLDAP');
$phpLDAPMock->shouldreceive([
'ldap_read' => null,
'ldap_errno' => 0,
'ldap_get_entries' => [
'count' => 1,
0 => [
'pwdaccountlockedtime' => [
'count' => 1,
0 => $dt->format("Ymdhis\Z"),
]
]
]
]);

$unlockDate = (new Ltb\Directory\OpenLDAP)->getUnlockDate(null, null, array('lockout_duration' => 86400));
$this->assertInstanceOf("DateTime", $unlockDate, "Unlock date should be a PHP DateTime object");
$this->assertEquals($dt->modify("+1 day")->format("Y/m/d - h:i:s"), $unlockDate->format("Y/m/d - h:i:s"), "Unlock date is correct");
}

public function test_activedirectory_islocked_locked_forever(): void
{
$ad_date = ((int)time() + 11644473600) * 10000000;
Expand Down Expand Up @@ -287,4 +332,50 @@ public function test_activedirectory_getlockdate_notempty(): void
$this->assertEquals($dt->format("Y/m/d - h:i:s"), $getLockDate->format("Y/m/d - h:i:s"), "Lock date is correct");
}

public function test_activedirectory_getunlockdate_noduration(): void
{
$ad_date = ((int)time() + 11644473600) * 10000000;
$phpLDAPMock = Mockery::mock('overload:Ltb\PhpLDAP');
$phpLDAPMock->shouldreceive([
'ldap_read' => null,
'ldap_errno' => 0,
'ldap_get_entries' => [
'count' => 1,
0 => [
'lockouttime' => [
'count' => 1,
0 => $ad_date,
]
]
]
]);

$unlockDate = (new Ltb\Directory\ActiveDirectory)->getUnlockDate(null, null, array('lockout_duration' => 0));
$this->assertNull($unlockDate, "Unock date should be null");
}

public function test_activedirectory_getunlockdate_duration(): void
{
$dt = new DateTime;
$ad_date = ((int)$dt->getTimestamp() + 11644473600) * 10000000;
$phpLDAPMock = Mockery::mock('overload:Ltb\PhpLDAP');
$phpLDAPMock->shouldreceive([
'ldap_read' => null,
'ldap_errno' => 0,
'ldap_get_entries' => [
'count' => 1,
0 => [
'lockouttime' => [
'count' => 1,
0 => $ad_date,
]
]
]
]);

$unlockDate = (new Ltb\Directory\ActiveDirectory)->getUnlockDate(null, null, array('lockout_duration' => 86400));
$this->assertInstanceOf("DateTime", $unlockDate, "Unlock date should be a PHP DateTime object");
$this->assertEquals($dt->modify("+1 day")->format("Y/m/d - h:i:s"), $unlockDate->format("Y/m/d - h:i:s"), "Unlock date is correct");
}

}

0 comments on commit 4837d12

Please sign in to comment.