Skip to content

Commit 4e0b7e5

Browse files
Merge branch '5.0' into 5.1
* 5.0: [SecurityBundle] Drop cache.security_expression_language definition if invalid [DI] disable preload.php on the CLI collect all transformation failures
2 parents d033677 + 8afd50e commit 4e0b7e5

File tree

7 files changed

+86
-40
lines changed

7 files changed

+86
-40
lines changed

src/Symfony/Bundle/SecurityBundle/DependencyInjection/Compiler/AddExpressionLanguageProvidersPass.php

+4
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,9 @@ public function process(ContainerBuilder $container)
3333
$definition->addMethodCall('registerProvider', [new Reference($id)]);
3434
}
3535
}
36+
37+
if (!$container->hasDefinition('cache.system')) {
38+
$container->removeDefinition('cache.security_expression_language');
39+
}
3640
}
3741
}

src/Symfony/Bundle/SecurityBundle/Resources/config/security.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
<service id="security.user_checker" class="Symfony\Component\Security\Core\User\UserChecker" />
7474

7575
<service id="security.expression_language" class="Symfony\Component\Security\Core\Authorization\ExpressionLanguage">
76-
<argument type="service" id="cache.security_expression_language"></argument>
76+
<argument type="service" id="cache.security_expression_language" on-invalid="null" />
7777
</service>
7878

7979
<service id="security.authentication_utils" class="Symfony\Component\Security\Http\Authentication\AuthenticationUtils" public="true">

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

+13-4
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function testUserProviders()
5656

5757
// chain provider
5858
$this->assertEquals([new IteratorArgument([
59-
new Reference('security.user.provider.concrete.service'),
59+
new Reference('user.manager'),
6060
new Reference('security.user.provider.concrete.basic'),
6161
])], $container->getDefinition('security.user.provider.concrete.chain')->getArguments());
6262
}
@@ -70,9 +70,9 @@ public function testFirewalls()
7070
foreach (array_keys($arguments[1]->getValues()) as $contextId) {
7171
$contextDef = $container->getDefinition($contextId);
7272
$arguments = $contextDef->getArguments();
73-
$listeners[] = array_map('strval', $arguments['index_0']->getValues());
73+
$listeners[] = array_map('strval', $arguments[0]->getValues());
7474

75-
$configDef = $container->getDefinition((string) $arguments['index_3']);
75+
$configDef = $container->getDefinition((string) $arguments[3]);
7676
$configs[] = array_values($configDef->getArguments());
7777
}
7878

