Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit da3ba9e

Browse filesBrowse files
Merge branch '5.4' into 6.0
* 5.4: [SecurityBundle] Fix using same handler for multiple authenticators [DependencyInjection] Fix dump order of inlined deps [VarExporter] Fix exporting enums [HttpClient] Let curl handle content-length headers
2 parents 402912e + 3ca58ba commit da3ba9e
Copy full SHA for da3ba9e

File tree

Expand file treeCollapse file tree

13 files changed

+191
-19
lines changed
Filter options
Expand file treeCollapse file tree

13 files changed

+191
-19
lines changed

‎src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/AbstractFactory.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/AbstractFactory.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ protected function createAuthenticationSuccessHandler(ContainerBuilder $containe
8080

8181
if (isset($config['success_handler'])) {
8282
$successHandler = $container->setDefinition($successHandlerId, new ChildDefinition('security.authentication.custom_success_handler'));
83-
$successHandler->replaceArgument(0, new Reference($config['success_handler']));
83+
$successHandler->replaceArgument(0, new ChildDefinition($config['success_handler']));
8484
$successHandler->replaceArgument(1, $options);
8585
$successHandler->replaceArgument(2, $id);
8686
} else {
@@ -99,7 +99,7 @@ protected function createAuthenticationFailureHandler(ContainerBuilder $containe
9999

100100
if (isset($config['failure_handler'])) {
101101
$failureHandler = $container->setDefinition($id, new ChildDefinition('security.authentication.custom_failure_handler'));
102-
$failureHandler->replaceArgument(0, new Reference($config['failure_handler']));
102+
$failureHandler->replaceArgument(0, new ChildDefinition($config['failure_handler']));
103103
$failureHandler->replaceArgument(1, $options);
104104
} else {
105105
$failureHandler = $container->setDefinition($id, new ChildDefinition('security.authentication.failure_handler'));

‎src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Security/Factory/AbstractFactoryTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Security/Factory/AbstractFactoryTest.php
+20-3Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\AbstractFactory;
16+
use Symfony\Component\DependencyInjection\ChildDefinition;
1617
use Symfony\Component\DependencyInjection\ContainerBuilder;
1718

1819
class AbstractFactoryTest extends TestCase
@@ -43,12 +44,19 @@ public function testDefaultFailureHandler($serviceId, $defaultHandlerInjection)
4344

4445
$failureHandler = $this->container->getDefinition('security.authentication.failure_handler.foo.stub');
4546

47+
$expectedFailureHandlerOptions = ['login_path' => '/bar'];
4648
$methodCalls = $failureHandler->getMethodCalls();
4749
if ($defaultHandlerInjection) {
4850
$this->assertEquals('setOptions', $methodCalls[0][0]);
49-
$this->assertEquals(['login_path' => '/bar'], $methodCalls[0][1][0]);
51+
$this->assertEquals($expectedFailureHandlerOptions, $methodCalls[0][1][0]);
5052
} else {
5153
$this->assertCount(0, $methodCalls);
54+
$this->assertInstanceOf(ChildDefinition::class, $failureHandler);
55+
$this->assertEquals('security.authentication.custom_failure_handler', $failureHandler->getParent());
56+
$failureHandlerArguments = $failureHandler->getArguments();
57+
$this->assertInstanceOf(ChildDefinition::class, $failureHandlerArguments['index_0']);
58+
$this->assertEquals($serviceId, $failureHandlerArguments['index_0']->getParent());
59+
$this->assertEquals($expectedFailureHandlerOptions, $failureHandlerArguments['index_1']);
5260
}
5361
}
5462

@@ -80,13 +88,22 @@ public function testDefaultSuccessHandler($serviceId, $defaultHandlerInjection)
8088
$successHandler = $this->container->getDefinition('security.authentication.success_handler.foo.stub');
8189
$methodCalls = $successHandler->getMethodCalls();
8290

91+
$expectedSuccessHandlerOptions = ['default_target_path' => '/bar'];
92+
$expectedFirewallName = 'foo';
8393
if ($defaultHandlerInjection) {
8494
$this->assertEquals('setOptions', $methodCalls[0][0]);
85-
$this->assertEquals(['default_target_path' => '/bar'], $methodCalls[0][1][0]);
95+
$this->assertEquals($expectedSuccessHandlerOptions, $methodCalls[0][1][0]);
8696
$this->assertEquals('setFirewallName', $methodCalls[1][0]);
87-
$this->assertEquals(['foo'], $methodCalls[1][1]);
97+
$this->assertEquals($expectedFirewallName, $methodCalls[1][1][0]);
8898
} else {
8999
$this->assertCount(0, $methodCalls);
100+
$this->assertInstanceOf(ChildDefinition::class, $successHandler);
101+
$this->assertEquals('security.authentication.custom_success_handler', $successHandler->getParent());
102+
$successHandlerArguments = $successHandler->getArguments();
103+
$this->assertInstanceOf(ChildDefinition::class, $successHandlerArguments['index_0']);
104+
$this->assertEquals($serviceId, $successHandlerArguments['index_0']->getParent());
105+
$this->assertEquals($expectedSuccessHandlerOptions, $successHandlerArguments['index_1']);
106+
$this->assertEquals($expectedFirewallName, $successHandlerArguments['index_2']);
90107
}
91108
}
92109

‎src/Symfony/Bundle/SecurityBundle/Tests/Functional/AuthenticatorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/SecurityBundle/Tests/Functional/AuthenticatorTest.php
+34Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,38 @@ public function testMultipleFirewalls()
102102
$client->request('GET', '/firewall2/profile');
103103
$this->assertResponseRedirects('http://localhost/login');
104104
}
105+
106+
public function testCustomSuccessHandler()
107+
{
108+
$client = $this->createClient(['test_case' => 'Authenticator', 'root_config' => 'custom_handlers.yml']);
109+
110+
$client->request('POST', '/firewall1/login', [
111+
'_username' => 'jane@example.org',
112+
'_password' => 'test',
113+
]);
114+
$this->assertResponseRedirects('http://localhost/firewall1/test');
115+
116+
$client->request('POST', '/firewall1/dummy_login', [
117+
'_username' => 'jane@example.org',
118+
'_password' => 'test',
119+
]);
120+
$this->assertResponseRedirects('http://localhost/firewall1/dummy');
121+
}
122+
123+
public function testCustomFailureHandler()
124+
{
125+
$client = $this->createClient(['test_case' => 'Authenticator', 'root_config' => 'custom_handlers.yml']);
126+
127+
$client->request('POST', '/firewall1/login', [
128+
'_username' => 'jane@example.org',
129+
'_password' => '',
130+
]);
131+
$this->assertResponseRedirects('http://localhost/firewall1/login');
132+
133+
$client->request('POST', '/firewall1/dummy_login', [
134+
'_username' => 'jane@example.org',
135+
'_password' => '',
136+
]);
137+
$this->assertResponseRedirects('http://localhost/firewall1/dummy_login');
138+
}
105139
}
+34Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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\SecurityBundle\Tests\Functional\Bundle\AuthenticatorBundle;
13+
14+
use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
use Symfony\Component\HttpKernel\Bundle\Bundle;
17+
18+
class AuthenticatorBundle extends Bundle
19+
{
20+
public function build(ContainerBuilder $container)
21+
{
22+
parent::build($container);
23+
24+
$this->configureSecurityExtension($container);
25+
}
26+
27+
private function configureSecurityExtension(ContainerBuilder $container): void
28+
{
29+
/** @var SecurityExtension $extension */
30+
$extension = $container->getExtension('security');
31+
32+
$extension->addAuthenticatorFactory(new DummyFormLoginFactory());
33+
}
34+
}
+43Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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\SecurityBundle\Tests\Functional\Bundle\AuthenticatorBundle;
13+
14+
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\FormLoginFactory;
15+
use Symfony\Component\DependencyInjection\ChildDefinition;
16+
use Symfony\Component\DependencyInjection\ContainerBuilder;
17+
use Symfony\Component\DependencyInjection\Reference;
18+
19+
class DummyFormLoginFactory extends FormLoginFactory
20+
{
21+
public function getKey(): string
22+
{
23+
return 'dummy_form_login';
24+
}
25+
26+
public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId): string
27+
{
28+
$authenticatorId = 'security.authenticator.dummy_form_login.'.$firewallName;
29+
$options = array_intersect_key($config, $this->options);
30+
$authenticator = $container
31+
->setDefinition($authenticatorId, new ChildDefinition('security.authenticator.form_login'))
32+
->replaceArgument(1, new Reference($userProviderId))
33+
->replaceArgument(2, new Reference($this->createAuthenticationSuccessHandler($container, $firewallName, $config)))
34+
->replaceArgument(3, new Reference($this->createAuthenticationFailureHandler($container, $firewallName, $config)))
35+
->replaceArgument(4, $options);
36+
37+
if ($options['use_forward'] ?? false) {
38+
$authenticator->addMethodCall('setHttpKernel', [new Reference('http_kernel')]);
39+
}
40+
41+
return $authenticatorId;
42+
}
43+
}

