|
13 | 13 |
|
14 | 14 | use PHPUnit\Framework\TestCase;
|
15 | 15 | use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
| 16 | +use Symfony\Component\Security\Core\Exception\BadCredentialsException; |
16 | 17 | use Symfony\Component\Security\Core\User\UserInterface;
|
17 | 18 | use Symfony\Component\Security\Guard\AuthenticatorInterface;
|
18 | 19 | use Symfony\Component\Security\Guard\Provider\GuardAuthenticationProvider;
|
@@ -87,6 +88,41 @@ public function testAuthenticate()
|
87 | 88 | $this->assertSame($authedToken, $actualAuthedToken);
|
88 | 89 | }
|
89 | 90 |
|
| 91 | + public function testCheckCredentialsReturningFalseFailsAuthentication() |
| 92 | + { |
| 93 | + $this->expectException(BadCredentialsException::class); |
| 94 | + $providerKey = 'my_uncool_firewall'; |
| 95 | + |
| 96 | + $authenticator = $this->createMock(AuthenticatorInterface::class); |
| 97 | + |
| 98 | + // make sure the authenticator is used |
| 99 | + $this->preAuthenticationToken->expects($this->any()) |
| 100 | + ->method('getGuardProviderKey') |
| 101 | + // the 0 index, to match the only authenticator |
| 102 | + ->willReturn('my_uncool_firewall_0'); |
| 103 | + |
| 104 | + $this->preAuthenticationToken->expects($this->atLeastOnce()) |
| 105 | + ->method('getCredentials') |
| 106 | + ->willReturn('non-null-value'); |
| 107 | + |
| 108 | + $mockedUser = $this->createMock(UserInterface::class); |
| 109 | + $authenticator->expects($this->once()) |
| 110 | + ->method('getUser') |
| 111 | + ->willReturn($mockedUser); |
| 112 | + // checkCredentials is called |
| 113 | + $authenticator->expects($this->once()) |
| 114 | + ->method('checkCredentials') |
| 115 | + // authentication fails :( |
| 116 | + ->willReturn(false); |
| 117 | + |
| 118 | + $provider = new GuardAuthenticationProvider([$authenticator], $this->userProvider, $providerKey, $this->userChecker); |
| 119 | + $provider->authenticate($this->preAuthenticationToken); |
| 120 | + } |
| 121 | + |
| 122 | + /** |
| 123 | + * @group legacy |
| 124 | + * @expectedDeprecation %s::checkCredentials() must return a boolean value. You returned NULL. This behavior is deprecated in Symfony 4.4 and will trigger a TypeError in Symfony 5. |
| 125 | + */ |
90 | 126 | public function testCheckCredentialsReturningNonTrueFailsAuthentication()
|
91 | 127 | {
|
92 | 128 | $this->expectException('Symfony\Component\Security\Core\Exception\BadCredentialsException');
|
|
0 commit comments