diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitTagCommand.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitTagCommand.java index 0dc42922d2..4cf65af3c6 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitTagCommand.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitTagCommand.java @@ -65,14 +65,12 @@ import static sonia.scm.ContextEntry.ContextBuilder.entity; import static sonia.scm.NotFoundException.notFound; public class GitTagCommand extends AbstractGitCommand implements TagCommand { - private final GPG gpg; private final HookContextFactory hookContextFactory; private final ScmEventBus eventBus; @Inject - GitTagCommand(GitContext context, GPG gpg, HookContextFactory hookContextFactory, ScmEventBus eventBus) { + GitTagCommand(GitContext context, HookContextFactory hookContextFactory, ScmEventBus eventBus) { super(context); - this.gpg = gpg; this.hookContextFactory = hookContextFactory; this.eventBus = eventBus; } @@ -114,20 +112,12 @@ public class GitTagCommand extends AbstractGitCommand implements TagCommand { User user = SecurityUtils.getSubject().getPrincipals().oneByType(User.class); PersonIdent taggerIdent = new PersonIdent(user.getDisplayName(), user.getMail()); -// Ref ref = git.tag() .setObjectId(revObject) .setTagger(taggerIdent) .setName(name) .call(); -// Uncomment lines once jgit added support for signing tags -// try (RevWalk walk = new RevWalk(git.getRepository())) { -// revObject = walk.parseTag(ref.getObjectId()); -// final Optional tagSignature = GitUtil.getTagSignature(revObject, gpg, walk); -// tagSignature.ifPresent(tag::addSignature); -// } - eventBus.post(new PostReceiveRepositoryHookEvent(hookEvent)); return tag; diff --git a/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/GitTagCommandTest.java b/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/GitTagCommandTest.java index 0225d40b5d..77178a3e4b 100644 --- a/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/GitTagCommandTest.java +++ b/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/GitTagCommandTest.java @@ -24,7 +24,12 @@ package sonia.scm.repository.spi; +import org.apache.shiro.SecurityUtils; +import org.apache.shiro.mgt.DefaultSecurityManager; +import org.apache.shiro.subject.Subject; +import org.apache.shiro.util.ThreadContext; import org.eclipse.jgit.lib.GpgSigner; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -42,6 +47,7 @@ import sonia.scm.repository.api.HookContextFactory; import sonia.scm.repository.api.TagDeleteRequest; import sonia.scm.repository.api.TagCreateRequest; import sonia.scm.security.GPG; +import sonia.scm.util.MockUtil; import java.io.IOException; import java.util.List; @@ -65,16 +71,34 @@ public class GitTagCommandTest extends AbstractGitCommandTestBase { @Mock private ScmEventBus eventBus; + private Subject subject; + @Before public void setSigner() { GpgSigner.setDefault(new GitTestHelper.SimpleGpgSigner()); } + @Before + public void bindThreadContext() { + SecurityUtils.setSecurityManager(new DefaultSecurityManager()); + subject = MockUtil.createUserSubject(SecurityUtils.getSecurityManager()); + ThreadContext.bind(subject); + } + + @After + public void unbindThreadContext() { + ThreadContext.unbindSubject(); + ThreadContext.unbindSecurityManager(); + } + @Test public void shouldCreateATag() throws IOException { createCommand().create(new TagCreateRequest("592d797cd36432e591416e8b2b98154f4f163411", "newtag")); - Optional tag = findTag(createContext(), "newtag"); - assertThat(tag).isNotEmpty(); + Optional optionalTag = findTag(createContext(), "newtag"); + assertThat(optionalTag).isNotEmpty(); + final Tag tag = optionalTag.get(); + assertThat(tag.getName()).isEqualTo("newtag"); + assertThat(tag.getRevision()).isEqualTo("592d797cd36432e591416e8b2b98154f4f163411"); } @Test @@ -126,7 +150,7 @@ public class GitTagCommandTest extends AbstractGitCommandTestBase { } private GitTagCommand createCommand() { - return new GitTagCommand(createContext(), gpg, hookContextFactory, eventBus); + return new GitTagCommand(createContext(), hookContextFactory, eventBus); } private List readTags(GitContext context) throws IOException {