diff options
author | MichaIng <micha@dietpi.com> | 2021-09-24 22:07:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-24 22:07:18 +0200 |
commit | 43bbe753a7c32e4d89e5d5fac583c702da3f10e8 (patch) | |
tree | 3bab7c96ca337e17a274bb45c71d6bf948402d5a | |
parent | ea39319d2e205f9fdcb0d4e5a8fd82c2c16518dd (diff) | |
parent | 4f7ffa69cb3eacc8d901a97dc7496c64e2ac7b06 (diff) | |
download | nextcloud-server-43bbe753a7c32e4d89e5d5fac583c702da3f10e8.tar.gz nextcloud-server-43bbe753a7c32e4d89e5d5fac583c702da3f10e8.zip |
Merge pull request #28950 from nextcloud/backport/28916/stable21
[stable21] fix caching of objectsid searches
-rw-r--r-- | apps/user_ldap/lib/Group_LDAP.php | 9 | ||||
-rw-r--r-- | apps/user_ldap/tests/Group_LDAPTest.php | 32 |
2 files changed, 37 insertions, 4 deletions
diff --git a/apps/user_ldap/lib/Group_LDAP.php b/apps/user_ldap/lib/Group_LDAP.php index f816279fec3..9c2e3ebb713 100644 --- a/apps/user_ldap/lib/Group_LDAP.php +++ b/apps/user_ldap/lib/Group_LDAP.php @@ -410,6 +410,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]; @@ -534,10 +535,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); diff --git a/apps/user_ldap/tests/Group_LDAPTest.php b/apps/user_ldap/tests/Group_LDAPTest.php index 4011d964a40..aad69ebf43d 100644 --- a/apps/user_ldap/tests/Group_LDAPTest.php +++ b/apps/user_ldap/tests/Group_LDAPTest.php @@ -321,6 +321,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(); |