aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2017-06-22 16:35:48 +0200
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2017-06-26 09:09:42 +0200
commit8137d0cbfe6c75fbc8ef6622e2fdf38492b99927 (patch)
tree553e577095fefaee6f403da6c487c07a590e3041 /server
parent628a25dc393859c3e0aa6a4ceec8047a223ab28e (diff)
downloadsonarqube-8137d0cbfe6c75fbc8ef6622e2fdf38492b99927.tar.gz
sonarqube-8137d0cbfe6c75fbc8ef6622e2fdf38492b99927.zip
SONAR-9448 Sanitize api/qualityprofiles/exporters
Diffstat (limited to 'server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ExportersAction.java4
-rw-r--r--server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/example-exporters.json8
-rw-r--r--server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/exporters-example.json33
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ExportersActionTest.java17
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/ExportersActionTest/exporters.json7
5 files changed, 45 insertions, 24 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ExportersAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ExportersAction.java
index fbfad01859e..f64b3b4aec3 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ExportersAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ExportersAction.java
@@ -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
index 86d3e20568d..00000000000
--- a/server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/example-exporters.json
+++ /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
index 00000000000..642a2bde09d
--- /dev/null
+++ b/server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/exporters-example.json
@@ -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"
+ ]
+ }
+ ]
+}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ExportersActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ExportersActionTest.java
index 90a07eb5137..6937d0fc7e3 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ExportersActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ExportersActionTest.java
@@ -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
index cc0788d870d..00000000000
--- a/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/ExportersActionTest/exporters.json
+++ /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"]}
- ]
-}