Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HttpFoundation] Fixed session migration with custom cookie lifetime #35656

Merged
merged 1 commit into from Apr 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -152,7 +152,7 @@ public function start()

// ok to try and start the session
if (!session_start()) {
throw new \RuntimeException('Failed to start the session');
throw new \RuntimeException('Failed to start the session.');
}

if (null !== $this->emulateSameSite) {
Expand Down 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 @@ -314,7 +316,7 @@ public function registerBag(SessionBagInterface $bag)
public function getBag($name)
{
if (!isset($this->bags[$name])) {
throw new \InvalidArgumentException(sprintf('The SessionBagInterface %s is not registered.', $name));
throw new \InvalidArgumentException(sprintf('The SessionBagInterface "%s" is not registered.', $name));
}

if (!$this->started && $this->saveHandler->isActive()) {
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