summaryrefslogtreecommitdiffstats
path: root/apps/user_ldap
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2017-04-25 15:07:05 +0200
committerArthur Schiwon <blizzz@arthur-schiwon.de>2017-04-25 15:07:05 +0200
commit43f451e9e0e92c99285a471209e6645ff0b0eed9 (patch)
treeee0d2c480fed33f5d625cff2efcec90d02a4193b /apps/user_ldap
parent685faad5ca437895e035cfe9583e1978e6ddedba (diff)
downloadnextcloud-server-43f451e9e0e92c99285a471209e6645ff0b0eed9.tar.gz
nextcloud-server-43f451e9e0e92c99285a471209e6645ff0b0eed9.zip
Fix usersInGroup retrieval
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/user_ldap')
-rw-r--r--apps/user_ldap/lib/Group_LDAP.php16
-rw-r--r--apps/user_ldap/tests/Group_LDAPTest.php37
2 files changed, 39 insertions, 14 deletions
diff --git a/apps/user_ldap/lib/Group_LDAP.php b/apps/user_ldap/lib/Group_LDAP.php
index 5a209a3317e..60ce664684a 100644
--- a/apps/user_ldap/lib/Group_LDAP.php
+++ b/apps/user_ldap/lib/Group_LDAP.php
@@ -804,16 +804,9 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface {
}
$primaryUsers = $this->getUsersInPrimaryGroup($groupDN, $search, $limit, $offset);
- $members = array_keys($this->_groupMembers($groupDN));
- if(!$members && empty($primaryUsers)) {
- //in case users could not be retrieved, return empty result set
- $this->access->connection->writeToCache($cacheKey, array());
- return array();
- }
-
$posixGroupUsers = $this->getUsersInGidNumber($groupDN, $search, $limit, $offset);
$members = array_keys($this->_groupMembers($groupDN));
- if(!$members && empty($posixGroupUsers)) {
+ if(!$members && empty($posixGroupUsers) && empty($primaryUsers)) {
//in case users could not be retrieved, return empty result set
$this->access->connection->writeToCache($cacheKey, []);
return [];
@@ -850,12 +843,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface {
}
}
- $groupUsers = array_unique(array_merge($groupUsers, $primaryUsers));
- natsort($groupUsers);
- $this->access->connection->writeToCache('usersInGroup-'.$gid.'-'.$search, $groupUsers);
- $groupUsers = array_slice($groupUsers, $offset, $limit);
-
- $groupUsers = array_unique(array_merge($groupUsers, $posixGroupUsers));
+ $groupUsers = array_unique(array_merge($groupUsers, $primaryUsers, $posixGroupUsers));
natsort($groupUsers);
$this->access->connection->writeToCache('usersInGroup-'.$gid.'-'.$search, $groupUsers);
$groupUsers = array_slice($groupUsers, $offset, $limit);
diff --git a/apps/user_ldap/tests/Group_LDAPTest.php b/apps/user_ldap/tests/Group_LDAPTest.php
index fc13b8a35e5..9b5216742fe 100644
--- a/apps/user_ldap/tests/Group_LDAPTest.php
+++ b/apps/user_ldap/tests/Group_LDAPTest.php
@@ -443,6 +443,43 @@ class Group_LDAPTest extends \Test\TestCase {
->will($this->returnCallback(function($dn, $attr) {
if($attr === 'primaryGroupToken') {
return array(1337);
+ } else if($attr === 'gidNumber') {
+ return [4211];
+ }
+ return array();
+ }));
+
+ $access->expects($this->any())
+ ->method('groupname2dn')
+ ->will($this->returnValue('cn=foobar,dc=foo,dc=bar'));
+
+ $access->expects($this->exactly(2))
+ ->method('nextcloudUserNames')
+ ->willReturnOnConsecutiveCalls(['lisa', 'bart', 'kira', 'brad'], ['walle', 'dino', 'xenia']);
+
+ $groupBackend = new GroupLDAP($access);
+ $users = $groupBackend->usersInGroup('foobar');
+
+ $this->assertSame(7, count($users));
+ }
+
+ /**
+ * tests that a user listing is complete, if all it's members have the group
+ * as their primary.
+ */
+ public function testUsersInGroupPrimaryAndUnixMembers() {
+ $access = $this->getAccessMock();
+ $this->enableGroups($access);
+
+ $access->connection->expects($this->any())
+ ->method('getFromCache')
+ ->will($this->returnValue(null));
+
+ $access->expects($this->any())
+ ->method('readAttribute')
+ ->will($this->returnCallback(function($dn, $attr) {
+ if($attr === 'primaryGroupToken') {
+ return array(1337);
}
return array();
}));