From 0085798dffe31e3e3134f1a7f39190becd97ecd6 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 20 Dec 2012 08:58:18 +0100 Subject: [PATCH] [FrameworkBundle] fixed XSD for the trusted-proxies setting --- .../FrameworkBundle/DependencyInjection/Configuration.php | 4 ++++ .../Resources/config/schema/symfony-1.0.xsd | 1 + .../Tests/DependencyInjection/ConfigurationTest.php | 2 +- .../Tests/DependencyInjection/Fixtures/php/full.php | 2 ++ .../Tests/DependencyInjection/Fixtures/xml/full.xml | 2 +- .../Tests/DependencyInjection/Fixtures/yml/full.yml | 2 ++ .../Tests/DependencyInjection/FrameworkExtensionTest.php | 8 ++++++++ 7 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index eab82121c0..668f37cb0f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -48,6 +48,10 @@ class Configuration implements ConfigurationInterface ->children() ->scalarNode('charset')->end() ->arrayNode('trusted_proxies') + ->beforeNormalization() + ->ifTrue(function($v) { return !is_array($v); }) + ->then(function($v) { return preg_split('/\s*,\s*/', $v); }) + ->end() ->prototype('scalar') ->validate() ->ifTrue(function($v) { return !filter_var($v, FILTER_VALIDATE_IP); }) diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd b/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd index 1ad5208612..836674af0e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd @@ -23,6 +23,7 @@ + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php index d6d7cf9a14..1c5c72098f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -57,7 +57,7 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException Symfony\Component\Config\Definition\Exception\InvalidTypeException + * @expectedException Symfony\Component\Config\Definition\Exception\InvalidConfigurationException */ public function testInvalidTypeTrustedProxies() { diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php index 995220bab9..d68b311808 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php @@ -3,6 +3,8 @@ $container->loadFromExtension('framework', array( 'secret' => 's3cr3t', 'form' => null, + 'trust_proxy_headers' => true, + 'trusted_proxies' => array('127.0.0.1', '10.0.0.1'), 'csrf_protection' => array( 'enabled' => true, 'field_name' => '_csrf', diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml index 1c025c8829..36e091215e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml @@ -6,7 +6,7 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd"> - + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml index 0dd5eaf42c..e8e09f88e1 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml @@ -1,6 +1,8 @@ framework: secret: s3cr3t form: ~ + trust_proxy_headers: true + trusted_proxies: ['127.0.0.1', '10.0.0.1'] csrf_protection: enabled: true field_name: _csrf diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index ba57323507..38e7234c02 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -33,6 +33,14 @@ abstract class FrameworkExtensionTest extends TestCase $this->assertEquals('s3cr3t', $container->getParameterBag()->resolveValue($container->findDefinition('form.csrf_provider')->getArgument(1))); } + public function testProxies() + { + $container = $this->createContainerFromFile('full'); + + $this->assertTrue($container->getParameter('kernel.trust_proxy_headers')); + $this->assertEquals(array('127.0.0.1', '10.0.0.1'), $container->getParameter('kernel.trusted_proxies')); + } + public function testEsi() { $container = $this->createContainerFromFile('full');