mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-12-22 00:09:47 +01:00
Fix branch and tag name validation
The validation for branch and tag names has been too limited. This led to errors in the frontend for branches, that had been created using the cli tools for git or hg but have not been seen as valid by SCM-Manager. To fix this, the patterns to validate branch and tag names are relaxed and relate to the git rules (https://git-scm.com/docs/git-check-ref-format). Because these rules could not be expressed using regular expressions alone, in addition possible exceptions will be handled in the git branch and tag commands. Committed-by: Konstantin Schaper <konstantin.schaper@cloudogu.com> Co-authored-by: Eduard Heimbuch <eduard.heimbuch@cloudogu.com> Co-authored-by: René Pfeuffer <rene.pfeuffer@cloudogu.com> Co-authored-by: Konstantin Schaper <konstantin.schaper@cloudogu.com>
This commit is contained in:
committed by
SCM-Manager
parent
b53f8bcf12
commit
8eb2687e10
@@ -30,8 +30,8 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import sonia.scm.ScmConstraintViolationException;
|
||||
import sonia.scm.event.ScmEventBus;
|
||||
import sonia.scm.repository.Branch;
|
||||
import sonia.scm.repository.Changeset;
|
||||
@@ -42,7 +42,6 @@ import sonia.scm.repository.PreProcessorUtil;
|
||||
import sonia.scm.repository.PreReceiveRepositoryHookEvent;
|
||||
import sonia.scm.repository.api.BranchRequest;
|
||||
import sonia.scm.repository.api.HookChangesetBuilder;
|
||||
import sonia.scm.repository.api.HookContext;
|
||||
import sonia.scm.repository.api.HookContextFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -130,6 +129,15 @@ public class GitBranchCommandTest extends AbstractGitCommandTestBase {
|
||||
assertThrows(CannotDeleteDefaultBranchException.class, () -> command.deleteOrClose(branchToBeDeleted));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldThrowViolationExceptionForInvalidBranchName() {
|
||||
BranchRequest branchRequest = new BranchRequest();
|
||||
branchRequest.setNewBranch("invalid..name");
|
||||
|
||||
GitBranchCommand command = createCommand();
|
||||
assertThrows(ScmConstraintViolationException.class, () -> command.branch(branchRequest));
|
||||
}
|
||||
|
||||
private GitBranchCommand createCommand() {
|
||||
return new GitBranchCommand(createContext(), hookContextFactory, eventBus, converterFactory);
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import sonia.scm.ScmConstraintViolationException;
|
||||
import sonia.scm.event.ScmEventBus;
|
||||
import sonia.scm.repository.Changeset;
|
||||
import sonia.scm.repository.GitChangesetConverter;
|
||||
@@ -63,6 +64,7 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -184,6 +186,14 @@ public class GitTagCommandTest extends AbstractGitCommandTestBase {
|
||||
.containsExactly("383b954b27e052db6880d57f1c860dc208795247");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldThrowViolationExceptionForInvalidBranchName() {
|
||||
TagCreateRequest tagRequest = new TagCreateRequest("592d797cd36432e591416e8b2b98154f4f163411", "invalid..name");
|
||||
|
||||
GitTagCommand command = createCommand();
|
||||
assertThrows(ScmConstraintViolationException.class, () -> command.create(tagRequest));
|
||||
}
|
||||
|
||||
private GitTagCommand createCommand() {
|
||||
return new GitTagCommand(createContext(), hookContextFactory, eventBus, converterFactory);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user