From 6e5c15d8aa0babf1da519f56f4bc8770a36e28ee Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 25 Jun 2018 11:39:34 +0200 Subject: [PATCH] bug #27701 [SecurityBundle] Dont throw if "security.http_utils" is not found (nicolas-grekas) This PR was merged into the 3.4 branch. Discussion ---------- [SecurityBundle] Dont throw if "security.http_utils" is not found | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #27445 | License | MIT | Doc PR | - The comment + test were misleading, the actual important thing is wiring `AddSessionDomainConstraintPass` before removing passes, which is already the case already. Commits ------- db88330448 [SecurityBundle] Dont throw if "security.http_utils" is not found --- .../Compiler/AddSessionDomainConstraintPass.php | 3 +-- .../Compiler/AddSessionDomainConstraintPassTest.php | 13 ------------- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Compiler/AddSessionDomainConstraintPass.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Compiler/AddSessionDomainConstraintPass.php index ba523382b66b..3dd18944de9f 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Compiler/AddSessionDomainConstraintPass.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Compiler/AddSessionDomainConstraintPass.php @@ -26,7 +26,7 @@ class AddSessionDomainConstraintPass implements CompilerPassInterface */ public function process(ContainerBuilder $container) { - if (!$container->hasParameter('session.storage.options')) { + if (!$container->hasParameter('session.storage.options') || !$container->has('security.http_utils')) { return; } @@ -34,7 +34,6 @@ public function process(ContainerBuilder $container) $domainRegexp = empty($sessionOptions['cookie_domain']) ? '%s' : sprintf('(?:%%s|(?:.+\.)?%s)', preg_quote(trim($sessionOptions['cookie_domain'], '.'))); $domainRegexp = (empty($sessionOptions['cookie_secure']) ? 'https?://' : 'https://').$domainRegexp; - // if the service doesn't exist, an exception must be thrown - ignoring would put security at risk $container->findDefinition('security.http_utils')->addArgument(sprintf('{^%s$}i', $domainRegexp)); } } diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Compiler/AddSessionDomainConstraintPassTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Compiler/AddSessionDomainConstraintPassTest.php index e12f3a64f31f..7d49ad3dd4ec 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Compiler/AddSessionDomainConstraintPassTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Compiler/AddSessionDomainConstraintPassTest.php @@ -96,19 +96,6 @@ public function testNoSession() $this->assertTrue($utils->createRedirectResponse($request, 'http://pirate.com/foo')->isRedirect('http://pirate.com/foo')); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException - * @expectedExceptionMessage You have requested a non-existent service "security.http_utils". - */ - public function testNoHttpUtils() - { - $container = new ContainerBuilder(); - $container->setParameter('session.storage.options', array()); - - $pass = new AddSessionDomainConstraintPass(); - $pass->process($container); - } - private function createContainer($sessionStorageOptions) { $container = new ContainerBuilder();