diff options
author | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2017-06-22 16:36:09 +0200 |
---|---|---|
committer | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2017-06-26 09:09:42 +0200 |
commit | 53a03e9368eb972cfd2255874b59ea1dfec19770 (patch) | |
tree | 3ae0a9628840bb2e4c4e1fbc36756ad7913dfef8 /server | |
parent | 8137d0cbfe6c75fbc8ef6622e2fdf38492b99927 (diff) | |
download | sonarqube-53a03e9368eb972cfd2255874b59ea1dfec19770.tar.gz sonarqube-53a03e9368eb972cfd2255874b59ea1dfec19770.zip |
SONAR-9448 Sanitize api/qualityprofiles/importers
Diffstat (limited to 'server')
5 files changed, 56 insertions, 24 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ImportersAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ImportersAction.java index 1f3694028e8..67ccefe79bf 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ImportersAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ImportersAction.java @@ -42,7 +42,7 @@ public class ImportersAction implements QProfileWsAction { controller.createAction("importers") .setSince("5.2") .setDescription("List supported importers.") - .setResponseExample(getClass().getResource("example-importers.json")) + .setResponseExample(getClass().getResource("importers-example.json")) .setHandler(this); } diff --git a/server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/example-importers.json b/server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/example-importers.json deleted file mode 100644 index d5faa647cfd..00000000000 --- a/server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/example-importers.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "importers": [ - {"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/importers-example.json b/server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/importers-example.json new file mode 100644 index 00000000000..8750609887a --- /dev/null +++ b/server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/importers-example.json @@ -0,0 +1,33 @@ +{ + "importers": [ + { + "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/ImportersActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ImportersActionTest.java index 3a481534a71..ef39a991fc4 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ImportersActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ImportersActionTest.java @@ -24,16 +24,28 @@ import org.junit.Test; import org.sonar.api.profiles.ProfileImporter; import org.sonar.api.profiles.RulesProfile; import org.sonar.api.utils.ValidationMessages; -import org.sonar.server.ws.WsTester; +import org.sonar.server.ws.WsActionTester; + +import static org.sonar.test.JsonAssert.assertJson; public class ImportersActionTest { + private WsActionTester ws = new WsActionTester(new ImportersAction(createImporters())); + + @Test + public void json_example() throws Exception { + String result = ws.newRequest().execute().getInput(); + + assertJson(result).isSimilarTo(ws.getDef().responseExampleAsString()); + } + @Test - public void importers_nominal() throws Exception { - WsTester wsTester = new WsTester(new QProfilesWs( - new ImportersAction(createImporters()))); + public void empty_importers() { + ws = new WsActionTester(new ImportersAction()); - wsTester.newGetRequest("api/qualityprofiles", "importers").execute().assertJson(getClass(), "importers.json"); + String result = ws.newRequest().execute().getInput(); + + assertJson(result).isSimilarTo("{ \"importers\": [] }"); } private ProfileImporter[] createImporters() { @@ -49,10 +61,12 @@ public class ImportersActionTest { } } + return new ProfileImporter[] { - 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/ImportersActionTest/importers.json b/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/ImportersActionTest/importers.json deleted file mode 100644 index 2c180eec988..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/ImportersActionTest/importers.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "importers": [ - {"key": "findbugs", "name": "FindBugs", "languages": ["java"]}, - {"key": "jslint", "name": "JS Lint", "languages": ["js"]}, - {"key": "vaadin", "name": "Vaadin", "languages": ["java", "js"]} - ] -} |