aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorskjnldsv <skjnldsv@protonmail.com>2025-07-11 09:17:45 +0200
committerJohn Molakvoæ <skjnldsv@users.noreply.github.com>2025-07-14 10:34:22 +0200
commit74d64942904e533e34e8da77bcd3c457fabace46 (patch)
treea9cb367bbc3250c168eb30f7112decc97e179924
parent19009b3620f21a63be19c5766a4c29126d41fd2f (diff)
downloadnextcloud-server-fix/newUser-provisioning_api.tar.gz
nextcloud-server-fix/newUser-provisioning_api.zip
fix(provisioning_api): catch failed user creationfix/newUser-provisioning_api
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
-rw-r--r--apps/provisioning_api/lib/Controller/UsersController.php8
-rw-r--r--apps/provisioning_api/tests/Controller/UsersControllerTest.php9
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 51b18306b51..1d1d0e8d2f9 100644
--- a/apps/provisioning_api/lib/Controller/UsersController.php
+++ b/apps/provisioning_api/lib/Controller/UsersController.php
@@ -542,10 +542,16 @@ class UsersController extends AUserDataOCSController {
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 85ec9e374d6..e838cd16633 100644
--- a/apps/provisioning_api/tests/Controller/UsersControllerTest.php
+++ b/apps/provisioning_api/tests/Controller/UsersControllerTest.php
@@ -452,7 +452,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')
@@ -517,7 +518,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')
@@ -567,7 +569,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')