mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 23:15:43 +01:00
Merge with 2.0.0-m3
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.github.sdorra.shiro.ShiroRule;
|
||||
import com.github.sdorra.shiro.SubjectAware;
|
||||
import com.google.inject.util.Providers;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import sonia.scm.web.JsonEnricherContext;
|
||||
import sonia.scm.web.VndMediaType;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import java.net.URI;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
@SubjectAware(configuration = "classpath:sonia/scm/configuration/shiro.ini")
|
||||
public class GitConfigInIndexResourceTest {
|
||||
|
||||
@Rule
|
||||
public final ShiroRule shiroRule = new ShiroRule();
|
||||
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
private final ObjectNode root = objectMapper.createObjectNode();
|
||||
private final GitConfigInIndexResource gitConfigInIndexResource;
|
||||
|
||||
public GitConfigInIndexResourceTest() {
|
||||
root.put("_links", objectMapper.createObjectNode());
|
||||
ScmPathInfoStore pathInfoStore = new ScmPathInfoStore();
|
||||
pathInfoStore.set(() -> URI.create("/"));
|
||||
gitConfigInIndexResource = new GitConfigInIndexResource(Providers.of(pathInfoStore), objectMapper);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SubjectAware(username = "admin", password = "secret")
|
||||
public void admin() {
|
||||
JsonEnricherContext context = new JsonEnricherContext(URI.create("/index"), MediaType.valueOf(VndMediaType.INDEX), root);
|
||||
|
||||
gitConfigInIndexResource.enrich(context);
|
||||
|
||||
assertEquals("/v2/config/git", root.get("_links").get("gitConfig").get("href").asText());
|
||||
}
|
||||
|
||||
@Test
|
||||
@SubjectAware(username = "readOnly", password = "secret")
|
||||
public void user() {
|
||||
JsonEnricherContext context = new JsonEnricherContext(URI.create("/index"), MediaType.valueOf(VndMediaType.INDEX), root);
|
||||
|
||||
gitConfigInIndexResource.enrich(context);
|
||||
|
||||
assertFalse(root.get("_links").iterator().hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void anonymous() {
|
||||
JsonEnricherContext context = new JsonEnricherContext(URI.create("/index"), MediaType.valueOf(VndMediaType.INDEX), root);
|
||||
|
||||
gitConfigInIndexResource.enrich(context);
|
||||
|
||||
assertFalse(root.get("_links").iterator().hasNext());
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
@@ -33,14 +34,17 @@
|
||||
|
||||
package sonia.scm.repository.spi;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.io.Files;
|
||||
import org.junit.Test;
|
||||
import sonia.scm.repository.Changeset;
|
||||
import sonia.scm.repository.ChangesetPagingResult;
|
||||
import sonia.scm.repository.GitConstants;
|
||||
import sonia.scm.repository.Modifications;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import static java.nio.charset.Charset.defaultCharset;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -48,8 +52,6 @@ import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Unit tests for {@link GitLogCommand}.
|
||||
*
|
||||
@@ -72,6 +74,8 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
|
||||
assertEquals("86a6645eceefe8b9a247db5eb16e3d89a7e6e6d1", result.getChangesets().get(1).getId());
|
||||
assertEquals("592d797cd36432e591416e8b2b98154f4f163411", result.getChangesets().get(2).getId());
|
||||
assertEquals("435df2f061add3589cb326cc64be9b9c3897ceca", result.getChangesets().get(3).getId());
|
||||
assertEquals("master", result.getBranchName());
|
||||
assertTrue(result.getChangesets().stream().allMatch(r -> r.getBranches().isEmpty()));
|
||||
|
||||
// set default branch and fetch again
|
||||
repository.setProperty(GitConstants.PROPERTY_DEFAULT_BRANCH, "test-branch");
|
||||
@@ -79,10 +83,12 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
|
||||
result = createCommand().getChangesets(new LogCommandRequest());
|
||||
|
||||
assertNotNull(result);
|
||||
assertEquals("test-branch", result.getBranchName());
|
||||
assertEquals(3, result.getTotal());
|
||||
assertEquals("3f76a12f08a6ba0dc988c68b7f0b2cd190efc3c4", result.getChangesets().get(0).getId());
|
||||
assertEquals("592d797cd36432e591416e8b2b98154f4f163411", result.getChangesets().get(1).getId());
|
||||
assertEquals("435df2f061add3589cb326cc64be9b9c3897ceca", result.getChangesets().get(2).getId());
|
||||
assertTrue(result.getChangesets().stream().allMatch(r -> r.getBranches().isEmpty()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -210,6 +216,32 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
|
||||
assertEquals("435df2f061add3589cb326cc64be9b9c3897ceca", c2.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFindDefaultBranchFromHEAD() throws Exception {
|
||||
setRepositoryHeadReference("ref: refs/heads/test-branch");
|
||||
|
||||
ChangesetPagingResult changesets = createCommand().getChangesets(new LogCommandRequest());
|
||||
|
||||
assertEquals("test-branch", changesets.getBranchName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFindMasterBranchWhenHEADisNoRef() throws Exception {
|
||||
setRepositoryHeadReference("592d797cd36432e591416e8b2b98154f4f163411");
|
||||
|
||||
ChangesetPagingResult changesets = createCommand().getChangesets(new LogCommandRequest());
|
||||
|
||||
assertEquals("master", changesets.getBranchName());
|
||||
}
|
||||
|
||||
private void setRepositoryHeadReference(String s) throws IOException {
|
||||
Files.write(s, repositoryHeadReferenceFile(), defaultCharset());
|
||||
}
|
||||
|
||||
private File repositoryHeadReferenceFile() {
|
||||
return new File(repositoryDirectory, "HEAD");
|
||||
}
|
||||
|
||||
private GitLogCommand createCommand()
|
||||
{
|
||||
return new GitLogCommand(createContext(), repository);
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
readOnly = secret, reader
|
||||
writeOnly = secret, writer
|
||||
readWrite = secret, readerWriter
|
||||
admin = secret, admin
|
||||
|
||||
[roles]
|
||||
reader = configuration:read:git
|
||||
writer = configuration:write:git
|
||||
readerWriter = configuration:*:git
|
||||
admin = *
|
||||
|
||||
Reference in New Issue
Block a user