mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-03-06 12:20:56 +01:00
Fix creating a repository permission without a name breaking the repository (#2126)
If a POST request is submitted to the rest api for repostory permissions, the regex validator ignores the name field if it is null, which leads to an internal server error and breaks any further attempts to interact with that repository. An additional not-null constraint resolves this problem.
This commit is contained in:
committed by
GitHub
parent
42bdd1d22e
commit
fe82c967b8
2
gradle/changelog/repository_permission_without_name.yaml
Normal file
2
gradle/changelog/repository_permission_without_name.yaml
Normal file
@@ -0,0 +1,2 @@
|
||||
- type: fixed
|
||||
description: Creating a repository permission without a name breaks the repository ([#2126](https://github.com/scm-manager/scm-manager/pull/2126))
|
||||
@@ -33,6 +33,7 @@ import lombok.ToString;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import sonia.scm.util.ValidationUtil;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Pattern;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -43,6 +44,7 @@ public class RepositoryPermissionDto extends HalRepresentation implements Update
|
||||
|
||||
public static final String GROUP_PREFIX = "@";
|
||||
|
||||
@NotNull
|
||||
@Pattern(regexp = ValidationUtil.REGEX_NAME)
|
||||
private String name;
|
||||
|
||||
|
||||
@@ -275,6 +275,21 @@ public class RepositoryPermissionRootResourceTest extends RepositoryTestBase {
|
||||
assertEquals(400, response.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGet400OnCreatingNewPermissionWithoutName() throws URISyntaxException {
|
||||
createUserWithRepository("user");
|
||||
String permissionJson = "{ \"verbs\": [\"*\"] }";
|
||||
MockHttpRequest request = MockHttpRequest
|
||||
.post("/" + RepositoryRootResource.REPOSITORIES_PATH_V2 + PATH_OF_ALL_PERMISSIONS)
|
||||
.content(permissionJson.getBytes())
|
||||
.contentType(VndMediaType.REPOSITORY_PERMISSION);
|
||||
MockHttpResponse response = new MockHttpResponse();
|
||||
|
||||
dispatcher.invoke(request, response);
|
||||
|
||||
assertEquals(400, response.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGetCreatedPermissions() throws URISyntaxException {
|
||||
createUserWithRepositoryAndPermissions(TEST_PERMISSIONS, PERMISSION_WRITE);
|
||||
|
||||
Reference in New Issue
Block a user