From c30c02480541523814b55f07b273a7b82f122a77 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Tue, 10 Oct 2023 14:36:53 +0100 Subject: [PATCH] test: fix magic url assertions --- app/controllers/api/account.php | 4 ++-- tests/e2e/Services/Account/AccountBase.php | 6 +++--- tests/e2e/Services/Account/AccountCustomClientTest.php | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 90d87a7f93..0e110861ba 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -1012,7 +1012,7 @@ App::post('/v1/account/sessions/magic-url') } $url = Template::parseURL($url); - $url['query'] = Template::mergeQuery(((isset($url['query'])) ? $url['query'] : ''), ['userId' => $user->getId(), 'secret' => $loginSecret, 'expire' => $expire, 'project' => $project->getId()]); + $url['query'] = Template::mergeQuery(((isset($url['query'])) ? $url['query'] : ''), ['userId' => $user->getId(), 'secret' => $tokenSecret, 'expire' => $expire, 'project' => $project->getId()]); $url = Template::unParseURL($url); $body = $locale->getText("emails.magicSession.body"); @@ -1102,7 +1102,7 @@ App::post('/v1/account/sessions/magic-url') ); // Hide secret for clients - $token->setAttribute('secret', $tokenSecret); + $token->setAttribute('secret', ($isPrivilegedUser || $isAppUser) ? $tokenSecret : ''); $response ->setStatusCode(Response::STATUS_CODE_CREATED) diff --git a/tests/e2e/Services/Account/AccountBase.php b/tests/e2e/Services/Account/AccountBase.php index 75a0e3ef29..bb418d771f 100644 --- a/tests/e2e/Services/Account/AccountBase.php +++ b/tests/e2e/Services/Account/AccountBase.php @@ -1300,7 +1300,7 @@ trait AccountBase $this->assertEquals(201, $response['headers']['status-code']); $this->assertNotEmpty($response['body']['$id']); - $this->assertNotEmpty($response['body']['secret']); + $this->assertEmpty($response['body']['secret']); $this->assertEquals(true, (new DatetimeValidator())->isValid($response['body']['expire'])); $userId = $response['body']['userId']; @@ -1393,6 +1393,7 @@ trait AccountBase $this->assertNotEmpty($response['body']); $this->assertNotEmpty($response['body']['$id']); $this->assertNotEmpty($response['body']['userId']); + $this->assertNotEmpty($response['body']['secret']); $sessionId = $response['body']['$id']; $session = $this->client->parseCookie((string)$response['headers']['set-cookie'])['a_session_' . $this->getProject()['$id']]; @@ -1407,7 +1408,6 @@ trait AccountBase $this->assertEquals($response['headers']['status-code'], 200); $this->assertNotEmpty($response['body']); $this->assertNotEmpty($response['body']['$id']); - $this->assertNotEmpty($response['body']['secret']); $this->assertEquals(true, (new DatetimeValidator())->isValid($response['body']['registration'])); $this->assertEquals($response['body']['email'], $email); $this->assertTrue($response['body']['emailVerification']); @@ -1468,7 +1468,6 @@ trait AccountBase $this->assertIsArray($response['body']); $this->assertNotEmpty($response['body']); $this->assertNotEmpty($response['body']['$id']); - $this->assertNotEmpty($response['body']['secret']); $this->assertEquals(true, (new DatetimeValidator())->isValid($response['body']['registration'])); $this->assertEquals($response['body']['email'], $email); @@ -1482,6 +1481,7 @@ trait AccountBase ]); $this->assertEquals($response['headers']['status-code'], 201); + $this->assertNotEmpty($response['body']['secret']); /** * Test for FAILURE diff --git a/tests/e2e/Services/Account/AccountCustomClientTest.php b/tests/e2e/Services/Account/AccountCustomClientTest.php index dcb5431c4d..89851686cb 100644 --- a/tests/e2e/Services/Account/AccountCustomClientTest.php +++ b/tests/e2e/Services/Account/AccountCustomClientTest.php @@ -760,7 +760,7 @@ class AccountCustomClientTest extends Scope $this->assertEquals(201, $response['headers']['status-code']); $this->assertNotEmpty($response['body']['$id']); - $this->assertNotEmpty($response['body']['secret']); + $this->assertEmpty($response['body']['secret']); $this->assertEquals(true, (new DatetimeValidator())->isValid($response['body']['expire'])); $userId = $response['body']['userId']; @@ -1003,7 +1003,7 @@ class AccountCustomClientTest extends Scope $this->assertEquals(201, $response['headers']['status-code']); $this->assertNotEmpty($response['body']['$id']); - $this->assertEmpty($response['body']['secret']); + $this->assertNotEmpty($response['body']['secret']); $this->assertEquals(true, (new DatetimeValidator())->isValid($response['body']['expire'])); \sleep(2);