]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7020 forbid login with a space when creating a user
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Mon, 1 Feb 2016 11:16:22 +0000 (12:16 +0100)
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Mon, 1 Feb 2016 15:36:21 +0000 (16:36 +0100)
server/sonar-server/src/main/java/org/sonar/server/user/UserUpdater.java
server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterTest.java
sonar-db/src/main/java/org/sonar/db/user/UserDto.java

index 915a6619b267f9eae32957c2021db69be9bc1be6..ad4324642533469647092c99218385da251a8e77 100644 (file)
@@ -277,7 +277,7 @@ public class UserUpdater {
         messages.add(Message.of(Validation.IS_TOO_SHORT_MESSAGE, LOGIN_PARAM, LOGIN_MIN_LENGTH));
       } else if (login.length() > LOGIN_MAX_LENGTH) {
         messages.add(Message.of(Validation.IS_TOO_LONG_MESSAGE, LOGIN_PARAM, LOGIN_MAX_LENGTH));
-      } else if (!login.matches("\\A\\w[\\w\\.\\-_@\\s]+\\z")) {
+      } else if (!login.matches("\\A\\w[\\w\\.\\-_@]+\\z")) {
         messages.add(Message.of("user.bad_login"));
       }
     }
index 6730b0de7c397a1bc3200e109612ddbfd186a46c..d5c915a48c581ea6e0c79fad98047bd1cfe2d4a4 100644 (file)
@@ -257,6 +257,20 @@ public class UserUpdaterTest {
     }
   }
 
+  @Test
+  public void fail_to_create_user_with_space_in_login() {
+    try {
+      userUpdater.create(NewUser.create()
+        .setLogin("mari us")
+        .setName("Marius")
+        .setEmail("marius@mail.com")
+        .setPassword("password"));
+      fail();
+    } catch (BadRequestException e) {
+      assertThat(e.errors().messages()).containsOnly(Message.of("user.bad_login"));
+    }
+  }
+
   @Test
   public void fail_to_create_user_with_too_short_login() {
     try {
index 3ab6379620ceb6ca794cb5d5613a5422600b6245..5e24f8862554be1fbecc3c57e51253c34e3ecb9f 100644 (file)
@@ -59,6 +59,10 @@ public class UserDto {
     return this;
   }
 
+  /**
+   * Spaces were authorized before SQ 5.4.
+   * For versions 5.4+ it's not possible to create a login with a space character.
+   */
   public String getLogin() {
     return login;
   }