Skip to content

Commit 42193aa

Browse files
MAGETWO-58862: Admin session lifetime is always 0
1 parent e193cf5 commit 42193aa

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

app/code/Magento/Backend/Model/Auth/Session.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,13 @@ public function isLoggedIn()
168168
*/
169169
public function prolong()
170170
{
171+
$lifetime = $this->_config->getValue(self::XML_PATH_SESSION_LIFETIME);
171172
$cookieValue = $this->cookieManager->getCookie($this->getName());
173+
172174
if ($cookieValue) {
173175
$this->setUpdatedAt(time());
174176
$cookieMetadata = $this->cookieMetadataFactory->createPublicCookieMetadata()
177+
->setDuration($lifetime)
175178
->setPath($this->sessionConfig->getCookiePath())
176179
->setDomain($this->sessionConfig->getCookieDomain())
177180
->setSecure($this->sessionConfig->getCookieSecure())

app/code/Magento/Backend/Test/Unit/Model/Auth/SessionTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,21 @@ public function testProlong()
158158
{
159159
$name = session_name();
160160
$cookie = 'cookie';
161+
$lifetime = 900;
161162
$path = '/';
162163
$domain = 'magento2';
163164
$secure = true;
164165
$httpOnly = true;
165166

167+
$this->config->expects($this->once())
168+
->method('getValue')
169+
->with(\Magento\Backend\Model\Auth\Session::XML_PATH_SESSION_LIFETIME)
170+
->willReturn($lifetime);
166171
$cookieMetadata = $this->getMock(\Magento\Framework\Stdlib\Cookie\PublicCookieMetadata::class);
172+
$cookieMetadata->expects($this->once())
173+
->method('setDuration')
174+
->with($lifetime)
175+
->will($this->returnSelf());
167176
$cookieMetadata->expects($this->once())
168177
->method('setPath')
169178
->with($path)

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ public function __construct(
133133
/**
134134
* Cookie settings: lifetime, path, domain, httpOnly. These govern settings for the session cookie.
135135
*/
136-
$this->configureCookieLifetime();
136+
$lifetime = $this->_scopeConfig->getValue($this->lifetimePath, $this->_scopeType);
137+
$this->setCookieLifetime($lifetime, self::COOKIE_LIFETIME_DEFAULT);
137138

138139
$path = $this->_scopeConfig->getValue(self::XML_PATH_COOKIE_PATH, $this->_scopeType);
139140
$path = empty($path) ? $this->_httpRequest->getBasePath() : $path;
@@ -515,15 +516,4 @@ public function __call($method, $args)
515516
throw new \BadMethodCallException(sprintf('Method "%s" does not exist in %s', $method, get_class($this)));
516517
}
517518
}
518-
519-
/**
520-
* Set session cookie lifetime according to configuration
521-
*
522-
* @return $this
523-
*/
524-
protected function configureCookieLifetime()
525-
{
526-
$lifetime = $this->_scopeConfig->getValue($this->lifetimePath, $this->_scopeType);
527-
return $this->setCookieLifetime($lifetime, self::COOKIE_LIFETIME_DEFAULT);
528-
}
529519
}

lib/internal/Magento/Framework/Session/Test/Unit/ConfigTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ public function constructorDataProvider()
351351
true,
352352
[
353353
'session.cache_limiter' => 'files',
354-
'session.cookie_lifetime' => 0,
354+
'session.cookie_lifetime' => 7200,
355355
'session.cookie_path' => '/',
356356
'session.cookie_domain' => 'init.host',
357357
'session.cookie_httponly' => false,
@@ -419,6 +419,7 @@ protected function getModel($validator)
419419

420420
$this->configMock = $this->getMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
421421
$getValueReturnMap = [
422+
['test_web/test_cookie/test_cookie_lifetime', 'store', null, 7200],
422423
['web/cookie/cookie_path', 'store', null, ''],
423424
];
424425
$this->configMock->method('getValue')

0 commit comments

Comments
 (0)