diff options
author | skjnldsv <skjnldsv@protonmail.com> | 2025-07-11 09:17:45 +0200 |
---|---|---|
committer | backportbot[bot] <backportbot[bot]@users.noreply.github.com> | 2025-07-28 07:21:22 +0000 |
commit | 3a76fb03109e31e884bfc054e1104a5a3fef9845 (patch) | |
tree | e16c92acd5f94af2e8392c26ac6b276806d28f33 | |
parent | d7f7b6c89d3aeb5faafb3e5fcbf9f0dad3916fd6 (diff) | |
download | nextcloud-server-backport/53909/stable30.tar.gz nextcloud-server-backport/53909/stable30.zip |
fix(provisioning_api): catch failed user creationbackport/53909/stable30
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
-rw-r--r-- | apps/provisioning_api/lib/Controller/UsersController.php | 8 | ||||
-rw-r--r-- | apps/provisioning_api/tests/Controller/UsersControllerTest.php | 9 |
2 files changed, 13 insertions, 4 deletions
diff --git a/apps/provisioning_api/lib/Controller/UsersController.php b/apps/provisioning_api/lib/Controller/UsersController.php index ba9c260224c..9cf232d46d0 100644 --- a/apps/provisioning_api/lib/Controller/UsersController.php +++ b/apps/provisioning_api/lib/Controller/UsersController.php @@ -536,10 +536,16 @@ class UsersController extends AUserData { throw new OCSException($this->l10n->t('Required email address was not provided'), 110); } + // Create the user try { $newUser = $this->userManager->createUser($userid, $password); - $this->logger->info('Successful addUser call with userid: ' . $userid, ['app' => 'ocs_api']); + if (!$newUser instanceof IUser) { + // If the user is not an instance of IUser, it means the user creation failed + $this->logger->error('Failed addUser attempt: User creation failed.', ['app' => 'ocs_api']); + throw new OCSException($this->l10n->t('User creation failed'), 111); + } + $this->logger->info('Successful addUser call with userid: ' . $userid, ['app' => 'ocs_api']); foreach ($groups as $group) { $this->groupManager->get($group)->addUser($newUser); $this->logger->info('Added userid ' . $userid . ' to group ' . $group, ['app' => 'ocs_api']); diff --git a/apps/provisioning_api/tests/Controller/UsersControllerTest.php b/apps/provisioning_api/tests/Controller/UsersControllerTest.php index 8240e968abb..05553d6b3e9 100644 --- a/apps/provisioning_api/tests/Controller/UsersControllerTest.php +++ b/apps/provisioning_api/tests/Controller/UsersControllerTest.php @@ -466,7 +466,8 @@ class UsersControllerTest extends TestCase { $this->userManager ->expects($this->once()) ->method('createUser') - ->with('NewUser', 'PasswordOfTheNewUser'); + ->with('NewUser', 'PasswordOfTheNewUser') + ->willReturn($this->createMock(IUser::class)); $this->logger ->expects($this->once()) ->method('info') @@ -529,7 +530,8 @@ class UsersControllerTest extends TestCase { $this->userManager ->expects($this->once()) ->method('createUser') - ->with('NewUser', 'PasswordOfTheNewUser'); + ->with('NewUser', 'PasswordOfTheNewUser') + ->willReturn($this->createMock(IUser::class)); $this->logger ->expects($this->once()) ->method('info') @@ -579,7 +581,8 @@ class UsersControllerTest extends TestCase { $this->userManager ->expects($this->once()) ->method('createUser') - ->with($this->anything(), 'PasswordOfTheNewUser'); + ->with($this->anything(), 'PasswordOfTheNewUser') + ->willReturn($this->createMock(IUser::class)); $this->logger ->expects($this->once()) ->method('info') |