mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-17 02:31:14 +01:00
Renames globalConfig to config.
From an SCMM point of view there is only one config, so no "global" necessary. The others configs are provided by plugins.
This commit is contained in:
@@ -12,10 +12,10 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.MockitoAnnotations.initMocks;
|
||||
|
||||
public class GlobalConfigDtoToScmConfigurationMapperTest {
|
||||
public class ConfigDtoToScmConfigurationMapperTest {
|
||||
|
||||
@InjectMocks
|
||||
private GlobalConfigDtoToScmConfigurationMapperImpl mapper;
|
||||
private ConfigDtoToScmConfigurationMapperImpl mapper;
|
||||
|
||||
private String[] expectedUsers = { "trillian", "arthur" };
|
||||
private String[] expectedGroups = { "admin", "plebs" };
|
||||
@@ -28,7 +28,7 @@ public class GlobalConfigDtoToScmConfigurationMapperTest {
|
||||
|
||||
@Test
|
||||
public void shouldMapFields() {
|
||||
GlobalConfigDto dto = createDefaultDto();
|
||||
ConfigDto dto = createDefaultDto();
|
||||
ScmConfiguration config = mapper.map(dto);
|
||||
|
||||
assertEquals("prPw" , config.getProxyPassword());
|
||||
@@ -53,29 +53,29 @@ public class GlobalConfigDtoToScmConfigurationMapperTest {
|
||||
assertTrue(config.isEnabledXsrfProtection());
|
||||
}
|
||||
|
||||
private GlobalConfigDto createDefaultDto() {
|
||||
GlobalConfigDto globalConfigDto = new GlobalConfigDto();
|
||||
globalConfigDto.setProxyPassword("prPw");
|
||||
globalConfigDto.setProxyPort(42);
|
||||
globalConfigDto.setProxyServer("srvr");
|
||||
globalConfigDto.setProxyUser("user");
|
||||
globalConfigDto.setEnableProxy(true);
|
||||
globalConfigDto.setRealmDescription("realm");
|
||||
globalConfigDto.setEnableRepositoryArchive(true);
|
||||
globalConfigDto.setDisableGroupingGrid(true);
|
||||
globalConfigDto.setDateFormat("yyyy");
|
||||
globalConfigDto.setAnonymousAccessEnabled(true);
|
||||
globalConfigDto.setAdminGroups(Sets.newSet(expectedGroups));
|
||||
globalConfigDto.setAdminUsers(Sets.newSet(expectedUsers));
|
||||
globalConfigDto.setBaseUrl("baseurl");
|
||||
globalConfigDto.setForceBaseUrl(true);
|
||||
globalConfigDto.setLoginAttemptLimit(41);
|
||||
globalConfigDto.setProxyExcludes(Sets.newSet(expectedExcludes));
|
||||
globalConfigDto.setSkipFailedAuthenticators(true);
|
||||
globalConfigDto.setPluginUrl("https://plug.ins");
|
||||
globalConfigDto.setLoginAttemptLimitTimeout(40);
|
||||
globalConfigDto.setEnabledXsrfProtection(true);
|
||||
private ConfigDto createDefaultDto() {
|
||||
ConfigDto configDto = new ConfigDto();
|
||||
configDto.setProxyPassword("prPw");
|
||||
configDto.setProxyPort(42);
|
||||
configDto.setProxyServer("srvr");
|
||||
configDto.setProxyUser("user");
|
||||
configDto.setEnableProxy(true);
|
||||
configDto.setRealmDescription("realm");
|
||||
configDto.setEnableRepositoryArchive(true);
|
||||
configDto.setDisableGroupingGrid(true);
|
||||
configDto.setDateFormat("yyyy");
|
||||
configDto.setAnonymousAccessEnabled(true);
|
||||
configDto.setAdminGroups(Sets.newSet(expectedGroups));
|
||||
configDto.setAdminUsers(Sets.newSet(expectedUsers));
|
||||
configDto.setBaseUrl("baseurl");
|
||||
configDto.setForceBaseUrl(true);
|
||||
configDto.setLoginAttemptLimit(41);
|
||||
configDto.setProxyExcludes(Sets.newSet(expectedExcludes));
|
||||
configDto.setSkipFailedAuthenticators(true);
|
||||
configDto.setPluginUrl("https://plug.ins");
|
||||
configDto.setLoginAttemptLimitTimeout(40);
|
||||
configDto.setEnabledXsrfProtection(true);
|
||||
|
||||
return globalConfigDto;
|
||||
return configDto;
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@ import static org.mockito.MockitoAnnotations.initMocks;
|
||||
configuration = "classpath:sonia/scm/configuration/shiro.ini",
|
||||
password = "secret"
|
||||
)
|
||||
public class GlobalConfigResourceTest {
|
||||
public class ConfigResourceTest {
|
||||
|
||||
@Rule
|
||||
public ShiroRule shiro = new ShiroRule();
|
||||
@@ -45,36 +45,35 @@ public class GlobalConfigResourceTest {
|
||||
private ResourceLinks resourceLinks = ResourceLinksMock.createMock(baseUri);
|
||||
|
||||
@InjectMocks
|
||||
private GlobalConfigDtoToScmConfigurationMapperImpl dtoToConfigMapper;
|
||||
private ConfigDtoToScmConfigurationMapperImpl dtoToConfigMapper;
|
||||
@InjectMocks
|
||||
private ScmConfigurationToGlobalConfigDtoMapperImpl configToDtoMapper;
|
||||
private ScmConfigurationToConfigDtoMapperImpl configToDtoMapper;
|
||||
|
||||
@Before
|
||||
public void prepareEnvironment() {
|
||||
initMocks(this);
|
||||
|
||||
GlobalConfigResource globalConfigResource = new GlobalConfigResource(dtoToConfigMapper,
|
||||
configToDtoMapper, createConfiguration());
|
||||
ConfigResource configResource = new ConfigResource(dtoToConfigMapper, configToDtoMapper, createConfiguration());
|
||||
|
||||
dispatcher.getRegistry().addSingletonResource(globalConfigResource);
|
||||
dispatcher.getRegistry().addSingletonResource(configResource);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SubjectAware(username = "readOnly")
|
||||
public void shouldGetGlobalConfig() throws URISyntaxException {
|
||||
MockHttpRequest request = MockHttpRequest.get("/" + GlobalConfigResource.GLOBAL_CONFIG_PATH_V2);
|
||||
MockHttpRequest request = MockHttpRequest.get("/" + ConfigResource.CONFIG_PATH_V2);
|
||||
MockHttpResponse response = new MockHttpResponse();
|
||||
dispatcher.invoke(request, response);
|
||||
assertEquals(HttpServletResponse.SC_OK, response.getStatus());
|
||||
assertTrue(response.getContentAsString().contains("\"proxyPassword\":\"heartOfGold\""));
|
||||
assertTrue(response.getContentAsString().contains("\"self\":{\"href\":\"/v2/config/global"));
|
||||
assertFalse("Update link present", response.getContentAsString().contains("\"update\":{\"href\":\"/v2/config/global"));
|
||||
assertTrue(response.getContentAsString().contains("\"self\":{\"href\":\"/v2/config"));
|
||||
assertFalse("Update link present", response.getContentAsString().contains("\"update\":{\"href\":\"/v2/config"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SubjectAware(username = "writeOnly")
|
||||
public void shouldGetGlobalConfigOnlyWhenAuthorized() throws URISyntaxException {
|
||||
MockHttpRequest request = MockHttpRequest.get("/" + GlobalConfigResource.GLOBAL_CONFIG_PATH_V2);
|
||||
public void shouldGetConfigOnlyWhenAuthorized() throws URISyntaxException {
|
||||
MockHttpRequest request = MockHttpRequest.get("/" + ConfigResource.CONFIG_PATH_V2);
|
||||
MockHttpResponse response = new MockHttpResponse();
|
||||
|
||||
thrown.expectMessage("Subject does not have permission [configuration:read:global]");
|
||||
@@ -84,39 +83,38 @@ public class GlobalConfigResourceTest {
|
||||
|
||||
@Test
|
||||
@SubjectAware(username = "readWrite")
|
||||
public void shouldUpdateGlobalConfig() throws URISyntaxException, IOException {
|
||||
URL url = Resources.getResource("sonia/scm/api/v2/globalConfig-test-update.json");
|
||||
public void shouldUpdateConfig() throws URISyntaxException, IOException {
|
||||
URL url = Resources.getResource("sonia/scm/api/v2/config-test-update.json");
|
||||
byte[] configJson = Resources.toByteArray(url);
|
||||
MockHttpRequest request = MockHttpRequest.put("/" + GlobalConfigResource.GLOBAL_CONFIG_PATH_V2)
|
||||
.contentType(VndMediaType.GLOBAL_CONFIG)
|
||||
MockHttpRequest request = MockHttpRequest.put("/" + ConfigResource.CONFIG_PATH_V2)
|
||||
.contentType(VndMediaType.CONFIG)
|
||||
.content(configJson);
|
||||
|
||||
MockHttpResponse response = new MockHttpResponse();
|
||||
dispatcher.invoke(request, response);
|
||||
assertEquals(HttpServletResponse.SC_NO_CONTENT, response.getStatus());
|
||||
|
||||
request = MockHttpRequest.get("/" + GlobalConfigResource.GLOBAL_CONFIG_PATH_V2);
|
||||
request = MockHttpRequest.get("/" + ConfigResource.CONFIG_PATH_V2);
|
||||
response = new MockHttpResponse();
|
||||
dispatcher.invoke(request, response);
|
||||
assertEquals(HttpServletResponse.SC_OK, response.getStatus());
|
||||
assertTrue(response.getContentAsString().contains("\"proxyPassword\":\"newPassword\""));
|
||||
assertTrue(response.getContentAsString().contains("\"self\":{\"href\":\"/v2/config/global"));
|
||||
assertTrue("link not found", response.getContentAsString().contains("\"update\":{\"href\":\"/v2/config/global"));
|
||||
assertTrue(response.getContentAsString().contains("\"self\":{\"href\":\"/v2/config"));
|
||||
assertTrue("link not found", response.getContentAsString().contains("\"update\":{\"href\":\"/v2/config"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SubjectAware(username = "readOnly")
|
||||
public void shouldUpdateGlobalConfigOnlyWhenAuthorized() throws URISyntaxException, IOException {
|
||||
URL url = Resources.getResource("sonia/scm/api/v2/globalConfig-test-update.json");
|
||||
public void shouldUpdateConfigOnlyWhenAuthorized() throws URISyntaxException, IOException {
|
||||
URL url = Resources.getResource("sonia/scm/api/v2/config-test-update.json");
|
||||
byte[] configJson = Resources.toByteArray(url);
|
||||
MockHttpRequest request = MockHttpRequest.put("/" + GlobalConfigResource.GLOBAL_CONFIG_PATH_V2)
|
||||
.contentType(VndMediaType.GLOBAL_CONFIG)
|
||||
MockHttpRequest request = MockHttpRequest.put("/" + ConfigResource.CONFIG_PATH_V2)
|
||||
.contentType(VndMediaType.CONFIG)
|
||||
.content(configJson);
|
||||
MockHttpResponse response = new MockHttpResponse();
|
||||
|
||||
thrown.expectMessage("Subject does not have permission [configuration:write:global]");
|
||||
|
||||
|
||||
dispatcher.invoke(request, response);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ public class ResourceLinksMock {
|
||||
when(resourceLinks.changesetCollection()).thenReturn(new ResourceLinks.ChangesetCollectionLinks(uriInfo));
|
||||
when(resourceLinks.sourceCollection()).thenReturn(new ResourceLinks.SourceCollectionLinks(uriInfo));
|
||||
when(resourceLinks.permissionCollection()).thenReturn(new ResourceLinks.PermissionCollectionLinks(uriInfo));
|
||||
when(resourceLinks.globalConfig()).thenReturn(new ResourceLinks.GlobalConfigLinks(uriInfo));
|
||||
when(resourceLinks.config()).thenReturn(new ResourceLinks.ConfigLinks(uriInfo));
|
||||
return resourceLinks;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,15 +133,15 @@ public class ResourceLinksTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCreateCorrectGlobalConfigSelfUrl() {
|
||||
String url = resourceLinks.globalConfig().self();
|
||||
assertEquals(BASE_URL + GlobalConfigResource.GLOBAL_CONFIG_PATH_V2, url);
|
||||
public void shouldCreateCorrectConfigSelfUrl() {
|
||||
String url = resourceLinks.config().self();
|
||||
assertEquals(BASE_URL + ConfigResource.CONFIG_PATH_V2, url);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCreateCorrectGlobalConfigUpdateUrl() {
|
||||
String url = resourceLinks.globalConfig().update();
|
||||
assertEquals(BASE_URL + GlobalConfigResource.GLOBAL_CONFIG_PATH_V2, url);
|
||||
public void shouldCreateCorrectConfigUpdateUrl() {
|
||||
String url = resourceLinks.config().update();
|
||||
assertEquals(BASE_URL + ConfigResource.CONFIG_PATH_V2, url);
|
||||
}
|
||||
|
||||
@Before
|
||||
|
||||
@@ -21,7 +21,7 @@ import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.MockitoAnnotations.initMocks;
|
||||
|
||||
public class ScmConfigurationToGlobalConfigDtoMapperTest {
|
||||
public class ScmConfigurationToConfigDtoMapperTest {
|
||||
|
||||
private URI baseUri = URI.create("http://example.com/base/");
|
||||
|
||||
@@ -33,7 +33,7 @@ public class ScmConfigurationToGlobalConfigDtoMapperTest {
|
||||
private ResourceLinks resourceLinks = ResourceLinksMock.createMock(baseUri);
|
||||
|
||||
@InjectMocks
|
||||
private ScmConfigurationToGlobalConfigDtoMapperImpl mapper;
|
||||
private ScmConfigurationToConfigDtoMapperImpl mapper;
|
||||
|
||||
private final Subject subject = mock(Subject.class);
|
||||
private final ThreadState subjectThreadState = new SubjectThreadState(subject);
|
||||
@@ -43,7 +43,7 @@ public class ScmConfigurationToGlobalConfigDtoMapperTest {
|
||||
@Before
|
||||
public void init() {
|
||||
initMocks(this);
|
||||
expectedBaseUri = baseUri.resolve(GlobalConfigResource.GLOBAL_CONFIG_PATH_V2);
|
||||
expectedBaseUri = baseUri.resolve(ConfigResource.CONFIG_PATH_V2);
|
||||
subjectThreadState.bind();
|
||||
ThreadContext.bind(subject);
|
||||
}
|
||||
@@ -59,7 +59,7 @@ public class ScmConfigurationToGlobalConfigDtoMapperTest {
|
||||
|
||||
|
||||
when(subject.isPermitted("configuration:write:global")).thenReturn(true);
|
||||
GlobalConfigDto dto = mapper.map(config);
|
||||
ConfigDto dto = mapper.map(config);
|
||||
|
||||
assertEquals("heartOfGold" , dto.getProxyPassword());
|
||||
assertEquals(1234 , dto.getProxyPort());
|
||||
@@ -91,7 +91,7 @@ public class ScmConfigurationToGlobalConfigDtoMapperTest {
|
||||
ScmConfiguration config = createConfiguration();
|
||||
|
||||
when(subject.hasRole("configuration:write:global")).thenReturn(false);
|
||||
GlobalConfigDto dto = mapper.map(config);
|
||||
ConfigDto dto = mapper.map(config);
|
||||
|
||||
assertEquals("baseurl", dto.getBaseUrl());
|
||||
assertEquals(expectedBaseUri.toString(), dto.getLinks().getLinkBy("self").get().getHref());
|
||||
Reference in New Issue
Block a user