[BUGFIX] Unconfigured typeNums should result in 404 instead of 500 response 44/62244/5
authorBenni Mack <benni@typo3.org>
Fri, 22 Nov 2019 13:59:49 +0000 (14:59 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Fri, 22 Nov 2019 15:52:14 +0000 (16:52 +0100)
Calling a URL with type=138 which is not configured should not result in
an "page unavailable" but a "page not found" (404) response.

Resolves: #86844
Releases: master, 9.5
Change-Id: Iaf739e9bac1b07914aa9e9856bc38a91fe558ed1
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/62244
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Oliver Hader <oliver.hader@typo3.org>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Oliver Hader <oliver.hader@typo3.org>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php
typo3/sysext/frontend/Tests/Functional/SiteHandling/SlugSiteRequestTest.php

index 15190f0..d25d5e8 100644 (file)
@@ -2051,13 +2051,13 @@ class TypoScriptFrontendController implements LoggerAwareInterface
                     $message = 'The page is not configured! [type=' . $this->type . '][' . $this->sPre . '].';
                     $this->logger->alert($message);
                     try {
-                        $response = GeneralUtility::makeInstance(ErrorController::class)->unavailableAction(
+                        $response = GeneralUtility::makeInstance(ErrorController::class)->pageNotFoundAction(
                             $GLOBALS['TYPO3_REQUEST'],
                             $message,
                             ['code' => PageAccessFailureReasons::RENDERING_INSTRUCTIONS_NOT_CONFIGURED]
                         );
                         throw new ImmediateResponseException($response, 1533931374);
-                    } catch (ServiceUnavailableException $e) {
+                    } catch (PageNotFoundException $e) {
                         $explanation = 'This means that there is no TypoScript object of type PAGE with typeNum=' . $this->type . ' configured.';
                         throw new ServiceUnavailableException($message . ' ' . $explanation, 1294587217);
                     }
index 731d781..8f425b3 100644 (file)
@@ -269,6 +269,7 @@ class SlugSiteRequestTest extends AbstractTestCase
             (string)$response->getBody()
         );
     }
+
     /**
      * @test
      */
@@ -300,6 +301,36 @@ class SlugSiteRequestTest extends AbstractTestCase
     }
 
     /**
+     * @test
+     */
+    public function unconfiguredTypeNumResultsIn404Error()
+    {
+        $this->writeSiteConfiguration(
+            'website-local',
+            $this->buildSiteConfiguration(1000, 'https://website.local/'),
+            [
+                $this->buildDefaultLanguageConfiguration('EN', '/en-en/')
+            ],
+            $this->buildErrorHandlingConfiguration('Fluid', [404])
+        );
+
+        $uri = 'https://website.local/en-en/?type=13';
+        $response = $this->executeFrontendRequest(
+            new InternalRequest($uri),
+            $this->internalRequestContext
+        );
+
+        self::assertSame(
+            404,
+            $response->getStatusCode()
+        );
+        self::assertStringContainsString(
+            'message: The page is not configured',
+            (string)$response->getBody()
+        );
+    }
+
+    /**
      * @return array
      */
     public function pageIsRenderedWithPathsDataProvider(): array