From eb81babf2a5070f14579d201009dfce7c2170e44 Mon Sep 17 00:00:00 2001 From: Sujith H Date: Wed, 11 Dec 2019 18:57:03 +0530 Subject: [PATCH] Recieve multiple users from backend for user sync Recieve multiple users from the backend for user sync instead of checking for single user. From the received users check if the user to be synced is available in the list. Signed-off-by: Sujith H --- core/Command/User/SyncBackend.php | 18 +++++++++++++----- tests/lib/Command/User/SyncBackendTest.php | 6 +++++- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/core/Command/User/SyncBackend.php b/core/Command/User/SyncBackend.php index 0aa093edbaa4..119ce9f482e6 100644 --- a/core/Command/User/SyncBackend.php +++ b/core/Command/User/SyncBackend.php @@ -252,15 +252,23 @@ private function syncSingleUser( $missingAccountsAction ) { $output->writeln("Syncing $uid ..."); - $users = $backend->getUsers($uid, 2); - if (\count($users) > 1) { - throw new \LengthException("Multiple users returned from backend for: $uid. Cancelling sync."); + $userUids = $backend->getUsers('', null); + $userToSync = null; + foreach ($userUids as $userUid) { + if ($userUid === $uid) { + if ($userToSync === null) { + $userToSync = $userUid; + } else { + throw new \LengthException("Multiple users returned from backend for: $uid. Cancelling sync."); + } + } } $dummy = new Account(); // to prevent null pointer when writing messages - if (\count($users) === 1) { + + if ($userToSync !== null) { // Run the sync using the internal username if mapped - $syncService->run($backend, new \ArrayIterator([$users[0]]), function () { + $syncService->run($backend, new \ArrayIterator([$userToSync]), function () { }); } else { // Not found diff --git a/tests/lib/Command/User/SyncBackendTest.php b/tests/lib/Command/User/SyncBackendTest.php index 0fa223a0a381..fbd121072e49 100644 --- a/tests/lib/Command/User/SyncBackendTest.php +++ b/tests/lib/Command/User/SyncBackendTest.php @@ -276,7 +276,9 @@ public function testSingleUserSyncExistingUserException() { $outputInterface = $this->createMock(OutputInterface::class); $syncService = $this->createMock(SyncService::class); - $this->dummyBackend->method('getUsers')->willReturn(['existing-uid', 'should-explode']); + $this->dummyBackend->method('getUsers')->willReturn(['existing-uid', 'existing-uid']); + $this->dummyBackend->method('getDisplayName') + ->willReturn('existing-uid'); $missingAccountsAction = 'disable'; $syncService->expects($this->never())->method('run'); @@ -297,6 +299,8 @@ public function testSingleUserSyncExistingUser() { $syncService = $this->createMock(SyncService::class); $this->dummyBackend->method('getUsers')->willReturn(['existing-uid']); + $this->dummyBackend->method('getDisplayName') + ->willReturn('existing-uid'); $missingAccountsAction = 'disable'; $syncService->expects($this