mirror of
https://github.com/nextcloud/server.git
synced 2026-06-10 01:00:50 -04:00
fix(federation): Fix returning "no display name" after cache result
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
878c4d5597
commit
a9d126a219
2 changed files with 33 additions and 2 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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'],
|
||||
|
|
|
|||
Loading…
Reference in a new issue