55dc59e13f71683825619fb01f0dfafca6cc9cf7
[yaffs-website] / vendor / symfony / http-kernel / Tests / EventListener / ValidateRequestListenerTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\HttpKernel\Tests\EventListener;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\EventDispatcher\EventDispatcher;
16 use Symfony\Component\HttpFoundation\Request;
17 use Symfony\Component\HttpKernel\EventListener\ValidateRequestListener;
18 use Symfony\Component\HttpKernel\Event\GetResponseEvent;
19 use Symfony\Component\HttpKernel\HttpKernelInterface;
20 use Symfony\Component\HttpKernel\KernelEvents;
21
22 class ValidateRequestListenerTest extends TestCase
23 {
24     /**
25      * @expectedException \Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException
26      */
27     public function testListenerThrowsWhenMasterRequestHasInconsistentClientIps()
28     {
29         $dispatcher = new EventDispatcher();
30         $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
31
32         $request = new Request();
33         $request->setTrustedProxies(array('1.1.1.1'));
34         $request->server->set('REMOTE_ADDR', '1.1.1.1');
35         $request->headers->set('FORWARDED', 'for=2.2.2.2');
36         $request->headers->set('X_FORWARDED_FOR', '3.3.3.3');
37
38         $dispatcher->addListener(KernelEvents::REQUEST, array(new ValidateRequestListener(), 'onKernelRequest'));
39         $event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
40
41         $dispatcher->dispatch(KernelEvents::REQUEST, $event);
42     }
43 }