* * 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:----oec5lTGFD+CUqyngyEtVP2BIZ5TDbSkhwfPmtD6/JBZLb4Oh9qW0BXOBx9LSVtICn+bxeDfKk2KlNAwipKhwFmSHTZIISjDPT+geXJMvjMab7bBITmPqqS47R30Tz6kB2MpgEOcOyoWIVopAcS2TL+FggpHN2IMSTeZtSO/0zcQI4YouIOE99YHI+ie2aIuP6AYlGaDpdxoIl0D+ssAhr9mC8ZXy1aB4DJmwjTudl35ZqKnXgTqZEYAmhrWOt8FXTWVBNXgwRkZbR1OAbYz8cADMGYQwyhQ0023ttYoBc2B4aq1uwRMliR8Aw5jv1PJR6ilr88YPfVZXMW5WQmY37vRf/MoRTR3kDBixF8bcWwI3JRMEpMjhq3Rs/m09qMdxyd+eH/UOUCM6XpxFNPiT/NvVQy6a95SwVgcFH+6n3sB6HdSXt0NEA9T/uCBETR5V4BUQlAk2njWnKQqPtveSl6+2JyJXJJe2tXkj03NF1K0CAlGeIJzclDnrJ3Swm/zAu0DThGXLx01raDHyNAvdvAw4t5m3TzsaFtpiOwxhl0KAxaCrRju5riJyC+kDR6wODD1Z1JDx+8Tqj/ZUQMZicVIdqLj823DwFr8Yt7ZaChyLUBJ+7bmv8G/gAE6E8tsmYOK6fuS0ahFn36JywTl2snCbYs98/u4kxOoFtBuSC7Q=----ATTACHMENT:----NTc4MTAyMjc0NTk1Njg5NSA2MjY2ODY5OTE4Mzk4NjU3IDEzMzMwNzQzNjMwNDMyNDU=