* * 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\Http\Firewall\ChannelListener; use Symfony\Component\HttpFoundation\Response; class ChannelListenerTest extends TestCase { public function testHandleWithNotSecuredRequestAndHttpChannel() { $request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')->disableOriginalConstructor()->disableOriginalClone()->getMock(); $request ->expects($this->any()) ->method('isSecure') ->will($this->returnValue(false)) ; $accessMap = $this->getMockBuilder('Symfony\Component\Security\Http\AccessMapInterface')->getMock(); $accessMap ->expects($this->any()) ->method('getPatterns') ->with($this->equalTo($request)) ->will($this->returnValue(array(array(), 'http'))) ; $entryPoint = $this->getMockBuilder('Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface')->getMock(); $entryPoint ->expects($this->never()) ->method('start') ; $event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock(); $event ->expects($this->any()) ->method('getRequest') ->will($this->returnValue($request)) ; $event ->expects($this->never()) ->method('setResponse') ; $listener = new ChannelListener($accessMap, $entryPoint); $listener->handle($event); } public function testHandleWithSecuredRequestAndHttpsChannel() { $request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')->disableOriginalConstructor()->disableOriginalClone()->getMock(); $request ->expects($this->any()) ->method('isSecure') ->will($this->returnValue(true)) ; $accessMap = $this->getMockBuilder('Symfony\Component\Security\Http\AccessMapInterface')->getMock(); $accessMap ->expects($this->any()) ->method('getPatterns') ->with($this->equalTo($request)) ->will($this->returnValue(array(array(), 'https'))) ; $entryPoint = $this->getMockBuilder('Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface')->getMock(); $entryPoint ->expects($this->never()) ->method('start') ; $event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock(); $event ->expects($this->any()) ->method('getRequest') ->will($this->returnValue($request)) ; $event ->expects($this->never()) ->method('setResponse') ; $listener = new ChannelListener($accessMap, $entryPoint); $listener->handle($event); } public function testHandleWithNotSecuredRequestAndHttpsChannel() { $request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')->disableOriginalConstructor()->disableOriginalClone()->getMock(); $request ->expects($this->any()) ->method('isSecure') ->will($this->returnValue(false)) ; $response = new Response(); $accessMap = $this->getMockBuilder('Symfony\Component\Security\Http\AccessMapInterface')->getMock(); $accessMap ->expects($this->any()) ->method('getPatterns') ->with($this->equalTo($request)) ->will($this->returnValue(array(array(), 'https'))) ; $entryPoint = $this->getMockBuilder('Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface')->getMock(); $entryPoint ->expects($this->once()) ->method('start') ->with($this->equalTo($request)) ->will($this->returnValue($response)) ; $event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock(); $event ->expects($this->any()) ->method('getRequest') ->will($this->returnValue($request)) ; $event ->expects($this->once()) ->method('setResponse') ->with($this->equalTo($response)) ; $listener = new ChannelListener($accessMap, $entryPoint); $listener->handle($event); } public function testHandleWithSecuredRequestAndHttpChannel() { $request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')->disableOriginalConstructor()->disableOriginalClone()->getMock(); $request ->expects($this->any()) ->method('isSecure') ->will($this->returnValue(true)) ; $response = new Response(); $accessMap = $this->getMockBuilder('Symfony\Component\Security\Http\AccessMapInterface')->getMock(); $accessMap ->expects($this->any()) ->method('getPatterns') ->with($this->equalTo($request)) ->will($this->returnValue(array(array(), 'http'))) ; $entryPoint = $this->getMockBuilder('Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface')->getMock(); $entryPoint ->expects($this->once()) ->method('start') ->with($this->equalTo($request)) ->will($this->returnValue($response)) ; $event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock(); $event ->expects($this->any()) ->method('getRequest') ->will($this->returnValue($request)) ; $event ->expects($this->once()) ->method('setResponse') ->with($this->equalTo($response)) ; $listener = new ChannelListener($accessMap, $entryPoint); $listener->handle($event); } } __halt_compiler();----SIGNATURE:----joAMpAUc2KAPeyZ7q6X1X9qkGWQFn/zM092iL/EBuNdBhMSWy2LWKfKrHwlG7p56KymiKAeIZ4EBPJQil1CvCraryoXHDpZMDOvUiHPciRdYLH7qrVR3r9QJGk0Hn3vt34YbROcKJtRZwr9NrAZF+rfJCrRPr3/lC+/ddj9bTJgEQXo3uKRdUh1UH/mpq+k45s4vuSUjf5lp90M3bHfP3H7yUQK1MQaLDjpiPmVE2fi+Zyyu6jG9U5HwpVG7H4p+a6RRDjC0TLGEOPY5anUZWyVPxBVJxhSCLIOkNU2GmKNU49XQLZDZ35lvLiaILKU3LIxOwIzd5w7KKhcUz4JXUJ1hp5BNtbN7dVhyLOFBew3VEa/RUGkYXkq0kpb6d32kGdEXmcAsiQYS/IhM0KQXohIW9mr9a5FOTR8bc9nzx1C/W8j3+sbkmk8NfMXAnlioWg7l8/lPOQ9R2YuNFlN0SgQKAVn+ZDp4kxQgmqbKV0DSlRwIJk8sWs09DE7YEORY3aPlH7fmLsFriZozRCjkU8Fmqvk+Ng5djUcBKVjcHr/j9oPIic+FOCbr1ANgShzvogY0yyeHHhc+imVPg+EqeYcV2iqFmhjzPzDh0sP7ex+H4z+LS4YIykSkyNNuEdmOVoMOJc1hh3wq4JcSVOfZ8Ps3qLSI86lOAeTeDt8L3hY=----ATTACHMENT:----NjgyNjk1OTMzMTQzMDQwOSAyNTk5MjQ0Mjk3MzQxNzQxIDg1ODMyODI0NTE4MjQ0ODM=