* * 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\Security\Core\Authentication\Token\AnonymousToken; use Symfony\Component\Security\Http\Firewall\AnonymousAuthenticationListener; class AnonymousAuthenticationListenerTest extends TestCase { public function testHandleWithTokenStorageHavingAToken() { $tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock(); $tokenStorage ->expects($this->any()) ->method('getToken') ->will($this->returnValue($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock())) ; $tokenStorage ->expects($this->never()) ->method('setToken') ; $authenticationManager = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')->getMock(); $authenticationManager ->expects($this->never()) ->method('authenticate') ; $listener = new AnonymousAuthenticationListener($tokenStorage, 'TheSecret', null, $authenticationManager); $listener->handle($this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock()); } public function testHandleWithTokenStorageHavingNoToken() { $tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock(); $tokenStorage ->expects($this->any()) ->method('getToken') ->will($this->returnValue(null)) ; $anonymousToken = new AnonymousToken('TheSecret', 'anon.', array()); $authenticationManager = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')->getMock(); $authenticationManager ->expects($this->once()) ->method('authenticate') ->with($this->callback(function ($token) { return 'TheSecret' === $token->getSecret(); })) ->will($this->returnValue($anonymousToken)) ; $tokenStorage ->expects($this->once()) ->method('setToken') ->with($anonymousToken) ; $listener = new AnonymousAuthenticationListener($tokenStorage, 'TheSecret', null, $authenticationManager); $listener->handle($this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock()); } public function testHandledEventIsLogged() { $tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock(); $logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock(); $logger->expects($this->once()) ->method('info') ->with('Populated the TokenStorage with an anonymous Token.') ; $authenticationManager = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')->getMock(); $listener = new AnonymousAuthenticationListener($tokenStorage, 'TheSecret', $logger, $authenticationManager); $listener->handle($this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock()); } } __halt_compiler();----SIGNATURE:----LFRYALcPOTALqFOLg4DI3aH0+XR8Qf3tI+yVXc/RlOuSMF4/Luk3VdfMXYSUXsmgwqnRmgAPmQipq416ZU1glvQjwk6xQLqAZlxZgmXvWP1h6InmMhwx4dyGCkgIGZ0v4ps1S0Cvp8i2/nyt35gnhmq95b2jRyVdqb3+w3XK09Cf//ihcOEIrgBspwNr4kCJ9NKdQvL8Va+wyEJw4pZd9M8KoO7/7uvi5YfBIIov1CepLhrkhEKaMrCuCP/0/y7lHBrmZ1w4yHoyR/P3R8Pj0bD4U3cvYayTugUiaMkpMxNBZx6mpQBluFU8bbIc/C8hxi5RMxq6o59wkkD0vGFUis3/Gw046D+rnnYkjNo9cS/TotPiGaxfK+LnaSQiiz2aGRr8VKgiX9UwkjjIJRBX7FyT7M2UuL5hxs5CokOTp65wmph/5/SdkqQkPA0SPq0olg/zcYoREOByJz1Ib3fGjWyQ21MjPl72g7yB4SWBtSyKJQsham96sQdfY/VyAqe5MFfpj0LXKkq1LndVB2qyazbt5+F5x/yWDE7qXv/w6/kbO0Pjnn25PClBEAc6N5wne2gbZYZdwv43OvlKFl5X+ijf4T267iSofA0rFNhmuufu55hfIc1YlVxq+16QAbU6suCkLwtBxqbi2q9jHpOpK5V8/Ul2HMc8MgfjnYe0m7U=----ATTACHMENT:----NTU2MzQxMjc2MjA0NTQ1MyA4MTAxNzYwNDQ0MzcyMzYgMzk3NzA2NDg5MzA1NjYyOQ==