Skip to content

Commit fdc7b50

Browse files
committed
Merge branch '5.2' into 5.x
* 5.2: [WebProfiler] Use ControllerReference instead of URL in twig render() [Serializer][Validator] Update some phpDoc relative to "getters" Update README.md [SecurityBundle] Empty line starting with dash under "access_control" causes all rules to be skipped [Cache] Apply NullAdapter as Null Object
2 parents edec0ec + d258a71 commit fdc7b50

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

DependencyInjection/SecurityExtension.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,12 @@ private function createAuthorization(array $config, ContainerBuilder $container)
231231
$attributes[] = $this->createExpression($container, $access['allow_if']);
232232
}
233233

234+
$emptyAccess = 0 === \count(array_filter($access));
235+
236+
if ($emptyAccess) {
237+
throw new InvalidConfigurationException('One or more access control items are empty. Did you accidentally add lines only containing a "-" under "security.access_control"?');
238+
}
239+
234240
$container->getDefinition('security.access_map')
235241
->addMethodCall('add', [$matcher, $attributes, $access['requires_channel']]);
236242
}

Tests/DependencyInjection/SecurityExtensionTest.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,56 @@ public function testSwitchUserWithSeveralDefinedProvidersButNoFirewallRootProvid
454454
$this->assertEquals(new Reference('security.user.provider.concrete.second'), $container->getDefinition('security.authentication.switchuser_listener.foobar')->getArgument(1));
455455
}
456456

457+
public function testInvalidAccessControlWithEmptyRow()
458+
{
459+
$container = $this->getRawContainer();
460+
461+
$container->loadFromExtension('security', [
462+
'providers' => [
463+
'default' => ['id' => 'foo'],
464+
],
465+
'firewalls' => [
466+
'some_firewall' => [
467+
'pattern' => '/.*',
468+
'http_basic' => [],
469+
],
470+
],
471+
'access_control' => [
472+
[],
473+
['path' => '/admin', 'roles' => 'ROLE_ADMIN'],
474+
],
475+
]);
476+
477+
$this->expectException(InvalidConfigurationException::class);
478+
$this->expectExceptionMessage('One or more access control items are empty. Did you accidentally add lines only containing a "-" under "security.access_control"?');
479+
$container->compile();
480+
}
481+
482+
public function testValidAccessControlWithEmptyRow()
483+
{
484+
$container = $this->getRawContainer();
485+
486+
$container->loadFromExtension('security', [
487+
'providers' => [
488+
'default' => ['id' => 'foo'],
489+
],
490+
'firewalls' => [
491+
'some_firewall' => [
492+
'pattern' => '/.*',
493+
'http_basic' => [],
494+
],
495+
],
496+
'access_control' => [
497+
['path' => '^/login'],
498+
['path' => '^/', 'roles' => 'ROLE_USER'],
499+
],
500+
]);
501+
502+
$container->compile();
503+
504+
$this->assertTrue(true, 'extension throws an InvalidConfigurationException if there is one more more empty access control items');
505+
}
506+
457507
/**
458508
* @dataProvider provideEntryPointFirewalls
459509
*/

0 commit comments

Comments
 (0)