4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\HttpKernel\Tests\EventListener;
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;
22 class ValidateRequestListenerTest extends TestCase
25 * @expectedException \Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException
27 public function testListenerThrowsWhenMasterRequestHasInconsistentClientIps()
29 $dispatcher = new EventDispatcher();
30 $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
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');
38 $dispatcher->addListener(KernelEvents::REQUEST, array(new ValidateRequestListener(), 'onKernelRequest'));
39 $event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
41 $dispatcher->dispatch(KernelEvents::REQUEST, $event);