Skip to content

Commit

Permalink
Unit tests for getPasswordExpirationDate
Browse files Browse the repository at this point in the history
  • Loading branch information
coudot committed Sep 17, 2024
1 parent f881b39 commit 9f64895
Showing 1 changed file with 89 additions and 0 deletions.
89 changes: 89 additions & 0 deletions tests/Ltb/DirectoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,50 @@ public function test_openldap_isexpired_not_expired(): void
$this->assertFalse($isPasswordExpired, "Password should not be expired");
}

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

$passwordExpirationDate = (new Ltb\Directory\OpenLDAP)->getPasswordExpirationDate(null, null, null);
$this->assertNull($passwordExpirationDate, "Password expiration date should be null");
}

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

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

public function test_activedirectory_islocked_locked_forever(): void
{
$ad_date = ((int)time() + 11644473600) * 10000000;
Expand Down Expand Up @@ -468,4 +512,49 @@ public function test_activedirectory_isexpired_not_expired(): void
$this->assertFalse($isPasswordExpired, "Password should not be expired");
}

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

$getPasswordExpirationDate = (new Ltb\Directory\ActiveDirectory)->getPasswordExpirationDate(null, null, null);
$this->assertNull($getPasswordExpirationDate, "Password expiration date should be null");
}

public function test_activedirectory_getpasswordexpirationdate_notempty(): 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 => [
'pwdlastset' => [
'count' => 1,
0 => $ad_date,
]
]
]
]);

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

}

0 comments on commit 9f64895

Please sign in to comment.