diff --git a/.gitignore b/.gitignore index 42cd73d..0794651 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -/vendor/ \ No newline at end of file +/vendor/ +composer.lock +.phpunit.result.cache diff --git a/README.md b/README.md index 2cbbb88..d43edb0 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # LDAP Tool Box PHP framework -[![Latest Stable Version](http://poser.pugx.org/ltb-project/ltb-common/v)](https://packagist.org/packages/ltb-project/ltb-common) -[![Latest Unstable Version](http://poser.pugx.org/ltb-project/ltb-common/v/unstable)](https://packagist.org/packages/ltb-project/ltb-common) -[![Total Downloads](http://poser.pugx.org/ltb-project/ltb-common/downloads)](https://packagist.org/packages/ltb-project/ltb-common) +[![Latest Stable Version](https://poser.pugx.org/ltb-project/ltb-common/v)](https://packagist.org/packages/ltb-project/ltb-common) +[![Latest Unstable Version](https://poser.pugx.org/ltb-project/ltb-common/v/unstable)](https://packagist.org/packages/ltb-project/ltb-common) +[![Total Downloads](https://poser.pugx.org/ltb-project/ltb-common/downloads)](https://packagist.org/packages/ltb-project/ltb-common) [![CI Status](https://github.com/ltb-project/ltb-common/actions/workflows/unittests.yml/badge.svg)](https://github.com/ltb-project/ltb-common/actions/workflows/unittests.yml) [![Composer Status](https://github.com/ltb-project/ltb-common/actions/workflows/php.yml/badge.svg)](https://github.com/ltb-project/ltb-common/actions/workflows/php.yml) @@ -17,7 +17,7 @@ Add the dependency in your [composer](https://getcomposer.org/) configuration: ```json { "require": { - "ltb-project/ltb-common": "v0.2" + "ltb-project/ltb-common": "v0.2.1" } } ``` diff --git a/src/Ltb/Ldap.php b/src/Ltb/Ldap.php index f1feb80..ca019cd 100644 --- a/src/Ltb/Ldap.php +++ b/src/Ltb/Ldap.php @@ -105,7 +105,7 @@ function search_with_scope(string $scope = "sub", ...$searchargs) } } - function search($ldap_filter,$attributes, $attributes_map, $search_result_title, $search_result_sortby, $search_result_items) + function search($ldap_filter,$attributes, $attributes_map, $search_result_title, $search_result_sortby, $search_result_items, $search_scope = "sub") { $result = ""; @@ -115,11 +115,9 @@ function search($ldap_filter,$attributes, $attributes_map, $search_result_title, # Connect to LDAP $ldap_connection = $this->connect(); - - $ldap = $ldap_connection[0]; $result = $ldap_connection[1]; - if ($ldap) { + if ($this->ldap) { foreach( $search_result_items as $item ) { $attributes[] = $attributes_map[$item]['attribute']; @@ -128,25 +126,25 @@ function search($ldap_filter,$attributes, $attributes_map, $search_result_title, $attributes[] = $attributes_map[$search_result_sortby]['attribute']; # Search for users - $search = \Ltb\PhpLDAP::ldap_search($ldap, $this->ldap_user_base, $ldap_filter, $attributes, 0, $this->ldap_size_limit); + $search = $this->search_with_scope($search_scope, $this->ldap_user_base, $ldap_filter, $attributes, 0, $this->ldap_size_limit); - $errno = \Ltb\PhpLDAP::ldap_errno($ldap); + $errno = \Ltb\PhpLDAP::ldap_errno($this->ldap); if ( $errno == 4) { $size_limit_reached = true; } if ( $errno != 0 and $errno !=4 ) { $result = "ldaperror"; - error_log("LDAP - Search error $errno (".\Ltb\PhpLDAP::ldap_error($ldap).")"); + error_log("LDAP - Search error $errno (".\Ltb\PhpLDAP::ldap_error($this->ldap).")"); } else { # Get search results - $nb_entries = \Ltb\PhpLDAP::ldap_count_entries($ldap, $search); + $nb_entries = \Ltb\PhpLDAP::ldap_count_entries($this->ldap, $search); if ($nb_entries === 0) { $result = "noentriesfound"; } else { - $entries = \Ltb\PhpLDAP::ldap_get_entries($ldap, $search); + $entries = \Ltb\PhpLDAP::ldap_get_entries($this->ldap, $search); # Sort entries if (isset($search_result_sortby)) { @@ -159,7 +157,7 @@ function search($ldap_filter,$attributes, $attributes_map, $search_result_title, } } - return [$ldap,$result,$nb_entries,$entries,$size_limit_reached]; + return [$this->ldap,$result,$nb_entries,$entries,$size_limit_reached]; } diff --git a/tests/Ltb/LdapTest.php b/tests/Ltb/LdapTest.php index db2d87c..782f5cf 100644 --- a/tests/Ltb/LdapTest.php +++ b/tests/Ltb/LdapTest.php @@ -2,6 +2,8 @@ require __DIR__ . '/../../vendor/autoload.php'; +use PHPUnit\Framework\Attributes\RunInSeparateProcess; + final class LdapTest extends \Mockery\Adapter\Phpunit\MockeryTestCase { @@ -115,7 +117,7 @@ public function test_search(): void $search_result_title = "fullname"; $search_result_sortby = "lastname"; $search_result_items = array('identifier', 'mail', 'mobile'); - + $search_scope = "sub"; $entries = [ 'count' => 2, @@ -200,7 +202,8 @@ public function test_search(): void $attributes_map, $search_result_title, $search_result_sortby, - $search_result_items + $search_result_items, + $search_scope ); $this->assertEquals("ldap_connection", $ldap, "Error while getting ldap_connection in search function"); @@ -598,10 +601,6 @@ public function test_get_password_value_with_dummy_pwdattribute(): void } - /** runInSeparateProcess is needed for \Ltb\Password - * not interfering with other tests - * @runInSeparateProcess - */ #[RunInSeparateProcess] public function test_change_ad_password_as_user(): void {