aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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')