‎src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/Authenticator/bundles.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/Authenticator/bundles.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@
1212
return [
1313
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
1414
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
15+
new Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\AuthenticatorBundle\AuthenticatorBundle(),
1516
];
+34Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
imports:
2+
- { resource: ./config.yml }
3+
- { resource: ./security.yml }
4+
5+
security:
6+
enable_authenticator_manager: true
7+
firewalls:
8+
firewall1:
9+
pattern: /firewall1
10+
provider: in_memory
11+
entry_point: form_login
12+
form_login:
13+
check_path: /firewall1/login
14+
success_handler: success_handler
15+
failure_handler: failure_handler
16+
default_target_path: /firewall1/test
17+
login_path: /firewall1/login
18+
dummy_form_login:
19+
check_path: /firewall1/dummy_login
20+
success_handler: success_handler
21+
failure_handler: failure_handler
22+
default_target_path: /firewall1/dummy
23+
login_path: /firewall1/dummy_login
24+
25+
services:
26+
success_handler:
27+
class: Symfony\Component\Security\Http\Authentication\DefaultAuthenticationSuccessHandler
28+
arguments:
29+
- '@security.http_utils'
30+
failure_handler:
31+
class: Symfony\Component\Security\Http\Authentication\DefaultAuthenticationFailureHandler
32+
arguments:
33+
- '@http_kernel'
34+
- '@security.http_utils'

