Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LDAP: make actually use of batch read known groups #25101

Merged
merged 1 commit into from
Jan 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/user_ldap/lib/Access.php
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ public function fetchListOfGroups($filter, $attr, $limit = null, $offset = null)

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);
}
Expand Down
44 changes: 44 additions & 0 deletions apps/user_ldap/tests/AccessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
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;
Expand All @@ -66,6 +67,8 @@ class AccessTest extends TestCase {
protected $userMapper;
/** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
protected $shareManager;
/** @var GroupMapping|\PHPUnit\Framework\MockObject\MockObject */
protected $groupMapper;
/** @var Connection|\PHPUnit\Framework\MockObject\MockObject */
private $connection;
/** @var LDAP|\PHPUnit\Framework\MockObject\MockObject */
Expand All @@ -88,6 +91,7 @@ protected function setUp(): void {
$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->shareManager = $this->createMock(IManager::class);

Expand All @@ -100,6 +104,7 @@ protected function setUp(): void {
$this->ncUserManager
);
$this->access->setUserMapper($this->userMapper);
$this->access->setGroupMapper($this->groupMapper);
}

private function getConnectorAndLdapMock() {
Expand Down Expand Up @@ -641,6 +646,45 @@ public function testFetchListOfUsers() {
$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';
Expand Down