From: Teryk Bellahsene Date: Tue, 19 Jan 2016 17:05:54 +0000 (+0100) Subject: SONAR-7208 WS api/user_tokens/generate forbid blank token name X-Git-Tag: 5.4-M9~26 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=70fb31a42d93ee99b19ffaf2db2a6f930a77a39f;p=sonarqube.git SONAR-7208 WS api/user_tokens/generate forbid blank token name --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/usertoken/ws/GenerateAction.java b/server/sonar-server/src/main/java/org/sonar/server/usertoken/ws/GenerateAction.java index fe693a26ccc..542b5de1755 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/usertoken/ws/GenerateAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/usertoken/ws/GenerateAction.java @@ -139,11 +139,13 @@ public class GenerateAction implements UserTokensWsAction { private GenerateWsRequest toCreateWsRequest(Request request) { GenerateWsRequest generateWsRequest = new GenerateWsRequest() .setLogin(request.param(PARAM_LOGIN)) - .setName(request.mandatoryParam(PARAM_NAME)); + .setName(request.mandatoryParam(PARAM_NAME).trim()); if (generateWsRequest.getLogin() == null) { generateWsRequest.setLogin(userSession.getLogin()); } + checkRequest(!generateWsRequest.getName().isEmpty(), "The '%s' parameter must not be blank", PARAM_NAME); + return generateWsRequest; } diff --git a/server/sonar-server/src/test/java/org/sonar/server/usertoken/ws/GenerateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/usertoken/ws/GenerateActionTest.java index 4bccd4fc0f6..942c205eee5 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/usertoken/ws/GenerateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/usertoken/ws/GenerateActionTest.java @@ -111,6 +111,14 @@ public class GenerateActionTest { newRequest("unknown-login", "any-name"); } + @Test + public void fail_if_name_is_blank() { + expectedException.expect(BadRequestException.class); + expectedException.expectMessage("The 'name' parameter must not be blank"); + + newRequest(GRACE_HOPPER, " "); + } + @Test public void fail_if_token_with_same_login_and_name_exists() { newRequest(GRACE_HOPPER, TOKEN_NAME);