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 #28577 (comment)

Commits
-------

3e824de [HttpFoundation] Fixed session migration with custom cookie lifetime
  • Loading branch information
nicolas-grekas committed Apr 5, 2020
2 parents 9b41a32 + 3e824de commit 78770e7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
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
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 78770e7

Please sign in to comment.