* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Security\Http\Tests\Firewall; use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Security\Core\Exception\AuthenticationException; use Symfony\Component\Security\Http\Event\InteractiveLoginEvent; use Symfony\Component\Security\Http\Firewall\SimplePreAuthenticationListener; use Symfony\Component\Security\Http\SecurityEvents; class SimplePreAuthenticationListenerTest extends TestCase { private $authenticationManager; private $dispatcher; private $event; private $logger; private $request; private $tokenStorage; private $token; public function testHandle() { $this->tokenStorage ->expects($this->once()) ->method('setToken') ->with($this->equalTo($this->token)) ; $this->authenticationManager ->expects($this->once()) ->method('authenticate') ->with($this->equalTo($this->token)) ->will($this->returnValue($this->token)) ; $simpleAuthenticator = $this->getMockBuilder('Symfony\Component\Security\Http\Authentication\SimplePreAuthenticatorInterface')->getMock(); $simpleAuthenticator ->expects($this->once()) ->method('createToken') ->with($this->equalTo($this->request), $this->equalTo('secured_area')) ->will($this->returnValue($this->token)) ; $loginEvent = new InteractiveLoginEvent($this->request, $this->token); $this->dispatcher ->expects($this->once()) ->method('dispatch') ->with($this->equalTo(SecurityEvents::INTERACTIVE_LOGIN), $this->equalTo($loginEvent)) ; $listener = new SimplePreAuthenticationListener($this->tokenStorage, $this->authenticationManager, 'secured_area', $simpleAuthenticator, $this->logger, $this->dispatcher); $listener->handle($this->event); } public function testHandlecatchAuthenticationException() { $exception = new AuthenticationException('Authentication failed.'); $this->authenticationManager ->expects($this->once()) ->method('authenticate') ->with($this->equalTo($this->token)) ->will($this->throwException($exception)) ; $this->tokenStorage->expects($this->once()) ->method('setToken') ->with($this->equalTo(null)) ; $simpleAuthenticator = $this->getMockBuilder('Symfony\Component\Security\Http\Authentication\SimplePreAuthenticatorInterface')->getMock(); $simpleAuthenticator ->expects($this->once()) ->method('createToken') ->with($this->equalTo($this->request), $this->equalTo('secured_area')) ->will($this->returnValue($this->token)) ; $listener = new SimplePreAuthenticationListener($this->tokenStorage, $this->authenticationManager, 'secured_area', $simpleAuthenticator, $this->logger, $this->dispatcher); $listener->handle($this->event); } protected function setUp() { $this->authenticationManager = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationProviderManager') ->disableOriginalConstructor() ->getMock() ; $this->dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock(); $this->request = new Request(array(), array(), array(), array(), array(), array()); $this->event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock(); $this->event ->expects($this->any()) ->method('getRequest') ->will($this->returnValue($this->request)) ; $this->logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock(); $this->tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock(); $this->token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock(); } protected function tearDown() { $this->authenticationManager = null; $this->dispatcher = null; $this->event = null; $this->logger = null; $this->request = null; $this->tokenStorage = null; $this->token = null; } } __halt_compiler();----SIGNATURE:----aAWRKl4fKF9QdoUAU97WRwynyIf3OQ6dHi5K6nTkiS6x/6ap+/Jlflq56JJcxwZrWYGx4LwyjtmX+wzwd41oe32pShTAsicz72cFQyMpf02ToHK10dVmwvU9VFStkzP/xX8UI8HP7o6yq964xNy8DRh2t9tOmUiQFaZyoHAxPmCt4C8yCIIQNuneJqfDbKPT+grylVWc737WL0JHq/QX2mxsUSdLO6i0J8wBlqEOO4vsH2GsFtqH7hmIkr4yoE9vWCIjKWGn65AJqtRb5ZNbCdm4HUcnxkFkriZRuzsxaCrqJ7saTRJXEsqlQ5cCJPy5oZML2u2GIjENImQqZ71KAq+Xi8IYOFSiMmGM+LGkya/w2SsUKSHduZWNBSX4loGh31maGhonsCrcEruxeVXQ63Hq2aSulUnqVw6lpuezMTp9ylW3jJkMBS4YQA4pqUSBaqn/Jk4oATL7HeGwwJkhy+mVz3F0nDFX0EW6TBGmDslW5job/aqnDpzf6wxIdfnc1ihrUJ7E3v5EkCuzGjy3iw1cK7Ils8QZlthXGaIUU/F++d30RVl6KE6Gz9eWmVKTLDSu6ymzGuIIYlpg4t2WNjvzgX3Gbp6CvPwF+59aUaBq2s2PqW2mqER4ZYm0LrEozjD82crluuEiRVQwvhTJ93K0P6YzCqf6Jx9h+obrAcs=----ATTACHMENT:----NzMwOTE3NzY0NzQwNjAxOCA2MzM0MTMyOTU1MTI3NzYwIDQ1OTMwODc2NTIwODc1NTg=