Skip to content

Commit

Permalink
Tests on isLocked for Active Directory
Browse files Browse the repository at this point in the history
  • Loading branch information
coudot committed Aug 29, 2024
1 parent ee0c7c8 commit e14bb2e
Showing 1 changed file with 88 additions and 0 deletions.
88 changes: 88 additions & 0 deletions tests/Ltb/DirectoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,92 @@ public function test_openldap_islocked_no_more_locked(): void
$this->assertFalse($isLocked, "Account should no more be locked");
}


public function test_activedirectory_islocked_locked_forever(): 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
]
]
]
]);

$isLocked = (new Ltb\Directory\ActiveDirectory)->isLocked(null, null, array('lockout_duration' => 0));
$this->assertTrue($isLocked, "Account should be locked forever");
}

public function test_activedirectory_islocked_not_locked(): void
{
$phpLDAPMock = Mockery::mock('overload:Ltb\PhpLDAP');
$phpLDAPMock->shouldreceive([
'ldap_read' => null,
'ldap_errno' => 0,
'ldap_get_entries' => [
'count' => 1,
0 => [
'lockouttime' => [
'count' => 1,
0 => null
]
]
]
]);

$isLocked = (new Ltb\Directory\ActiveDirectory)->isLocked(null, null, array('lockout_duration' => 0));
$this->assertFalse($isLocked, "Account should not be locked");
}

public function test_activedirectory_islocked_still_locked(): 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
]
]
]
]);

$isLocked = (new Ltb\Directory\ActiveDirectory)->isLocked(null, null, array('lockout_duration' => 86400));
$this->assertTrue($isLocked, "Account should be still locked");
}

public function test_activedirectory_islocked_no_more_locked(): void
{
$ad_date = ((int)time() - 864000 + 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
]
]
]
]);

$isLocked = (new Ltb\Directory\ActiveDirectory)->isLocked(null, null, array('lockout_duration' => 86400));
$this->assertFalse($isLocked, "Account should no more be locked");
}

}

0 comments on commit e14bb2e

Please sign in to comment.