]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7208 WS api/user_tokens/generate forbid blank token name
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Tue, 19 Jan 2016 17:05:54 +0000 (18:05 +0100)
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Tue, 19 Jan 2016 17:05:54 +0000 (18:05 +0100)
server/sonar-server/src/main/java/org/sonar/server/usertoken/ws/GenerateAction.java
server/sonar-server/src/test/java/org/sonar/server/usertoken/ws/GenerateActionTest.java

index fe693a26ccceeb0ebd085f442c705a5a0346842c..542b5de17553f796c8b2562f63aaab49c7cce332 100644 (file)
@@ -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;
   }
 
index 4bccd4fc0f611b4584cf259288a518b8bdad33c9..942c205eee55ab686cfc1b8dad7e7bd5881ef074 100644 (file)
@@ -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);