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

2.3.7 release - https://github.com/magento/magento2/pull/34514 #34606

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/code/Magento/Security/Model/AdminSessionInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class AdminSessionInfo extends \Magento\Framework\Model\AbstractModel
/**
* All other open sessions were terminated
* @since 100.1.0
* @var bool
*/
protected $isOtherSessionsTerminated = false;

Expand Down Expand Up @@ -132,10 +133,10 @@ public function isSessionExpired()
$currentTime = $this->dateTime->gmtTimestamp();
$lastUpdatedTime = $this->getUpdatedAt();
if (!is_numeric($lastUpdatedTime)) {
$lastUpdatedTime = strtotime($lastUpdatedTime);
$lastUpdatedTime = $lastUpdatedTime === null ? 0 : strtotime($lastUpdatedTime);
}

return $lastUpdatedTime <= ($currentTime - $lifetime) ? true : false;
return $lastUpdatedTime <= ($currentTime - $lifetime);
}

/**
Expand Down
12 changes: 9 additions & 3 deletions app/code/Magento/Security/Model/AdminSessionsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*
* @api
* @since 100.1.0
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
*/
class AdminSessionsManager
{
Expand Down Expand Up @@ -305,6 +306,8 @@ protected function createNewSession()
}

/**
* Retrieve new instance of admin session info collection
*
* @return \Magento\Security\Model\ResourceModel\AdminSessionInfo\Collection
* @since 100.1.0
*/
Expand All @@ -314,8 +317,7 @@ protected function createAdminSessionInfoCollection()
}

/**
* Calculates diff between now and last session updated_at
* and decides whether new prolong must be triggered or not
* Calculates diff between now and last session updated_at and decides whether new prolong must be triggered or not
*
* This is done to limit amount of session prolongs and updates to database
* within some period of time - X
Expand All @@ -326,7 +328,11 @@ protected function createAdminSessionInfoCollection()
*/
private function lastProlongIsOldEnough()
{
$lastProlongTimestamp = strtotime($this->getCurrentSession()->getUpdatedAt());
$lastUpdatedTime = $this->getCurrentSession()->getUpdatedAt();
if ($lastUpdatedTime === null || is_numeric($lastUpdatedTime)) {
$lastUpdatedTime = "now";
}
$lastProlongTimestamp = strtotime($lastUpdatedTime);
$nowTimestamp = $this->authSession->getUpdatedAt();

$diff = $nowTimestamp - $lastProlongTimestamp;
Expand Down
20 changes: 20 additions & 0 deletions app/code/Magento/Security/Test/Unit/Model/AdminSessionInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,26 @@ public function dataProviderSessionLifetime()
];
}

/**
* @return void
*/
public function testSessionExpiredWhenUpdatedAtIsNull()
{
$timestamp = time();
$sessionLifetime = '1';

$this->securityConfigMock->expects($this->once())
->method('getAdminSessionLifetime')
->willReturn($sessionLifetime);

$this->dateTimeMock->expects($this->once())
->method('gmtTimestamp')
->willReturn($timestamp);

$this->model->setUpdatedAt(null);
$this->assertTrue($this->model->isSessionExpired());
}

/**
* @return void
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ class AdminSessionsManagerTest extends \PHPUnit\Framework\TestCase
/** @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager */
protected $objectManager;

/*
* @var RemoteAddress
*/
/** @var RemoteAddress */
protected $remoteAddressMock;

/**
Expand Down Expand Up @@ -256,6 +254,48 @@ public function testProcessProlong()
$this->model->processProlong();
}

/**
* @return void
*/
public function testUpdatedAtIsNull()
{
$newUpdatedAt = '2016-01-01 00:00:30';
$adminSessionInfoId = 50;
$this->authSessionMock->expects($this->any())
->method('getAdminSessionInfoId')
->willReturn($adminSessionInfoId);

$this->adminSessionInfoFactoryMock->expects($this->any())
->method('create')
->willReturn($this->currentSessionMock);

$this->currentSessionMock->expects($this->once())
->method('load')
->willReturnSelf();

$this->currentSessionMock->expects($this->once())
->method('getUpdatedAt')
->willReturn(null);

$this->authSessionMock->expects($this->once())
->method('getUpdatedAt')
->willReturn(strtotime($newUpdatedAt));

$this->securityConfigMock->expects($this->once())
->method('getAdminSessionLifetime')
->willReturn(100);

$this->currentSessionMock->expects($this->never())
->method('setData')
->willReturnSelf();

$this->currentSessionMock->expects($this->never())
->method('save')
->willReturnSelf();

$this->model->processProlong();
}

/**
* @return void
*/
Expand Down