/** * @return \Magento\Security\Model\ResourceModel\AdminSessionInfo\Collection */ public function getSessionInfoCollection() { if (null === $this->sessionsInfoCollection) { $this->sessionsInfoCollection = $this->sessionsManager->getSessionsForCurrentUser(); } return $this->sessionsInfoCollection; }
/** * Before execute login * * @param Login $login * @return void */ public function beforeExecute(Login $login) { $logoutReasonCode = $this->securityCookieHelper->getLogoutReasonCookie(); if ($this->isLoginForm($login) && $logoutReasonCode >= 0) { $this->messageManager->addError($this->sessionsManager->getLogoutReasonMessageByStatus($logoutReasonCode)); $this->securityCookieHelper->deleteLogoutReasonCookie(); } }
/** * Add user logout notification * * @return $this */ protected function addUserLogoutNotification() { if ($this->isAjaxRequest()) { $this->securityCookieHelper->setLogoutReasonCookie($this->sessionsManager->getCurrentSession()->getStatus()); } else { $this->messageManager->addError($this->sessionsManager->getLogoutReasonMessage()); } return $this; }
/** * @param bool $result * @dataProvider dataProviderTestExecute */ public function testExecute($result) { $resultExpectation = ['isActive' => $result]; $jsonMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Json')->disableOriginalConstructor()->getMock(); $this->sessionsManager->expects($this->any())->method('getCurrentSession')->willReturn($this->currentSession); $this->currentSession->expects($this->any())->method('isActive')->will($this->returnValue($result)); $this->jsonFactory->expects($this->any())->method('create')->willReturn($jsonMock); $jsonMock->expects($this->once())->method('setData')->with($resultExpectation)->willReturnSelf(); $this->assertEquals($jsonMock, $this->controller->execute()); }
/** * @return void */ public function execute() { try { $this->sessionsManager->logoutOtherUserSessions(); $this->messageManager->addSuccess(__('All other open sessions for this account were terminated.')); } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addException($e, __("We couldn't logout because of an error.")); } $this->_redirect('*/*/activity'); }
/** * Test of prolong user action * * @magentoDbIsolation enabled */ public function testProcessProlong() { $this->auth->login(\Magento\TestFramework\Bootstrap::ADMIN_NAME, \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD); $sessionId = $this->authSession->getSessionId(); $dateInPast = $this->dateTime->formatDate($this->authSession->getUpdatedAt() - 100); $this->adminSessionsManager->getCurrentSession()->setData('updated_at', $dateInPast)->save(); $this->adminSessionInfo->load($sessionId, 'session_id'); $oldUpdatedAt = $this->adminSessionInfo->getUpdatedAt(); $this->authSession->prolong(); $this->adminSessionInfo->load($sessionId, 'session_id'); $updatedAt = $this->adminSessionInfo->getUpdatedAt(); $this->assertGreaterThan($oldUpdatedAt, $updatedAt); }
/** * @return void */ public function testBeforeExecute() { $logoutReasonCode = 2; $uri = '/uri/'; $errorMessage = 'Error Message'; $this->securityCookieHelperMock->expects($this->once())->method('getLogoutReasonCookie')->willReturn($logoutReasonCode); $this->backendControllerAuthLoginMock->expects($this->once())->method('getRequest')->willReturn($this->requestMock); $this->requestMock->expects($this->once())->method('getUri')->willReturn($uri); $this->backendControllerAuthLoginMock->expects($this->once())->method('getUrl')->willReturn($uri); $this->adminSessionsManagerMock->expects($this->once())->method('getLogoutReasonMessageByStatus')->with($logoutReasonCode)->willReturn($errorMessage); $this->messageManagerMock->expects($this->once())->method('addError')->with($errorMessage); $this->securityCookieHelperMock->expects($this->once())->method('deleteLogoutReasonCookie')->willReturnSelf(); $this->controller->beforeExecute($this->backendControllerAuthLoginMock); }
/** * @return void */ public function testExecuteException() { $phrase = new \Magento\Framework\Phrase('We couldn\'t logout because of an error.'); $this->sessionsManager->expects($this->once())->method('logoutOtherUserSessions')->willThrowException(new \Exception()); $this->messageManager->expects($this->once())->method('addException')->with(new \Exception(), $phrase); $this->controller->execute(); }
/** * @return void */ public function testAroundProlongSessionIsActive() { $result = 'result'; $proceed = function () use($result) { return $result; }; $this->currentSessionMock->expects($this->any())->method('isLoggedInStatus')->willReturn(true); $this->adminSessionsManagerMock->expects($this->any())->method('processProlong'); $this->assertEquals($result, $this->model->aroundProlong($this->authSessionMock, $proceed)); }
/** * Test for cleanExpiredSessions() method * * @magentoDataFixture Magento/Security/_files/adminsession.php * @magentoAdminConfigFixture admin/security/session_lifetime 1 * @magentoDbIsolation enabled */ public function testCleanExpiredSessions() { /** @var \Magento\Security\Model\AdminSessionInfo $session */ $session = $this->objectManager->create('Magento\\Security\\Model\\AdminSessionInfo'); $collection = $this->getCollectionForCleanExpiredSessions($session); $sizeBefore = $collection->getSize(); $this->adminSessionsManager->cleanExpiredSessions(); $collection = $this->getCollectionForCleanExpiredSessions($session); $sizeAfter = $collection->getSize(); $this->assertGreaterThan($sizeAfter, $sizeBefore); }
/** * @return void */ public function testLogoutOtherUserSessions() { $useId = 1; $sessionLifetime = 100; $sessionId = 50; $this->adminSessionInfoCollectionFactoryMock->expects($this->once())->method('create')->willReturn($this->adminSessionInfoCollectionMock); $this->authSessionMock->expects($this->once())->method('getUser')->willReturn($this->userMock); $this->authSessionMock->expects($this->once())->method('getSessionId')->willReturn($sessionId); $this->userMock->expects($this->once())->method('getId')->willReturn($useId); $this->adminSessionInfoCollectionMock->expects($this->once())->method('filterByUser')->with($useId, \Magento\Security\Model\AdminSessionInfo::LOGGED_IN, $sessionId)->willReturnSelf(); $this->securityConfigMock->expects($this->once())->method('getAdminSessionLifetime')->willReturn($sessionLifetime); $this->adminSessionInfoCollectionMock->expects($this->once())->method('filterExpiredSessions')->with($sessionLifetime)->willReturnSelf(); $this->adminSessionInfoCollectionMock->expects($this->once())->method('loadData')->willReturnSelf(); $this->adminSessionInfoCollectionMock->expects($this->once())->method('setDataToAll')->with($this->equalTo('status'), \Magento\Security\Model\AdminSessionInfo::LOGGED_OUT_MANUALLY)->willReturnSelf(); $this->adminSessionInfoCollectionMock->expects($this->once())->method('save'); $this->model->logoutOtherUserSessions(); }
/** * @param bool $expectedResult * @param int $sessionsNumber * @dataProvider dataProviderAreMultipleSessionsActive */ public function testAreMultipleSessionsActive($expectedResult, $sessionsNumber) { $this->sessionsManager->expects($this->once())->method('getSessionsForCurrentUser')->willReturn($this->collectionMock); $this->collectionMock->expects($this->any())->method('count')->willReturn($sessionsNumber); $this->assertEquals($expectedResult, $this->block->areMultipleSessionsActive()); }
/** * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { /** @var \Magento\Framework\Controller\Result\Json $resultJson */ return $this->jsonFactory->create()->setData(['isActive' => $this->sessionsManager->getCurrentSession()->isLoggedInStatus()]); }
/** * @param \Magento\Backend\Model\Auth $authModel * @return void * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function beforeLogout(\Magento\Backend\Model\Auth $authModel) { $this->sessionsManager->processLogout(); }
/** * @return void */ public function testBeforeLogout() { $this->sessionsManager->expects($this->once())->method('processLogout'); $this->model->beforeLogout($this->authMock); }