/**
  * @param bool $expectedResult
  * @param bool $sessionLifetime
  * @dataProvider dataProviderIsActive
  */
 public function testIsActive($expectedResult, $sessionLifetime)
 {
     $this->model->setData('status', \Magento\Security\Model\AdminSessionInfo::LOGGED_IN);
     $this->securityConfigMock->expects($this->any())->method('getAdminSessionLifetime')->will($this->returnValue($sessionLifetime));
     $this->securityConfigMock->expects($this->any())->method('getCurrentTimestamp')->will($this->returnValue(10));
     $this->model->setUpdatedAt(9);
     $this->assertEquals($expectedResult, $this->model->isActive());
 }
Exemplo n.º 2
0
 /**
  * @return void
  */
 public function testFilterExpiredSessions()
 {
     $sessionLifeTime = '600';
     $timestamp = time();
     $this->securityConfigMock->expects($this->once())->method('getCurrentTimestamp')->willReturn($timestamp);
     $this->collectionMock->expects($this->once())->method('addFieldToFilter')->with('updated_at', ['gt' => $this->dateTimeMock->formatDate($timestamp - $sessionLifeTime)])->willReturnSelf();
     $this->assertEquals($this->collectionMock, $this->collectionMock->filterExpiredSessions($sessionLifeTime));
 }
 /**
  * @return void
  */
 public function testCleanExpiredRecords()
 {
     $timestamp = time();
     $this->passwordResetRequestEventCollectionFactoryMock->expects($this->once())->method('create')->willReturn($this->passwordResetRequestEventCollectionMock);
     $this->securityConfigMock->expects($this->once())->method('getCurrentTimestamp')->willReturn($timestamp);
     $this->passwordResetRequestEventCollectionMock->expects($this->once())->method('deleteRecordsOlderThen')->with($timestamp - \Magento\Security\Model\SecurityManager::SECURITY_CONTROL_RECORDS_LIFE_TIME)->willReturnSelf();
     $this->model->cleanExpiredRecords();
 }
 /**
  * @param bool $expectedResult
  * @param string $sessionLifetime
  * @dataProvider dataProviderSessionLifetime
  */
 public function testSessionExpired($expectedResult, $sessionLifetime)
 {
     $timestamp = time();
     $this->securityConfigMock->expects($this->once())->method('getAdminSessionLifetime')->will($this->returnValue($sessionLifetime));
     $this->securityConfigMock->expects($this->once())->method('getCurrentTimestamp')->willReturn($timestamp);
     $this->model->setUpdatedAt(date("Y-m-d H:i:s", $timestamp - 1));
     $this->assertEquals($expectedResult, $this->model->isSessionExpired());
 }
Exemplo n.º 5
0
 /**
  * @param int $requestsMethod
  * @param int $limitTimeBetweenPasswordResetRequests
  */
 protected function prepareTestCheck($requestsMethod, $limitTimeBetweenPasswordResetRequests)
 {
     $this->securityConfigMock->expects($this->once())->method('getRemoteIp')->will($this->returnValue(12345));
     $this->securityConfigMock->expects($this->any())->method('getLimitPasswordResetRequestsMethod')->will($this->returnValue($requestsMethod));
     $this->securityConfigMock->expects($this->once())->method('getLimitTimeBetweenPasswordResetRequests')->will($this->returnValue($limitTimeBetweenPasswordResetRequests));
     $this->securityConfigMock->expects($this->any())->method('getCustomerServiceEmail')->will($this->returnValue('*****@*****.**'));
     $this->passwordResetRequestEventCollectionFactoryMock->expects($this->once())->method('create')->willReturn($this->passwordResetRequestEventCollectionMock);
     $this->passwordResetRequestEventCollectionMock->expects($this->any())->method('addFieldToFilter')->willReturnSelf();
     $this->passwordResetRequestEventCollectionMock->expects($this->once())->method('filterLastItem')->willReturnSelf();
 }
 /**
  * @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();
 }
Exemplo n.º 7
0
 /**
  * @return void
  */
 public function testGetRemoteIp()
 {
     $this->securityConfig->expects($this->once())->method('getRemoteIp')->with(false);
     $this->block->getRemoteIp();
 }