Skip to content

Commit

Permalink
Tests for Active Directory
Browse files Browse the repository at this point in the history
  • Loading branch information
coudot committed Nov 19, 2024
1 parent 42f74e1 commit 27e54d0
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Ltb/Directory/ActiveDirectory.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ public function isAccountValid($ldap, $dn) : bool {
$entry = \Ltb\PhpLDAP::ldap_get_entries($ldap, $search);
}

if (!$entry[0]['accountexpires']) {
if (!isset($entry[0]['accountexpires'])) {
return true;
}

Expand Down
61 changes: 61 additions & 0 deletions tests/Ltb/DirectoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1059,4 +1059,65 @@ public function test_openldap_disable_account_ko(): void
$this->assertFalse($disableAccountResult, "Should have encountered error while disabling OpenLDAP account");
}

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

$isAccountValid = (new Ltb\Directory\ActiveDirectory)->isAccountValid(null, null);
$this->assertTrue($isAccountValid, "Account should be valid");
}

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

$isAccountValid = (new Ltb\Directory\ActiveDirectory)->isAccountValid(null, null);
$this->assertFalse($isAccountValid, "Account should not be valid");
}

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

$isAccountValid = (new Ltb\Directory\ActiveDirectory)->isAccountValid(null, null);
$this->assertTrue($isAccountValid, "Account should be valid");
}

}

0 comments on commit 27e54d0

Please sign in to comment.