Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/UserBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ public function getBackendName(): string {
}

/**
* Creates a user if it does not exist.
* Creates a user if it does not exist in this or any other user backend.
*/
public function createUserIfNotExists(string $uid, bool $firstLoginIfNeeded = true): void {
if (!$this->loadUser($uid)) {
if (!$this->loadUser($uid) && $this->userManager->userExists($uid)) {
$this->logger->warning('Account "' . $uid . '" exists in another user backend, not provisioning it by global scale', ['app' => Application::APP_ID]);
} elseif (!$this->loadUser($uid)) {
$values = [
'uid' => $uid,
];
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/lib/UserBackendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ public function testCreateExistingUserWritesNoAuditLog(): void {
$this->getBackend(true)->createUserIfNotExists('alice', false);
}

public function testCreateUserKnownToOtherBackendInsertsNothing(): void {
$this->userManager->expects($this->once())
->method('userExists')
->with('alice')
->willReturn(true);
$this->db->expects($this->never())->method('getQueryBuilder');
$this->auditLogService->expects($this->never())->method('log');
$this->stopAtHomeSetup();

$this->getBackend(false)->createUserIfNotExists('alice', false);
}

private function prepareGroups(array $currentGroups): void {
$user = $this->createMock(IUser::class);
$user->method('getUID')->willReturn('alice');
Expand Down
Loading