8000 Merge branch '5.4' into 6.3 · symfony/symfony@01efac5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 01efac5

Browse files
committed
Merge branch '5.4' into 6.3
* 5.4: fix tests Remove full DSNs from exception messages [Yaml] Fix uid binary parsing [HttpKernel] Preventing error 500 when function putenv is disabled [PasswordHasher][Tests] Do not invoke methods with additional arguments in tests remove invalid group Fix block scalar array parsing
2 parents e8ce12a + 5c949c1 commit 01efac5

File tree

9 files changed

+94
-50
lines changed

9 files changed

+94
-50
lines changed

src/Symfony/Component/Form/Tests/Resources/TranslationFilesTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ public function testTranslationFileIsValid($filePath)
3131

3232
/**
3333
* @dataProvider provideTranslationFiles
34-
*
35-
* @group Legacy
3634
*/
3735
public function testTranslationFileIsValidWithoutEntityLoader($filePath)
3836
{

src/Symfony/Component/HttpKernel/Kernel.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,9 @@ private function preBoot(): ContainerInterface
748748
$this->startTime = microtime(true);
749749
}
750750
if ($this->debug && !isset($_ENV['SHELL_VERBOSITY']) && !isset($_SERVER['SHELL_VERBOSITY'])) {
751-
putenv('SHELL_VERBOSITY=3');
751+
if (\function_exists('putenv')) {
752+
putenv('SHELL_VERBOSITY=3');
753+
}
752754
$_ENV['SHELL_VERBOSITY'] = 3;
753755
$_SERVER['SHELL_VERBOSITY'] = 3;
754756
}

src/Symfony/Component/PasswordHasher/Tests/Hasher/NativePasswordHasherTest.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,25 @@ public function testValidation()
5151
{
5252
$hasher = new NativePasswordHasher();
5353
$result = $hasher->hash('password', null);
54-
$this->assertTrue($hasher->verify($result, 'password', null));
55-
$this->assertFalse($hasher->verify($result, 'anotherPassword', null));
56-
$this->assertFalse($hasher->verify($result, '', null));
54+
$this->assertTrue($hasher->verify($result, 'password'));
55+
$this->assertFalse($hasher->verify($result, 'anotherPassword'));
56+
$this->assertFalse($hasher->verify($result, ''));
5757
}
5858

5959
public function testNonArgonValidation()
6060
{
6161
$hasher = new NativePasswordHasher();
62-
$this->assertTrue($hasher->verify('$5$abcdefgh$ZLdkj8mkc2XVSrPVjskDAgZPGjtj1VGVaa1aUkrMTU/', 'password', null));
63-
$this->assertFalse($hasher->verify('$5$abcdefgh$ZLdkj8mkc2XVSrPVjskDAgZPGjtj1VGVaa1aUkrMTU/', 'anotherPassword', null));
64-
$this->assertTrue($hasher->verify('$6$abcdefgh$yVfUwsw5T.JApa8POvClA1pQ5peiq97DUNyXCZN5IrF.BMSkiaLQ5kvpuEm/VQ1Tvh/KV2TcaWh8qinoW5dhA1', 'password', null));
65-
$this->assertFalse($hasher->verify('$6$abcdefgh$yVfUwsw5T.JApa8POvClA1pQ5peiq97DUNyXCZN5IrF.BMSkiaLQ5kvpuEm/VQ1Tvh/KV2TcaWh8qinoW5dhA1', 'anotherPassword', null));
62+
$this->assertTrue($hasher->verify('$5$abcdefgh$ZLdkj8mkc2XVSrPVjskDAgZPGjtj1VGVaa1aUkrMTU/', 'password'));
63+
$this->assertFalse($hasher->verify('$5$abcdefgh$ZLdkj8mkc2XVSrPVjskDAgZPGjtj1VGVaa1aUkrMTU/', 'anotherPassword'));
64+
$this->assertTrue($hasher->verify('$6$abcdefgh$yVfUwsw5T.JApa8POvClA1pQ5peiq97DUNyXCZN5IrF.BMSkiaLQ5kvpuEm/VQ1Tvh/KV2TcaWh8qinoW5dhA1', 'password'));
65+
$this->assertFalse($hasher->verify('$6$abcdefgh$yVfUwsw5T.JApa8POvClA1pQ5peiq97DUNyXCZN5IrF.BMSkiaLQ5kvpuEm/VQ1Tvh/KV2TcaWh8qinoW5dhA1', 'anotherPassword'));
6666
}
6767

