Skip to content

Commit d258a71

Browse files
committed
Merge branch '4.4' into 5.2
* 4.4: [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 24e298f + e9cf8e6 commit d258a71

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
@@ -208,6 +208,12 @@ private function createAuthorization(array $config, ContainerBuilder $container)
208208
$attributes[] = $this->createExpression($container, $access['allow_if']);
209209
}
210210

211+
$emptyAccess = 0 === \count(array_filter($access));
212+
213+
if ($emptyAccess) {
214+
throw new InvalidConfigurationException('One or more access control items are empty. Did you accidentally add lines only containing a "-" under "security.access_control"?');
215+
}
216+
211217
$container->getDefinition('security.access_map')
212218
->addMethodCall('add', [$matcher, $attributes, $access['requires_channel']]);
213219
}

Tests/DependencyInjection/SecurityExtensionTest.php

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

435+
public function testInvalidAccessControlWithEmptyRow()
436+
{
437+
$container = $this->getRawContainer();
438+
439+
$container->loadFromExtension('security', [
440+
'providers' => [
441+
'default' => ['id' => 'foo'],
442+
],
443+
'firewalls' => [
444+
'some_firewall' => [
445+
'pattern' => '/.*',
446+
'http_basic' => [],
447+
],
448+
],
449+
'access_control' => [
450+
[],
451+
['path' => '/admin', 'roles' => 'ROLE_ADMIN'],
452+
],
453+
]);
454+
455+
$this->expectException(InvalidConfigurationException::class);
456+
$this->expectExceptionMessage('One or more access control items are empty. Did you accidentally add lines only containing a "-" under "security.access_control"?');
457+
$container->compile();
458+
}
459+
460+
public function testValidAccessControlWithEmptyRow()
461+
{
462+
$container = $this->getRawContainer();
463+
464+
$container->loadFromExtension('security', [
465+
'providers' => [
466+
'default' => ['id' => 'foo'],
467+
],
468+
'firewalls' => [
469+
'some_firewall' => [
470+
'pattern' => '/.*',
471+
'http_basic' => [],
472+
],
473+
],
474+
'access_control' => [
475+
['path' => '^/login'],
476+
['path' => '^/', 'roles' => 'ROLE_USER'],
477+
],
478+
]);
479+
480+
$container->compile();
481+
482+
$this->assertTrue(true, 'extension throws an InvalidConfigurationException if there is one more more empty access control items');
483+
}
484+
435485
/**
436486
* @dataProvider provideEntryPointFirewalls
437487
*/

0 commit comments

Comments
 (0)