Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 93d5bf7

Browse files
committed
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
2 parents c1b0917 + 93b831b commit 93d5bf7

File tree

6 files changed

+65
-9
lines changed

6 files changed

+65
-9
lines changed

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/CompleteConfigurationTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
abstract class CompleteConfigurationTest extends \PHPUnit_Framework_TestCase
2121
{
22+
private static $containerCache = array();
23+
2224
abstract protected function loadFromFile(ContainerBuilder $container, $file);
2325

2426
public function testRolesHierarchy()
@@ -235,6 +237,9 @@ public function testRememberMeThrowExceptions()
235237

236238
protected function getContainer($file)
237239
{
240+
if (isset(self::$containerCache[$file])) {
241+
return self::$containerCache[$file];
242+
}
238243
$container = new ContainerBuilder();
239244
$security = new SecurityExtension();
240245
$container->registerExtension($security);
@@ -247,6 +252,6 @@ protected function getContainer($file)
247252
$container->getCompilerPassConfig()->setRemovingPasses(array());
248253
$container->compile();
249254

250-
return $container;
255+
return self::$containerCache[$file] = $container;
251256
}
252257
}

src/Symfony/Component/HttpFoundation/ServerBag.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ public function getHeaders()
8686
}
8787
}
8888

89+
if (isset($headers['AUTHORIZATION'])) {
90+
return $headers;
91+
}
92+
8993
// PHP_AUTH_USER/PHP_AUTH_PW
9094
if (isset($headers['PHP_AUTH_USER'])) {
9195
$headers['AUTHORIZATION'] = 'Basic '.base64_encode($headers['PHP_AUTH_USER'].':'.$headers['PHP_AUTH_PW']);

src/Symfony/Component/HttpFoundation/Tests/ServerBagTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,19 @@ public function testOAuthBearerAuthWithRedirect()
151151
'AUTHORIZATION' => $headerContent,
152152
), $bag->getHeaders());
153153
}
154+
155+
/**
156+
* @see https://github.com/symfony/symfony/issues/17345
157+
*/
158+
public function testItDoesNotOverwriteTheAuthorizationHeaderIfItIsAlreadySet()
159+
{
160+
$headerContent = 'Bearer L-yLEOr9zhmUYRkzN1jwwxwQ-PBNiKDc8dgfB4hTfvo';
161+
$bag = new ServerBag(array('PHP_AUTH_USER' => 'foo', 'HTTP_AUTHORIZATION' => $headerContent));
162+
163+
$this->assertEquals(array(
164+
'AUTHORIZATION' => $headerContent,
165+
'PHP_AUTH_USER' => 'foo',
166+
'PHP_AUTH_PW' => '',
167+
), $bag->getHeaders());
168+
}
154169
}

src/Symfony/Component/Yaml/Inline.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public static function dump($value, $exceptionOnInvalidType = false, $objectSupp
105105
return 'null';
106106
case is_object($value):
107107
if ($objectSupport) {
108-
return '!!php/object:'.serialize($value);
108+
return '!php/object:'.serialize($value);
109109
}
110110

111111
if ($exceptionOnInvalidType) {
@@ -469,6 +469,16 @@ private static function evaluateScalar($scalar, $references = array())
469469
return (string) substr($scalar, 5);
470470
case 0 === strpos($scalar, '! '):
471471
return (int) self::parseScalar(substr($scalar, 2));
472+
case 0 === strpos($scalar, '!php/object:'):
473+
if (self::$objectSupport) {
474+
return unserialize(substr($scalar, 12));
475+
}
476+
477+
if (self::$exceptionOnInvalidType) {
478+
throw new ParseException('Object support when parsing a YAML file has been disabled.');
479+
}
480+
481+
return;
472482
case 0 === strpos($scalar, '!!php/object:'):
473483
if (self::$objectSupport) {
474484
return unserialize(substr($scalar, 13));

src/Symfony/Component/Yaml/Tests/DumperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public function testObjectSupportEnabled()
180180
{
181181
$dump = $this->dumper->dump(array('foo' => new A(), 'bar' => 1), 0, 0, false, true);
182182

183-
$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');
183+
$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');
184184
}
185185

186186
public function testObjectSupportDisabledButNoExceptions()

src/Symfony/Component/Yaml/Tests/ParserTest.php

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -426,15 +426,19 @@ public function testObjectSupportEnabled()
426426
bar: 1
427427
EOF;
428428
$this->assertEquals(array('foo' => new B(), 'bar' => 1), $this->parser->parse($input, false, true), '->parse() is able to parse objects');
429-
}
430429

431-
public function testObjectSupportDisabledButNoExceptions()
432-
{
433430
$input = <<<EOF
434-
foo: !!php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";}
431+
foo: !php/object:O:30:"Symfony\Component\Yaml\Tests\B":1:{s:1:"b";s:3:"foo";}
435432
bar: 1
436433
EOF;
434+
$this->assertEquals(array('foo' => new B(), 'bar' => 1), $this->parser->parse($input, false, true), '->parse() is able to parse objects');
435+
}
437436

437+
/**
438+
* @dataProvider invalidDumpedObjectProvider
439+
*/
440+
public function testObjectSupportDisabledButNoExceptions($input)
441+
{
438442
$this->assertEquals(array('foo' => null, 'bar' => 1), $this->parser->parse($input), '->parse() does not parse objects');
439443
}
440444

@@ -461,11 +465,29 @@ public function testObjectForMapEnabledWithInlineMapping()
461465
}
462466

463467
/**
468+
* @dataProvider invalidDumpedObjectProvider
464469
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
465470
*/
466-
public function testObjectsSupportDisabledWithExceptions()
471+
public function testObjectsSupportDisabledWithExceptions($yaml)
472+
{
473+
$this->parser->parse($yaml, true, false);
474+
}
475+
476+
public function invalidDumpedObjectProvider()
467477
{
468-
$this->parser->parse('foo: !!php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";}', true, false);
478+
$yamlTag = <<<EOF
479+
foo: !!php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";}
480+
bar: 1
481+
EOF;
482+
$localTag = <<<EOF
483+
foo: !php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";}
484+
bar: 1
485+
EOF;
486+
487+
return array(
488+
'yaml-tag' => array($yamlTag),
489+
'local-tag' => array($localTag),
490+
);
469491
}
470492

471493
/**

0 commit comments

Comments
 (0)