From: Teryk Bellahsene Date: Mon, 1 Feb 2016 11:16:22 +0000 (+0100) Subject: SONAR-7020 forbid login with a space when creating a user X-Git-Tag: 5.4-M11~1 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=68ac319d78630e20a13e6b540fee4a9011f40ef1;p=sonarqube.git SONAR-7020 forbid login with a space when creating a user --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/user/UserUpdater.java b/server/sonar-server/src/main/java/org/sonar/server/user/UserUpdater.java index 915a6619b26..ad432464253 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/user/UserUpdater.java +++ b/server/sonar-server/src/main/java/org/sonar/server/user/UserUpdater.java @@ -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")); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterTest.java index 6730b0de7c3..d5c915a48c5 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterTest.java @@ -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 { diff --git a/sonar-db/src/main/java/org/sonar/db/user/UserDto.java b/sonar-db/src/main/java/org/sonar/db/user/UserDto.java index 3ab6379620c..5e24f886255 100644 --- a/sonar-db/src/main/java/org/sonar/db/user/UserDto.java +++ b/sonar-db/src/main/java/org/sonar/db/user/UserDto.java @@ -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; }