]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9448 Sanitize api/qualityprofiles/exporters
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Thu, 22 Jun 2017 14:35:48 +0000 (16:35 +0200)
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Mon, 26 Jun 2017 07:09:42 +0000 (09:09 +0200)
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ExportersAction.java
server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/example-exporters.json [deleted file]
server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/exporters-example.json [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ExportersActionTest.java
server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/ExportersActionTest/exporters.json [deleted file]

index fbfad01859e85971a5df992407e9f6a364f98b71..f64b3b4aec3f7522a18f228b88709b176386607f 100644 (file)
@@ -34,7 +34,7 @@ public class ExportersAction implements QProfileWsAction {
   }
 
   /**
-   * Used by Pico is no {@link ProfileExporter} is found
+   * Used by Pico if no {@link ProfileExporter} is found
    */
   public ExportersAction() {
     this(new ProfileExporter[0]);
@@ -45,7 +45,7 @@ public class ExportersAction implements QProfileWsAction {
     context.createAction("exporters")
       .setDescription("Lists available profile export formats.")
       .setHandler(this)
-      .setResponseExample(getClass().getResource("example-exporters.json"))
+      .setResponseExample(getClass().getResource("exporters-example.json"))
       .setSince("5.2");
   }
 
diff --git a/server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/example-exporters.json b/server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/example-exporters.json
deleted file mode 100644 (file)
index 86d3e20..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-{
-  "exporters": [
-    {"key": "pmd", "name": "PMD", "languages": ["java"]},
-    {"key": "checkstyle", "name": "Checkstyle", "languages": ["java"]},
-    {"key": "js-lint", "name": "JS Lint", "languages": ["js"]},
-    {"key": "android-lint", "name": "Android Lint", "languages": ["xml", "java"]}
-  ]
-}
diff --git a/server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/exporters-example.json b/server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/exporters-example.json
new file mode 100644 (file)
index 0000000..642a2bd
--- /dev/null
@@ -0,0 +1,33 @@
+{
+  "exporters": [
+    {
+      "key": "pmd",
+      "name": "PMD",
+      "languages": [
+        "java"
+      ]
+    },
+    {
+      "key": "checkstyle",
+      "name": "Checkstyle",
+      "languages": [
+        "java"
+      ]
+    },
+    {
+      "key": "js-lint",
+      "name": "JS Lint",
+      "languages": [
+        "js"
+      ]
+    },
+    {
+      "key": "android-lint",
+      "name": "Android Lint",
+      "languages": [
+        "xml",
+        "java"
+      ]
+    }
+  ]
+}
index 90a07eb5137f68976ba8c2c0024ea48b25ddfbdb..6937d0fc7e363036b4eda0394d90563e2a378f68 100644 (file)
@@ -23,16 +23,18 @@ import java.io.Writer;
 import org.junit.Test;
 import org.sonar.api.profiles.ProfileExporter;
 import org.sonar.api.profiles.RulesProfile;
-import org.sonar.server.ws.WsTester;
+import org.sonar.server.ws.WsActionTester;
+
+import static org.sonar.test.JsonAssert.assertJson;
 
 public class ExportersActionTest {
+  private WsActionTester ws = new WsActionTester(new ExportersAction(createExporters()));
 
   @Test
   public void importers_nominal() throws Exception {
-    WsTester wsTester = new WsTester(new QProfilesWs(
-      new ExportersAction(createExporters())));
+    String result = ws.newRequest().execute().getInput();
 
-    wsTester.newGetRequest("api/qualityprofiles", "exporters").execute().assertJson(getClass(), "exporters.json");
+    assertJson(result).isSimilarTo(ws.getDef().responseExampleAsString());
   }
 
   private ProfileExporter[] createExporters() {
@@ -49,9 +51,10 @@ public class ExportersActionTest {
 
     }
     return new ProfileExporter[] {
-      new NoopImporter("findbugs", "FindBugs", "java"),
-      new NoopImporter("jslint", "JS Lint", "js"),
-      new NoopImporter("vaadin", "Vaadin", "java", "js")
+      new NoopImporter("pmd", "PMD", "java"),
+      new NoopImporter("checkstyle", "Checkstyle", "java"),
+      new NoopImporter("js-lint", "JS Lint", "js"),
+      new NoopImporter("android-lint", "Android Lint", "xml", "java")
     };
   }
 }
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/ExportersActionTest/exporters.json b/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/ExportersActionTest/exporters.json
deleted file mode 100644 (file)
index cc0788d..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-{
-  "exporters": [
-    {"key": "findbugs", "name": "FindBugs", "languages": ["java"]},
-    {"key": "jslint", "name": "JS Lint", "languages": ["js"]},
-    {"key": "vaadin", "name": "Vaadin", "languages": ["java", "js"]}
-  ]
-}