mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
Merge pull request #28949 from nextcloud/backport/28916/stable22
[stable22] fix caching of objectsid searches
This commit is contained in:
commit
068e977b07
2 changed files with 37 additions and 4 deletions
|
|
@ -409,6 +409,7 @@ class Group_LDAP extends BackendUtility implements GroupInterface, IGroupLDAP, I
|
|||
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];
|
||||
|
|
@ -533,10 +534,10 @@ class Group_LDAP extends BackendUtility implements GroupInterface, IGroupLDAP, I
|
|||
* @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);
|
||||
|
|
|
|||
|
|
@ -320,6 +320,38 @@ class Group_LDAPTest extends TestCase {
|
|||
$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();
|
||||
|
|
|
|||
Loading…
Reference in a new issue