Skip to content

Commit bdbab10

Browse files
authored
Merge pull request #1153 from magento-troll/MAGETWO-65236
[Troll] MAGETWO-65236: Expiration date of PHPSESSID cookie is not updated
2 parents 25bf998 + e168f57 commit bdbab10

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

dev/tests/integration/testsuite/Magento/Backend/Model/Auth/SessionTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
/**
99
* @magentoAppArea adminhtml
10+
* @magentoAppIsolation enabled
11+
* @magentoDbIsolation enabled
1012
*/
1113
class SessionTest extends \PHPUnit_Framework_TestCase
1214
{
@@ -34,6 +36,7 @@ protected function setUp()
3436
$this->auth = $this->objectManager->create(\Magento\Backend\Model\Auth::class);
3537
$this->authSession = $this->objectManager->create(\Magento\Backend\Model\Auth\Session::class);
3638
$this->auth->setAuthStorage($this->authSession);
39+
$this->auth->logout();
3740
}
3841

3942
protected function tearDown()

lib/internal/Magento/Framework/Session/SessionManager.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ public function start()
188188
$this->setSessionId($this->sidResolver->getSid($this));
189189
session_start();
190190
$this->validator->validate($this);
191+
$this->renewCookie();
191192

192193
register_shutdown_function([$this, 'writeClose']);
193194

@@ -198,6 +199,35 @@ public function start()
198199
return $this;
199200
}
200201

202+
/**
203+
* Renew session cookie to prolong session
204+
*
205+
* @return $this
206+
*/
207+
private function renewCookie()
208+
{
209+
if (!$this->getCookieLifetime()) {
210+
return $this;
211+
}
212+
$cookieValue = $this->cookieManager->getCookie($this->getName());
213+
if ($cookieValue) {
214+
$metadata = $this->cookieMetadataFactory->createPublicCookieMetadata();
215+
$metadata->setPath($this->sessionConfig->getCookiePath());
216+
$metadata->setDomain($this->sessionConfig->getCookieDomain());
217+
$metadata->setDuration($this->sessionConfig->getCookieLifetime());
218+
$metadata->setSecure($this->sessionConfig->getCookieSecure());
219+
$metadata->setHttpOnly($this->sessionConfig->getCookieHttpOnly());
220+
221+
$this->cookieManager->setPublicCookie(
222+
$this->getName(),
223+
$cookieValue,
224+
$metadata
225+
);
226+
}
227+
228+
return $this;
229+
}
230+
201231
/**
202232
* Register save handler
203233
*

0 commit comments

Comments
 (0)