mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 15:05:44 +01:00
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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user