From 6259a6182aa2982da80e6b9ecb49cff35cdfa30c Mon Sep 17 00:00:00 2001 From: hamza Date: Wed, 28 Oct 2026 17:11:15 +0100 Subject: [PATCH] fix(UserBackend): do not provision accounts that exist in another backend Assisted-by: ClaudeCode:claude-fable-5-1 Signed-off-by: hamza --- lib/UserBackend.php | 6 ++++-- tests/unit/lib/UserBackendTest.php | 12 ++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/UserBackend.php b/lib/UserBackend.php index dd9c199..e2e60ec 100644 --- a/lib/UserBackend.php +++ b/lib/UserBackend.php @@ -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, ]; diff --git a/tests/unit/lib/UserBackendTest.php b/tests/unit/lib/UserBackendTest.php index d1b2525..a12fe97 100644 --- a/tests/unit/lib/UserBackendTest.php +++ b/tests/unit/lib/UserBackendTest.php @@ -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');