From cd4f478e67f7c8776a13b17e7d44241fd66261ad Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 12 Oct 2022 11:34:45 +0200 Subject: [PATCH] [HttpFoundation] Fix session tests --- Tests/Session/Storage/Handler/Fixtures/common.inc | 14 ++++++++++++-- .../Storage/Handler/Fixtures/regenerate.expected | 3 +-- .../Fixtures/with_samesite_and_migration.expected | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Tests/Session/Storage/Handler/Fixtures/common.inc b/Tests/Session/Storage/Handler/Fixtures/common.inc index fd662e3a1..ef8775423 100644 --- a/Tests/Session/Storage/Handler/Fixtures/common.inc +++ b/Tests/Session/Storage/Handler/Fixtures/common.inc @@ -54,10 +54,12 @@ ob_start(); class TestSessionHandler extends AbstractSessionHandler { private $data; + private $sessionId; - public function __construct($data = '') + public function __construct($data = '', $sessionId = null) { $this->data = $data; + $this->sessionId = $sessionId; } public function open($path, $name): bool @@ -131,7 +133,13 @@ class TestSessionHandler extends AbstractSessionHandler protected function doRead($sessionId): string { - echo __FUNCTION__.': ', $this->data, "\n"; + if (isset($this->sessionId) && $sessionId !== $this->sessionId) { + echo __FUNCTION__ . ": invalid sessionId\n"; + + return ''; + } + echo __FUNCTION__ . ': ', $this->data, "\n"; + $this->sessionId = $sessionId; return $this->data; } @@ -139,6 +147,7 @@ class TestSessionHandler extends AbstractSessionHandler protected function doWrite($sessionId, $data): bool { echo __FUNCTION__.': ', $data, "\n"; + $this->sessionId = $sessionId; return true; } @@ -146,6 +155,7 @@ class TestSessionHandler extends AbstractSessionHandler protected function doDestroy($sessionId): bool { echo __FUNCTION__, "\n"; + $this->sessionId = ''; return true; } diff --git a/Tests/Session/Storage/Handler/Fixtures/regenerate.expected b/Tests/Session/Storage/Handler/Fixtures/regenerate.expected index d825f44f7..95c96f0cc 100644 --- a/Tests/Session/Storage/Handler/Fixtures/regenerate.expected +++ b/Tests/Session/Storage/Handler/Fixtures/regenerate.expected @@ -9,9 +9,8 @@ close open validateId read -doRead: abc|i:123; +doRead: invalid sessionId read -doRead: abc|i:123; write doWrite: abc|i:123; diff --git a/Tests/Session/Storage/Handler/Fixtures/with_samesite_and_migration.expected b/Tests/Session/Storage/Handler/Fixtures/with_samesite_and_migration.expected index 8b5fc08bd..b7cae201c 100644 --- a/Tests/Session/Storage/Handler/Fixtures/with_samesite_and_migration.expected +++ b/Tests/Session/Storage/Handler/Fixtures/with_samesite_and_migration.expected @@ -8,7 +8,7 @@ close open validateId read -doRead: +doRead: invalid sessionId read write