From 3f5a637793f76ebde3bad41cb26cc4653acfaf96 Mon Sep 17 00:00:00 2001 From: Teryk Bellahsene Date: Fri, 23 Jun 2017 11:47:05 +0200 Subject: [PATCH] SONAR-9448 Sanitize api/qualityprofiles/search --- .../server/qualityprofile/ws/SearchAction.java | 12 +++++++----- .../server/qualityprofile/ws/SearchActionTest.java | 13 +++++-------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java index f7f78adbd7a..caf8046ba21 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java @@ -55,6 +55,7 @@ import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters. import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_LANGUAGE; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_ORGANIZATION; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROFILE_NAME; +import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROJECT; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROJECT_KEY; public class SearchAction implements QProfileWsAction { @@ -75,7 +76,7 @@ public class SearchAction implements QProfileWsAction { public void define(WebService.NewController controller) { NewAction action = controller.createAction(ACTION_SEARCH) .setSince("5.2") - .setDescription("List quality profiles.") + .setDescription("Search quality profiles") .setHandler(this) .setResponseExample(getClass().getResource("search-example.json")); @@ -90,12 +91,13 @@ public class SearchAction implements QProfileWsAction { action .createParam(PARAM_DEFAULTS) - .setDescription(format("If set to true, return only the quality profile marked as default for each language, the '%s' parameter must not be set.", PARAM_PROJECT_KEY)) + .setDescription(format("If set to true, return only the quality profile marked as default for each language, the '%s' parameter must not be set.", PARAM_PROJECT)) .setDefaultValue(false) .setBooleanPossibleValues(); - action.createParam(PARAM_PROJECT_KEY) + action.createParam(PARAM_PROJECT) .setDescription(format("Project or module key. If provided, the '%s' parameter should not be provided.", PARAM_DEFAULTS)) + .setDeprecatedKey("projectKey", "6.5") .setExampleValue("my-project-key"); action @@ -108,7 +110,7 @@ public class SearchAction implements QProfileWsAction { action.createParam(PARAM_PROFILE_NAME) .setDeprecatedSince("6.4") - .setDescription(format("Profile name. It should be always used with the '%s' or '%s' parameter.", PARAM_PROJECT_KEY, PARAM_DEFAULTS)) + .setDescription(format("Profile name. It should be always used with the '%s' or '%s' parameter.", PARAM_PROJECT, PARAM_DEFAULTS)) .setExampleValue("SonarQube Way"); } @@ -121,7 +123,7 @@ public class SearchAction implements QProfileWsAction { private static SearchWsRequest toSearchWsRequest(Request request) { return new SearchWsRequest() .setOrganizationKey(request.param(PARAM_ORGANIZATION)) - .setProjectKey(request.param(PARAM_PROJECT_KEY)) + .setProjectKey(request.param(PARAM_PROJECT)) .setProfileName(request.param(PARAM_PROFILE_NAME)) .setDefaults(request.paramAsBoolean(PARAM_DEFAULTS)) .setLanguage(request.param(PARAM_LANGUAGE)); diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java index 42fd65b7170..6ce4f9bfa7e 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java @@ -77,7 +77,6 @@ public class SearchActionTest { private ComponentDbTester componentDb = new ComponentDbTester(db); private DbClient dbClient = db.getDbClient(); private DbSession dbSession = db.getSession(); - private QualityProfileDao qualityProfileDao = dbClient.qualityProfileDao(); private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db); private QProfileWsSupport qProfileWsSupport = new QProfileWsSupport(dbClient, userSession, defaultOrganizationProvider); @@ -94,10 +93,7 @@ public class SearchActionTest { Languages languages = new Languages(xoo1, xoo2); underTest = new SearchAction( - new SearchDataLoader( - languages, - new QProfileLookup(dbClient), - dbClient), + new SearchDataLoader(languages, new QProfileLookup(dbClient), dbClient), languages, dbClient, qProfileWsSupport); @@ -120,10 +116,11 @@ public class SearchActionTest { WebService.Param defaults = action.param("defaults"); assertThat(defaults.description()).isEqualTo("If set to true, return only the quality profile marked as default for each language, " + - "the 'projectKey' parameter must not be set."); + "the 'project' parameter must not be set."); - WebService.Param projectKey = action.param("projectKey"); + WebService.Param projectKey = action.param("project"); assertThat(projectKey.description()).isEqualTo("Project or module key. If provided, the 'defaults' parameter should not be provided."); + assertThat(projectKey.deprecatedKey()).isEqualTo("projectKey"); WebService.Param language = action.param("language"); assertThat(language.possibleValues()).containsExactly("xoo1", "xoo2"); @@ -133,7 +130,7 @@ public class SearchActionTest { WebService.Param profileName = action.param("profileName"); assertThat(profileName.deprecatedSince()).isEqualTo("6.4"); - assertThat(profileName.description()).isEqualTo("Profile name. It should be always used with the 'projectKey' or 'defaults' parameter."); + assertThat(profileName.description()).isEqualTo("Profile name. It should be always used with the 'project' or 'defaults' parameter."); } @Test -- 2.39.5