Skip to content

Commit

Permalink
bug #35656 [HttpFoundation] Fixed session migration with custom cooki…
Browse files Browse the repository at this point in the history
…e lifetime (Guite)

This PR was squashed before being merged into the 3.4 branch.

Discussion
----------

[HttpFoundation] Fixed session migration with custom cookie lifetime

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #28577
| License       | MIT
| Doc PR        |

This PR adds the fix proposed in symfony/symfony#28577 (comment)

Commits
-------

3e824de385 [HttpFoundation] Fixed session migration with custom cookie lifetime
  • Loading branch information
nicolas-grekas committed Apr 5, 2020
2 parents 7fd8435 + 9a692b6 commit 940167f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Session/Storage/NativeSessionStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,10 @@ public function regenerate($destroy = false, $lifetime = null)
return false;
}

if (null !== $lifetime) {
if (null !== $lifetime && $lifetime != ini_get('session.cookie_lifetime')) {
$this->save();
ini_set('session.cookie_lifetime', $lifetime);
$this->start();
}

if ($destroy) {
Expand Down
13 changes: 13 additions & 0 deletions Tests/Session/Storage/NativeSessionStorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,19 @@ public function testRegenerateDestroy()
$this->assertEquals(11, $storage->getBag('attributes')->get('legs'));
}

public function testRegenerateWithCustomLifetime()
{
$storage = $this->getStorage();
$storage->start();
$id = $storage->getId();
$lifetime = 999999;
$storage->getBag('attributes')->set('legs', 11);
$storage->regenerate(false, $lifetime);
$this->assertNotEquals($id, $storage->getId());
$this->assertEquals(11, $storage->getBag('attributes')->get('legs'));
$this->assertEquals($lifetime, ini_get('session.cookie_lifetime'));
}

public function testSessionGlobalIsUpToDateAfterIdRegeneration()
{
$storage = $this->getStorage();
Expand Down

0 comments on commit 940167f

Please sign in to comment.