From e14bb2ec57c600c913d2a7215ef6573a1140070a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20OUDOT?= Date: Thu, 29 Aug 2024 17:06:28 +0200 Subject: [PATCH] Tests on isLocked for Active Directory --- tests/Ltb/DirectoryTest.php | 88 +++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/tests/Ltb/DirectoryTest.php b/tests/Ltb/DirectoryTest.php index f2e2795..ababbb6 100644 --- a/tests/Ltb/DirectoryTest.php +++ b/tests/Ltb/DirectoryTest.php @@ -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"); + } + }