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:
Konstantin Schaper
2022-09-30 10:27:41 +02:00
committed by GitHub
parent 42bdd1d22e
commit fe82c967b8
3 changed files with 19 additions and 0 deletions

View 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))

View File

@@ -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;

View File

@@ -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);