-
Notifications
You must be signed in to change notification settings - Fork 9
Generate a session id for new sessions with data #21
Generate a session id for new sessions with data #21
Conversation
src/PhpSessionPersistence.php
Outdated
// Regenerate if the session is marked as regenerated | ||
// Regenerate if there is no cookie id set but the session has changed (new session with data) | ||
if ($session->isRegenerated() | ||
|| ($session->hasChanged() && ! $this->cookie)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
) {
from if
statement should be in new line
test/PhpSessionPersistenceTest.php
Outdated
@@ -422,4 +422,30 @@ public function testPersistSessionReturnsExpectedResponseWithoutAddedCacheHeader | |||
|
|||
$this->restoreOriginalSessionIniSettings($ini); | |||
} | |||
|
|||
public function testCookiesNotSetWithoutRegenerate(): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually we are not adding : void
in tests, but if we keep it here, there should be one space before :
(consistency).
test/PhpSessionPersistenceTest.php
Outdated
$response = new Response(); | ||
$response = $persistence->persistSession($session, $response); | ||
|
||
$this->assertEmpty($response->getHeaderLine('Set-Cookie')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can just check $this->assertFalse($response->hasHeader())
?
Hello @xtreamwayz |
Incorporated changes from @webimpress and @pine3ree. |
src/PhpSessionPersistence.php
Outdated
@@ -16,7 +15,6 @@ | |||
use Zend\Expressive\Session\Session; | |||
use Zend\Expressive\Session\SessionInterface; | |||
use Zend\Expressive\Session\SessionPersistenceInterface; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert this change, we should have an empty line between different type of imports.
Generate a session id for new sessions with data
Forward port #21 Conflicts: CHANGELOG.md
Thanks, @xtreamwayz! |
Issue with session creation is fixed. See zendframework/zend-expressive-session-ext#21
If a new session was generated, the session id isn't stored. On persistence it doesn't (re)generate an id which is expected. You only need a session if there is data to store. However there is never a check performed for changed data session.
This PR tries to fix that and checks if session data is changed and generates a session id if there wasn't one. This makes sure that data is stored if there wasn't a session yet.