updated invalidation session during the change password in the account endpoint

This commit is contained in:
ArnabChatterjee20k
2025-06-18 13:30:24 +05:30
parent 8d62ada545
commit 56494ca427
2 changed files with 38 additions and 0 deletions
+9
View File
@@ -2843,6 +2843,15 @@ App::patch('/v1/account/password')
->setAttribute('hash', Auth::DEFAULT_ALGO)
->setAttribute('hashOptions', Auth::DEFAULT_ALGO_OPTIONS);
$sessions = $user->getAttribute('sessions', []);
$current = Auth::sessionVerify($sessions, Auth::$secret);
foreach ($sessions as $session) {
/** @var Document $session */
if ($session->getId() !== $current) {
$dbForProject->deleteDocument('sessions', $session->getId());
}
}
$user = $dbForProject->updateDocument('users', $user->getId(), $user);
$queueForEvents->setParam('userId', $user->getId());
@@ -480,6 +480,20 @@ class AccountCustomClientTest extends Scope
$password = $data['password'] ?? '';
$session = $data['session'] ?? '';
for ($i = 0; $i < 5; $i++) {
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([
'origin' => 'http://localhost',
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
]), [
'email' => $email,
'password' => $password,
]);
$this->assertEquals(201, $response['headers']['status-code']);
sleep(1);
}
/**
* Test for SUCCESS
*/
@@ -500,6 +514,21 @@ class AccountCustomClientTest extends Scope
$this->assertTrue((new DatetimeValidator())->isValid($response['body']['registration']));
$this->assertEquals($response['body']['email'], $email);
// checking for all non active sessions are cleared
$sessionId = $data['sessionId'] ?? '';
$response = $this->client->call(Client::METHOD_GET, '/account/sessions', array_merge([
'origin' => 'http://localhost',
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
]));
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertEquals(1, $response['body']['total']);
// checking the current session or not
$this->assertEquals($sessionId, $response['body']['sessions'][0]['$id']);
$this->assertTrue($response['body']['sessions'][0]['current']);
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([
'origin' => 'http://localhost',
'content-type' => 'application/json',