‎src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/Authenticator/routing.yml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/Authenticator/routing.yml
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ security_custom_profile:
2222
firewall1_login:
2323
path: /firewall1/login
2424

25+
firewall_dummy_login:
26+
path: /firewall1/dummy_login
27+
2528
firewall2_profile:
2629
path: /firewall2/profile
2730
defaults:

‎src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ private function collectCircularReferences(string $sourceId, array $edges, array
486486
$loop = [];
487487
}
488488
}
489-
$this->addCircularReferences($first, $loop, true);
489+
$this->addCircularReferences($first, $loop, $loopByConstructor);
490490
break;
491491
}
492492
}

‎src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_almost_circular_private.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_almost_circular_private.php
+4-5Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -419,17 +419,16 @@ protected function getMonologInline_LoggerService()
419419
*/
420420
protected function getPAService()
421421
{
422-
$a = new \stdClass();
423-
424-
$b = ($this->privates['pC'] ?? $this->getPCService());
422+
$a = ($this->privates['pC'] ?? $this->getPCService());
425423

426424
if (isset($this->services['pA'])) {
427425
return $this->services['pA'];
428426
}
427+
$b = new \stdClass();
429428

430-
$this->services['pA'] = $instance = new \stdClass($a, $b);
429+
$this->services['pA'] = $instance = new \stdClass($b, $a);
431430

432-
$a->d = ($this->privates['pD'] ?? $this->getPDService());
431+
$b->d = ($this->privates['pD'] ?? $this->getPDService());
433432

434433
return $instance;
435434
}

