Disable repository types (#1908)

Disable repository types via global config for Git, Mercurial and Subversion. It is only possible to disable a type, if no repositories of this type exist. Also prevent repository creation if no type is allowed at all to catch nasty errors.

Co-authored-by: Konstantin Schaper <konstantin.schaper@cloudogu.com>
This commit is contained in:
Eduard Heimbuch
2022-01-06 10:05:01 +01:00
committed by GitHub
parent 82ac06f896
commit aa1558dbac
24 changed files with 252 additions and 185 deletions

View File

@@ -37,11 +37,15 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import sonia.scm.repository.GitConfig;
import sonia.scm.repository.RepositoryManager;
import sonia.scm.repository.RepositoryTestData;
import java.net.URI;
import java.util.Collections;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -53,6 +57,9 @@ public class GitConfigToGitConfigDtoMapperTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private ScmPathInfoStore scmPathInfoStore;
@Mock
private RepositoryManager repositoryManager;
@InjectMocks
private GitConfigToGitConfigDtoMapperImpl mapper;
@@ -78,15 +85,28 @@ public class GitConfigToGitConfigDtoMapperTest {
public void shouldMapFields() {
GitConfig config = createConfiguration();
when(repositoryManager.getAll()).thenReturn(Collections.singleton(RepositoryTestData.create42Puzzle("git")));
when(subject.isPermitted("configuration:write:git")).thenReturn(true);
GitConfigDto dto = mapper.map(config);
assertFalse(dto.isAllowDisable());
assertEquals("express", dto.getGcExpression());
assertFalse(dto.isDisabled());
assertEquals(expectedBaseUri.toString(), dto.getLinks().getLinkBy("self").get().getHref());
assertEquals(expectedBaseUri.toString(), dto.getLinks().getLinkBy("update").get().getHref());
}
@Test
public void shouldAllowDisableIfNoGitRepositoryExist() {
GitConfig config = createConfiguration();
when(repositoryManager.getAll()).thenReturn(Collections.singleton(RepositoryTestData.create42Puzzle("hg")));
when(subject.isPermitted("configuration:write:git")).thenReturn(true);
GitConfigDto dto = mapper.map(config);
assertTrue(dto.isAllowDisable());
}
@Test
public void shouldMapFieldsWithoutUpdate() {
GitConfig config = createConfiguration();