Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Generate a session id for new sessions with data #21

Merged
merged 7 commits into from
May 14, 2018
Merged

Generate a session id for new sessions with data #21

merged 7 commits into from
May 14, 2018

Conversation

geerteltink
Copy link
Member

@geerteltink geerteltink commented May 12, 2018

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.

// 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)) {
Copy link
Member

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

@@ -422,4 +422,30 @@ public function testPersistSessionReturnsExpectedResponseWithoutAddedCacheHeader

$this->restoreOriginalSessionIniSettings($ini);
}

public function testCookiesNotSetWithoutRegenerate(): void
Copy link
Member

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).

$response = new Response();
$response = $persistence->persistSession($session, $response);

$this->assertEmpty($response->getHeaderLine('Set-Cookie'));
Copy link
Member

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()) ?

@pine3ree
Copy link
Contributor

pine3ree commented May 12, 2018

Hello @xtreamwayz
I would just put ! $this->cookie before the hasChanged test to avoid function call (I know, I know micro-opt... :-) ) . kind regards.

@geerteltink
Copy link
Member Author

Incorporated changes from @webimpress and @pine3ree.

@@ -16,7 +15,6 @@
use Zend\Expressive\Session\Session;
use Zend\Expressive\Session\SessionInterface;
use Zend\Expressive\Session\SessionPersistenceInterface;

Copy link
Member

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.

@weierophinney weierophinney merged commit cfca5e7 into zendframework:master May 14, 2018
weierophinney added a commit that referenced this pull request May 14, 2018
Generate a session id for new sessions with data
weierophinney added a commit that referenced this pull request May 14, 2018
weierophinney added a commit that referenced this pull request May 14, 2018
weierophinney added a commit that referenced this pull request May 14, 2018
Forward port #21

Conflicts:
	CHANGELOG.md
@weierophinney
Copy link
Member

Thanks, @xtreamwayz!

@geerteltink geerteltink deleted the hotfix/session-persistence branch May 14, 2018 15:13
jbelien added a commit to geo6/batch-geocoder that referenced this pull request May 15, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants