/** * @test */ public function authenticationWithCorrectCredentialsResetsFailedAuthenticationCount() { $this->authenticationToken->_set('credentials', ['username' => 'username', 'password' => 'wrongPW']); $this->persistedUsernamePasswordProvider->authenticate($this->authenticationToken); $account = $this->accountRepository->findActiveByAccountIdentifierAndAuthenticationProviderName('username', 'myTestProvider'); $this->assertEquals(1, $account->getFailedAuthenticationCount()); $this->authenticationToken->_set('credentials', ['username' => 'username', 'password' => 'password']); $this->persistedUsernamePasswordProvider->authenticate($this->authenticationToken); $account = $this->accountRepository->findActiveByAccountIdentifierAndAuthenticationProviderName('username', 'myTestProvider'); $this->assertEquals((new \DateTime())->format(\DateTime::W3C), $account->getLastSuccessfulAuthenticationDate()->format(\DateTime::W3C)); $this->assertEquals(0, $account->getFailedAuthenticationCount()); }
/** * @test */ public function canAuthenticateReturnsTrueOnlyForAnTokenThatHasTheCorrectProviderNameSet() { $mockToken1 = $this->createMock(Security\Authentication\TokenInterface::class); $mockToken1->expects($this->once())->method('getAuthenticationProviderName')->will($this->returnValue('myProvider')); $mockToken2 = $this->createMock(Security\Authentication\TokenInterface::class); $mockToken2->expects($this->once())->method('getAuthenticationProviderName')->will($this->returnValue('someOtherProvider')); $usernamePasswordProvider = new Security\Authentication\Provider\PersistedUsernamePasswordProvider('myProvider', array()); $this->assertTrue($usernamePasswordProvider->canAuthenticate($mockToken1)); $this->assertFalse($usernamePasswordProvider->canAuthenticate($mockToken2)); }