From 0f4d6aba25a7ded22f71926cc50f06c395aa786f Mon Sep 17 00:00:00 2001 From: Vidar Date: Fri, 3 Nov 2023 08:13:12 +0100 Subject: [PATCH] IBX-6207: Requests containing front controller script causes session-not-found exception (#377) --- .../EventListener/SessionInitByPostListener.php | 7 +++++-- .../Tests/EventListener/SessionInitByPostListenerTest.php | 8 ++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/eZ/Bundle/EzPublishCoreBundle/EventListener/SessionInitByPostListener.php b/eZ/Bundle/EzPublishCoreBundle/EventListener/SessionInitByPostListener.php index 3c9beb91e0..5048b939de 100644 --- a/eZ/Bundle/EzPublishCoreBundle/EventListener/SessionInitByPostListener.php +++ b/eZ/Bundle/EzPublishCoreBundle/EventListener/SessionInitByPostListener.php @@ -27,9 +27,12 @@ public static function getSubscribedEvents() public function onSiteAccessMatch(PostSiteAccessMatchEvent $event) { $request = $event->getRequest(); - $session = $request->getSession(); + $session = null; + if ($request->hasSession()) { + $session = $request->getSession(); + } - if (!$session || $event->getRequestType() !== HttpKernelInterface::MAIN_REQUEST) { + if (null === $session || $event->getRequestType() !== HttpKernelInterface::MAIN_REQUEST) { return; } diff --git a/eZ/Bundle/EzPublishCoreBundle/Tests/EventListener/SessionInitByPostListenerTest.php b/eZ/Bundle/EzPublishCoreBundle/Tests/EventListener/SessionInitByPostListenerTest.php index c5ce15ea8d..76e3cbc50c 100644 --- a/eZ/Bundle/EzPublishCoreBundle/Tests/EventListener/SessionInitByPostListenerTest.php +++ b/eZ/Bundle/EzPublishCoreBundle/Tests/EventListener/SessionInitByPostListenerTest.php @@ -117,4 +117,12 @@ public function testOnSiteAccessMatchNewSessionName() $this->listener->onSiteAccessMatch($event); } + + public function testOnSiteAccessMatchNoSession(): void + { + $request = new Request(); + + $event = new PostSiteAccessMatchEvent(new SiteAccess('test'), $request, HttpKernelInterface::MAIN_REQUEST); + $this->listener->onSiteAccessMatch($event); + } }