From dd8440595146b577e598d981610530cf1cb8c630 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 --- changelog/unreleased/36576 | 11 +++++++++++ core/Command/User/SyncBackend.php | 18 +++++++++++++----- tests/lib/Command/User/SyncBackendTest.php | 6 +++++- 3 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 changelog/unreleased/36576 diff --git a/changelog/unreleased/36576 b/changelog/unreleased/36576 new file mode 100644 index 000000000000..9dbb4af2c959 --- /dev/null +++ b/changelog/unreleased/36576 @@ -0,0 +1,11 @@ +Bugfix: Receive multiple users for user sync command + +Recieve multiple users for user sync command. Previously +when multiple users were returned, an exception was thrown +and the command was aborted. In this fix we allow multiple +users to be returned, and we check for the uid provided by the +admin matches with the returned users. And if we find matches +of more than one users with same uid, then we throw the exception +that was thrown previously. The messages are kept intact. + +https://github.com/owncloud/core/pull/36576 \ No newline at end of file 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