* * 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:----f2ER+aO8lX5gyCg0kJnmL0rs4mVwq2zJloTFzg8GqojQ1X85qFv8Oz4xSP+oxjTlez719p2IFdnSVbKfq1roT8wKWODzlqe1r/UakUGyJjT+8xaIAN5Um3ilnWsbfKL5KjmWG1o7RniST4JiS9mfYFEwl7JMOVhI9AsZ5JN5HYBA02QO121eh2Rwo47OtRg5O9/1kQHmX1xGq6xfFDuNCwJPQqb1YFkLMGjpuTk45WaMgVolnk1h3KYqdgvLr7VegPF7vra28OBE11xP8o7V4p8XMTG4wrToyIfFsvXbumBIQ0AfKLltnugd18KeeSJJKfEjWqjI+6LU41256MAQINLe7rgfU2tNwPeNYg0hWzcykoOh3Np08ixHtWYY2jDEAKH/k+B69YVKECPyaHc0JFDRou6aRvtd+77fOtSubeV3P7IYj6nmfpkGWpwced/v5MHUqpYN/7hd0luBYOjcX3uNY0K3eN0ybgfmoicIj+twULTDtRbVQW8DydLho9by1aguyqS3yB+ka0zuXU59yYkWMdUiU5U3ooWthLiSWxgKB0592XSjfAl7FZsWXqooHaTtQ8+X1Wc+HW2A/6PGKieQfRI0OKE+7PcThYP7usyvYZi2e/3xgph+QjNfQcUxLFy8bKByLFheEqfORKIjcwexPNAWfryDLMGp+5gz1j0=----ATTACHMENT:----MTIzMzczMzEwNzgyNTM2OSAyMTI0ODYwMzE4MzM5NzIxIDU0NjAxODkyNDI0Mjg0MTA=