diff options
author | Louis <louis@chmn.me> | 2024-01-02 12:30:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-02 12:30:50 +0100 |
commit | 138a4714b39a9d037522a477337f07a351cf2930 (patch) | |
tree | eba3ea70075bb7f16731162d6903eb236453569f /apps | |
parent | 725585f53e25f396419121a510864f12c206e086 (diff) | |
parent | 68af059ebe72afddc28ebc452f3fa5dc4181f5ea (diff) | |
download | nextcloud-server-138a4714b39a9d037522a477337f07a351cf2930.tar.gz nextcloud-server-138a4714b39a9d037522a477337f07a351cf2930.zip |
Merge pull request #42447 from nextcloud/backport/42405/stable27
[stable27] fix(LDAP): ensure stored groups are formatted as simple list
Diffstat (limited to 'apps')
-rw-r--r-- | apps/user_ldap/lib/Group_LDAP.php | 4 | ||||
-rw-r--r-- | apps/user_ldap/tests/Group_LDAPTest.php | 27 |
2 files changed, 29 insertions, 2 deletions
diff --git a/apps/user_ldap/lib/Group_LDAP.php b/apps/user_ldap/lib/Group_LDAP.php index 999dc403c2f..a1943244d1f 100644 --- a/apps/user_ldap/lib/Group_LDAP.php +++ b/apps/user_ldap/lib/Group_LDAP.php @@ -683,7 +683,7 @@ class Group_LDAP extends BackendUtility implements GroupInterface, IGroupLDAP, I protected function getCachedGroupsForUserId(string $uid): array { $groupStr = $this->config->getUserValue($uid, 'user_ldap', 'cached-group-memberships-' . $this->access->connection->getConfigPrefix(), '[]'); - return json_decode($groupStr) ?? []; + return json_decode($groupStr, true) ?? []; } /** @@ -836,7 +836,7 @@ class Group_LDAP extends BackendUtility implements GroupInterface, IGroupLDAP, I return $groups; } - $groups = array_unique($groups, SORT_LOCALE_STRING); + $groups = array_values(array_unique($groups, SORT_LOCALE_STRING)); $this->access->connection->writeToCache($cacheKey, $groups); $groupStr = \json_encode($groups); diff --git a/apps/user_ldap/tests/Group_LDAPTest.php b/apps/user_ldap/tests/Group_LDAPTest.php index 8d6c4539cec..e2698696bb0 100644 --- a/apps/user_ldap/tests/Group_LDAPTest.php +++ b/apps/user_ldap/tests/Group_LDAPTest.php @@ -901,6 +901,33 @@ class Group_LDAPTest extends TestCase { $this->assertTrue(in_array('groupF', $returnedGroups)); } + /** + * regression tests against a case where a json object was stored instead of expected list + * @see https://github.com/nextcloud/server/issues/42374 + */ + public function testGetUserGroupsOfflineUserUnexpectedJson() { + $this->enableGroups(); + + $offlineUser = $this->createMock(OfflineUser::class); + + $this->config->expects($this->any()) + ->method('getUserValue') + ->with('userX', 'user_ldap', 'cached-group-memberships-', $this->anything()) + // results in a json object: {"0":"groupB","2":"groupF"} + ->willReturn(\json_encode([0 => 'groupB', 2 => 'groupF'])); + + $this->access->userManager->expects($this->any()) + ->method('get') + ->with('userX') + ->willReturn($offlineUser); + + $this->initBackend(); + $returnedGroups = $this->groupBackend->getUserGroups('userX'); + $this->assertCount(2, $returnedGroups); + $this->assertTrue(in_array('groupB', $returnedGroups)); + $this->assertTrue(in_array('groupF', $returnedGroups)); + } + public function testGetUserGroupsUnrecognizedOfflineUser() { $this->enableGroups(); $dn = 'cn=userX,dc=foobar'; |