8000 merged branch bamarni/2.0 (PR #6154) · symfony/symfony@c0fc33d · GitHub
[go: up one dir, main page]

Skip to content

Commit c0fc33d

Browse files
committed
merged branch bamarni/2.0 (PR #6154)
This PR was merged into the 2.0 branch. Commits ------- f0743b1 Merge pull request #1 from pylebecq/2.0 555e777 [FrameworkBundle] Added tests for trusted_proxies configuration. a0e2391 [FrameworkBundle] used the new method for trusted proxies Discussion ---------- [FrameworkBundle] used the new method for trusted proxies This makes the framework bundle using the new method from the request class. --------------------------------------------------------------------------- by fabpot at 2012-12-05T10:38:20Z As this is a sensitive issue, can you add some tests? Thanks. --------------------------------------------------------------------------- by bamarni at 2012-12-06T13:00:24Z Well I don't know why it fails on travis, I can't run the full test suite locally because of a segfault but ```phpunit src/Symfony/Bundle/``` marks all the tests as passing. --------------------------------------------------------------------------- by fabpot at 2012-12-06T13:08:11Z But it looks like the failing tests come from what you've changed. --------------------------------------------------------------------------- by bamarni at 2012-12-06T13:29:33Z Yes, I'm not saying it's not my fault but I can't reproduce this as locally it tells me they pass, I'll try to fix this this evening. --------------------------------------------------------------------------- by bamarni at 2012-12-06T17:49:28Z Apparently it fails only when running the whole testsuite, looking at other travis builds I can see this one on 2.0 : https://travis-ci.org/symfony/symfony/jobs/3495511 which fails in a similar way than here (https://travis-ci.org/symfony/symfony/jobs/3530928). Because of a place trying to access an undefined $_SERVER key : ```PHP Notice: Undefined index: SCRIPT_NAME ...``` but I can't find where, and the stack trace references some phpunit classes. I'd be happy if someone could give me some pointers in here as I don't have any clue about how to fix this.. --------------------------------------------------------------------------- by bamarni at 2012-12-06T18:00:57Z As a consulsion I'd say I can't run the whole testsuite locally (it fails even when I revert my commit), so there is no reliable way for me to fix this, if anyone is up for continuing this feel free. --------------------------------------------------------------------------- by fabpot at 2012-12-11T09:47:48Z @bamarni Can you just update this PR with the code change and no tests at all? I will then finish the PR. Thanks. --------------------------------------------------------------------------- by bamarni at 2012-12-11T16:58:17Z @fabpot: thanks for helping me out on this, hope you won't run into the same issue!
2 parents da98371 + f0743b1 commit c0fc33d

File tree

4 files changed

+94
-3
lines changed

4 files changed

+94
-3
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,15 @@ public function getConfigTreeBuilder()
4747
$rootNode
4848
->children()
4949
->scalarNode('charset')->end()
50-
->scalarNode('trust_proxy_headers')->defaultFalse()->end()
50+
->arrayNode('trusted_proxies')
51+
->prototype('scalar')
52+
->validate()
53+
->ifTrue(function($v) { return !filter_var($v, FILTER_VALIDATE_IP); })
54+
->thenInvalid('Invalid proxy IP "%s"')
55+
->end()
56+
->end()
57+
->end()
58+
->scalarNode('trust_proxy_headers')->defaultFalse()->end() // @deprecated, to be removed in 2.3
5159
->scalarNode('secret')->isRequired()->end()
5260
->scalarNode('ide')->defaultNull()->end()
5361
->booleanNode('test')->end()

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ public function load(array $configs, ContainerBuilder $container)
6262
}
6363
$container->setParameter('kernel.secret', $config['secret']);
6464

65+
$container->setParameter('kernel.trusted_proxies', $config['trusted_proxies']);
66+
67+
// @deprecated, to be removed in 2.3
6568
$container->setParameter('kernel.trust_proxy_headers', $config['trust_proxy_headers']);
6669

6770
if (!empty($config['test'])) {

src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ class FrameworkBundle extends Bundle
3737
{
3838
public function boot()
3939
{
40-
if ($this->container->getParameter('kernel.trust_proxy_headers')) {
41-
Request::trustProxyData();
40+
if ($trustedProxies = $this->container->getParameter('kernel.trusted_proxies')) {
41+
Request::setTrustedProxies($trustedProxies);
42+
} elseif ($this->container->getParameter('kernel.trust_proxy_headers')) {
43+
Request::trustProxyData(); // @deprecated, to be removed in 2.3
4244
}
4345
}
4446

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection;
13+
14+
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Configuration;
15+
use Symfony\Component\Config\Definition\Processor;
16+
17+
class ConfigurationTest extends \PHPUnit_Framework_TestCase
18+
{
19+
/**
20+
* @dataProvider getTestConfigTreeData
21+
*/
22+
public function testConfigTree($options, $results)
23+
{
24+
$processor = new Processor();
25+
$configuration = new Configuration(array());
26+
$config = $processor->processConfiguration($configuration, array($options));
27+
28+
$this->assertEquals($results, $config);
29+
}
30+
31+
public function getTestConfigTreeData()
32+
{
33+
return array(
34+
array(array('secret' => 's3cr3t'), array('secret' => 's3cr3t', 'trusted_proxies' => array(), 'trust_proxy_headers' => false, 'ide' => NULL, 'annotations' => array('cache' => 'file', 'file_cache_dir' => '%kernel.cache_dir%/annotations', 'debug' => false))),
35+
);
36+
}
37+
38+
/**
39+
* @dataProvider getTestValidTrustedProxiesData
40+
*/
41+
public function testValidTrustedProxies($options, $results)
42+
{
43+
$processor = new Processor();
44+
$configuration = new Configuration(array());
45+
$config = $processor->processConfiguration($configuration, array($options));
46+
47+
$this->assertEquals($results, $config);
48+
}
49+
50+
public function getTestValidTrustedProxiesData()
51+
{
52+
return array(
53+
array(array('secret' => 's3cr3t', 'trusted_proxies' => array('127.0.0.1')), array('secret' => 's3cr3t', 'trusted_proxies' => array('127.0.0.1'), 'trust_proxy_headers' => false, 'ide' => NULL, 'annotations' => array('cache' => 'file', 'file_cache_dir' => '%kernel.cache_dir%/annotations', 'debug' => false))),
54+
array(array('secret' => 's3cr3t', 'trusted_proxies' => array('::1')), array('secret' => 's3cr3t', 'trusted_proxies' => array('::1'), 'trust_proxy_headers' => false, 'ide' => NULL, 'annotations' => array('cache' => 'file', 'file_cache_dir' => '%kernel.cache_dir%/annotations', 'debug' => false))),
55+
array(array('secret' => 's3cr3t', 'trusted_proxies' => array('127.0.0.1', '::1')), array('secret' => 's3cr3t', 'trusted_proxies' => array('127.0.0.1', '::1'), 'trust_proxy_headers' => false, 'ide' => NULL, 'annotations' => array('cache' => 'file', 'file_cache_dir' => '%kernel.cache_dir%/annotations', 'debug' => false))),
56+
);
57+
}
58+
59+
/**
60+
* @expectedException Symfony\Component\Config\Definition\Exception\InvalidTypeException
61+
*/
62+
public function testInvalidTypeTrustedProxies()
63+
{
64+
$processor = new Processor();
65+
$configuration = new Configuration(array());
66+
$config = $processor->processConfiguration($configuration, array(array('secret' => 's3cr3t', 'trusted_proxies' => 'Not an IP address')));
67+
}
68+
69+
/**
70+
* @expectedException Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
71+
*/
72+
public function testInvalidValueTrustedProxies()
73+
{
74+
$processor = new Processor();
75+
$configuration = new Configuration(array());
76+
$config = $processor->processConfiguration($configuration, array(array('secret' => 's3cr3t', 'trusted_proxies' => array('Not an IP address'))));
77+
}
78+
}

0 commit comments

Comments
 (0)
0