diff options
author | Dave Borowitz <dborowitz@google.com> | 2015-07-13 12:03:42 -0700 |
---|---|---|
committer | Dave Borowitz <dborowitz@google.com> | 2015-07-15 18:09:41 -0700 |
commit | 5706c8e38e501bb1f9721167ca6cbcc169df8b10 (patch) | |
tree | 2229ca975a6d222bd3ace282cb7a15fd2a26b4ce /org.eclipse.jgit.test | |
parent | 16ba9919dbb8802c6566dfda3b5bc02a162ec4a4 (diff) | |
download | jgit-5706c8e38e501bb1f9721167ca6cbcc169df8b10.tar.gz jgit-5706c8e38e501bb1f9721167ca6cbcc169df8b10.zip |
Allow saving push certs on a subset of refs
Consider a BatchRefUpdate produced by Gerrit Code Review, where the
original command pushed over the wire might refer to
"refs/for/master", but that command is ignored and replaced with some
additional commands like creating "refs/changes/34/1234/1". We do not
want to store the cert in "refs/for/master@{cert}", since that may
lead someone looking to the ref to the incorrect conclusion that that
ref exists.
Add a separate put method that takes a collection of commands, and
only stores certs on those refs that have a matching command in the
cert.
Change-Id: I4661bfe2ead28a2883b33a4e3dfe579b3157d68a
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushCertificateStoreTest.java | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushCertificateStoreTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushCertificateStoreTest.java index 77a0708e1b..ef479ffaaf 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushCertificateStoreTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushCertificateStoreTest.java @@ -55,6 +55,7 @@ import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; @@ -284,15 +285,36 @@ public class PushCertificateStoreTest { List<ReceiveCommand> commands = batch.getCommands(); assertEquals(1, commands.size()); ReceiveCommand cmd = commands.get(0); + assertEquals("refs/meta/push-certs", cmd.getRefName()); + assertEquals(ReceiveCommand.Result.NOT_ATTEMPTED, cmd.getResult()); try (RevWalk rw = new RevWalk(repo)) { - assertEquals("refs/meta/push-certs", cmd.getRefName()); - assertEquals(ReceiveCommand.Result.NOT_ATTEMPTED, cmd.getResult()); batch.execute(rw, NullProgressMonitor.INSTANCE); assertEquals(ReceiveCommand.Result.OK, cmd.getResult()); } } + @Test + public void putMatchingWithNoMatchingRefs() throws Exception { + PushCertificate addMaster = newCert( + command(zeroId(), ID1, "refs/heads/master"), + command(zeroId(), ID2, "refs/heads/branch")); + store.put(addMaster, newIdent(), Collections.<ReceiveCommand> emptyList()); + assertEquals(NO_CHANGE, store.save()); + } + + @Test + public void putMatchingWithSomeMatchingRefs() throws Exception { + PushCertificate addMasterAndBranch = newCert( + command(zeroId(), ID1, "refs/heads/master"), + command(zeroId(), ID2, "refs/heads/branch")); + store.put(addMasterAndBranch, newIdent(), + Collections.singleton(addMasterAndBranch.getCommands().get(0))); + assertEquals(NEW, store.save()); + assertCerts("refs/heads/master", addMasterAndBranch); + assertCerts("refs/heads/branch"); + } + private PersonIdent newIdent() { return new PersonIdent( "A U. Thor", "author@example.com", ts.getAndIncrement(), 0); |