@@ -87,6 +87,14 @@ public function testFirewalls()
8787
'security.user_checker',
8888
'.security.request_matcher.xmi9dcw',
8989
false,
90+
false,
91+
'',
92+
'',
93+
'',
94+
'',
95+
'',
96+
[],
97+
null,
9098
],
9199
[
92100
'secure',
@@ -637,6 +645,8 @@ protected function getContainer($file)
637645

638646
$container = new ContainerBuilder();
639647
$container->setParameter('kernel.debug', false);
648+
$container->setParameter('request_listener.http_port', 80);
649+
$container->setParameter('request_listener.https_port', 443);
640650

641651
$security = new SecurityExtension();
642652
$container->registerExtension($security);
@@ -645,7 +655,6 @@ protected function getContainer($file)
645655
$bundle->build($container); // Attach all default factories
646656
$this->getLoader($container)->load($file);
647657

648-
$container->getCompilerPassConfig()->setOptimizationPasses([]);
649658
$container->getCompilerPassConfig()->setRemovingPasses([]);
650659
$container->getCompilerPassConfig()->setAfterRemovingPasses([]);
651660
$container->compile();

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

+4
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,10 @@ class %s extends {$options['class']}
339339
340340
use Symfony\Component\DependencyInjection\Dumper\Preloader;
341341
342+
if (in_array(PHP_SAPI, ['cli', 'phpdbg'], true)) {
343+
return;
344+
}
345+
342346
require $autoloadFile;
343347
require __DIR__.'/$preloadedFiles';
344348

src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@ public function validate($form, Constraint $formConstraint)
153153
foreach ($form as $child) {
154154
if (!$child->isSynchronized()) {
155155
$childrenSynchronized = false;
156-
break;
156+
157+
$fieldFormConstraint = new Form();
158+
$this->context->setNode($this->context->getValue(), $child, $this->context->getMetadata(), $this->context->getPropertyPath());
159+
$validator->atPath(sprintf('children[%s]', $child->getName()))->validate($child, $fieldFormConstraint);
157160
}
158161
}
159162

src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorFunctionalTest.php

+60
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Form\AbstractType;
16+
use Symfony\Component\Form\CallbackTransformer;
17+
use Symfony\Component\Form\Exception\TransformationFailedException;
18+
use Symfony\Component\Form\Extension\Core\Type\DateType;
1619
use Symfony\Component\Form\Extension\Core\Type\FormType;
1720
use Symfony\Component\Form\Extension\Core\Type\TextType;
1821
use Symfony\Component\Form\Extension\Validator\ValidatorExtension;
@@ -330,6 +333,63 @@ public function testContextIsPopulatedWithFormBeingValidatedUsingGroupSequence()
330333

331334
$this->assertCount(0, $violations);
332335
}
336+
337+
public function testSubmitFormChoiceInvalid()
338+
{
339+
$form = $this->formFactory->create(DateType::class, null, [
340+
'widget' => 'choice',
341+
'years' => [2021],
342+
]);
343+
344+
$form->submit([
345+
'year' => '2020',
346+
'month' => '13',
347+
'day' => '13',
348+
]);
349+
350+
$this->assertTrue($form->isSubmitted());
351+
$this->assertFalse($form->isValid());
352+
$this->assertCount(2, $form->getErrors());
353+
$this->assertSame('This value is not valid.', $form->getErrors()[0]->getMessage());
354+
$this->assertSame($form->get('year'), $form->getErrors()[0]->getOrigin());
355+
$this->assertSame('This value is not valid.', $form->getErrors()[1]->getMessage());
356+
$this->assertSame($form->get('month'), $form->getErrors()[1]->getOrigin());
357+
}
358+
359+
public function testDoNotAddInvalidMessageIfChildFormIsAlreadyNotSynchronized()
360+
{
361+
$formBuilder = $this->formFactory->createBuilder()
362+
->add('field1')
363+
->add('field2')
364+
->addModelTransformer(new CallbackTransformer(
365+
function () {
366+
},
367+
function () {
368+
throw new TransformationFailedException('This value is invalid.');
369+
}
370+
));
371+
$formBuilder->get('field2')->addModelTransformer(new CallbackTransformer(
372+
function () {
373+
},
374+
function () {
375+
throw new TransformationFailedException('This value is invalid.');
376+
}
377+
));
378+
$form = $formBuilder->getForm();
379+
380+
$form->submit([
381+
'field1' => 'foo',
382+
'field2' => 'bar',
383+
]);
384+
385+
$this->assertTrue($form->isSubmitted());
386+
$this->assertFalse($form->isValid());
387+
$this->assertCount(0, $form->getErrors());
388+
$this->assertTrue($form->get('field1')->isValid());
389+
$this->assertCount(0, $form->get('field1')->getErrors());
390+
$this->assertFalse($form->get('field2')->isValid());
391+
$this->assertCount(1, $form->get('field2')->getErrors());
392+
}
333393
}
334394

335395
class Foo

src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php

-34
Original file line numberDiff line numberDiff line change
@@ -405,40 +405,6 @@ function () {
405405
;
406406
}
407407

408-
// https://github.com/symfony/symfony/issues/4359
409-
public function testDontMarkInvalidIfAnyChildIsNotSynchronized()
410-
{
411-
$object = new \stdClass();
412-
$object->child = 'bar';
413-
414-
$failingTransformer = new CallbackTransformer(
415-
function ($data) { return $data; },
416-
function () { throw new TransformationFailedException(); }
417-
);
418-
419-
$form = $this->getBuilder('name', '\stdClass')
420-
->setData($object)
421-
->addViewTransformer($failingTransformer)
422-
->setCompound(true)
423-
->setDataMapper(new PropertyPathMapper())
424-
->add(
425-
$this->getBuilder('child')
426-
->addViewTransformer($failingTransformer)
427-
)
428-
->getForm();
429-
430-
// Launch transformer
431-
$form->submit(['child' => 'foo']);
432-
433-
$this->assertTrue($form->isSubmitted());
434-
$this->assertFalse($form->isSynchronized());
435-
$this->expectNoValidate();
436-
437-
$this->validator->validate($form, new Form());
438-
439-
$this->assertNoViolation();
440-
}
441-
442408
public function testHandleGroupSequenceValidationGroups()
443409
{
444410
$object = new \stdClass();

0 commit comments

Comments
 (0)