Merge branch '2.3' into 2.7
* 2.3: [SecurityBundle] Optimize dependency injection tests [HttpFoundation] Do not overwrite the Authorization header if it is already set tag for dumped PHP objects must be a local one
This commit is contained in:
commit
93d5bf7424
@ -19,6 +19,8 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|||||||
|
|
||||||
abstract class CompleteConfigurationTest extends \PHPUnit_Framework_TestCase
|
abstract class CompleteConfigurationTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
private static $containerCache = array();
|
||||||
|
|
||||||
abstract protected function loadFromFile(ContainerBuilder $container, $file);
|
abstract protected function loadFromFile(ContainerBuilder $container, $file);
|
||||||
|
|
||||||
public function testRolesHierarchy()
|
public function testRolesHierarchy()
|
||||||
@ -235,6 +237,9 @@ abstract class CompleteConfigurationTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
protected function getContainer($file)
|
protected function getContainer($file)
|
||||||
{
|
{
|
||||||
|
if (isset(self::$containerCache[$file])) {
|
||||||
|
return self::$containerCache[$file];
|
||||||
|
}
|
||||||
$container = new ContainerBuilder();
|
$container = new ContainerBuilder();
|
||||||
$security = new SecurityExtension();
|
$security = new SecurityExtension();
|
||||||
$container->registerExtension($security);
|
$container->registerExtension($security);
|
||||||
@ -247,6 +252,6 @@ abstract class CompleteConfigurationTest extends \PHPUnit_Framework_TestCase
|
|||||||
$container->getCompilerPassConfig()->setRemovingPasses(array());
|
$container->getCompilerPassConfig()->setRemovingPasses(array());
|
||||||
$container->compile();
|
$container->compile();
|
||||||
|
|
||||||
return $container;
|
return self::$containerCache[$file] = $container;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,6 +86,10 @@ class ServerBag extends ParameterBag
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($headers['AUTHORIZATION'])) {
|
||||||
|
return $headers;
|
||||||
|
}
|
||||||
|
|
||||||
// PHP_AUTH_USER/PHP_AUTH_PW
|
// PHP_AUTH_USER/PHP_AUTH_PW
|
||||||
if (isset($headers['PHP_AUTH_USER'])) {
|
if (isset($headers['PHP_AUTH_USER'])) {
|
||||||
$headers['AUTHORIZATION'] = 'Basic '.base64_encode($headers['PHP_AUTH_USER'].':'.$headers['PHP_AUTH_PW']);
|
$headers['AUTHORIZATION'] = 'Basic '.base64_encode($headers['PHP_AUTH_USER'].':'.$headers['PHP_AUTH_PW']);
|
||||||
|
@ -151,4 +151,19 @@ class ServerBagTest extends \PHPUnit_Framework_TestCase
|
|||||||
'AUTHORIZATION' => $headerContent,
|
'AUTHORIZATION' => $headerContent,
|
||||||
), $bag->getHeaders());
|
), $bag->getHeaders());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see https://github.com/symfony/symfony/issues/17345
|
||||||
|
*/
|
||||||
|
public function testItDoesNotOverwriteTheAuthorizationHeaderIfItIsAlreadySet()
|
||||||
|
{
|
||||||
|
$headerContent = 'Bearer L-yLEOr9zhmUYRkzN1jwwxwQ-PBNiKDc8dgfB4hTfvo';
|
||||||
|
$bag = new ServerBag(array('PHP_AUTH_USER' => 'foo', 'HTTP_AUTHORIZATION' => $headerContent));
|
||||||
|
|
||||||
|
$this->assertEquals(array(
|
||||||
|
'AUTHORIZATION' => $headerContent,
|
||||||
|
'PHP_AUTH_USER' => 'foo',
|
||||||
|
'PHP_AUTH_PW' => '',
|
||||||
|
), $bag->getHeaders());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -105,7 +105,7 @@ class Inline
|
|||||||
return 'null';
|
return 'null';
|
||||||
case is_object($value):
|
case is_object($value):
|
||||||
if ($objectSupport) {
|
if ($objectSupport) {
|
||||||
return '!!php/object:'.serialize($value);
|
return '!php/object:'.serialize($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($exceptionOnInvalidType) {
|
if ($exceptionOnInvalidType) {
|
||||||
@ -469,6 +469,16 @@ class Inline
|
|||||||
return (string) substr($scalar, 5);
|
return (string) substr($scalar, 5);
|
||||||
case 0 === strpos($scalar, '! '):
|
case 0 === strpos($scalar, '! '):
|
||||||
return (int) self::parseScalar(substr($scalar, 2));
|
return (int) self::parseScalar(substr($scalar, 2));
|
||||||
|
case 0 === strpos($scalar, '!php/object:'):
|
||||||
|
if (self::$objectSupport) {
|
||||||
|
return unserialize(substr($scalar, 12));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (self::$exceptionOnInvalidType) {
|
||||||
|
throw new ParseException('Object support when parsing a YAML file has been disabled.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
case 0 === strpos($scalar, '!!php/object:'):
|
case 0 === strpos($scalar, '!!php/object:'):
|
||||||
if (self::$objectSupport) {
|
if (self::$objectSupport) {
|
||||||
return unserialize(substr($scalar, 13));
|
return unserialize(substr($scalar, 13));
|
||||||
|
@ -180,7 +180,7 @@ EOF;
|
|||||||
{
|
{
|
||||||
$dump = $this->dumper->dump(array('foo' => new A(), 'bar' => 1), 0, 0, false, true);
|
$dump = $this->dumper->dump(array('foo' => new A(), 'bar' => 1), 0, 0, false, true);
|
||||||
|
|
||||||
$this->assertEquals('{ foo: !!php/object:O:30:"Symfony\Component\Yaml\Tests\A":1:{s:1:"a";s:3:"foo";}, bar: 1 }', $dump, '->dump() is able to dump objects');
|
$this->assertEquals('{ foo: !php/object:O:30:"Symfony\Component\Yaml\Tests\A":1:{s:1:"a";s:3:"foo";}, bar: 1 }', $dump, '->dump() is able to dump objects');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testObjectSupportDisabledButNoExceptions()
|
public function testObjectSupportDisabledButNoExceptions()
|
||||||
|
@ -426,15 +426,19 @@ foo: !!php/object:O:30:"Symfony\Component\Yaml\Tests\B":1:{s:1:"b";s:3:"foo";}
|
|||||||
bar: 1
|
bar: 1
|
||||||
EOF;
|
EOF;
|
||||||
$this->assertEquals(array('foo' => new B(), 'bar' => 1), $this->parser->parse($input, false, true), '->parse() is able to parse objects');
|
$this->assertEquals(array('foo' => new B(), 'bar' => 1), $this->parser->parse($input, false, true), '->parse() is able to parse objects');
|
||||||
}
|
|
||||||
|
|
||||||
public function testObjectSupportDisabledButNoExceptions()
|
|
||||||
{
|
|
||||||
$input = <<<EOF
|
$input = <<<EOF
|
||||||
foo: !!php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";}
|
foo: !php/object:O:30:"Symfony\Component\Yaml\Tests\B":1:{s:1:"b";s:3:"foo";}
|
||||||
bar: 1
|
bar: 1
|
||||||
EOF;
|
EOF;
|
||||||
|
$this->assertEquals(array('foo' => new B(), 'bar' => 1), $this->parser->parse($input, false, true), '->parse() is able to parse objects');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider invalidDumpedObjectProvider
|
||||||
|
*/
|
||||||
|
public function testObjectSupportDisabledButNoExceptions($input)
|
||||||
|
{
|
||||||
$this->assertEquals(array('foo' => null, 'bar' => 1), $this->parser->parse($input), '->parse() does not parse objects');
|
$this->assertEquals(array('foo' => null, 'bar' => 1), $this->parser->parse($input), '->parse() does not parse objects');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -461,11 +465,29 @@ EOF;
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @dataProvider invalidDumpedObjectProvider
|
||||||
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
|
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
|
||||||
*/
|
*/
|
||||||
public function testObjectsSupportDisabledWithExceptions()
|
public function testObjectsSupportDisabledWithExceptions($yaml)
|
||||||
{
|
{
|
||||||
$this->parser->parse('foo: !!php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";}', true, false);
|
$this->parser->parse($yaml, true, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function invalidDumpedObjectProvider()
|
||||||
|
{
|
||||||
|
$yamlTag = <<<EOF
|
||||||
|
foo: !!php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";}
|
||||||
|
bar: 1
|
||||||
|
EOF;
|
||||||
|
$localTag = <<<EOF
|
||||||
|
foo: !php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";}
|
||||||
|
bar: 1
|
||||||
|
EOF;
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'yaml-tag' => array($yamlTag),
|
||||||
|
'local-tag' => array($localTag),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user