6868
public function testConfiguredAlgorithm()
6969
{
7070
$hasher = new NativePasswordHasher(null, null, null, \PASSWORD_BCRYPT);
71-
$result = $hasher->hash('password', null);
72-
$this->assertTrue($hasher->verify($result, 'password', null));
71+
$result = $hasher->hash('password');
72+
$this->assertTrue($hasher->verify($result, 'password'));
7373
$this->assertStringStartsWith('$2', $result);
7474
}
7575

@@ -84,8 +84,8 @@ public function testDefaultAlgorithm()
8484
public function testConfiguredAlgorithmWithLegacyConstValue()
8585
{
8686
$hasher = new NativePasswordHasher(null, null, null, '1');
87-
$result = $hasher->hash('password', null);
88-
$this->assertTrue($hasher->verify($result, 'password', null));
87+
$result = $hasher->hash('password');
88+
$this->assertTrue($hasher->verify($result, 'password'));
8989
$this->assertStringStartsWith('$2', $result);
9090
}
9191

@@ -94,17 +94,17 @@ public function testBcryptWithLongPassword()
9494
$hasher = new NativePasswordHasher(null, null, 4, \PASSWORD_BCRYPT);
9595
$plainPassword = str_repeat('a', 100);
9696

97-
$this->assertFalse($hasher->verify(password_hash($plainPassword, \PASSWORD_BCRYPT, ['cost' => 4]), $plainPassword, 'salt'));
98-
$this->assertTrue($hasher->verify($hasher->hash($plainPassword), $plainPassword, 'salt'));
97+
$this->assertFalse($hasher->verify(password_hash($plainPassword, \PASSWORD_BCRYPT, ['cost' => 4]), $plainPassword));
98+
$this->assertTrue($hasher->verify($hasher->hash($plainPassword), $plainPassword));
9999
}
100100

101101
public function testBcryptWithNulByte()
102102
{
103103
$hasher = new NativePasswordHasher(null, null, 4, \PASSWORD_BCRYPT);
104104
$plainPassword = "a\0b";
105105

106-
$this->assertFalse($hasher->verify(password_hash($plainPassword, \PASSWORD_BCRYPT, ['cost' => 4]), $plainPassword, 'salt'));
107-
$this->assertTrue($hasher->verify($hasher->hash($plainPassword), $plainPassword, 'salt'));
106+
$this->assertFalse($hasher->verify(password_hash($plainPassword, \PASSWORD_BCRYPT, ['cost' => 4]), $plainPassword));
107+
$this->assertTrue($hasher->verify($hasher->hash($plainPassword), $plainPassword));
108108
}
109109

110110
public function testNeedsRehash()
@@ -113,7 +113,7 @@ public function testNeedsRehash()
113113

114114
$this->assertTrue($hasher->needsRehash('dummyhash'));
115115

116-
$hash = $hasher->hash('foo', 'salt');
116+
$hash = $hasher->hash('foo');
117117
$this->assertFalse($hasher->needsRehash($hash));
118118

119119
$hasher = new NativePasswordHasher(5, 11000, 5);

src/Symfony/Component/PasswordHasher/Tests/Hasher/PasswordHasherFactoryTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public function testGetNamedHasherForHasherAware()
109109
'hasher_name' => new MessageDigestPasswordHasher('sha1'),
110110
]);
111111

112-
$hasher = $factory->getPasswordHasher(new HasherAwareUser('user', 'pass'));
112+
$hasher = $factory->getPasswordHasher(new HasherAwareUser());
113113
$expectedHasher = new MessageDigestPasswordHasher('sha1');
114114
$this->assertEquals($expectedHasher->hash('foo', ''), $hasher->hash('foo', ''));
115115
}
@@ -121,7 +121,7 @@ public function testGetNullNamedHasherForHasherAware()
121121
'hasher_name' => new MessageDigestPasswordHasher('sha256'),
122122
]);
123123

