From ff055ef7f377f524288a491255a33da00fbc15cc Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sat, 3 Jun 2017 12:01:46 +0200 Subject: [PATCH] mitigate BC break with empty trusted_proxies --- .../DependencyInjection/Configuration.php | 6 +++- .../DependencyInjection/ConfigurationTest.php | 32 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 87d722b91e..2ff6141359 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -67,7 +67,11 @@ class Configuration implements ConfigurationInterface ->end() ->arrayNode('trusted_proxies') // @deprecated in version 3.3, to be removed in 4.0 ->beforeNormalization() - ->always() + ->ifTrue(function ($v) { return empty($v); }) + ->then(function () { @trigger_error('The "framework.trusted_proxies" configuration key has been removed in Symfony 3.3. Use the Request::setTrustedProxies() method in your front controller instead.', E_USER_DEPRECATED); }) + ->end() + ->beforeNormalization() + ->ifTrue(function ($v) { return !empty($v); }) ->thenInvalid('The "framework.trusted_proxies" configuration key has been removed in Symfony 3.3. Use the Request::setTrustedProxies() method in your front controller instead.') ->end() ->end() diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php index 353e959c68..96835c7be3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -43,6 +43,38 @@ class ConfigurationTest extends TestCase $this->assertEquals(array('FrameworkBundle:Form'), $config['templating']['form']['resources']); } + /** + * @group legacy + * @expectedDeprecation The "framework.trusted_proxies" configuration key has been removed in Symfony 3.3. Use the Request::setTrustedProxies() method in your front controller instead. + */ + public function testTrustedProxiesSetToNullIsDeprecated() + { + $processor = new Processor(); + $configuration = new Configuration(true); + $processor->processConfiguration($configuration, array(array('trusted_proxies' => null))); + } + + /** + * @group legacy + * @expectedDeprecation The "framework.trusted_proxies" configuration key has been removed in Symfony 3.3. Use the Request::setTrustedProxies() method in your front controller instead. + */ + public function testTrustedProxiesSetToEmptyArrayIsDeprecated() + { + $processor = new Processor(); + $configuration = new Configuration(true); + $processor->processConfiguration($configuration, array(array('trusted_proxies' => array()))); + } + + /** + * @expectedException \InvalidArgumentException + */ + public function testTrustedProxiesSetToNonEmptyArrayIsInvalid() + { + $processor = new Processor(); + $configuration = new Configuration(true); + $processor->processConfiguration($configuration, array(array('trusted_proxies' => array('127.0.0.1')))); + } + public function testAssetsCanBeEnabled() { $processor = new Processor();