]> source.dussan.org Git - sonarqube.git/commitdiff
Clean some code related to rails 1656/head
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 10 Feb 2017 10:28:22 +0000 (11:28 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 10 Feb 2017 10:28:22 +0000 (11:28 +0100)
server/sonar-server/src/main/java/org/sonar/server/app/ServerProcessLogging.java
server/sonar-server/src/main/java/org/sonar/server/authentication/JwtCsrfVerifier.java
server/sonar-server/src/main/java/org/sonar/server/authentication/UserSessionInitializer.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java
server/sonar-server/src/test/java/org/sonar/ce/log/CeProcessLoggingTest.java
server/sonar-server/src/test/java/org/sonar/server/app/WebServerProcessLoggingTest.java
server/sonar-server/src/test/java/org/sonar/server/authentication/JwtCsrfVerifierTest.java
server/sonar-server/src/test/java/org/sonar/server/authentication/UserSessionInitializerTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileExportersTest.java

index f3814406a3a65841034e5738e5c501dfb6f56316..db586731f7b667020201177a2934b0e3c25784e3 100644 (file)
@@ -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);
index 28ada037e160be0a29274d9cc9703bb8c259d68b..0a9b730a2775a678ebb5ef3b1a0859ff41749324 100644 (file)
@@ -42,7 +42,6 @@ public class JwtCsrfVerifier {
 
   private static final Set<String> UPDATE_METHODS = ImmutableSet.of("POST", "PUT", "DELETE");
   private static final String API_URL = "/api";
-  private static final Set<String> 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();
-  }
-
 }
index 4ed5d460dd818c0b01e5ac7cfd8d0d880ab54d82..a0c42039333445fce4235309b4227f068a5a8d34 100644 (file)
@@ -60,8 +60,7 @@ public class UserSessionInitializer {
   // SONAR-6546 these urls should be get from WebService
   private static final Set<String> 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;
     }
   }
index 9579ac9e3f7e803038a6e303c73eff3acb0e698c..31b307d0c787228151a82829871c4fba2c125f8f 100644 (file)
@@ -138,24 +138,11 @@ public class QProfileExporters {
     throw new NotFoundException("Unknown quality profile exporter: " + exporterKey);
   }
 
-  /**
-   * Used by rails
-   */
-  public List<ProfileImporter> findProfileImportersForLanguage(String language) {
-    List<ProfileImporter> 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);
index 451aac9e379e8a20b3a44f00b37ce3a2f39590bc..10ee6caea4cabdc6c3d9247eae8ec76efacfcdf3 100644 (file)
@@ -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);
index 24d661249e7df7bd77cbde9bae116bd8bf2ea8e5..a75cf1b680940404f097c069fa7716c825d01b86 100644 (file)
@@ -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);
index 2d62f24942a9c7fc7958bb7b87b6e7de2805d055..898703642053171ec3b0014ed5a12dce7dc6c324 100644 (file)
@@ -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");
index 9b6bc45bcacee21e09eec58c1097438cfd6cc378..ef55f70fd938be4f921f7b6a1ade3b4ba46e9b4e 100644 (file)
@@ -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");
index 357673c6ac7bb011328d6b7d27a392ce4c8c43de..3f95500aa93145dce2f04cad6093a3d28534fe98 100644 (file)
@@ -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");