124-
$user = new HasherAwareUser('mathilde', 'krogulec');
124+
$user = new HasherAwareUser();
125125
$user->hasherName = null;
126126
$hasher = $factory->getPasswordHasher($user);
127127
$expectedHasher = new MessageDigestPasswordHasher('sha1');
@@ -136,7 +136,7 @@ public function testGetInvalidNamedHasherForHasherAware()
136136
'hasher_name' => new MessageDigestPasswordHasher('sha256'),
137137
]);
138138

139-
$user = new HasherAwareUser('user', 'pass');
139+
$user = new HasherAwareUser();
140140
$user->hasherName = 'invalid_hasher_name';
141141
$factory->getPasswordHasher($user);
142142
}
@@ -167,9 +167,9 @@ public function testMigrateFrom()
167167
$hasher = $factory->getPasswordHasher(SomeUser::class);
168168
$this->assertInstanceOf(MigratingPasswordHasher::class, $hasher);
169169

170-
$this->assertTrue($hasher->verify((new SodiumPasswordHasher())->hash('foo', null), 'foo', null));
171-
$this->assertTrue($hasher->verify((new NativePasswordHasher(null, null, null, \PASSWORD_BCRYPT))->hash('foo', null), 'foo', null));
172-
$this->assertTrue($hasher->verify($digest->hash('foo', null), 'foo', null));
170+
$this->assertTrue($hasher->verify((new SodiumPasswordHasher())->hash('foo'), 'foo', null));
171+
$this->assertTrue($hasher->verify((new NativePasswordHasher(null, null, null, \PASSWORD_BCRYPT))->hash('foo'), 'foo', null));
172+
$this->assertTrue($hasher->verify($digest->hash('foo'), 'foo', null));
173173
$this->assertStringStartsWith(\SODIUM_CRYPTO_PWHASH_STRPREFIX, $hasher->hash('foo', null));
174174
}
175175

src/Symfony/Component/PasswordHasher/Tests/Hasher/SodiumPasswordHasherTest.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,65 +28,65 @@ protected function setUp(): void
2828
public function testValidation()
2929
{
3030
$hasher = new SodiumPasswordHasher();
31-
$result = $hasher->hash('password', null);
32-
$this->assertTrue($hasher->verify($result, 'password', null));
33-
$this->assertFalse($hasher->verify($result, 'anotherPassword', null));
34-
$this->assertFalse($hasher->verify($result, '', null));
31+
$result = $hasher->hash('password');
32+
$this->assertTrue($hasher->verify($result, 'password'));
33+
$this->assertFalse($hasher->verify($result, 'anotherPassword'));
34+
$this->assertFalse($hasher->verify($result, ''));
3535
}
3636

3737
public function testBcryptValidation()
3838
{
3939
$hasher = new SodiumPasswordHasher();
40-
$this->assertTrue($hasher->verify('$2y$04$M8GDODMoGQLQRpkYCdoJh.lbiZPee3SZI32RcYK49XYTolDGwoRMm', 'abc', null));
40+
$this->assertTrue($hasher->verify('$2y$04$M8GDODMoGQLQRpkYCdoJh.lbiZPee3SZI32RcYK49XYTolDGwoRMm', 'abc'));
4141
}
4242

4343
public function testNonArgonValidation()
4444
{
4545
$hasher = new SodiumPasswordHasher();
46-
$this->assertTrue($hasher->verify('$5$abcdefgh$ZLdkj8mkc2XVSrPVjskDAgZPGjtj1VGVaa1aUkrMTU/', 'password', null));
47-
$this->assertFalse($hasher->verify('$5$abcdefgh$ZLdkj8mkc2XVSrPVjskDAgZPGjtj1VGVaa1aUkrMTU/', 'anotherPassword', null));
48-
$this->assertTrue($hasher->verify('$6$abcdefgh$yVfUwsw5T.JApa8POvClA1pQ5peiq97DUNyXCZN5IrF.BMSkiaLQ5kvpuEm/VQ1Tvh/KV2TcaWh8qinoW5dhA1', 'password', null));
49-
$this->assertFalse($hasher->verify('$6$abcdefgh$yVfUwsw5T.JApa8POvClA1pQ5peiq97DUNyXCZN5IrF.BMSkiaLQ5kvpuEm/VQ1Tvh/KV2TcaWh8qinoW5dhA1', 'anotherPassword', null));
46+
$this->assertTrue($hasher->verify('$5$abcdefgh$ZLdkj8mkc2XVSrPVjskDAgZPGjtj1VGVaa1aUkrMTU/', 'password'));
47+
$this->assertFalse($hasher->verify('$5$abcdefgh$ZLdkj8mkc2XVSrPVjskDAgZPGjtj1VGVaa1aUkrMTU/', 'anotherPassword'));
48+
$this->assertTrue($hasher->verify('$6$abcdefgh$yVfUwsw5T.JApa8POvClA1pQ5peiq97DUNyXCZN5IrF.BMSkiaLQ5kvpuEm/VQ1Tvh/KV2TcaWh8qinoW5dhA1', 'password'));
49+
$this->assertFalse($hasher->verify('$6$abcdefgh$yVfUwsw5T.JApa8POvClA1pQ5peiq97DUNyXCZN5IrF.BMSkiaLQ5kvpuEm/VQ1Tvh/KV2TcaWh8qinoW5dhA1', 'anotherPassword'));
5050
}
5151