‎src/Symfony/Component/HttpClient/CurlHttpClient.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/CurlHttpClient.php
+13-6Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,14 @@ public function request(string $method, string $url, array $options = []): Respo
199199
if (\extension_loaded('zlib') && !isset($options['normalized_headers']['accept-encoding'])) {
200200
$options['headers'][] = 'Accept-Encoding: gzip'; // Expose only one encoding, some servers mess up when more are provided
201201
}
202+
$body = $options['body'];
202203

203-
foreach ($options['headers'] as $header) {
204+
foreach ($options['headers'] as $i => $header) {
205+
if (\is_string($body) && '' !== $body && 0 === stripos($header, 'Content-Length: ')) {
206+
// Let curl handle Content-Length headers
207+
unset($options['headers'][$i]);
208+
continue;
209+
}
204210
if (':' === $header[-2] && \strlen($header) - 2 === strpos($header, ': ')) {
205211
// curl requires a special syntax to send empty headers
206212
$curlopts[\CURLOPT_HTTPHEADER][] = substr_replace($header, ';', -2);
@@ -216,7 +222,7 @@ public function request(string $method, string $url, array $options = []): Respo
216222
}
217223
}
218224

219-
if (!\is_string($body = $options['body'])) {
225+
if (!\is_string($body)) {
220226
if (\is_resource($body)) {
221227
$curlopts[\CURLOPT_INFILE] = $body;
222228
} else {
@@ -228,15 +234,16 @@ public function request(string $method, string $url, array $options = []): Respo
228234
}
229235

230236
if (isset($options['normalized_headers']['content-length'][0])) {
231-
$curlopts[\CURLOPT_INFILESIZE] = substr($options['normalized_headers']['content-length'][0], \strlen('Content-Length: '));
232-
} elseif (!isset($options['normalized_headers']['transfer-encoding'])) {
233-
$curlopts[\CURLOPT_HTTPHEADER][] = 'Transfer-Encoding: chunked'; // Enable chunked request bodies
237+
$curlopts[\CURLOPT_INFILESIZE] = (int) substr($options['normalized_headers']['content-length'][0], \strlen('Content-Length: '));
238+
}
239+
if (!isset($options['normalized_headers']['transfer-encoding'])) {
240+
$curlopts[\CURLOPT_HTTPHEADER][] = 'Transfer-Encoding:'.(isset($curlopts[\CURLOPT_INFILESIZE]) ? '' : ' chunked');
234241
}
235242

236243
if ('POST' !== $method) {
237244
$curlopts[\CURLOPT_UPLOAD] = true;
238245

239-
if (!isset($options['normalized_headers']['content-type'])) {
246+
if (!isset($options['normalized_headers']['content-type']) && 0 !== ($curlopts[\CURLOPT_INFILESIZE] ?? null)) {
240247
$curlopts[\CURLOPT_HTTPHEADER][] = 'Content-Type: application/x-www-form-urlencoded';
241248
}
242249
}

‎src/Symfony/Component/VarExporter/Internal/Exporter.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarExporter/Internal/Exporter.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public static function export($value, string $indent = '')
198198
case true === $value: return 'true';
199199
case null === $value: return 'null';
200200
case '' === $value: return "''";
201-
case $value instanceof \UnitEnum: return ltrim(var_export($value, true), '\\');
201+
case $value instanceof \UnitEnum: return '\\'.ltrim(var_export($value, true), '\\');
202202
}
203203

204204
if ($value instanceof Reference) {
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
22

33
return [
4-
Symfony\Component\VarExporter\Tests\Fixtures\FooUnitEnum::Bar,
4+
\Symfony\Component\VarExporter\Tests\Fixtures\FooUnitEnum::Bar,
55
];

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.