From 8137d0cbfe6c75fbc8ef6622e2fdf38492b99927 Mon Sep 17 00:00:00 2001 From: Teryk Bellahsene Date: Thu, 22 Jun 2017 16:35:48 +0200 Subject: [PATCH] SONAR-9448 Sanitize api/qualityprofiles/exporters --- .../qualityprofile/ws/ExportersAction.java | 4 +-- .../qualityprofile/ws/example-exporters.json | 8 ----- .../qualityprofile/ws/exporters-example.json | 33 +++++++++++++++++++ .../ws/ExportersActionTest.java | 17 ++++++---- .../ws/ExportersActionTest/exporters.json | 7 ---- 5 files changed, 45 insertions(+), 24 deletions(-) delete mode 100644 server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/example-exporters.json create mode 100644 server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/exporters-example.json delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/ExportersActionTest/exporters.json 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"]} - ] -} -- 2.39.5