diff --git a/core/modules/dblog/src/Controller/DbLogController.php b/core/modules/dblog/src/Controller/DbLogController.php index c61e501..ae2fa71 100644 --- a/core/modules/dblog/src/Controller/DbLogController.php +++ b/core/modules/dblog/src/Controller/DbLogController.php @@ -17,6 +17,7 @@ use Drupal\user\Entity\User; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\Link; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** * Returns responses for dblog routes. @@ -242,6 +243,9 @@ public function overview() { * @return array * If the ID is located in the Database Logging table, a build array in the * format expected by \Drupal\Core\Render\RendererInterface::render(). + * + * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException + * If no event found for the given ID. */ public function eventDetails($event_id) { $build = []; @@ -299,6 +303,9 @@ public function eventDetails($event_id) { ], ]; } + else { + throw new NotFoundHttpException(); + } return $build; } diff --git a/core/modules/dblog/tests/src/Functional/DbLogTest.php b/core/modules/dblog/tests/src/Functional/DbLogTest.php index 9f7475b..d2254c7 100644 --- a/core/modules/dblog/tests/src/Functional/DbLogTest.php +++ b/core/modules/dblog/tests/src/Functional/DbLogTest.php @@ -136,6 +136,24 @@ public function testLogEventPage() { } /** + * Test not-existing log event page. + */ + public function testLogEventNotFoundPage() { + // Login the admin user. + $this->drupalLogin($this->adminUser); + + // Random (not existing) event ID. + $connection = Database::getConnection(); + $wid = $connection->query('SELECT MAX(wid) FROM {watchdog}')->fetchField(); + $wid += rand(100, 999); + + // Try to read details of not existing event. + $this->drupalGet('admin/reports/dblog/event/' . $wid); + // Verify 404 response. + $this->assertResponse(404); + } + + /** * Test individual log event page with missing log attributes. * * In some cases few log attributes are missing. For example: