diff options
author | Vincent Petry <pvince81@owncloud.com> | 2016-06-10 11:06:41 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-06-10 11:06:41 +0200 |
commit | 1abe5b0408f7db851129bf283ac9ad159c6ebb9d (patch) | |
tree | 4d942fbf5b94b0b33118bd713ebc936bd8113cf1 /apps/user_ldap | |
parent | d81dac24aaeea49fc942686c144d570f11497e01 (diff) | |
parent | 059778bef0fbc37b7d46a0ca2a02dcb339e36f9a (diff) | |
download | nextcloud-server-1abe5b0408f7db851129bf283ac9ad159c6ebb9d.tar.gz nextcloud-server-1abe5b0408f7db851129bf283ac9ad159c6ebb9d.zip |
Merge pull request #25024 from owncloud/ldap-cachedgroupsbymember
Use array_merge when reading cached groups members
Diffstat (limited to 'apps/user_ldap')
-rw-r--r-- | apps/user_ldap/lib/Group_LDAP.php | 2 | ||||
-rw-r--r-- | apps/user_ldap/tests/Group_LDAPTest.php | 53 |
2 files changed, 54 insertions, 1 deletions
diff --git a/apps/user_ldap/lib/Group_LDAP.php b/apps/user_ldap/lib/Group_LDAP.php index 7c12613f34d..14d86fb0619 100644 --- a/apps/user_ldap/lib/Group_LDAP.php +++ b/apps/user_ldap/lib/Group_LDAP.php @@ -535,7 +535,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface { } if(isset($this->cachedGroupsByMember[$uid])) { - $groups[] = $this->cachedGroupsByMember[$uid]; + $groups = array_merge($groups, $this->cachedGroupsByMember[$uid]); } else { $groupsByMember = array_values($this->getGroupsByMember($uid)); $groupsByMember = $this->access->ownCloudGroupNames($groupsByMember); diff --git a/apps/user_ldap/tests/Group_LDAPTest.php b/apps/user_ldap/tests/Group_LDAPTest.php index 556c4b0b394..35d525068a6 100644 --- a/apps/user_ldap/tests/Group_LDAPTest.php +++ b/apps/user_ldap/tests/Group_LDAPTest.php @@ -454,4 +454,57 @@ class Group_LDAPTest extends \Test\TestCase { $groupBackend->getUserGroups('userX'); } + public function testGetGroupsByMember() { + $access = $this->getAccessMock(); + + $access->connection->expects($this->any()) + ->method('__get') + ->will($this->returnCallback(function($name) { + if($name === 'useMemberOfToDetectMembership') { + return 0; + } else if($name === 'ldapDynamicGroupMemberURL') { + return ''; + } else if($name === 'ldapNestedGroups') { + return false; + } + return 1; + })); + + $dn = 'cn=userX,dc=foobar'; + + $access->connection->hasPrimaryGroups = false; + + $access->expects($this->exactly(2)) + ->method('username2dn') + ->will($this->returnValue($dn)); + + $access->expects($this->never()) + ->method('readAttribute') + ->with($dn, 'memberOf'); + + $group1 = [ + 'cn' => 'group1', + 'dn' => ['cn=group1,ou=groups,dc=domain,dc=com'], + ]; + $group2 = [ + 'cn' => 'group2', + 'dn' => ['cn=group2,ou=groups,dc=domain,dc=com'], + ]; + + $access->expects($this->once()) + ->method('ownCloudGroupNames') + ->with([$group1, $group2]) + ->will($this->returnValue(['group1', 'group2'])); + + $access->expects($this->once()) + ->method('fetchListOfGroups') + ->will($this->returnValue([$group1, $group2])); + + $groupBackend = new GroupLDAP($access); + $groups = $groupBackend->getUserGroups('userX'); + $this->assertEquals(['group1', 'group2'], $groups); + + $groupsAgain = $groupBackend->getUserGroups('userX'); + $this->assertEquals(['group1', 'group2'], $groupsAgain); + } } |