2012-12-14 10:26:52 +00:00
|
|
|
<?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\Bundle\FrameworkBundle\Tests\DependencyInjection;
|
|
|
|
|
|
|
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Configuration;
|
|
|
|
use Symfony\Component\Config\Definition\Processor;
|
|
|
|
|
|
|
|
class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @dataProvider getTestConfigTreeData
|
|
|
|
*/
|
|
|
|
public function testConfigTree($options, $results)
|
|
|
|
{
|
|
|
|
$processor = new Processor();
|
|
|
|
$configuration = new Configuration(array());
|
|
|
|
$config = $processor->processConfiguration($configuration, array($options));
|
|
|
|
|
|
|
|
$this->assertEquals($results, $config);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getTestConfigTreeData()
|
|
|
|
{
|
|
|
|
return array(
|
2012-12-15 16:50:23 +00:00
|
|
|
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' => '%kernel.debug%'), 'default_locale' => 'en', 'charset' => null)),
|
2012-12-14 10:26:52 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider getTestValidTrustedProxiesData
|
|
|
|
*/
|
|
|
|
public function testValidTrustedProxies($options, $results)
|
|
|
|
{
|
|
|
|
$processor = new Processor();
|
|
|
|
$configuration = new Configuration(array());
|
|
|
|
$config = $processor->processConfiguration($configuration, array($options));
|
|
|
|
|
|
|
|
$this->assertEquals($results, $config);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getTestValidTrustedProxiesData()
|
|
|
|
{
|
|
|
|
return array(
|
2012-12-15 16:50:23 +00:00
|
|
|
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' => '%kernel.debug%'), 'default_locale' => 'en', 'charset' => null)),
|
|
|
|
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' => '%kernel.debug%'), 'default_locale' => 'en', 'charset' => null)),
|
|
|
|
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' => '%kernel.debug%'), 'default_locale' => 'en', 'charset' => null)),
|
2012-12-20 22:18:21 +00:00
|
|
|
array(array('secret' => 's3cr3t', 'trusted_proxies' => null), array('secret' => 's3cr3t', 'trusted_proxies' => array(), 'trust_proxy_headers' => false, 'ide' => NULL, 'annotations' => array('cache' => 'file', 'file_cache_dir' => '%kernel.cache_dir%/annotations', 'debug' => '%kernel.debug%'), 'default_locale' => 'en', 'charset' => null)),
|
|
|
|
array(array('secret' => 's3cr3t', 'trusted_proxies' => false), array('secret' => 's3cr3t', 'trusted_proxies' => array(), 'trust_proxy_headers' => false, 'ide' => NULL, 'annotations' => array('cache' => 'file', 'file_cache_dir' => '%kernel.cache_dir%/annotations', 'debug' => '%kernel.debug%'), 'default_locale' => 'en', 'charset' => null)),
|
|
|
|
array(array('secret' => 's3cr3t', 'trusted_proxies' => array()), array('secret' => 's3cr3t', 'trusted_proxies' => array(), 'trust_proxy_headers' => false, 'ide' => NULL, 'annotations' => array('cache' => 'file', 'file_cache_dir' => '%kernel.cache_dir%/annotations', 'debug' => '%kernel.debug%'), 'default_locale' => 'en', 'charset' => null)),
|
2012-12-14 10:26:52 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-01-05 17:52:40 +00:00
|
|
|
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
|
2012-12-14 10:26:52 +00:00
|
|
|
*/
|
|
|
|
public function testInvalidTypeTrustedProxies()
|
|
|
|
{
|
|
|
|
$processor = new Processor();
|
|
|
|
$configuration = new Configuration(array());
|
2013-01-07 08:41:41 +00:00
|
|
|
$processor->processConfiguration($configuration, array(array('secret' => 's3cr3t', 'trusted_proxies' => 'Not an IP address')));
|
2012-12-14 10:26:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-01-05 17:52:40 +00:00
|
|
|
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
|
2012-12-14 10:26:52 +00:00
|
|
|
*/
|
|
|
|
public function testInvalidValueTrustedProxies()
|
|
|
|
{
|
|
|
|
$processor = new Processor();
|
|
|
|
$configuration = new Configuration(array());
|
2013-01-07 08:41:41 +00:00
|
|
|
$processor->processConfiguration($configuration, array(array('secret' => 's3cr3t', 'trusted_proxies' => array('Not an IP address'))));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
|
|
|
|
*/
|
|
|
|
public function testDefaultSecretIsUsed()
|
|
|
|
{
|
|
|
|
$processor = new Processor();
|
|
|
|
$configuration = new Configuration(array());
|
|
|
|
$processor->processConfiguration($configuration, array(array('secret' => 'ThisTokenIsNotSoSecretChangeIt')));
|
2012-12-14 10:26:52 +00:00
|
|
|
}
|
|
|
|
}
|