Merge with default

This commit is contained in:
Rene Pfeuffer
2019-12-13 08:57:16 +01:00
209 changed files with 2725 additions and 1077 deletions

View File

@@ -2,14 +2,11 @@ package sonia.scm.api.v2.resources;
import com.github.sdorra.shiro.ShiroRule;
import com.github.sdorra.shiro.SubjectAware;
import org.jboss.resteasy.core.Dispatcher;
import org.jboss.resteasy.mock.MockDispatcherFactory;
import org.jboss.resteasy.mock.MockHttpRequest;
import org.jboss.resteasy.mock.MockHttpResponse;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.ArgumentCaptor;
@@ -27,6 +24,7 @@ import sonia.scm.repository.RepositoryManager;
import sonia.scm.store.ConfigurationStore;
import sonia.scm.store.ConfigurationStoreFactory;
import sonia.scm.web.GitVndMediaType;
import sonia.scm.web.RestDispatcher;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
@@ -52,10 +50,7 @@ public class GitConfigResourceTest {
@Rule
public ShiroRule shiro = new ShiroRule();
@Rule
public ExpectedException thrown = ExpectedException.none();
private Dispatcher dispatcher = MockDispatcherFactory.createDispatcher();
private RestDispatcher dispatcher = new RestDispatcher();
private final URI baseUri = URI.create("/");
@@ -89,7 +84,7 @@ public class GitConfigResourceTest {
when(repositoryHandler.getConfig()).thenReturn(gitConfig);
GitRepositoryConfigResource gitRepositoryConfigResource = new GitRepositoryConfigResource(repositoryConfigMapper, repositoryManager, new GitRepositoryConfigStoreProvider(configurationStoreFactory));
GitConfigResource gitConfigResource = new GitConfigResource(dtoToConfigMapper, configToDtoMapper, repositoryHandler, of(gitRepositoryConfigResource));
dispatcher.getRegistry().addSingletonResource(gitConfigResource);
dispatcher.addSingletonResource(gitConfigResource);
when(scmPathInfoStore.get().getApiRestUri()).thenReturn(baseUri);
}
@@ -137,10 +132,11 @@ public class GitConfigResourceTest {
@Test
@SubjectAware(username = "writeOnly")
public void shouldNotGetConfigWhenNotAuthorized() throws URISyntaxException {
thrown.expectMessage("Subject does not have permission [configuration:read:git]");
public void shouldNotGetConfigWhenNotAuthorized() throws URISyntaxException, UnsupportedEncodingException {
MockHttpResponse response = get();
get();
assertEquals("Subject does not have permission [configuration:read:git]", response.getContentAsString());
assertEquals(HttpServletResponse.SC_FORBIDDEN, response.getStatus());
}
@Test
@@ -152,10 +148,11 @@ public class GitConfigResourceTest {
@Test
@SubjectAware(username = "readOnly")
public void shouldNotUpdateConfigWhenNotAuthorized() throws URISyntaxException {
thrown.expectMessage("Subject does not have permission [configuration:write:git]");
public void shouldNotUpdateConfigWhenNotAuthorized() throws URISyntaxException, UnsupportedEncodingException {
MockHttpResponse response = put();
put();
assertEquals("Subject does not have permission [configuration:write:git]", response.getContentAsString());
assertEquals(HttpServletResponse.SC_FORBIDDEN, response.getStatus());
}
@Test