From 88cf7ea9e831ff98b7342d2bd35f252e2c544257 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 24 Jan 2024 15:31:58 +0100 Subject: [PATCH] fix: race condition with creating a user with targets --- app/controllers/api/users.php | 4 ++-- phpunit.xml | 2 +- tests/e2e/Services/Messaging/MessagingBase.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index 275ea334e..117338b9a 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -108,6 +108,8 @@ function createUser(string $hash, mixed $hashOptions, string $userId, ?string $e $hooks->trigger('passwordValidator', [$dbForProject, $project, $plaintextPassword, &$user, true]); } + $user = $dbForProject->createDocument('users', $user); + if ($email) { try { $target = $dbForProject->createDocument('targets', new Document([ @@ -143,8 +145,6 @@ function createUser(string $hash, mixed $hashOptions, string $userId, ?string $e } $dbForProject->deleteCachedDocument('users', $user->getId()); - - $user = $dbForProject->createDocument('users', $user); } catch (Duplicate $th) { throw new Exception(Exception::USER_ALREADY_EXISTS); } diff --git a/phpunit.xml b/phpunit.xml index 90ebd4225..e77286605 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -6,7 +6,7 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" - stopOnFailure="false" + stopOnFailure="true" > diff --git a/tests/e2e/Services/Messaging/MessagingBase.php b/tests/e2e/Services/Messaging/MessagingBase.php index d6c4b59ce..1a1667465 100644 --- a/tests/e2e/Services/Messaging/MessagingBase.php +++ b/tests/e2e/Services/Messaging/MessagingBase.php @@ -634,7 +634,7 @@ trait MessagingBase $this->assertEquals(201, $response['headers']['status-code'], "Error creating user: " . var_export($response['body'], true)); $user = $response['body']; - + var_dump($user); $this->assertEquals(1, \count($user['targets'])); $targetId = $user['targets'][0]['$id'];