Skip to content

Commit 951878a

Browse files
authored
Merge branch '5.0' into fix-response-descriptions
2 parents 0c6d963 + 09a2626 commit 951878a

5 files changed

Lines changed: 55 additions & 4 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"symfony/security-csrf": "^7.4",
4545
"symfony/yaml": "^7.4",
4646
"twig/twig": "^3.0",
47-
"webmozart/assert": "^1.11"
47+
"webmozart/assert": "^2.3"
4848
},
4949
"require-dev": {
5050
"ibexa/code-style": "~2.0.0",

src/bundle/Resources/config/services.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ services:
422422
arguments:
423423
$parsingDispatcher: '@Ibexa\Contracts\Rest\Input\ParsingDispatcher'
424424

425-
Ibexa\Contracts\Rest\Output\ValueObjectVisitorResolverInterface: '@Ibexa\Contracts\Rest\Output\ValueObjectVisitor'
425+
Ibexa\Contracts\Rest\Output\ValueObjectVisitorResolverInterface: '@Ibexa\Contracts\Rest\Output\ValueObjectVisitorResolver'
426426

427427
Ibexa\Contracts\Rest\Output\ValueObjectVisitorResolver: ~
428428

src/lib/Server/Controller/Session/SessionBaseController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ protected function logout(Request $request): Response
9393
$response->setStatusCode(Response::HTTP_NOT_FOUND);
9494
$requestSession->clear();
9595

96+
$this->securityTokenStorage->setToken(null);
97+
9698
return $response;
9799
}
98100
}

tests/bundle/Functional/SessionTest.php

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,55 @@ public function testLoginWithExistingFrontendSession(): void
142142
$this->assertHttpResponseCodeEquals($response, 201);
143143
}
144144

145+
public function testDeletedSessionCookieCannotReauthenticate(): void
146+
{
147+
$session = $this->login();
148+
149+
// Logged-in server-side session check
150+
$currentSessionRequest = $this->createHttpRequest(
151+
'GET',
152+
'/api/ibexa/v2/user/sessions/current',
153+
'',
154+
'Session+json',
155+
'',
156+
[
157+
'Cookie' => sprintf('%s=%s', $session->name, $session->identifier),
158+
'X-CSRF-Token' => $session->csrfToken,
159+
]
160+
);
161+
$currentSessionResponse = $this->sendHttpRequest($currentSessionRequest);
162+
self::assertHttpResponseCodeEquals($currentSessionResponse, 200);
163+
$authenticatedData = json_decode($currentSessionResponse->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR);
164+
$authenticatedUserHref = $authenticatedData['Session']['User']['_href'];
165+
166+
// Logout
167+
$deleteResponse = $this->sendHttpRequest($this->createDeleteRequest($session));
168+
self::assertHttpResponseCodeEquals($deleteResponse, 204);
169+
170+
// Re-use the old cookie — the server-side session must no longer be authenticated as the original user
171+
$reusedResponse = $this->sendHttpRequest(
172+
$this->createHttpRequest(
173+
'GET',
174+
'/api/ibexa/v2/user/sessions/current',
175+
'',
176+
'Session+json',
177+
'',
178+
['Cookie' => sprintf('%s=%s', $session->name, $session->identifier)]
179+
)
180+
);
181+
182+
$reusedData = json_decode($reusedResponse->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR);
183+
self::assertNotEquals(
184+
$authenticatedUserHref,
185+
$reusedData['Session']['User']['_href'],
186+
'Old session cookie must not re-authenticate as the original user after logout'
187+
);
188+
self::assertEquals(
189+
'/api/ibexa/v2/user/users/10',
190+
$reusedData['Session']['User']['_href']
191+
);
192+
}
193+
145194
public function testDeleteSessionExpired(): void
146195
{
147196
$session = $this->login();
@@ -195,7 +244,7 @@ public function testCheckSession(): void
195244
$this->assertHttpResponseCodeEquals($response, 200);
196245

197246
$contents = $response->getBody()->getContents();
198-
$data = json_decode($contents, true, JSON_THROW_ON_ERROR);
247+
$data = json_decode($contents, true, 512, JSON_THROW_ON_ERROR);
199248
self::assertArrayHasKey('Session', $data);
200249
}
201250

tests/bundle/Functional/TestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ protected function login(): \stdClass
352352
$response = $this->sendHttpRequest($request);
353353
self::assertHttpResponseCodeEquals($response, 201);
354354

355-
return json_decode($response->getBody()->getContents(), false, JSON_THROW_ON_ERROR)->Session;
355+
return json_decode($response->getBody()->getContents(), false, 512, JSON_THROW_ON_ERROR)->Session;
356356
}
357357

358358
/**

0 commit comments

Comments
 (0)