Skip to content

Commit 1045e26

Browse files
committed
fix(provisioning_api): catch failed user creation
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
1 parent 6f0255d commit 1045e26

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

apps/provisioning_api/lib/Controller/UsersController.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,10 +542,16 @@ public function addUser(
542542
throw new OCSException($this->l10n->t('Required email address was not provided'), 110);
543543
}
544544

545+
// Create the user
545546
try {
546547
$newUser = $this->userManager->createUser($userid, $password);
547-
$this->logger->info('Successful addUser call with userid: ' . $userid, ['app' => 'ocs_api']);
548+
if (!$newUser instanceof IUser) {
549+
// If the user is not an instance of IUser, it means the user creation failed
550+
$this->logger->error('Failed addUser attempt: User creation failed.', ['app' => 'ocs_api']);
551+
throw new OCSException($this->l10n->t('User creation failed'), 111);
552+
}
548553

554+
$this->logger->info('Successful addUser call with userid: ' . $userid, ['app' => 'ocs_api']);
549555
foreach ($groups as $group) {
550556
$this->groupManager->get($group)->addUser($newUser);
551557
$this->logger->info('Added userid ' . $userid . ' to group ' . $group, ['app' => 'ocs_api']);

apps/provisioning_api/tests/Controller/UsersControllerTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,8 @@ public function testAddUserSuccessful(): void {
452452
$this->userManager
453453
->expects($this->once())
454454
->method('createUser')
455-
->with('NewUser', 'PasswordOfTheNewUser');
455+
->with('NewUser', 'PasswordOfTheNewUser')
456+
->willReturn($this->createMock(IUser::class));
456457
$this->logger
457458
->expects($this->once())
458459
->method('info')
@@ -517,7 +518,8 @@ public function testAddUserSuccessfulWithDisplayName(): void {
517518
$this->userManager
518519
->expects($this->once())
519520
->method('createUser')
520-
->with('NewUser', 'PasswordOfTheNewUser');
521+
->with('NewUser', 'PasswordOfTheNewUser')
522+
->willReturn($this->createMock(IUser::class));
521523
$this->logger
522524
->expects($this->once())
523525
->method('info')
@@ -567,7 +569,8 @@ public function testAddUserSuccessfulGenerateUserID(): void {
567569
$this->userManager
568570
->expects($this->once())
569571
->method('createUser')
570-
->with($this->anything(), 'PasswordOfTheNewUser');
572+
->with($this->anything(), 'PasswordOfTheNewUser')
573+
->willReturn($this->createMock(IUser::class));
571574
$this->logger
572575
->expects($this->once())
573576
->method('info')

0 commit comments

Comments
 (0)