1
0
Fork 0
mirror of synced 2024-10-02 18:26:49 +13:00

fix: empty payload deleting single user session

This commit is contained in:
geisterfurz007 2022-10-27 19:32:49 +02:00
parent 1b0abf4643
commit e891424c17
2 changed files with 58 additions and 12 deletions

View file

@ -1004,7 +1004,8 @@ App::delete('/v1/users/:userId/sessions/:sessionId')
$events
->setParam('userId', $user->getId())
->setParam('sessionId', $sessionId);
->setParam('sessionId', $sessionId)
->setPayload($response->output($session, Response::MODEL_SESSION));
$response->noContent();
});

View file

@ -458,21 +458,29 @@ class RealtimeCustomClientTest extends Scope
$this->assertContains("users.*", $response['data']['events']);
$this->assertNotEmpty($response['data']['payload']);
$createSession = function () use ($projectId): array {
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([
'origin' => 'http://localhost',
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
]), [
'email' => 'torsten@appwrite.io',
'password' => 'new-password',
]);
$sessionNew = $this->client->parseCookie((string)$response['headers']['set-cookie'])['a_session_' . $projectId];
$sessionNewId = $response['body']['$id'];
return array("session" => $sessionNew, "sessionId" => $sessionNewId);
};
/**
* Test Account Session Create
*/
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([
'origin' => 'http://localhost',
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
]), [
'email' => 'torsten@appwrite.io',
'password' => 'new-password',
]);
$sessionNew = $this->client->parseCookie((string)$response['headers']['set-cookie'])['a_session_' . $projectId];
$sessionNewId = $response['body']['$id'];
$sessionData = $createSession();
$sessionNew = $sessionData['session'];
$sessionNewId = $sessionData['sessionId'];
$response = json_decode($client->receive(), true);
$this->assertArrayHasKey('type', $response);
@ -527,6 +535,43 @@ class RealtimeCustomClientTest extends Scope
$this->assertContains("users.*", $response['data']['events']);
$this->assertNotEmpty($response['data']['payload']);
/**
* Test User Account Session Delete
*/
$sessionData = $createSession();
$sessionNew = $sessionData['session'];
$sessionNewId = $sessionData['sessionId'];
$client->receive(); // Receive the creation message and drop; this was tested earlier already
$this->client->call(Client::METHOD_DELETE, '/users/' . $userId . '/sessions/' . $sessionNewId, array_merge([
'origin' => 'http://localhost',
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
'x-appwrite-key' => $this->getProject()['apiKey'],
]));
$response = json_decode($client->receive(), true);
$this->assertArrayHasKey('type', $response);
$this->assertArrayHasKey('data', $response);
$this->assertEquals('event', $response['type']);
$this->assertNotEmpty($response['data']);
$this->assertCount(2, $response['data']['channels']);
$this->assertArrayHasKey('timestamp', $response['data']);
$this->assertContains('account', $response['data']['channels']);
$this->assertContains('account.' . $userId, $response['data']['channels']);
$this->assertContains("users.{$userId}.sessions.{$sessionNewId}.delete", $response['data']['events']);
$this->assertContains("users.{$userId}.sessions.{$sessionNewId}", $response['data']['events']);
$this->assertContains("users.{$userId}.sessions.*.delete", $response['data']['events']);
$this->assertContains("users.{$userId}.sessions.*", $response['data']['events']);
$this->assertContains("users.{$userId}", $response['data']['events']);
$this->assertContains("users.*.sessions.{$sessionNewId}.delete", $response['data']['events']);
$this->assertContains("users.*.sessions.{$sessionNewId}", $response['data']['events']);
$this->assertContains("users.*.sessions.*.delete", $response['data']['events']);
$this->assertContains("users.*.sessions.*", $response['data']['events']);
$this->assertContains("users.*", $response['data']['events']);
$this->assertNotEmpty($response['data']['payload']);
/**
* Test Account Create Recovery
*/