From e4f8927d7f668f1deb5be2d058447a4b2b644f0b Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Tue, 4 Aug 2020 14:23:50 -0500 Subject: [PATCH] SONAR-13735 Fix SSF-120 --- .../org/sonar/server/app/EmbeddedTomcat.java | 1 + .../sonar/server/app/TomcatErrorHandling.java | 32 +++++++++++++++ .../server/app/TomcatErrorHandlingTest.java | 40 +++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 server/sonar-webserver/src/main/java/org/sonar/server/app/TomcatErrorHandling.java create mode 100644 server/sonar-webserver/src/test/java/org/sonar/server/app/TomcatErrorHandlingTest.java diff --git a/server/sonar-webserver/src/main/java/org/sonar/server/app/EmbeddedTomcat.java b/server/sonar-webserver/src/main/java/org/sonar/server/app/EmbeddedTomcat.java index e083d7ea4a0..d0b0d4f74d0 100644 --- a/server/sonar-webserver/src/main/java/org/sonar/server/app/EmbeddedTomcat.java +++ b/server/sonar-webserver/src/main/java/org/sonar/server/app/EmbeddedTomcat.java @@ -58,6 +58,7 @@ class EmbeddedTomcat { tomcat.getHost().setAutoDeploy(false); tomcat.getHost().setCreateDirs(false); tomcat.getHost().setDeployOnStartup(true); + new TomcatErrorHandling().configure(tomcat); new TomcatAccessLog().configure(tomcat, props); TomcatConnectors.configure(tomcat, props); webappContext = new TomcatContexts().configure(tomcat, props); diff --git a/server/sonar-webserver/src/main/java/org/sonar/server/app/TomcatErrorHandling.java b/server/sonar-webserver/src/main/java/org/sonar/server/app/TomcatErrorHandling.java new file mode 100644 index 00000000000..9a24fe8b594 --- /dev/null +++ b/server/sonar-webserver/src/main/java/org/sonar/server/app/TomcatErrorHandling.java @@ -0,0 +1,32 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.app; + +import org.apache.catalina.startup.Tomcat; +import org.apache.catalina.valves.ErrorReportValve; + +public class TomcatErrorHandling { + void configure(Tomcat tomcat) { + ErrorReportValve valve = new ErrorReportValve(); + valve.setShowServerInfo(false); + valve.setShowReport(false); + tomcat.getHost().getPipeline().addValve(valve); + } +} diff --git a/server/sonar-webserver/src/test/java/org/sonar/server/app/TomcatErrorHandlingTest.java b/server/sonar-webserver/src/test/java/org/sonar/server/app/TomcatErrorHandlingTest.java new file mode 100644 index 00000000000..81f5f382c74 --- /dev/null +++ b/server/sonar-webserver/src/test/java/org/sonar/server/app/TomcatErrorHandlingTest.java @@ -0,0 +1,40 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.app; + +import org.apache.catalina.startup.Tomcat; +import org.apache.catalina.valves.ErrorReportValve; +import org.junit.Test; +import org.mockito.Mockito; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +public class TomcatErrorHandlingTest { + private TomcatErrorHandling underTest = new TomcatErrorHandling(); + + @Test + public void enable_access_logs_by_Default() { + Tomcat tomcat = mock(Tomcat.class, Mockito.RETURNS_DEEP_STUBS); + underTest.configure(tomcat); + verify(tomcat.getHost().getPipeline()).addValve(any(ErrorReportValve.class)); + } +} -- 2.39.5