mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-11 07:55:47 +01:00
merge and fix
This commit is contained in:
@@ -9,6 +9,6 @@ public final class ValidationConstraints {
|
|||||||
* and it not contains whitespaces
|
* and it not contains whitespaces
|
||||||
* and the characters: . - _ @ are allowed
|
* and the characters: . - _ @ are allowed
|
||||||
*/
|
*/
|
||||||
public static final String USER_GROUP_PATTERN = "^[^@\\s][A-Za-z0-9\\.\\-_@]+$";
|
public static final String USER_GROUP_PATTERN = "^[A-Za-z0-9\\.\\-_][A-Za-z0-9\\.\\-_@]+$";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package sonia.scm.api.v2;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.junit.runners.Parameterized;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.IntStream;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import static java.util.Arrays.asList;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static sonia.scm.api.v2.ValidationConstraints.USER_GROUP_PATTERN;
|
||||||
|
|
||||||
|
@RunWith(Parameterized.class)
|
||||||
|
public class ValidationConstraints_IllegalCharactersTest {
|
||||||
|
|
||||||
|
private static final List<Character> ACCEPTED_CHARS = asList('@', '_', '-', '.');
|
||||||
|
|
||||||
|
private final Pattern userGroupPattern=Pattern.compile(USER_GROUP_PATTERN);
|
||||||
|
|
||||||
|
private final String expression;
|
||||||
|
|
||||||
|
public ValidationConstraints_IllegalCharactersTest(String expression) {
|
||||||
|
this.expression = expression;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Parameterized.Parameters(name = "{0}")
|
||||||
|
public static Collection<String[]> createParameters() {
|
||||||
|
return Stream.concat(IntStream.range(0x20, 0x2f).mapToObj(i -> (char) i), // chars before '0'
|
||||||
|
Stream.concat(IntStream.range(0x3a, 0x40).mapToObj(i -> (char) i), // chars between '9' and 'A'
|
||||||
|
Stream.concat(IntStream.range(0x5b, 0x60).mapToObj(i -> (char) i), // chars between 'Z' and 'a'
|
||||||
|
IntStream.range(0x7b, 0xff).mapToObj(i -> (char) i)))) // chars after 'z'
|
||||||
|
.filter(c -> !ACCEPTED_CHARS.contains(c))
|
||||||
|
.flatMap(c -> Stream.of("abc" + c + "xyz", "@" + c, c + "tail"))
|
||||||
|
.map(c -> new String[] {c})
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldNotAcceptCharactersBetween_Z_and_a() {
|
||||||
|
assertFalse(userGroupPattern.matcher(expression).matches());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user