* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Security\Core\Tests\Authentication\Provider; use PHPUnit\Framework\TestCase; use Symfony\Component\Security\Core\Authentication\Provider\SimpleAuthenticationProvider; use Symfony\Component\Security\Core\Exception\DisabledException; use Symfony\Component\Security\Core\Exception\LockedException; use Symfony\Component\Security\Core\User\UserChecker; class SimpleAuthenticationProviderTest extends TestCase { /** * @expectedException \Symfony\Component\Security\Core\Exception\DisabledException */ public function testAuthenticateWhenPreChecksFails() { $user = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock(); $token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock(); $token->expects($this->any()) ->method('getUser') ->will($this->returnValue($user)); $userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock(); $userChecker->expects($this->once()) ->method('checkPreAuth') ->will($this->throwException(new DisabledException())); $authenticator = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\SimpleAuthenticatorInterface')->getMock(); $authenticator->expects($this->once()) ->method('authenticateToken') ->will($this->returnValue($token)); $provider = $this->getProvider($authenticator, null, $userChecker); $provider->authenticate($token); } /** * @expectedException \Symfony\Component\Security\Core\Exception\LockedException */ public function testAuthenticateWhenPostChecksFails() { $user = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock(); $token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock(); $token->expects($this->any()) ->method('getUser') ->will($this->returnValue($user)); $userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock(); $userChecker->expects($this->once()) ->method('checkPostAuth') ->will($this->throwException(new LockedException())); $authenticator = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\SimpleAuthenticatorInterface')->getMock(); $authenticator->expects($this->once()) ->method('authenticateToken') ->will($this->returnValue($token)); $provider = $this->getProvider($authenticator, null, $userChecker); $provider->authenticate($token); } public function testAuthenticateSkipsUserChecksForNonUserInterfaceObjects() { $token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock(); $token->expects($this->any()) ->method('getUser') ->will($this->returnValue('string-user')); $authenticator = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\SimpleAuthenticatorInterface')->getMock(); $authenticator->expects($this->once()) ->method('authenticateToken') ->will($this->returnValue($token)); $this->assertSame($token, $this->getProvider($authenticator, null, new UserChecker())->authenticate($token)); } protected function getProvider($simpleAuthenticator = null, $userProvider = null, $userChecker = null, $key = 'test') { if (null === $userChecker) { $userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock(); } if (null === $simpleAuthenticator) { $simpleAuthenticator = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\SimpleAuthenticatorInterface')->getMock(); } if (null === $userProvider) { $userProvider = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserProviderInterface')->getMock(); } return new SimpleAuthenticationProvider($simpleAuthenticator, $userProvider, $key, $userChecker); } } __halt_compiler();----SIGNATURE:----gM2sMnAV/zu9jAVI+2kSr5EtlkmHnL23Pv6sC6/E9IfXyaM41QpuqgKfLwMv1ZefSnQKQgNUXHiTVRxdnlR32+33o5JoTL720yh4HyqPxC7FGgH7sZeFcfT36t838F5G6RlA27KQq5X5E9eX317dA1cE0uPj4FYwKvebUJEl0W2lh7+Vzg5sHUbIxHSFdDSCa/Ffmwm1kyVgiVzwLfnSoZgF5sTtKj4Ubbt2J9pKw8JTgNMxyzCBgF/ubZ3DQPFJTH2JWbzAs8T5ncGaXecLcvA/B0fYfsEBFqPej4/hQsq7JXwG34VQaB1K1SNKX48sgrbFC3VxXvz8Vk0Ji81GOoKanjOgOzxCvyocum99nFXmF6kyuyiU7jE9I6VHhv5eR8Qr/CBXUeN80wGfwDwBVHcCE8NBO1tI4cwtvc8GlaEOqm5RQdwClXADr2ZiJYZNTr7PBJB/ad4qJhVW6K2xMk6CTOSHn0UAEJSl2lWK5vGUMVkfUApmi0T4Vb19N4TteGT8ejhE9PLLNWU0gUd3OBh7+aFFX/vbChTYz7SsPI0b5hetix+ug1hgIUzhq7ulSm3cSOVzYxenwdbcgnAn7zsxwIMuId1S6H62X+VH9NQ1/kv0ZhLp0SN3Uvy/4saCMAw2LGmXJwz/ZzMEAcezmei2qi+wrRHIo7WAgjPN+wY=----ATTACHMENT:----MzY2MTM0MjUyODcyOTA3NiA4MTMzODg3Nzc5MTI1MzgwIDg4ODUwOTY4ODM0MTAzNzY=