Skip to content

Commit

Permalink
Merge branch 'main' into 16-active-directory-support
Browse files Browse the repository at this point in the history
  • Loading branch information
coudot committed Aug 27, 2024
2 parents cad43ec + c4c8507 commit 3076c23
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/vendor/
/vendor/
composer.lock
.phpunit.result.cache
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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"
}
}
```
Expand Down
18 changes: 8 additions & 10 deletions src/Ltb/Ldap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand All @@ -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'];
Expand All @@ -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)) {
Expand All @@ -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];

}

Expand Down
11 changes: 5 additions & 6 deletions tests/Ltb/LdapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

require __DIR__ . '/../../vendor/autoload.php';

use PHPUnit\Framework\Attributes\RunInSeparateProcess;

final class LdapTest extends \Mockery\Adapter\Phpunit\MockeryTestCase
{

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit 3076c23

Please sign in to comment.