* * 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:----sOmyHOwM2qbkIbk2ITwtt8iVyWI0hVp9m/7Xa2Edv0lEyFc2QrkRQUs+Ktj5n3w66UObISEsku+99q8lGOFEZaHFbQjlAcPSeuwZAPO9cX2d+3p1/1q4wGHyKBCsvj9O6TuMFcHAGEmuB51+p5dwZEYtbJg/rk2cEU8JI2px7JKgCRgMc0tzaRrtyl/uBlY+wThZVWz66fkY8449yA2DPxe4pyJlNOS3B9rDNPpPOsCYgd1O/KnCBLMVRVss/Ec+Ep3z32f7XwUkITw+rbCLK/uccLN2yrxkrohantyAS2WAOMZo8mJmeesZHvHwqPslNiH8IpN+OdV1f1nJGsBzDZSRcaiPeqLSfFy2/ONfkwvK4lWw7n5v9NWWEpctse2h9i7+4faoLfnZZ/lBpc+oW76al2seZrtKczhhFEliTpn2od+OJ4fdV6mYisvg50EtQm4MCBWBIi2hFnchN7rdDSxet7fpMN1oRXpjzkP78FdCMrzLzBE/RG1Y7qfs0zWgjivrpfITCpuNsBKD4LnQwb8c+NlrbijSmlJ1T8rO22EFsWYBm/6fC8mTkyVPlNoikHC49ZzVZpIgZxO9mDmzYcykvohGrvB79x+Ark7evqrh2lsGa5HBZNMJBYLLDoZ7P+p865JAolUvs5fZnC69IPbE52WL8fkXNpNqRo08ZSw=----ATTACHMENT:----NTQ0NjM5OTc5NTIyODY1OSAxNTQyMjcxMzYzOTI1Mjk5IDk2MTYxNzU0MTQ2NTM1MDE=