Ejemplo n.º 1
0
 /**
  * @param int $failureNum
  * @param string $firstFailure
  * @param string $lockExpires
  * @param int $setFailureNumCallCtr
  * @param int $setFailureNumValue
  * @param int $setFirstFailureCallCtr
  * @param int $setFirstFailureValue
  * @param int $setLockExpiresCallCtr
  * @param int $setLockExpiresValue
  * @dataProvider processAuthenticationFailureDataProvider
  */
 public function testProcessAuthenticationFailureFirstAttempt($failureNum, $firstFailure, $lockExpires, $setFailureNumCallCtr, $setFailureNumValue, $setFirstFailureCallCtr, $setLockExpiresCallCtr, $setLockExpiresValue)
 {
     $customerId = 1;
     $this->backendConfigMock->expects($this->exactly(2))->method('getValue')->withConsecutive([\Magento\Customer\Model\Authentication::LOCKOUT_THRESHOLD_PATH], [\Magento\Customer\Model\Authentication::MAX_FAILURES_PATH])->willReturnOnConsecutiveCalls(10, 5);
     $this->customerRegistryMock->expects($this->once())->method('retrieveSecureData')->with($customerId)->willReturn($this->customerSecureMock);
     $this->customerAuthUpdate->expects($this->once())->method('saveAuth')->with($customerId)->willReturnSelf();
     $this->customerSecureMock->expects($this->once())->method('getFailuresNum')->willReturn($failureNum);
     $this->customerSecureMock->expects($this->once())->method('getFirstFailure')->willReturn($firstFailure ? (new \DateTime())->modify($firstFailure)->format('Y-m-d H:i:s') : null);
     $this->customerSecureMock->expects($this->once())->method('getLockExpires')->willReturn($lockExpires ? (new \DateTime())->modify($lockExpires)->format('Y-m-d H:i:s') : null);
     $this->customerSecureMock->expects($this->exactly($setFirstFailureCallCtr))->method('setFirstFailure');
     $this->customerSecureMock->expects($this->exactly($setFailureNumCallCtr))->method('setFailuresNum')->with($setFailureNumValue);
     $this->customerSecureMock->expects($this->exactly($setLockExpiresCallCtr))->method('setLockExpires')->with($setLockExpiresValue);
     $this->authentication->processAuthenticationFailure($customerId);
 }
Ejemplo n.º 2
0
 /**
  * @return void
  */
 public function testCustomerHasFailedMaxNumberOfAttempts()
 {
     $customerId = 1;
     $date = new \DateTime();
     $date->modify('-500 second');
     $formattedDate = $date->format('Y-m-d H:i:s');
     $this->backendConfigMock->expects($this->exactly(2))->method('getValue')->withConsecutive([\Magento\Customer\Model\Authentication::LOCKOUT_THRESHOLD_PATH], [\Magento\Customer\Model\Authentication::MAX_FAILURES_PATH])->willReturnOnConsecutiveCalls(10, 5);
     $this->customerRegistryMock->expects($this->once())->method('retrieveSecureData')->with($customerId)->willReturn($this->customerSecure);
     $customerMock = $this->getMockBuilder(CustomerInterface::class)->disableOriginalConstructor()->getMock();
     $this->customerRepositoryMock->expects($this->once())->method('getById')->with($customerId)->willReturn($customerMock);
     $this->customerRepositoryMock->expects($this->once())->method('save')->with($customerMock);
     $this->customerSecure->expects($this->once())->method('getFailuresNum')->willReturn(5);
     $this->customerSecure->expects($this->once())->method('getFirstFailure')->willReturn($formattedDate);
     $this->customerSecure->expects($this->once())->method('setLockExpires');
     $this->customerSecure->expects($this->once())->method('setFailuresNum');
     $this->authentication->processAuthenticationFailure($customerId);
 }