1
0
Fork 0
mirror of synced 2024-07-02 05:00:33 +12:00

fix: race condition with creating a user with targets

This commit is contained in:
Torsten Dittmann 2024-01-24 15:31:58 +01:00
parent 62e459c581
commit 88cf7ea9e8
3 changed files with 4 additions and 4 deletions

View file

@ -108,6 +108,8 @@ function createUser(string $hash, mixed $hashOptions, string $userId, ?string $e
$hooks->trigger('passwordValidator', [$dbForProject, $project, $plaintextPassword, &$user, true]); $hooks->trigger('passwordValidator', [$dbForProject, $project, $plaintextPassword, &$user, true]);
} }
$user = $dbForProject->createDocument('users', $user);
if ($email) { if ($email) {
try { try {
$target = $dbForProject->createDocument('targets', new Document([ $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()); $dbForProject->deleteCachedDocument('users', $user->getId());
$user = $dbForProject->createDocument('users', $user);
} catch (Duplicate $th) { } catch (Duplicate $th) {
throw new Exception(Exception::USER_ALREADY_EXISTS); throw new Exception(Exception::USER_ALREADY_EXISTS);
} }

View file

@ -6,7 +6,7 @@
convertNoticesToExceptions="true" convertNoticesToExceptions="true"
convertWarningsToExceptions="true" convertWarningsToExceptions="true"
processIsolation="false" processIsolation="false"
stopOnFailure="false" stopOnFailure="true"
> >
<extensions> <extensions>
<extension class="Appwrite\Tests\TestHook" /> <extension class="Appwrite\Tests\TestHook" />

View file

@ -634,7 +634,7 @@ trait MessagingBase
$this->assertEquals(201, $response['headers']['status-code'], "Error creating user: " . var_export($response['body'], true)); $this->assertEquals(201, $response['headers']['status-code'], "Error creating user: " . var_export($response['body'], true));
$user = $response['body']; $user = $response['body'];
var_dump($user);
$this->assertEquals(1, \count($user['targets'])); $this->assertEquals(1, \count($user['targets']));
$targetId = $user['targets'][0]['$id']; $targetId = $user['targets'][0]['$id'];