5252
public function testHashLength()
5353
{
5454
$this->expectException(InvalidPasswordException::class);
5555
$hasher = new SodiumPasswordHasher();
56-
$hasher->hash(str_repeat('a', 4097), 'salt');
56+
$hasher->hash(str_repeat('a', 4097));
5757
}
5858

5959
public function testCheckPasswordLength()
6060
{
6161
$hasher = new SodiumPasswordHasher();
62-
$result = $hasher->hash(str_repeat('a', 4096), null);
63-
$this->assertFalse($hasher->verify($result, str_repeat('a', 4097), null));
64-
$this->assertTrue($hasher->verify($result, str_repeat('a', 4096), null));
62+
$result = $hasher->hash(str_repeat('a', 4096));
63+
$this->assertFalse($hasher->verify($result, str_repeat('a', 4097)));
64+
$this->assertTrue($hasher->verify($result, str_repeat('a', 4096)));
6565
}
6666

6767
public function testBcryptWithLongPassword()
6868
{
69-
$hasher = new SodiumPasswordHasher(null, null, 4);
69+
$hasher = new SodiumPasswordHasher(null, null);
7070
$plainPassword = str_repeat('a', 100);
7171

72-
$this->assertFalse($hasher->verify(password_hash($plainPassword, \PASSWORD_BCRYPT, ['cost' => 4]), $plainPassword, 'salt'));
73-
$this->assertTrue($hasher->verify((new NativePasswordHasher(null, null, 4, \PASSWORD_BCRYPT))->hash($plainPassword), $plainPassword, 'salt'));
72+
$this->assertFalse($hasher->verify(password_hash($plainPassword, \PASSWORD_BCRYPT, ['cost' => 4]), $plainPassword));
73+
$this->assertTrue($hasher->verify((new NativePasswordHasher(null, null, 4, \PASSWORD_BCRYPT))->hash($plainPassword), $plainPassword));
7474
}
7575

7676
public function testBcryptWithNulByte()
7777
{
78-
$hasher = new SodiumPasswordHasher(null, null, 4);
78+
$hasher = new SodiumPasswordHasher(null, null);
7979
$plainPassword = "a\0b";
8080

81-
$this->assertFalse($hasher->verify(password_hash($plainPassword, \PASSWORD_BCRYPT, ['cost' => 4]), $plainPassword, 'salt'));
82-
$this->assertTrue($hasher->verify((new NativePasswordHasher(null, null, 4, \PASSWORD_BCRYPT))->hash($plainPassword), $plainPassword, 'salt'));
81+
$this->assertFalse($hasher->verify(password_hash($plainPassword, \PASSWORD_BCRYPT, ['cost' => 4]), $plainPassword));
82+
$this->assertTrue($hasher->verify((new NativePasswordHasher(null, null, 4, \PASSWORD_BCRYPT))->hash($plainPassword), $plainPassword));
8383
}
8484

8585
public function testUserProvidedSaltIsNotUsed()
8686
{
8787
$hasher = new SodiumPasswordHasher();
88-
$result = $hasher->hash('password', 'salt');
89-
$this->assertTrue($hasher->verify($result, 'password', 'anotherSalt'));
88+
$result = $hasher->hash('password');
89+
$this->assertTrue($hasher->verify($result, 'password'));
9090
}
9191

9292
public function testNeedsRehash()
@@ -95,7 +95,7 @@ public function testNeedsRehash()
9595

