summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2016-06-09 17:57:07 +0200
committerVincent Petry <pvince81@owncloud.com>2016-06-09 17:57:07 +0200
commit059778bef0fbc37b7d46a0ca2a02dcb339e36f9a (patch)
tree63649db5e3f56cacef785729c5cb526c62225f63 /apps
parentc5a6c8b70bbe15de631a472370c783885a943f72 (diff)
downloadnextcloud-server-059778bef0fbc37b7d46a0ca2a02dcb339e36f9a.tar.gz
nextcloud-server-059778bef0fbc37b7d46a0ca2a02dcb339e36f9a.zip
Add unit test for LDAP multi group caching
Diffstat (limited to 'apps')
-rw-r--r--apps/user_ldap/tests/Group_LDAPTest.php53
1 files changed, 53 insertions, 0 deletions
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);
+ }
}