fix(federation): Fix returning "no display name" after cache result

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2025-04-10 09:20:27 +02:00
parent 878c4d5597
commit a9d126a219
No known key found for this signature in database
GPG key ID: F72FA5B49FFA96B0
2 changed files with 33 additions and 2 deletions

View file

@ -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;
}
}
}

View file

@ -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'],