Skip to content

Commit

Permalink
Recieve multiple users from backend for user sync
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
sharidas committed Dec 13, 2019
1 parent cf40428 commit eb81bab
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
18 changes: 13 additions & 5 deletions core/Command/User/SyncBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion tests/lib/Command/User/SyncBackendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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
Expand Down

0 comments on commit eb81bab

Please sign in to comment.