From 4837d1282b2de9c998a4e040108f10ef0a726c7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20OUDOT?= Date: Thu, 29 Aug 2024 17:58:11 +0200 Subject: [PATCH] Tests on getUnlockDate --- tests/Ltb/DirectoryTest.php | 91 +++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/tests/Ltb/DirectoryTest.php b/tests/Ltb/DirectoryTest.php index a0e4fef..d64e019 100644 --- a/tests/Ltb/DirectoryTest.php +++ b/tests/Ltb/DirectoryTest.php @@ -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; @@ -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"); + } + }