diff options
author | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2017-06-21 12:51:48 +0200 |
---|---|---|
committer | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2017-06-26 09:07:48 +0200 |
commit | 7ac92581bbed6357a781bb77a5147d0a141e620e (patch) | |
tree | 5899c639ae479aa4b9c541983882727690dd70e9 /sonar-ws | |
parent | 70b6899988da0d2ba0a39b846e4f1bd3fa27304f (diff) | |
download | sonarqube-7ac92581bbed6357a781bb77a5147d0a141e620e.tar.gz sonarqube-7ac92581bbed6357a781bb77a5147d0a141e620e.zip |
SONAR-9448 Sanitize api/qualityprofiles/activate_rule
Diffstat (limited to 'sonar-ws')
3 files changed, 57 insertions, 22 deletions
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/qualityprofile/QualityProfileWsParameters.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/qualityprofile/QualityProfileWsParameters.java index 7c3f36cd380..74d5e20df22 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/qualityprofile/QualityProfileWsParameters.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/qualityprofile/QualityProfileWsParameters.java @@ -22,42 +22,44 @@ package org.sonarqube.ws.client.qualityprofile; public class QualityProfileWsParameters { public static final String CONTROLLER_QUALITY_PROFILES = "api/qualityprofiles"; - - public static final String ACTION_ACTIVATE_RULE = "activate_rule"; public interface ActivateActionParameters { String PARAM_PROFILE_KEY = "profile_key"; String PARAM_RULE_KEY = "rule_key"; - String PARAM_SEVERITY = "severity"; - String PARAM_RESET = "reset"; - String PARAM_PARAMS = "params"; } - public static final String ACTION_RESTORE = "restore"; + public interface RestoreActionParameters { String PARAM_BACKUP = "backup"; } + public static final String ACTION_ACTIVATE_RULE = "activate_rule"; - public static final String ACTION_DEACTIVATE_RULE = "deactivate_rule"; - public static final String ACTION_SEARCH = "search"; public static final String ACTION_ADD_PROJECT = "add_project"; - public static final String ACTION_REMOVE_PROJECT = "remove_project"; - public static final String ACTION_CREATE = "create"; - public static final String ACTION_COPY = "copy"; public static final String ACTION_CHANGE_PARENT = "change_parent"; - public static final String ACTION_SET_DEFAULT = "set_default"; + public static final String ACTION_COPY = "copy"; + public static final String ACTION_CREATE = "create"; + public static final String ACTION_DEACTIVATE_RULE = "deactivate_rule"; public static final String ACTION_DELETE = "delete"; + public static final String ACTION_REMOVE_PROJECT = "remove_project"; + public static final String ACTION_SEARCH = "search"; + public static final String ACTION_SET_DEFAULT = "set_default"; - public static final String PARAM_ORGANIZATION = "organization"; public static final String PARAM_DEFAULTS = "defaults"; + public static final String PARAM_FROM_KEY = "fromKey"; + public static final String PARAM_ORGANIZATION = "organization"; public static final String PARAM_LANGUAGE = "language"; - public static final String PARAM_PROFILE_NAME = "profileName"; + public static final String PARAM_PARAMS = "params"; + public static final String PARAM_PARENT_KEY = "parentKey"; + public static final String PARAM_PARENT_NAME = "parentName"; + public static final String PARAM_PROFILE = "profile"; public static final String PARAM_PROFILE_KEY = "profileKey"; + public static final String PARAM_PROFILE_NAME = "profileName"; public static final String PARAM_PROJECT_KEY = "projectKey"; public static final String PARAM_PROJECT_UUID = "projectUuid"; - public static final String PARAM_FROM_KEY = "fromKey"; + public static final String PARAM_RESET = "reset"; + public static final String PARAM_RULE = "rule"; + public static final String PARAM_RULE_KEY = "ruleKey"; + public static final String PARAM_SEVERITY = "severity"; public static final String PARAM_TO_NAME = "toName"; - public static final String PARAM_PARENT_NAME = "parentName"; - public static final String PARAM_PARENT_KEY = "parentKey"; private QualityProfileWsParameters() { // Only static stuff diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/qualityprofile/QualityProfilesService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/qualityprofile/QualityProfilesService.java index c3a6d02a925..d7658b35b7b 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/qualityprofile/QualityProfilesService.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/qualityprofile/QualityProfilesService.java @@ -45,12 +45,18 @@ import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters. import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_FROM_KEY; 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_PARAMS; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PARENT_KEY; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PARENT_NAME; +import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROFILE; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROFILE_KEY; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROFILE_NAME; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROJECT_KEY; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROJECT_UUID; +import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_RESET; +import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_RULE; +import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_RULE_KEY; +import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_SEVERITY; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_TO_NAME; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.RestoreActionParameters.PARAM_BACKUP; @@ -63,11 +69,11 @@ public class QualityProfilesService extends BaseService { public void activateRule(ActivateRuleWsRequest request) { PostRequest httpRequest = new PostRequest(path(ACTION_ACTIVATE_RULE)); httpRequest.setParam(PARAM_ORGANIZATION, request.getOrganization().orElse(null)); - httpRequest.setParam(ActivateActionParameters.PARAM_PARAMS, request.getParams().orElse(null)); - httpRequest.setParam(ActivateActionParameters.PARAM_PROFILE_KEY, request.getProfileKey()); - httpRequest.setParam(ActivateActionParameters.PARAM_RESET, request.getReset().orElse(null)); - httpRequest.setParam(ActivateActionParameters.PARAM_RULE_KEY, request.getRuleKey()); - httpRequest.setParam(ActivateActionParameters.PARAM_SEVERITY, request.getSeverity().map(Enum::name).orElse(null)); + httpRequest.setParam(PARAM_PARAMS, request.getParams().orElse(null)); + httpRequest.setParam(PARAM_PROFILE, request.getProfileKey()); + httpRequest.setParam(PARAM_RESET, request.getReset().orElse(null)); + httpRequest.setParam(PARAM_RULE, request.getRuleKey()); + httpRequest.setParam(PARAM_SEVERITY, request.getSeverity().map(Enum::name).orElse(null)); call(httpRequest); } diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/qualityprofile/QualityProfilesServiceTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/qualityprofile/QualityProfilesServiceTest.java index 60052f0b4b4..81b080a4a59 100644 --- a/sonar-ws/src/test/java/org/sonarqube/ws/client/qualityprofile/QualityProfilesServiceTest.java +++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/qualityprofile/QualityProfilesServiceTest.java @@ -21,6 +21,7 @@ package org.sonarqube.ws.client.qualityprofile; import org.junit.Rule; import org.junit.Test; +import org.sonarqube.ws.Common.Severity; import org.sonarqube.ws.QualityProfiles; import org.sonarqube.ws.client.GetRequest; import org.sonarqube.ws.client.PostRequest; @@ -32,9 +33,14 @@ import static org.mockito.Mockito.mock; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_DEFAULTS; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_FROM_KEY; 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_PARAMS; +import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROFILE; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROFILE_KEY; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROFILE_NAME; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROJECT_KEY; +import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_RULE; +import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_SEVERITY; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_TO_NAME; public class QualityProfilesServiceTest { @@ -151,4 +157,25 @@ public class QualityProfilesServiceTest { .hasParam(QualityProfileWsParameters.ActivateActionParameters.PARAM_RULE_KEY, "R1") .andNoOtherParam(); } + + @Test + public void activate_rule() { + underTest.activateRule(ActivateRuleWsRequest.builder() + .setRuleKey("R1") + .setProfileKey("P1") + .setOrganization("O1") + .setParams("PS1") + .setSeverity(Severity.INFO) + .build()); + PostRequest request = serviceTester.getPostRequest(); + + serviceTester.assertThat(request) + .hasPath("activate_rule") + .hasParam(PARAM_PROFILE, "P1") + .hasParam(PARAM_RULE, "R1") + .hasParam(PARAM_ORGANIZATION, "O1") + .hasParam(PARAM_PARAMS, "PS1") + .hasParam(PARAM_SEVERITY, Severity.INFO.toString()) + .andNoOtherParam(); + } } |