[FrameworkBundle] fixed XSD for the trusted-proxies setting

This commit is contained in:
Fabien Potencier 2012-12-20 08:58:18 +01:00
parent 16c554bc1f
commit 0085798dff
7 changed files with 19 additions and 2 deletions

View File

@ -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); })

View File

@ -23,6 +23,7 @@
<xsd:attribute name="charset" type="xsd:string" />
<xsd:attribute name="trust-proxy-headers" type="xsd:string" />
<xsd:attribute name="trusted-proxies" type="xsd:string" />
<xsd:attribute name="ide" type="xsd:string" />
<xsd:attribute name="secret" type="xsd:string" />
<xsd:attribute name="test" type="xsd:boolean" />

View File

@ -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()
{

View File

@ -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',

View File

@ -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">
<framework:config secret="s3cr3t" ide="file%%link%%format">
<framework:config secret="s3cr3t" ide="file%%link%%format" trust-proxy-headers="true" trusted-proxies="127.0.0.1, 10.0.0.1">
<framework:csrf-protection enabled="true" field-name="_csrf" />
<framework:form />
<framework:esi enabled="true" />

View File

@ -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

View File

@ -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');