Skip to content

Commit f77da0c

Browse files
authored
Merge branch '2.4-develop' into MCP-648
2 parents 44b2551 + 5788e74 commit f77da0c

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

app/code/Magento/Security/Model/AdminSessionsManager.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
namespace Magento\Security\Model;
99

1010
use Magento\Framework\HTTP\PhpEnvironment\RemoteAddress;
11-
use \Magento\Security\Model\ResourceModel\AdminSessionInfo\CollectionFactory;
11+
use Magento\Security\Model\ResourceModel\AdminSessionInfo\CollectionFactory;
1212

1313
/**
1414
* Admin Sessions Manager Model
@@ -174,8 +174,15 @@ public function processLogout()
174174
public function getCurrentSession()
175175
{
176176
if (!$this->currentSession) {
177+
$adminSessionInfoId = $this->authSession->getAdminSessionInfoId();
178+
if (!$adminSessionInfoId) {
179+
$this->createNewSession();
180+
$adminSessionInfoId = $this->authSession->getAdminSessionInfoId();
181+
$this->logoutOtherUserSessions();
182+
}
183+
177184
$this->currentSession = $this->adminSessionInfoFactory->create();
178-
$this->currentSession->load($this->authSession->getAdminSessionInfoId(), 'id');
185+
$this->currentSession->load($adminSessionInfoId, 'id');
179186
}
180187

181188
return $this->currentSession;

app/code/Magento/Security/Test/Unit/Model/AdminSessionsManagerTest.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,32 @@ public function testCleanExpiredSessions()
335335
*/
336336
public function testGetLogoutReasonMessage($expectedResult, $sessionStatus)
337337
{
338-
$this->adminSessionInfoFactoryMock->expects($this->once())
338+
$this->adminSessionInfoFactoryMock->expects($this->exactly(2))
339339
->method('create')
340340
->willReturn($this->currentSessionMock);
341+
$this->authSessionMock->expects($this->any())
342+
->method('getUser')
343+
->willReturn($this->userMock);
344+
$this->currentSessionMock->expects($this->once())
345+
->method('setData')
346+
->willReturn($this->currentSessionMock);
347+
$this->currentSessionMock->expects($this->once())
348+
->method('save')
349+
->willReturn($this->currentSessionMock);
350+
$this->adminSessionInfoCollectionFactoryMock->expects($this->once())
351+
->method('create')
352+
->willReturn($this->adminSessionInfoCollectionMock);
353+
$this->adminSessionInfoCollectionMock->expects($this->once())->method('filterByUser')
354+
->willReturnSelf();
355+
$this->adminSessionInfoCollectionMock->expects($this->once())
356+
->method('filterExpiredSessions')
357+
->willReturnSelf();
358+
$this->adminSessionInfoCollectionMock->expects($this->once())
359+
->method('loadData')
360+
->willReturnSelf();
361+
$this->adminSessionInfoCollectionMock->expects($this->once())
362+
->method('setDataToAll')
363+
->willReturnSelf();
341364
$this->currentSessionMock->expects($this->once())
342365
->method('getStatus')
343366
->willReturn($sessionStatus);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ protected function setUp(): void
3939
->setCurrentScope(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE);
4040
$this->auth = $this->objectManager->create(\Magento\Backend\Model\Auth::class);
4141
$this->authSession = $this->objectManager->create(\Magento\Backend\Model\Auth\Session::class);
42+
$this->authSession->setUser($this->objectManager->create(\Magento\User\Model\User::class));
4243
$this->auth->setAuthStorage($this->authSession);
4344
$this->auth->logout();
4445
}

0 commit comments

Comments
 (0)