From 9f1b2644e1d0d46fb7a955bcd9b709e5b00c8d9e Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Mon, 25 Apr 2022 14:58:34 +0200 Subject: [PATCH 1/3] fix(account): magic link session verifies email --- app/controllers/api/account.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 200b845987..587d0da862 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -838,6 +838,7 @@ App::put('/v1/account/sessions/magic-url') } $user + ->setAttribute('emailVerification', true) ->setAttribute('sessions', $session, Document::SET_TYPE_APPEND) ->setAttribute('tokens', $tokens); From 5dedd629bd2a580fe4c3c36554f550d757d8049c Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Mon, 25 Apr 2022 14:59:08 +0200 Subject: [PATCH 2/3] fix(account): countryName from session locale --- app/controllers/api/account.php | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 587d0da862..4b7db25b7b 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -869,9 +869,7 @@ App::put('/v1/account/sessions/magic-url') ->setStatusCode(Response::STATUS_CODE_CREATED) ; - $countryName = (isset($countries[strtoupper($session->getAttribute('countryCode'))])) - ? $countries[strtoupper($session->getAttribute('countryCode'))] - : $locale->getText('locale.country.unknown'); + $countryName = $locale->getText('countries.'.strtolower($session->getAttribute('countryCode')), $locale->getText('locale.country.unknown')); $session ->setAttribute('current', true) @@ -1014,9 +1012,7 @@ App::post('/v1/account/sessions/anonymous') ->setStatusCode(Response::STATUS_CODE_CREATED) ; - $countryName = (isset($countries[strtoupper($session->getAttribute('countryCode'))])) - ? $countries[strtoupper($session->getAttribute('countryCode'))] - : $locale->getText('locale.country.unknown'); + $countryName = $locale->getText('countries.'.strtolower($session->getAttribute('countryCode')), $locale->getText('locale.country.unknown')); $session ->setAttribute('current', true) @@ -1281,15 +1277,13 @@ App::get('/v1/account/sessions/:sessionId') $sessions = $user->getAttribute('sessions', []); $sessionId = ($sessionId === 'current') - ? Auth::sessionVerify($user->getAttribute('sessions'), Auth::$secret) - : $sessionId; + ? Auth::sessionVerify($user->getAttribute('sessions'), Auth::$secret) + : $sessionId; foreach ($sessions as $session) {/** @var Document $session */ if ($sessionId == $session->getId()) { - $countryName = (isset($countries[strtoupper($session->getAttribute('countryCode'))])) - ? $countries[strtoupper($session->getAttribute('countryCode'))] - : $locale->getText('locale.country.unknown'); + $countryName = $locale->getText('countries.'.strtolower($session->getAttribute('countryCode')), $locale->getText('locale.country.unknown')); $session ->setAttribute('current', ($session->getAttribute('secret') == Auth::hash(Auth::$secret))) @@ -1623,7 +1617,7 @@ App::delete('/v1/account/sessions/:sessionId') if ($session->getAttribute('secret') == Auth::hash(Auth::$secret)) { // If current session delete the cookies too $session ->setAttribute('current', true) - ->setAttribute('countryName', (isset($countries[strtoupper($session->getAttribute('countryCode'))])) ? $countries[strtoupper($session->getAttribute('countryCode'))] : $locale->getText('locale.country.unknown')) + ->setAttribute('countryName', $locale->getText('countries.'.strtolower($session->getAttribute('countryCode')), $locale->getText('locale.country.unknown'))) ; if (!Config::getParam('domainVerification')) { @@ -1807,7 +1801,7 @@ App::delete('/v1/account/sessions') $session ->setAttribute('current', false) - ->setAttribute('countryName', (isset($countries[strtoupper($session->getAttribute('countryCode'))])) ? $countries[strtoupper($session->getAttribute('countryCode'))] : $locale->getText('locale.country.unknown')) + ->setAttribute('countryName', $locale->getText('countries.'.strtolower($session->getAttribute('countryCode')), $locale->getText('locale.country.unknown'))) ; if ($session->getAttribute('secret') == Auth::hash(Auth::$secret)) { // If current session delete the cookies too From 501563f8c4da6e111cf4b7171c4299fe5c2b359a Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Mon, 25 Apr 2022 15:07:39 +0200 Subject: [PATCH 3/3] tests: adapt magic url tests --- tests/e2e/Services/Account/AccountBase.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/e2e/Services/Account/AccountBase.php b/tests/e2e/Services/Account/AccountBase.php index cca6c8ff72..2fbe65a0e5 100644 --- a/tests/e2e/Services/Account/AccountBase.php +++ b/tests/e2e/Services/Account/AccountBase.php @@ -1279,7 +1279,7 @@ trait AccountBase $expireTime = strpos($lastEmail['text'], 'expire='.$response['body']['expire'], 0); $this->assertNotFalse($expireTime); - + $secretTest = strpos($lastEmail['text'], 'secret='.$response['body']['secret'], 0); $this->assertNotFalse($secretTest); @@ -1339,6 +1339,7 @@ trait AccountBase { $id = $data['id'] ?? ''; $token = $data['token'] ?? ''; + $email = $data['email'] ?? ''; /** * Test for SUCCESS @@ -1361,6 +1362,20 @@ trait AccountBase $sessionId = $response['body']['$id']; $session = $this->client->parseCookie((string)$response['headers']['set-cookie'])['a_session_'.$this->getProject()['$id']]; + $response = $this->client->call(Client::METHOD_GET, '/account', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'cookie' => 'a_session_'.$this->getProject()['$id'].'=' . $session, + ])); + + $this->assertEquals($response['headers']['status-code'], 200); + $this->assertNotEmpty($response['body']); + $this->assertNotEmpty($response['body']['$id']); + $this->assertIsNumeric($response['body']['registration']); + $this->assertEquals($response['body']['email'], $email); + $this->assertTrue($response['body']['emailVerification']); + /** * Test for FAILURE */