From d118b09d90b79b6d9de995c5dbf4cc3bf93463f1 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Thu, 20 May 2021 15:41:55 +0200 Subject: [PATCH] fix(account): add anon sessiom id --- app/controllers/api/account.php | 10 ++++++++-- tests/e2e/Services/Account/AccountCustomClientTest.php | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index a325bdd66..61b0e27be 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -714,10 +714,16 @@ App::post('/v1/account/sessions/anonymous') $detector->getDevice() )); - $user->setAttribute('sessions', $session, Document::SET_TYPE_APPEND); - Authorization::setRole('user:'.$user->getId()); + $session = $projectDB->createDocument($session->getArrayCopy()); + + if (false === $session) { + throw new Exception('Failed saving session to DB', 500); + } + + $user->setAttribute('sessions', $session, Document::SET_TYPE_APPEND); + $user = $projectDB->updateDocument($user->getArrayCopy()); if (false === $user) { diff --git a/tests/e2e/Services/Account/AccountCustomClientTest.php b/tests/e2e/Services/Account/AccountCustomClientTest.php index 6c4de08fd..77a4f9368 100644 --- a/tests/e2e/Services/Account/AccountCustomClientTest.php +++ b/tests/e2e/Services/Account/AccountCustomClientTest.php @@ -240,6 +240,10 @@ class AccountCustomClientTest extends Scope ]); $this->assertEquals(201, $response['headers']['status-code']); + $this->assertIsArray($response['body']); + $this->assertNotEmpty($response['body']); + $this->assertNotEmpty($response['body']['$id']); + $this->assertNotEmpty($response['body']['userId']); $session = $this->client->parseCookie((string)$response['headers']['set-cookie'])['a_session_'.$this->getProject()['$id']];