diff options
author | Joas Schilling <coding@schilljs.com> | 2025-04-10 09:20:27 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2025-04-10 09:20:27 +0200 |
commit | d8744f84e8ab224e0beb1714dbce37f912350e29 (patch) | |
tree | bca8068af34fc3f0f18aa760d1ed86280082cb16 | |
parent | e94fe91cd1e1d152c6126f3304890ca767ba908a (diff) | |
download | nextcloud-server-bugfix/noid/fix-cached-return-of-display-name.tar.gz nextcloud-server-bugfix/noid/fix-cached-return-of-display-name.zip |
fix(federation): Fix returning "no display name" after cache resultbugfix/noid/fix-cached-return-of-display-name
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r-- | lib/private/Federation/CloudIdManager.php | 7 | ||||
-rw-r--r-- | tests/lib/Federation/CloudIdManagerTest.php | 28 |
2 files changed, 33 insertions, 2 deletions
diff --git a/lib/private/Federation/CloudIdManager.php b/lib/private/Federation/CloudIdManager.php index fa8ac0fa0c2..a7d36eda4a0 100644 --- a/lib/private/Federation/CloudIdManager.php +++ b/lib/private/Federation/CloudIdManager.php @@ -119,6 +119,9 @@ class CloudIdManager implements ICloudIdManager { public function getDisplayNameFromContact(string $cloudId): ?string { $cachedName = $this->displayNameCache->get($cloudId); if ($cachedName !== null) { + if ($cachedName === $cloudId) { + return null; + } return $cachedName; } @@ -138,8 +141,8 @@ class CloudIdManager implements ICloudIdManager { $this->displayNameCache->set($cloudId, $entry['FN'], 15 * 60); return $entry['FN']; } else { - $this->displayNameCache->set($cloudId, $cloudID, 15 * 60); - return $cloudID; + $this->displayNameCache->set($cloudId, $cloudId, 15 * 60); + return null; } } } diff --git a/tests/lib/Federation/CloudIdManagerTest.php b/tests/lib/Federation/CloudIdManagerTest.php index 14daef27142..1775c18a5e9 100644 --- a/tests/lib/Federation/CloudIdManagerTest.php +++ b/tests/lib/Federation/CloudIdManagerTest.php @@ -56,6 +56,34 @@ class CloudIdManagerTest extends TestCase { $this->overwriteService(ICloudIdManager::class, $this->cloudIdManager); } + public function dataGetDisplayNameFromContact(): array { + return [ + ['test1@example.tld', 'test', 'test'], + ['test2@example.tld', null, null], + ['test3@example.tld', 'test3@example', 'test3@example'], + ['test4@example.tld', 'test4@example.tld', null], + ]; + } + + /** + * @dataProvider dataGetDisplayNameFromContact + */ + public function testGetDisplayNameFromContact(string $cloudId, ?string $displayName, ?string $expected): void { + $returnedContact = [ + 'CLOUD' => [$cloudId], + 'FN' => $expected, + ]; + if ($displayName === null) { + unset($returnedContact['FN']); + } + $this->contactsManager->method('search') + ->with($cloudId, ['CLOUD']) + ->willReturn([$returnedContact]); + + $this->assertEquals($expected, $this->cloudIdManager->getDisplayNameFromContact($cloudId)); + $this->assertEquals($expected, $this->cloudIdManager->getDisplayNameFromContact($cloudId)); + } + public function cloudIdProvider(): array { return [ ['test@example.com', 'test', 'example.com', 'test@example.com'], |