diff options
author | Vincent Petry <pvince81@owncloud.com> | 2016-06-09 18:02:09 +0200 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2016-06-09 18:02:09 +0200 |
commit | fba4460342bdcea7753e70c89a11c2ecc1b8824d (patch) | |
tree | d4bf44abe33e55e5f56adb08b3987959958bad35 | |
parent | b37f2e230b0ca8aa4498567b40e5b465240586ff (diff) | |
download | nextcloud-server-fba4460342bdcea7753e70c89a11c2ecc1b8824d.tar.gz nextcloud-server-fba4460342bdcea7753e70c89a11c2ecc1b8824d.zip |
Add unit test for LDAP multi group caching
-rw-r--r-- | apps/user_ldap/tests/group_ldap.php | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/apps/user_ldap/tests/group_ldap.php b/apps/user_ldap/tests/group_ldap.php index 51bb1d84732..a81bf70f54a 100644 --- a/apps/user_ldap/tests/group_ldap.php +++ b/apps/user_ldap/tests/group_ldap.php @@ -455,4 +455,57 @@ class Test_Group_Ldap 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); + } } |