]> source.dussan.org Git - nextcloud-server.git/commitdiff
really use known groups 25379/head
authorArthur Schiwon <blizzz@arthur-schiwon.de>
Tue, 12 Jan 2021 19:52:52 +0000 (20:52 +0100)
committerArthur Schiwon <blizzz@arthur-schiwon.de>
Wed, 17 Feb 2021 12:51:08 +0000 (13:51 +0100)
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
apps/user_ldap/lib/Access.php
apps/user_ldap/tests/AccessTest.php

index c572c9b056067cee38229b8af75a862597466297..087969b7ffeb53e642e3a81cbb9d8f3c362877c0 100644 (file)
@@ -948,7 +948,7 @@ class Access extends LDAPUtility {
 
                array_walk($groupRecords, function ($record) use ($idsByDn) {
                        $newlyMapped = false;
-                       $gid = $uidsByDn[$record['dn'][0]] ?? null;
+                       $gid = $idsByDn[$record['dn'][0]] ?? null;
                        if ($gid === null) {
                                $gid = $this->dn2ocname($record['dn'][0], null, false, $newlyMapped, $record);
                        }
index 549f6600b4dbc96fed6d603a4aa0a09adf771ca1..f5f6e162f3c67fcf96cd165e63638b465a44b96e 100644 (file)
@@ -42,6 +42,7 @@ use OCA\User_LDAP\Helper;
 use OCA\User_LDAP\ILDAPWrapper;
 use OCA\User_LDAP\LDAP;
 use OCA\User_LDAP\LogWrapper;
+use OCA\User_LDAP\Mapping\GroupMapping;
 use OCA\User_LDAP\Mapping\UserMapping;
 use OCA\User_LDAP\User\Manager;
 use OCA\User_LDAP\User\OfflineUser;
@@ -64,6 +65,8 @@ use Test\TestCase;
 class AccessTest extends TestCase {
        /** @var UserMapping|\PHPUnit\Framework\MockObject\MockObject */
        protected $userMapper;
+       /** @var GroupMapping|\PHPUnit\Framework\MockObject\MockObject */
+       protected $groupMapper;
        /** @var Connection|\PHPUnit\Framework\MockObject\MockObject */
        private $connection;
        /** @var LDAP|\PHPUnit\Framework\MockObject\MockObject */
@@ -86,6 +89,7 @@ class AccessTest extends TestCase {
                $this->helper = $this->createMock(Helper::class);
                $this->config  = $this->createMock(IConfig::class);
                $this->userMapper = $this->createMock(UserMapping::class);
+               $this->groupMapper = $this->createMock(GroupMapping::class);
                $this->ncUserManager = $this->createMock(IUserManager::class);
 
                $this->access = new Access(
@@ -97,6 +101,7 @@ class AccessTest extends TestCase {
                        $this->ncUserManager
                );
                $this->access->setUserMapper($this->userMapper);
+               $this->access->setGroupMapper($this->groupMapper);
        }
 
        private function getConnectorAndLdapMock() {
@@ -638,6 +643,45 @@ class AccessTest extends TestCase {
                $this->assertSame($expected, $list);
        }
 
+       public function testFetchListOfGroupsKnown() {
+               $filter  = 'objectClass=nextcloudGroup';
+               $attributes = ['cn', 'gidNumber', 'dn'];
+               $base = 'ou=SomeGroups,dc=my,dc=directory';
+
+               $fakeConnection = ldap_connect();
+               $fakeSearchResultResource = ldap_connect();
+               $fakeLdapEntries = [
+                       'count' => 2,
+                       [
+                               'dn' => 'cn=Good Team,' . $base,
+                               'cn' => ['Good Team'],
+                       ],
+                       [
+                               'dn' => 'cn=Another Good Team,' . $base,
+                               'cn' => ['Another Good Team'],
+                       ]
+               ];
+
+               $this->prepareMocksForSearchTests($base, $fakeConnection, $fakeSearchResultResource, $fakeLdapEntries);
+
+               $this->groupMapper->expects($this->any())
+                       ->method('getListOfIdsByDn')
+                       ->willReturn([
+                               'cn=Good Team,' . $base => 'Good_Team',
+                               'cn=Another Good Team,' . $base => 'Another_Good_Team',
+                       ]);
+               $this->groupMapper->expects($this->never())
+                       ->method('getNameByDN');
+
+               $this->connection->expects($this->exactly(2))
+                       ->method('writeToCache');
+
+               $groups = $this->access->fetchListOfGroups($filter, $attributes);
+               $this->assertSame(2, count($groups));
+               $this->assertSame('Good Team', $groups[0]['cn'][0]);
+               $this->assertSame('Another Good Team', $groups[1]['cn'][0]);
+       }
+
        public function intUsernameProvider() {
                // system dependent :-/
                $translitExpected = @iconv('UTF-8', 'ASCII//TRANSLIT', 'fränk') ? 'frank' : 'frnk';