9696
$this->assertTrue($hasher->needsRehash('dummyhash'));
9797

98-
$hash = $hasher->hash('foo', 'salt');
98+
$hash = $hasher->hash('foo');
9999
$this->assertFalse($hasher->needsRehash($hash));
100100

101101
$hasher = new SodiumPasswordHasher(5, 11000);

src/Symfony/Component/Yaml/Inline.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ private static function parseMapping(string $mapping, int $flags, int &$i = 0, a
531531
if ('<<' === $key) {
532532
$output += $value;
533533
} elseif ($allowOverwrite || !isset($output[$key])) {
534-
if (!$isValueQuoted && \is_string($value) && '' !== $value && '&' === $value[0] && Parser::preg_match(Parser::REFERENCE_PATTERN, $value, $matches)) {
534+
if (!$isValueQuoted && \is_string($value) && '' !== $value && '&' === $value[0] && !self::isBinaryString($value) && Parser::preg_match(Parser::REFERENCE_PATTERN, $value, $matches)) {
535535
$references[$matches['ref']] = $matches['value'];
536536
$value = $matches['value'];
537537
}

src/Symfony/Component/Yaml/Parser.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,8 @@ private function doParse(string $value, int $flags): mixed
182182
|| self::preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|[^ \'"\{\[].*?) *\:(\s+(?P<value>.+?))?\s*$#u', $this->trimTag($values['value']), $matches)
183183
)
184184
) {
185-
// this is a compact notation element, add to next block and parse
186185
$block = $values['value'];
187-
if ($this->isNextLineIndented()) {
186+
if ($this->isNextLineIndented() || isset($matches['value']) && '>-' === $matches['value']) {
188187
$block .= "\n".$this->getNextEmbedBlock($this->getCurrentLineIndentation() + \strlen($values['leadspaces']) + 1);
189188
}
190189

@@ -932,6 +931,10 @@ private function isNextLineIndented(): bool
932931
} while (!$EOF && ($this->isCurrentLineEmpty() || $this->isCurrentLineComment()));
933932

934933
if ($EOF) {
934+
for ($i = 0; $i < $movements; ++$i) {
935+
$this->moveToPreviousLine();
936+
}
937+
935938
return false;
936939
}
937940

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,9 @@ public static function getTestsForParse()
398398

399399
['[foo, bar: { foo: bar }]', ['foo', '1' => ['bar' => ['foo' => 'bar']]]],
400400
['[foo, \'@foo.baz\', { \'%foo%\': \'foo is %foo%\', bar: \'%foo%\' }, true, \'@service_container\']', ['foo', '@foo.baz', ['%foo%' => 'foo is %foo%', 'bar' => '%foo%'], true, '@service_container']],
401+
402+
// Binary string not utf8-compliant but starting with and utf8-equivalent "&" character
403+
['{ uid: !!binary Ju0Yh+uqSXOagJZFTlUt8g== }', ['uid' => hex2bin('26ed1887ebaa49739a8096454e552df2')]],
401404
];
402405
}
403406

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2712,6 +2712,44 @@ public static function circularReferenceProvider()
27122712
return $tests;
27132713
}
27142714

2715+
public function testBlockScalarArray()
2716+
{
2717+
$yaml = <<<'YAML'
2718+
anyOf:
2719+
- $ref: >-
2720+
#/string/bar
2721+
anyOfMultiline:
2722+
- $ref: >-
2723+
#/string/bar
2724+
second line
2725+
nested:
2726+
anyOf:
2727+
- $ref: >-
2728+
#/string/bar
2729+
YAML;
2730+
$expected = [
2731+
'anyOf' => [
2732+
0 => [
2733+
'$ref' => '#/string/bar',
2734+
],
2735+
],
2736+
'anyOfMultiline' => [
2737+
0 => [
2738+
'$ref' => '#/string/bar second line',
2739+
],
2740+
],
2741+
'nested' => [
2742+
'anyOf' => [
2743+
0 => [
2744+
'$ref' => '#/string/bar',
2745+
],
2746+
],
2747+
],
2748+
];
2749+
2750+
$this->assertSame($expected, $this->parser->parse($yaml));
2751+
}
2752+
27152753
/**
27162754
* @dataProvider indentedMappingData
27172755
*/

0 commit comments

Comments
 (0)
0