Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix paged search with multiple bases (LDAP) #13865

Merged
merged 3 commits into from
Jan 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,7 @@ services:
matrix:
TESTS: acceptance
openldap:
image: nextcloudci/openldap:openldap-5
image: nextcloudci/openldap:openldap-6
environment:
- SLAPD_DOMAIN=nextcloud.ci
- SLAPD_ORGANIZATION=Nextcloud
Expand Down
33 changes: 28 additions & 5 deletions apps/user_ldap/lib/Access.php
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,11 @@ private function fetchList($list, $manyAttributes) {
* Executes an LDAP search
*/
public function searchUsers($filter, $attr = null, $limit = null, $offset = null) {
return $this->search($filter, $this->connection->ldapBaseUsers, $attr, $limit, $offset);
$result = [];
foreach($this->connection->ldapBaseUsers as $base) {
$result = array_merge($result, $this->search($filter, [$base], $attr, $limit, $offset));
}
return $result;
}

/**
Expand All @@ -986,7 +990,12 @@ public function searchUsers($filter, $attr = null, $limit = null, $offset = null
* @return false|int
*/
public function countUsers($filter, $attr = array('dn'), $limit = null, $offset = null) {
return $this->count($filter, $this->connection->ldapBaseUsers, $attr, $limit, $offset);
$result = false;
foreach($this->connection->ldapBaseUsers as $base) {
$count = $this->count($filter, [$base], $attr, $limit, $offset);
$result = is_int($count) ? (int)$result + $count : $result;
}
return $result;
}

/**
Expand All @@ -1000,7 +1009,11 @@ public function countUsers($filter, $attr = array('dn'), $limit = null, $offset
* Executes an LDAP search
*/
public function searchGroups($filter, $attr = null, $limit = null, $offset = null) {
return $this->search($filter, $this->connection->ldapBaseGroups, $attr, $limit, $offset);
$result = [];
foreach($this->connection->ldapBaseGroups as $base) {
$result = array_merge($result, $this->search($filter, [$base], $attr, $limit, $offset));
}
return $result;
}

/**
Expand All @@ -1012,7 +1025,12 @@ public function searchGroups($filter, $attr = null, $limit = null, $offset = nul
* @return int|bool
*/
public function countGroups($filter, $attr = array('dn'), $limit = null, $offset = null) {
return $this->count($filter, $this->connection->ldapBaseGroups, $attr, $limit, $offset);
$result = false;
foreach($this->connection->ldapBaseGroups as $base) {
$count = $this->count($filter, [$base], $attr, $limit, $offset);
$result = is_int($count) ? (int)$result + $count : $result;
}
return $result;
}

/**
Expand All @@ -1023,7 +1041,12 @@ public function countGroups($filter, $attr = array('dn'), $limit = null, $offset
* @return int|bool
*/
public function countObjects($limit = null, $offset = null) {
return $this->count('objectclass=*', $this->connection->ldapBase, array('dn'), $limit, $offset);
$result = false;
foreach($this->connection->ldapBase as $base) {
$count = $this->count('objectclass=*', [$base], ['dn'], $limit, $offset);
$result = is_int($count) ? (int)$result + $count : $result;
}
return $result;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion build/integration/ldap_features/ldap-openldap.feature
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Feature: LDAP
And Sending a "GET" to "/remote.php/webdav/welcome.txt" with requesttoken
Then the HTTP status code should be "200"

Scenario: Test valid configuration with LDAP protoccol and port by logging in
Scenario: Test valid configuration with LDAP protocol and port by logging in
Given modify LDAP configuration
| ldapHost | ldap://openldap:389 |
And cookies are reset
Expand Down
22 changes: 22 additions & 0 deletions build/integration/ldap_features/openldap-uid-username.feature
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,25 @@ Feature: LDAP
| juliana |
| leo |
| stigur |

Scenario: Fetch from second batch of all users, invoking pagination with two bases
Given modify LDAP configuration
| ldapBaseUsers | ou=PagingTest,dc=nextcloud,dc=ci;ou=PagingTestSecondBase,dc=nextcloud,dc=ci |
| ldapPagingSize | 2 |
And As an "admin"
And sending "GET" to "/cloud/users?limit=10&offset=2"
Then the OCS status code should be "200"
And the "users" result should contain "5" of
| ebba |
| eindis |
| fjolnir |
| gunna |
| juliana |
| leo |
| stigur |
And the "users" result should contain "3" of
| allisha |
| dogukan |
| lloyd |
| priscilla |
| shannah |