/**
  * @return void
  */
 public function testAfterLogin()
 {
     $warningMessage = __('All other open sessions for this account were terminated.');
     $this->sessionsManager->expects($this->once())->method('processLogin');
     $this->sessionsManager->expects($this->once())->method('getCurrentSession')->willReturn($this->currentSession);
     $this->currentSession->expects($this->once())->method('isOtherSessionsTerminated')->willReturn(true);
     $this->messageManager->expects($this->once())->method('addWarning')->with($warningMessage);
     $this->model->afterLogin($this->authMock);
 }
 /**
  * @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());
 }
 /**
  * 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);
 }
 /**
  * Get current session record
  *
  * @return AdminSessionInfo
  */
 public function getCurrentSession()
 {
     if (!$this->currentSession) {
         $this->currentSession = $this->adminSessionInfoFactory->create();
         $this->currentSession->load($this->authSession->getSessionId(), 'session_id');
     }
     return $this->currentSession;
 }
 /**
  * @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));
 }
 /**
  * @param bool $isOtherSessionsTerminated
  * @dataProvider dataProviderIsOtherSessionsTerminated
  */
 public function testSetIsOtherSessionsTerminated($isOtherSessionsTerminated)
 {
     $this->assertInstanceOf('\\Magento\\Security\\Model\\AdminSessionInfo', $this->model->setIsOtherSessionsTerminated($isOtherSessionsTerminated));
 }
 /**
  * Collection getter with filters populated for testCleanExpiredSessions() method
  *
  * @param AdminSessionInfo $session
  * @return ResourceModel\AdminSessionInfo\Collection
  */
 protected function getCollectionForCleanExpiredSessions(\Magento\Security\Model\AdminSessionInfo $session)
 {
     /** @var \Magento\Security\Model\ResourceModel\AdminSessionInfo\Collection $collection */
     $collection = $session->getResourceCollection()->load();
     return $collection;
 }
 /**
  * @param string $expectedResult
  * @param int $sessionStatus
  * @dataProvider dataProviderLogoutReasonMessage
  */
 public function testGetLogoutReasonMessage($expectedResult, $sessionStatus)
 {
     $this->adminSessionInfoFactoryMock->expects($this->once())->method('create')->willReturn($this->currentSessionMock);
     $this->currentSessionMock->expects($this->once())->method('getStatus')->will($this->returnValue($sessionStatus));
     $this->assertEquals($expectedResult, $this->model->getLogoutReasonMessage());
 }