Skip to content

Commit 6a3321c

Browse files
Merge pull request #25101 from nextcloud/fix/noid/ldap-known-groups
LDAP: make actually use of batch read known groups
2 parents 395826b + 02b7031 commit 6a3321c

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

apps/user_ldap/lib/Access.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ public function fetchListOfGroups($filter, $attr, $limit = null, $offset = null)
945945

946946
array_walk($groupRecords, function ($record) use ($idsByDn) {
947947
$newlyMapped = false;
948-
$gid = $uidsByDn[$record['dn'][0]] ?? null;
948+
$gid = $idsByDn[$record['dn'][0]] ?? null;
949949
if ($gid === null) {
950950
$gid = $this->dn2ocname($record['dn'][0], null, false, $newlyMapped, $record);
951951
}

apps/user_ldap/tests/AccessTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
use OCA\User_LDAP\ILDAPWrapper;
4343
use OCA\User_LDAP\LDAP;
4444
use OCA\User_LDAP\LogWrapper;
45+
use OCA\User_LDAP\Mapping\GroupMapping;
4546
use OCA\User_LDAP\Mapping\UserMapping;
4647
use OCA\User_LDAP\User\Manager;
4748
use OCA\User_LDAP\User\OfflineUser;
@@ -66,6 +67,8 @@ class AccessTest extends TestCase {
6667
protected $userMapper;
6768
/** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
6869
protected $shareManager;
70+
/** @var GroupMapping|\PHPUnit\Framework\MockObject\MockObject */
71+
protected $groupMapper;
6972
/** @var Connection|\PHPUnit\Framework\MockObject\MockObject */
7073
private $connection;
7174
/** @var LDAP|\PHPUnit\Framework\MockObject\MockObject */
@@ -88,6 +91,7 @@ protected function setUp(): void {
8891
$this->helper = $this->createMock(Helper::class);
8992
$this->config = $this->createMock(IConfig::class);
9093
$this->userMapper = $this->createMock(UserMapping::class);
94+
$this->groupMapper = $this->createMock(GroupMapping::class);
9195
$this->ncUserManager = $this->createMock(IUserManager::class);
9296
$this->shareManager = $this->createMock(IManager::class);
9397

@@ -100,6 +104,7 @@ protected function setUp(): void {
100104
$this->ncUserManager
101105
);
102106
$this->access->setUserMapper($this->userMapper);
107+
$this->access->setGroupMapper($this->groupMapper);
103108
}
104109

105110
private function getConnectorAndLdapMock() {
@@ -641,6 +646,45 @@ public function testFetchListOfUsers() {
641646
$this->assertSame($expected, $list);
642647
}
643648

649+
public function testFetchListOfGroupsKnown() {
650+
$filter = 'objectClass=nextcloudGroup';
651+
$attributes = ['cn', 'gidNumber', 'dn'];
652+
$base = 'ou=SomeGroups,dc=my,dc=directory';
653+
654+
$fakeConnection = ldap_connect();
655+
$fakeSearchResultResource = ldap_connect();
656+
$fakeLdapEntries = [
657+
'count' => 2,
658+
[
659+
'dn' => 'cn=Good Team,' . $base,
660+
'cn' => ['Good Team'],
661+
],
662+
[
663+
'dn' => 'cn=Another Good Team,' . $base,
664+
'cn' => ['Another Good Team'],
665+
]
666+
];
667+
668+
$this->prepareMocksForSearchTests($base, $fakeConnection, $fakeSearchResultResource, $fakeLdapEntries);
669+
670+
$this->groupMapper->expects($this->any())
671+
->method('getListOfIdsByDn')
672+
->willReturn([
673+
'cn=Good Team,' . $base => 'Good_Team',
674+
'cn=Another Good Team,' . $base => 'Another_Good_Team',
675+
]);
676+
$this->groupMapper->expects($this->never())
677+
->method('getNameByDN');
678+
679+
$this->connection->expects($this->exactly(2))
680+
->method('writeToCache');
681+
682+
$groups = $this->access->fetchListOfGroups($filter, $attributes);
683+
$this->assertSame(2, count($groups));
684+
$this->assertSame('Good Team', $groups[0]['cn'][0]);
685+
$this->assertSame('Another Good Team', $groups[1]['cn'][0]);
686+
}
687+
644688
public function intUsernameProvider() {
645689
// system dependent :-/
646690
$translitExpected = @iconv('UTF-8', 'ASCII//TRANSLIT', 'fränk') ? 'frank' : 'frnk';

0 commit comments

Comments
 (0)