diff options
author | Fabien Potencier <fabien.potencier@gmail.com> | 2015-11-02 21:34:04 +0100 |
---|---|---|
committer | Fabien Potencier <fabien.potencier@gmail.com> | 2015-11-02 21:34:04 +0100 |
commit | 3ebe37fa9b133e4b9b0d784de95124e2af66f820 (patch) | |
tree | ebc7ecda2902d02a4bcc8605773d78af4c93bc40 /Guard/Tests/Provider/GuardAuthenticationProviderTest.php | |
parent | 5c0b69ecabbb26a1181d3f25b7e6434bd47d977e (diff) | |
parent | 6844219adbbdbbfaf159e816fa988a6de6ed6478 (diff) | |
download | symfony-security-3ebe37fa9b133e4b9b0d784de95124e2af66f820.zip symfony-security-3ebe37fa9b133e4b9b0d784de95124e2af66f820.tar.gz symfony-security-3ebe37fa9b133e4b9b0d784de95124e2af66f820.tar.bz2 |
Merge branch '2.8'
* 2.8:
removed @covers annotations in tests
removed @covers annotations in tests
removed all @covers annotations
checkCredentials() force it to be an affirmative yes!
[PropertyAccess] Major performance improvement
Diffstat (limited to 'Guard/Tests/Provider/GuardAuthenticationProviderTest.php')
-rw-r--r-- | Guard/Tests/Provider/GuardAuthenticationProviderTest.php | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/Guard/Tests/Provider/GuardAuthenticationProviderTest.php b/Guard/Tests/Provider/GuardAuthenticationProviderTest.php index 33c00e5..bfcf24b 100644 --- a/Guard/Tests/Provider/GuardAuthenticationProviderTest.php +++ b/Guard/Tests/Provider/GuardAuthenticationProviderTest.php @@ -60,7 +60,9 @@ class GuardAuthenticationProviderTest extends \PHPUnit_Framework_TestCase // checkCredentials is called $authenticatorB->expects($this->once()) ->method('checkCredentials') - ->with($enteredCredentials, $mockedUser); + ->with($enteredCredentials, $mockedUser) + // authentication works! + ->will($this->returnValue(true)); $authedToken = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface'); $authenticatorB->expects($this->once()) ->method('createAuthenticatedToken') @@ -81,6 +83,39 @@ class GuardAuthenticationProviderTest extends \PHPUnit_Framework_TestCase } /** + * @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException + */ + public function testCheckCredentialsReturningNonTrueFailsAuthentication() + { + $providerKey = 'my_uncool_firewall'; + + $authenticator = $this->getMock('Symfony\Component\Security\Guard\GuardAuthenticatorInterface'); + + // make sure the authenticator is used + $this->preAuthenticationToken->expects($this->any()) + ->method('getGuardProviderKey') + // the 0 index, to match the only authenticator + ->will($this->returnValue('my_uncool_firewall_0')); + + $this->preAuthenticationToken->expects($this->atLeastOnce()) + ->method('getCredentials') + ->will($this->returnValue('non-null-value')); + + $mockedUser = $this->getMock('Symfony\Component\Security\Core\User\UserInterface'); + $authenticator->expects($this->once()) + ->method('getUser') + ->will($this->returnValue($mockedUser)); + // checkCredentials is called + $authenticator->expects($this->once()) + ->method('checkCredentials') + // authentication fails :( + ->will($this->returnValue(null)); + + $provider = new GuardAuthenticationProvider(array($authenticator), $this->userProvider, $providerKey, $this->userChecker); + $provider->authenticate($this->preAuthenticationToken); + } + + /** * @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationExpiredException */ public function testGuardWithNoLongerAuthenticatedTriggersLogout() |