Merge branch '3.1'
* 3.1: [Form] fixed ChoiceTypeTest after #17822 [DoctrineBridge] fixed DoctrineChoiceLoaderTest by removing deprecated factory [ci] Upgrade phpunit wrapper deps [FrameworkBundle] Fix fixtures [HttpKernel] Inline ValidateRequestListener logic into HttpKernel fixed HttpKernel dependencies after #18688
This commit is contained in:
commit
d08cbe6e8b
2
phpunit
2
phpunit
@ -11,7 +11,7 @@
|
||||
*/
|
||||
|
||||
// Please update when phpunit needs to be reinstalled with fresh deps:
|
||||
// Cache-Id-Version: 2016-03-25 09:45 UTC
|
||||
// Cache-Id-Version: 2016-06-29 13:45 UTC
|
||||
|
||||
use Symfony\Component\Process\ProcessUtils;
|
||||
|
||||
|
@ -18,18 +18,12 @@ use Symfony\Bridge\Doctrine\Form\ChoiceList\DoctrineChoiceLoader;
|
||||
use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityLoaderInterface;
|
||||
use Symfony\Bridge\Doctrine\Form\ChoiceList\IdReader;
|
||||
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
|
||||
use Symfony\Component\Form\ChoiceList\Factory\ChoiceListFactoryInterface;
|
||||
|
||||
/**
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var ChoiceListFactoryInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private $factory;
|
||||
|
||||
/**
|
||||
* @var ObjectManager|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
@ -98,36 +92,60 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
public function testLoadChoiceList()
|
||||
{
|
||||
$loader = new DoctrineChoiceLoader(
|
||||
$this->factory,
|
||||
$this->om,
|
||||
$this->class,
|
||||
$this->idReader
|
||||
);
|
||||
|
||||
$choices = array($this->obj1, $this->obj2, $this->obj3);
|
||||
$choiceList = new ArrayChoiceList(array());
|
||||
$value = function () {};
|
||||
$choiceList = new ArrayChoiceList($choices, $value);
|
||||
|
||||
$this->repository->expects($this->once())
|
||||
->method('findAll')
|
||||
->willReturn($choices);
|
||||
|
||||
$this->factory->expects($this->once())
|
||||
->method('createListFromChoices')
|
||||
->with($choices, $value)
|
||||
->willReturn($choiceList);
|
||||
|
||||
$this->assertSame($choiceList, $loader->loadChoiceList($value));
|
||||
$this->assertEquals($choiceList, $loader->loadChoiceList($value));
|
||||
|
||||
// no further loads on subsequent calls
|
||||
|
||||
$this->assertSame($choiceList, $loader->loadChoiceList($value));
|
||||
$this->assertEquals($choiceList, $loader->loadChoiceList($value));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testLegacyLoadChoiceList()
|
||||
{
|
||||
$factory = $this->getMock('Symfony\Component\Form\ChoiceList\Factory\ChoiceListFactoryInterface');
|
||||
$loader = new DoctrineChoiceLoader(
|
||||
$factory,
|
||||
$this->om,
|
||||
$this->class,
|
||||
$this->idReader
|
||||
);
|
||||
|
||||
$choices = array($this->obj1, $this->obj2, $this->obj3);
|
||||
$value = function () {};
|
||||
$choiceList = new ArrayChoiceList($choices, $value);
|
||||
|
||||
$this->repository->expects($this->once())
|
||||
->method('findAll')
|
||||
->willReturn($choices);
|
||||
|
||||
$factory->expects($this->never())
|
||||
->method('createListFromChoices');
|
||||
|
||||
$this->assertEquals($choiceList, $loaded = $loader->loadChoiceList($value));
|
||||
|
||||
// no further loads on subsequent calls
|
||||
|
||||
$this->assertSame($loaded, $loader->loadChoiceList($value));
|
||||
}
|
||||
|
||||
public function testLoadChoiceListUsesObjectLoaderIfAvailable()
|
||||
{
|
||||
$loader = new DoctrineChoiceLoader(
|
||||
$this->factory,
|
||||
$this->om,
|
||||
$this->class,
|
||||
$this->idReader,
|
||||
@ -135,7 +153,7 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
);
|
||||
|
||||
$choices = array($this->obj1, $this->obj2, $this->obj3);
|
||||
$choiceList = new ArrayChoiceList(array());
|
||||
$choiceList = new ArrayChoiceList($choices);
|
||||
|
||||
$this->repository->expects($this->never())
|
||||
->method('findAll');
|
||||
@ -144,39 +162,27 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
->method('getEntities')
|
||||
->willReturn($choices);
|
||||
|
||||
$this->factory->expects($this->once())
|
||||
->method('createListFromChoices')
|
||||
->with($choices)
|
||||
->willReturn($choiceList);
|
||||
|
||||
$this->assertSame($choiceList, $loader->loadChoiceList());
|
||||
$this->assertEquals($choiceList, $loaded = $loader->loadChoiceList());
|
||||
|
||||
// no further loads on subsequent calls
|
||||
|
||||
$this->assertSame($choiceList, $loader->loadChoiceList());
|
||||
$this->assertSame($loaded, $loader->loadChoiceList());
|
||||
}
|
||||
|
||||
public function testLoadValuesForChoices()
|
||||
{
|
||||
$loader = new DoctrineChoiceLoader(
|
||||
$this->factory,
|
||||
$this->om,
|
||||
$this->class,
|
||||
$this->idReader
|
||||
);
|
||||
|
||||
$choices = array($this->obj1, $this->obj2, $this->obj3);
|
||||
$choiceList = new ArrayChoiceList($choices);
|
||||
|
||||
$this->repository->expects($this->once())
|
||||
->method('findAll')
|
||||
->willReturn($choices);
|
||||
|
||||
$this->factory->expects($this->once())
|
||||
->method('createListFromChoices')
|
||||
->with($choices)
|
||||
->willReturn($choiceList);
|
||||
|
||||
$this->assertSame(array('1', '2'), $loader->loadValuesForChoices(array($this->obj2, $this->obj3)));
|
||||
|
||||
// no further loads on subsequent calls
|
||||
@ -187,7 +193,6 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
public function testLoadValuesForChoicesDoesNotLoadIfEmptyChoices()
|
||||
{
|
||||
$loader = new DoctrineChoiceLoader(
|
||||
$this->factory,
|
||||
$this->om,
|
||||
$this->class,
|
||||
$this->idReader
|
||||
@ -196,16 +201,12 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$this->repository->expects($this->never())
|
||||
->method('findAll');
|
||||
|
||||
$this->factory->expects($this->never())
|
||||
->method('createListFromChoices');
|
||||
|
||||
$this->assertSame(array(), $loader->loadValuesForChoices(array()));
|
||||
}
|
||||
|
||||
public function testLoadValuesForChoicesDoesNotLoadIfSingleIntId()
|
||||
{
|
||||
$loader = new DoctrineChoiceLoader(
|
||||
$this->factory,
|
||||
$this->om,
|
||||
$this->class,
|
||||
$this->idReader
|
||||
@ -218,9 +219,6 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$this->repository->expects($this->never())
|
||||
->method('findAll');
|
||||
|
||||
$this->factory->expects($this->never())
|
||||
->method('createListFromChoices');
|
||||
|
||||
$this->idReader->expects($this->any())
|
||||
->method('getIdValue')
|
||||
->with($this->obj2)
|
||||
@ -232,7 +230,6 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
public function testLoadValuesForChoicesLoadsIfSingleIntIdAndValueGiven()
|
||||
{
|
||||
$loader = new DoctrineChoiceLoader(
|
||||
$this->factory,
|
||||
$this->om,
|
||||
$this->class,
|
||||
$this->idReader
|
||||
@ -240,7 +237,6 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$choices = array($this->obj1, $this->obj2, $this->obj3);
|
||||
$value = function (\stdClass $object) { return $object->name; };
|
||||
$choiceList = new ArrayChoiceList($choices, $value);
|
||||
|
||||
$this->idReader->expects($this->any())
|
||||
->method('isSingleId')
|
||||
@ -250,11 +246,6 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
->method('findAll')
|
||||
->willReturn($choices);
|
||||
|
||||
$this->factory->expects($this->once())
|
||||
->method('createListFromChoices')
|
||||
->with($choices, $value)
|
||||
->willReturn($choiceList);
|
||||
|
||||
$this->assertSame(array('B'), $loader->loadValuesForChoices(
|
||||
array($this->obj2),
|
||||
$value
|
||||
@ -264,7 +255,6 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
public function testLoadValuesForChoicesDoesNotLoadIfValueIsIdReader()
|
||||
{
|
||||
$loader = new DoctrineChoiceLoader(
|
||||
$this->factory,
|
||||
$this->om,
|
||||
$this->class,
|
||||
$this->idReader
|
||||
@ -279,9 +269,6 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$this->repository->expects($this->never())
|
||||
->method('findAll');
|
||||
|
||||
$this->factory->expects($this->never())
|
||||
->method('createListFromChoices');
|
||||
|
||||
$this->idReader->expects($this->any())
|
||||
->method('getIdValue')
|
||||
->with($this->obj2)
|
||||
@ -296,24 +283,17 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
public function testLoadChoicesForValues()
|
||||
{
|
||||
$loader = new DoctrineChoiceLoader(
|
||||
$this->factory,
|
||||
$this->om,
|
||||
$this->class,
|
||||
$this->idReader
|
||||
);
|
||||
|
||||
$choices = array($this->obj1, $this->obj2, $this->obj3);
|
||||
$choiceList = new ArrayChoiceList($choices);
|
||||
|
||||
$this->repository->expects($this->once())
|
||||
->method('findAll')
|
||||
->willReturn($choices);
|
||||
|
||||
$this->factory->expects($this->once())
|
||||
->method('createListFromChoices')
|
||||
->with($choices)
|
||||
->willReturn($choiceList);
|
||||
|
||||
$this->assertSame(array($this->obj2, $this->obj3), $loader->loadChoicesForValues(array('1', '2')));
|
||||
|
||||
// no further loads on subsequent calls
|
||||
@ -324,7 +304,6 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
public function testLoadChoicesForValuesDoesNotLoadIfEmptyValues()
|
||||
{
|
||||
$loader = new DoctrineChoiceLoader(
|
||||
$this->factory,
|
||||
$this->om,
|
||||
$this->class,
|
||||
$this->idReader
|
||||
@ -333,16 +312,12 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$this->repository->expects($this->never())
|
||||
->method('findAll');
|
||||
|
||||
$this->factory->expects($this->never())
|
||||
->method('createListFromChoices');
|
||||
|
||||
$this->assertSame(array(), $loader->loadChoicesForValues(array()));
|
||||
}
|
||||
|
||||
public function testLoadChoicesForValuesLoadsOnlyChoicesIfSingleIntId()
|
||||
{
|
||||
$loader = new DoctrineChoiceLoader(
|
||||
$this->factory,
|
||||
$this->om,
|
||||
$this->class,
|
||||
$this->idReader,
|
||||
@ -362,9 +337,6 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$this->repository->expects($this->never())
|
||||
->method('findAll');
|
||||
|
||||
$this->factory->expects($this->never())
|
||||
->method('createListFromChoices');
|
||||
|
||||
$this->objectLoader->expects($this->once())
|
||||
->method('getEntitiesByIds')
|
||||
->with('idField', array(4 => '3', 7 => '2'))
|
||||
@ -386,7 +358,6 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
public function testLoadChoicesForValuesLoadsAllIfSingleIntIdAndValueGiven()
|
||||
{
|
||||
$loader = new DoctrineChoiceLoader(
|
||||
$this->factory,
|
||||
$this->om,
|
||||
$this->class,
|
||||
$this->idReader
|
||||
@ -394,7 +365,6 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$choices = array($this->obj1, $this->obj2, $this->obj3);
|
||||
$value = function (\stdClass $object) { return $object->name; };
|
||||
$choiceList = new ArrayChoiceList($choices, $value);
|
||||
|
||||
$this->idReader->expects($this->any())
|
||||
->method('isSingleId')
|
||||
@ -404,11 +374,6 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
->method('findAll')
|
||||
->willReturn($choices);
|
||||
|
||||
$this->factory->expects($this->once())
|
||||
->method('createListFromChoices')
|
||||
->with($choices, $value)
|
||||
->willReturn($choiceList);
|
||||
|
||||
$this->assertSame(array($this->obj2), $loader->loadChoicesForValues(
|
||||
array('B'),
|
||||
$value
|
||||
@ -418,7 +383,6 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
public function testLoadChoicesForValuesLoadsOnlyChoicesIfValueIsIdReader()
|
||||
{
|
||||
$loader = new DoctrineChoiceLoader(
|
||||
$this->factory,
|
||||
$this->om,
|
||||
$this->class,
|
||||
$this->idReader,
|
||||
@ -439,9 +403,6 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$this->repository->expects($this->never())
|
||||
->method('findAll');
|
||||
|
||||
$this->factory->expects($this->never())
|
||||
->method('createListFromChoices');
|
||||
|
||||
$this->objectLoader->expects($this->once())
|
||||
->method('getEntitiesByIds')
|
||||
->with('idField', array('2'))
|
||||
|
@ -61,9 +61,5 @@
|
||||
<argument type="service" id="request_stack" />
|
||||
<tag name="kernel.event_subscriber" />
|
||||
</service>
|
||||
|
||||
<service id="validate_request_listener" class="Symfony\Component\HttpKernel\EventListener\ValidateRequestListener">
|
||||
<tag name="kernel.event_subscriber" />
|
||||
</service>
|
||||
</services>
|
||||
</container>
|
||||
|
@ -1,5 +1,5 @@
|
||||
--------------------- -----------------------------------------------------------------
|
||||
[32mParameter[39m [32mValue[39m
|
||||
[32m Parameter [39m [32m Value [39m
|
||||
--------------------- -----------------------------------------------------------------
|
||||
twig.form.resources ["bootstrap_3_horizontal_layout.html.twig","bootstrap_3_layo...
|
||||
--------------------- -----------------------------------------------------------------
|
||||
|
@ -3,7 +3,7 @@
|
||||
[33m=================================[39m
|
||||
|
||||
------------------- --------------------------------------------------------
|
||||
[32mService ID[39m [32mClass name[39m
|
||||
[32m Service ID [39m [32m Class name [39m
|
||||
------------------- --------------------------------------------------------
|
||||
alias_1 alias for "service_1"
|
||||
alias_2 alias for "service_2"
|
||||
|
@ -3,7 +3,7 @@
|
||||
[33m=============================================[39m
|
||||
|
||||
------------------- --------------------------------------------------------
|
||||
[32mService ID[39m [32mClass name[39m
|
||||
[32m Service ID [39m [32m Class name [39m
|
||||
------------------- --------------------------------------------------------
|
||||
alias_1 alias for "service_1"
|
||||
alias_2 alias for "service_2"
|
||||
|
@ -3,7 +3,7 @@
|
||||
[33m====================================================================[39m
|
||||
|
||||
-------------- ------- ------- ------- -----------------------
|
||||
[32mService ID[39m [32mattr1[39m [32mattr2[39m [32mattr3[39m [32mClass name[39m
|
||||
[32m Service ID [39m [32m attr1 [39m [32m attr2 [39m [32m attr3 [39m [32m Class name [39m
|
||||
-------------- ------- ------- ------- -----------------------
|
||||
definition_2 val1 val2 Full\Qualified\Class2
|
||||
" val3
|
||||
|
@ -1,5 +1,5 @@
|
||||
------------------ -----------------------------
|
||||
[32mOption[39m [32mValue[39m
|
||||
[32m Option [39m [32m Value [39m
|
||||
------------------ -----------------------------
|
||||
Service ID -
|
||||
Class Full\Qualified\Class1
|
||||
|
@ -1,5 +1,5 @@
|
||||
------------------ -------------------------------------------------------
|
||||
[32mOption[39m [32mValue[39m
|
||||
[32m Option [39m [32m Value [39m
|
||||
------------------ -------------------------------------------------------
|
||||
Service ID -
|
||||
Class Full\Qualified\Class2
|
||||
|
@ -3,7 +3,7 @@
|
||||
[33m=======================================[39m
|
||||
|
||||
------- ------------------- ----------
|
||||
[32mOrder[39m [32mCallable[39m [32mPriority[39m
|
||||
[32m Order [39m [32m Callable [39m [32m Priority [39m
|
||||
------- ------------------- ----------
|
||||
#1 global_function() 255
|
||||
#2 \Closure() -1
|
||||
|
@ -6,7 +6,7 @@
|
||||
[33m--------------[39m
|
||||
|
||||
------- ------------------- ----------
|
||||
[32mOrder[39m [32mCallable[39m [32mPriority[39m
|
||||
[32m Order [39m [32m Callable [39m [32m Priority [39m
|
||||
------- ------------------- ----------
|
||||
#1 global_function() 255
|
||||
#2 \Closure() -1
|
||||
@ -16,7 +16,7 @@
|
||||
[33m--------------[39m
|
||||
|
||||
------- ----------------------------------------------------------------------------------- ----------
|
||||
[32mOrder[39m [32mCallable[39m [32mPriority[39m
|
||||
[32m Order [39m [32m Callable [39m [32m Priority [39m
|
||||
------- ----------------------------------------------------------------------------------- ----------
|
||||
#1 Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor\CallableClass::__invoke() 0
|
||||
------- ----------------------------------------------------------------------------------- ----------
|
||||
|
@ -1,5 +1,5 @@
|
||||
--------------- ---------
|
||||
[32mParameter[39m [32mValue[39m
|
||||
[32m Parameter [39m [32m Value [39m
|
||||
--------------- ---------
|
||||
database_name symfony
|
||||
--------------- ---------
|
||||
|
@ -3,7 +3,7 @@
|
||||
[33m============================[39m
|
||||
|
||||
----------- --------------------------
|
||||
[32mParameter[39m [32mValue[39m
|
||||
[32m Parameter [39m [32m Value [39m
|
||||
----------- --------------------------
|
||||
array [12,"Hello world!",true]
|
||||
boolean true
|
||||
|
@ -1,5 +1,5 @@
|
||||
--------- ---------- ------------ ----------- ---------------
|
||||
[32mName[39m [32mMethod[39m [32mScheme[39m [32mHost[39m [32mPath[39m
|
||||
[32m Name [39m [32m Method [39m [32m Scheme [39m [32m Host [39m [32m Path [39m
|
||||
--------- ---------- ------------ ----------- ---------------
|
||||
route_1 GET|HEAD http|https localhost /hello/{name}
|
||||
route_2 PUT|POST http|https localhost /name/add
|
||||
|
@ -39,7 +39,7 @@
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/browser-kit": "~2.8|~3.0",
|
||||
"symfony/console": "~2.8|~3.0",
|
||||
"symfony/console": "~2.8.8|~3.0.8|~3.1.2|~3.2",
|
||||
"symfony/css-selector": "~2.8|~3.0",
|
||||
"symfony/dom-crawler": "~2.8|~3.0",
|
||||
"symfony/polyfill-intl-icu": "~1.0",
|
||||
|
@ -590,7 +590,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
'choices' => array('test'),
|
||||
'choices_as_values' => true,
|
||||
'empty_data' => 'test',
|
||||
));
|
||||
|
||||
@ -605,7 +604,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'multiple' => true,
|
||||
'expanded' => false,
|
||||
'choices' => array('test'),
|
||||
'choices_as_values' => true,
|
||||
'empty_data' => array('test'),
|
||||
));
|
||||
|
||||
@ -620,7 +618,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'multiple' => false,
|
||||
'expanded' => true,
|
||||
'choices' => array('test'),
|
||||
'choices_as_values' => true,
|
||||
'empty_data' => 'test',
|
||||
));
|
||||
|
||||
@ -635,7 +632,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
'choices' => array('test'),
|
||||
'choices_as_values' => true,
|
||||
'empty_data' => array('test'),
|
||||
));
|
||||
|
||||
|
@ -1,56 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\EventListener;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
use Symfony\Component\HttpKernel\KernelEvents;
|
||||
|
||||
/**
|
||||
* Validates that the headers and other information indicating the
|
||||
* client IP address of a request are consistent.
|
||||
*
|
||||
* @author Magnus Nordlander <magnus@fervo.se>
|
||||
*/
|
||||
class ValidateRequestListener implements EventSubscriberInterface
|
||||
{
|
||||
/**
|
||||
* Performs the validation.
|
||||
*
|
||||
* @param GetResponseEvent $event
|
||||
*/
|
||||
public function onKernelRequest(GetResponseEvent $event)
|
||||
{
|
||||
if ($event->isMasterRequest()) {
|
||||
try {
|
||||
// This will throw an exception if the headers are inconsistent.
|
||||
$event->getRequest()->getClientIps();
|
||||
} catch (ConflictingHeadersException $e) {
|
||||
throw new BadRequestHttpException('The request headers contain conflicting information regarding the origin of this request.', $e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return array(
|
||||
KernelEvents::REQUEST => array(
|
||||
array('onKernelRequest', 256),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -15,6 +15,7 @@ use Symfony\Component\HttpKernel\Controller\ArgumentResolver;
|
||||
use Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface;
|
||||
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
|
||||
use Symfony\Component\HttpKernel\Event\FilterControllerArgumentsEvent;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
|
||||
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
|
||||
@ -24,6 +25,7 @@ use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
|
||||
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
|
||||
use Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
@ -117,6 +119,13 @@ class HttpKernel implements HttpKernelInterface, TerminableInterface
|
||||
*/
|
||||
private function handleRaw(Request $request, $type = self::MASTER_REQUEST)
|
||||
{
|
||||
if (self::MASTER_REQUEST === $type && $request::getTrustedProxies()) {
|
||||
try {
|
||||
$request->getClientIps();
|
||||
} catch (ConflictingHeadersException $e) {
|
||||
throw new BadRequestHttpException('The request headers contain conflicting information regarding the origin of this request.', $e);
|
||||
}
|
||||
}
|
||||
$this->requestStack->push($request);
|
||||
|
||||
// request
|
||||
|
@ -1,67 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\EventListener;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\EventListener\ValidateRequestListener;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\HttpKernel\KernelEvents;
|
||||
|
||||
class ValidateRequestListenerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testListenerThrowsWhenMasterRequestHasInconsistentClientIps()
|
||||
{
|
||||
$dispatcher = new EventDispatcher();
|
||||
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
|
||||
$listener = new ValidateRequestListener();
|
||||
$request = $this->getMock('Symfony\Component\HttpFoundation\Request');
|
||||
$request->method('getClientIps')
|
||||
->will($this->throwException(new ConflictingHeadersException()));
|
||||
|
||||
$dispatcher->addListener(KernelEvents::REQUEST, array($listener, 'onKernelRequest'));
|
||||
$event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
|
||||
|
||||
$this->setExpectedException('Symfony\Component\HttpKernel\Exception\BadRequestHttpException');
|
||||
$dispatcher->dispatch(KernelEvents::REQUEST, $event);
|
||||
}
|
||||
|
||||
public function testListenerDoesNothingOnValidRequests()
|
||||
{
|
||||
$dispatcher = new EventDispatcher();
|
||||
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
|
||||
$listener = new ValidateRequestListener();
|
||||
$request = $this->getMock('Symfony\Component\HttpFoundation\Request');
|
||||
$request->method('getClientIps')
|
||||
->willReturn(array('127.0.0.1'));
|
||||
|
||||
$dispatcher->addListener(KernelEvents::REQUEST, array($listener, 'onKernelRequest'));
|
||||
$event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
|
||||
$dispatcher->dispatch(KernelEvents::REQUEST, $event);
|
||||
}
|
||||
|
||||
public function testListenerDoesNothingOnSubrequests()
|
||||
{
|
||||
$dispatcher = new EventDispatcher();
|
||||
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
|
||||
$listener = new ValidateRequestListener();
|
||||
$request = $this->getMock('Symfony\Component\HttpFoundation\Request');
|
||||
$request->method('getClientIps')
|
||||
->will($this->throwException(new ConflictingHeadersException()));
|
||||
|
||||
$dispatcher->addListener(KernelEvents::REQUEST, array($listener, 'onKernelRequest'));
|
||||
$event = new GetResponseEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST);
|
||||
$dispatcher->dispatch(KernelEvents::REQUEST, $event);
|
||||
}
|
||||
}
|
@ -302,6 +302,33 @@ class HttpKernelTest extends \PHPUnit_Framework_TestCase
|
||||
$kernel->handle($request, HttpKernelInterface::MASTER_REQUEST);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Symfony\Component\HttpKernel\Exception\BadRequestHttpException
|
||||
*/
|
||||
public function testInconsistentClientIpsOnMasterRequests()
|
||||
{
|
||||
$kernel = $this->getHttpKernel(new EventDispatcher());
|
||||
$request = new Request();
|
||||
$request->setTrustedProxies(array('1.1.1.1'));
|
||||
$request->server->set('REMOTE_ADDR', '1.1.1.1');
|
||||
$request->headers->set('FORWARDED', '2.2.2.2');
|
||||
$request->headers->set('X_FORWARDED_FOR', '3.3.3.3');
|
||||
|
||||
$kernel->handle($request, $kernel::MASTER_REQUEST, false);
|
||||
}
|
||||
|
||||
public function testInconsistentClientIpsOnSubRequests()
|
||||
{
|
||||
$kernel = $this->getHttpKernel(new EventDispatcher());
|
||||
$request = new Request();
|
||||
$request->setTrustedProxies(array('1.1.1.1'));
|
||||
$request->server->set('REMOTE_ADDR', '1.1.1.1');
|
||||
$request->headers->set('FORWARDED', '2.2.2.2');
|
||||
$request->headers->set('X_FORWARDED_FOR', '3.3.3.3');
|
||||
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $kernel->handle($request, $kernel::SUB_REQUEST, false));
|
||||
}
|
||||
|
||||
private function getHttpKernel(EventDispatcherInterface $eventDispatcher, $controller = null, RequestStack $requestStack = null, array $arguments = array())
|
||||
{
|
||||
if (null === $controller) {
|
||||
|
@ -18,7 +18,7 @@
|
||||
"require": {
|
||||
"php": ">=5.5.9",
|
||||
"symfony/event-dispatcher": "~2.8|~3.0",
|
||||
"symfony/http-foundation": "~2.8|~3.0",
|
||||
"symfony/http-foundation": "~2.8.8|~3.0.8|~3.1.2|~3.2",
|
||||
"symfony/debug": "~2.8|~3.0",
|
||||
"psr/log": "~1.0"
|
||||
},
|
||||
|
Reference in New Issue
Block a user