From 03cca30312c962174881c3e7d4b7098e2ca7dc67 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Fri, 10 Feb 2017 11:28:22 +0100 Subject: [PATCH] Clean some code related to rails --- .../sonar/server/app/ServerProcessLogging.java | 1 - .../server/authentication/JwtCsrfVerifier.java | 8 +------- .../authentication/UserSessionInitializer.java | 5 ++--- .../server/qualityprofile/QProfileExporters.java | 15 +-------------- .../org/sonar/ce/log/CeProcessLoggingTest.java | 1 - .../server/app/WebServerProcessLoggingTest.java | 3 +-- .../authentication/JwtCsrfVerifierTest.java | 6 ------ .../UserSessionInitializerTest.java | 1 + .../qualityprofile/QProfileExportersTest.java | 5 ----- 9 files changed, 6 insertions(+), 39 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/app/ServerProcessLogging.java b/server/sonar-server/src/main/java/org/sonar/server/app/ServerProcessLogging.java index f3814406a3a..db586731f7b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/app/ServerProcessLogging.java +++ b/server/sonar-server/src/main/java/org/sonar/server/app/ServerProcessLogging.java @@ -61,7 +61,6 @@ public abstract class ServerProcessLogging { private LogLevelConfig createLogLevelConfiguration(ProcessId processId) { LogLevelConfig.Builder builder = LogLevelConfig.newBuilder(); builder.rootLevelFor(processId); - builder.immutableLevel("rails", Level.WARN); builder.immutableLevel("org.apache.ibatis", Level.WARN); builder.immutableLevel("java.sql", Level.WARN); builder.immutableLevel("java.sql.ResultSet", Level.WARN); diff --git a/server/sonar-server/src/main/java/org/sonar/server/authentication/JwtCsrfVerifier.java b/server/sonar-server/src/main/java/org/sonar/server/authentication/JwtCsrfVerifier.java index 28ada037e16..0a9b730a277 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/authentication/JwtCsrfVerifier.java +++ b/server/sonar-server/src/main/java/org/sonar/server/authentication/JwtCsrfVerifier.java @@ -42,7 +42,6 @@ public class JwtCsrfVerifier { private static final Set UPDATE_METHODS = ImmutableSet.of("POST", "PUT", "DELETE"); private static final String API_URL = "/api"; - private static final Set RAILS_UPDATE_API_URLS = ImmutableSet.of("/api/projects/create", "/api/user_properties"); public String generateState(HttpServletRequest request, HttpServletResponse response, int timeoutInSeconds) { // Create a state token to prevent request forgery. @@ -89,14 +88,9 @@ public class JwtCsrfVerifier { private static boolean shouldRequestBeChecked(HttpServletRequest request) { if (UPDATE_METHODS.contains(request.getMethod())) { String path = request.getRequestURI().replaceFirst(request.getContextPath(), ""); - return path.startsWith(API_URL) - && !isRailsWsUrl(path); + return path.startsWith(API_URL); } return false; } - private static boolean isRailsWsUrl(String uri) { - return RAILS_UPDATE_API_URLS.stream().filter(uri::startsWith).findFirst().isPresent(); - } - } diff --git a/server/sonar-server/src/main/java/org/sonar/server/authentication/UserSessionInitializer.java b/server/sonar-server/src/main/java/org/sonar/server/authentication/UserSessionInitializer.java index 4ed5d460dd8..a0c42039333 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/authentication/UserSessionInitializer.java +++ b/server/sonar-server/src/main/java/org/sonar/server/authentication/UserSessionInitializer.java @@ -60,8 +60,7 @@ public class UserSessionInitializer { // SONAR-6546 these urls should be get from WebService private static final Set SKIPPED_URLS = ImmutableSet.of( "/batch/index", "/batch/file", - "/maintenance/*", - "/setup/*", + "/maintenance/*", "/setup/*", "/sessions/*", "/oauth2/callback/*", "/api/system/db_migration_status", "/api/system/status", "/api/system/migrate_db", "/api/server/version", @@ -113,7 +112,7 @@ public class UserSessionInitializer { handleAuthenticationError(e, response, request.getContextPath()); return false; } - // Rails will redirect to login page + // Web pages should redirect to the index.html file return true; } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java index 9579ac9e3f7..31b307d0c78 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java @@ -138,24 +138,11 @@ public class QProfileExporters { throw new NotFoundException("Unknown quality profile exporter: " + exporterKey); } - /** - * Used by rails - */ - public List findProfileImportersForLanguage(String language) { - List result = new ArrayList<>(); - for (ProfileImporter importer : importers) { - if (importer.getSupportedLanguages() == null || importer.getSupportedLanguages().length == 0 || ArrayUtils.contains(importer.getSupportedLanguages(), language)) { - result.add(importer); - } - } - return result; - } - public QProfileResult importXml(QualityProfileDto profileDto, String importerKey, InputStream xml, DbSession dbSession) { return importXml(profileDto, importerKey, new InputStreamReader(xml, StandardCharsets.UTF_8), dbSession); } - public QProfileResult importXml(QualityProfileDto profileDto, String importerKey, Reader xml, DbSession dbSession) { + private QProfileResult importXml(QualityProfileDto profileDto, String importerKey, Reader xml, DbSession dbSession) { QProfileResult result = new QProfileResult(); ValidationMessages messages = ValidationMessages.create(); ProfileImporter importer = getProfileImporter(importerKey); diff --git a/server/sonar-server/src/test/java/org/sonar/ce/log/CeProcessLoggingTest.java b/server/sonar-server/src/test/java/org/sonar/ce/log/CeProcessLoggingTest.java index 451aac9e379..10ee6caea4c 100644 --- a/server/sonar-server/src/test/java/org/sonar/ce/log/CeProcessLoggingTest.java +++ b/server/sonar-server/src/test/java/org/sonar/ce/log/CeProcessLoggingTest.java @@ -451,7 +451,6 @@ public class CeProcessLoggingTest { } private void verifyImmutableLogLevels(LoggerContext ctx) { - assertThat(ctx.getLogger("rails").getLevel()).isEqualTo(Level.WARN); assertThat(ctx.getLogger("org.apache.ibatis").getLevel()).isEqualTo(Level.WARN); assertThat(ctx.getLogger("java.sql").getLevel()).isEqualTo(Level.WARN); assertThat(ctx.getLogger("java.sql.ResultSet").getLevel()).isEqualTo(Level.WARN); diff --git a/server/sonar-server/src/test/java/org/sonar/server/app/WebServerProcessLoggingTest.java b/server/sonar-server/src/test/java/org/sonar/server/app/WebServerProcessLoggingTest.java index 24d661249e7..a75cf1b6809 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/app/WebServerProcessLoggingTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/app/WebServerProcessLoggingTest.java @@ -37,9 +37,9 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; -import org.sonar.process.logging.LogbackHelper; import org.sonar.process.ProcessProperties; import org.sonar.process.Props; +import org.sonar.process.logging.LogbackHelper; import static org.assertj.core.api.Assertions.assertThat; import static org.slf4j.Logger.ROOT_LOGGER_NAME; @@ -452,7 +452,6 @@ public class WebServerProcessLoggingTest { } private void verifyImmutableLogLevels(LoggerContext ctx) { - assertThat(ctx.getLogger("rails").getLevel()).isEqualTo(Level.WARN); assertThat(ctx.getLogger("org.apache.ibatis").getLevel()).isEqualTo(Level.WARN); assertThat(ctx.getLogger("java.sql").getLevel()).isEqualTo(Level.WARN); assertThat(ctx.getLogger("java.sql.ResultSet").getLevel()).isEqualTo(Level.WARN); diff --git a/server/sonar-server/src/test/java/org/sonar/server/authentication/JwtCsrfVerifierTest.java b/server/sonar-server/src/test/java/org/sonar/server/authentication/JwtCsrfVerifierTest.java index 2d62f24942a..89870364205 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/authentication/JwtCsrfVerifierTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/authentication/JwtCsrfVerifierTest.java @@ -146,12 +146,6 @@ public class JwtCsrfVerifierTest { underTest.verifyState(request, null, LOGIN); } - @Test - public void ignore_rails_ws_requests() throws Exception { - executeVerifyStateDoesNotFailOnRequest("/api/projects/create?key=ABCD", "POST"); - executeVerifyStateDoesNotFailOnRequest("/api/user_properties", "POST"); - } - @Test public void ignore_not_api_requests() throws Exception { executeVerifyStateDoesNotFailOnRequest("/events", "POST"); diff --git a/server/sonar-server/src/test/java/org/sonar/server/authentication/UserSessionInitializerTest.java b/server/sonar-server/src/test/java/org/sonar/server/authentication/UserSessionInitializerTest.java index 9b6bc45bcac..ef55f70fd93 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/authentication/UserSessionInitializerTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/authentication/UserSessionInitializerTest.java @@ -105,6 +105,7 @@ public class UserSessionInitializerTest { assertPathIsIgnored("/setup/index"); assertPathIsIgnored("/sessions/new"); assertPathIsIgnored("/sessions/logout"); + assertPathIsIgnored("/sessions/unauthorized"); assertPathIsIgnored("/oauth2/callback/github"); assertPathIsIgnored("/oauth2/callback/foo"); assertPathIsIgnored("/api/system/db_migration_status"); diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileExportersTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileExportersTest.java index 357673c6ac7..3f95500aa93 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileExportersTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileExportersTest.java @@ -102,11 +102,6 @@ public class QProfileExportersTest { assertThat(exporters.mimeType("standard")).isEqualTo("text/plain"); } - @Test - public void profile_importers_for_language() { - assertThat(exporters.findProfileImportersForLanguage("xoo")).hasSize(3); - } - @Test public void import_xml() { QualityProfileDto profileDto = QProfileTesting.newQProfileDto(QProfileName.createFor("xoo", "import_xml"), "import_xml"); -- 2.39.5