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