Skip to content
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
9 changes: 5 additions & 4 deletions apps/user_ldap/lib/Group_LDAP.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ public function gidNumber2Name(string $gid, string $dn) {
private function getNameOfGroup(string $filter, string $cacheKey) {
$result = $this->access->searchGroups($filter, ['dn'], 1);
if (empty($result)) {
$this->access->connection->writeToCache($cacheKey, false);
return null;
}
$dn = $result[0]['dn'][0];
Expand Down Expand Up @@ -534,10 +535,10 @@ public function getUserGroupByGid(string $dn) {
* @throws ServerNotAvailableException
*/
public function primaryGroupID2Name(string $gid, string $dn) {
$cacheKey = 'primaryGroupIDtoName';
$groupNames = $this->access->connection->getFromCache($cacheKey);
if (!is_null($groupNames) && isset($groupNames[$gid])) {
return $groupNames[$gid];
$cacheKey = 'primaryGroupIDtoName_' . $gid;
$groupName = $this->access->connection->getFromCache($cacheKey);
if (!is_null($groupName)) {
return $groupName;
}

$domainObjectSid = $this->access->getSID($dn);
Expand Down
32 changes: 32 additions & 0 deletions apps/user_ldap/tests/Group_LDAPTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,38 @@ public function testGetEntryGidNumberNoValue() {
$this->assertSame(false, $gid);
}

public function testPrimaryGroupID2NameSuccessCache() {
$access = $this->getAccessMock();
$pluginManager = $this->getPluginManagerMock();

$this->enableGroups($access);

$userDN = 'cn=alice,cn=foo,dc=barfoo,dc=bar';
$gid = '3117';
$groupDN = 'cn=foo,dc=barfoo,dc=bar';

/** @var MockObject $connection */
$connection = $access->connection;
$connection->expects($this->once())
->method('getFromCache')
->with('primaryGroupIDtoName_' . $gid)
->willReturn('MyGroup');

$access->expects($this->never())
->method('getSID');

$access->expects($this->never())
->method('searchGroups');

$access->expects($this->never())
->method('dn2groupname');

$groupBackend = new GroupLDAP($access, $pluginManager);
$group = $groupBackend->primaryGroupID2Name($gid, $userDN);

$this->assertSame('MyGroup', $group);
}

public function testPrimaryGroupID2NameSuccess() {
$access = $this->getAccessMock();
$pluginManager = $this->getPluginManagerMock();
Expand Down