From 036a8865814b00f576b261c82e37a36475391451 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Fri, 11 Jul 2014 03:27:28 +0200 Subject: [PATCH] test: test subkey revocation --- .../keychain/tests/PgpKeyOperationTest.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/tests/PgpKeyOperationTest.java b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/tests/PgpKeyOperationTest.java index f55e638f2..dc58fe5a7 100644 --- a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/tests/PgpKeyOperationTest.java +++ b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/tests/PgpKeyOperationTest.java @@ -171,6 +171,41 @@ public class PgpKeyOperationTest { } + @Test + public void testSubkeyRevoke() throws Exception { + + SaveKeyringParcel parcel = new SaveKeyringParcel(); + parcel.mMasterKeyId = ring.getMasterKeyId(); + parcel.mFingerprint = ring.getFingerprint(); + { + Iterator it = ring.getPublicKeys(); + it.next(); + parcel.revokeSubKeys.add(it.next().getKeyId()); + } + + UncachedKeyRing modified = applyModificationWithChecks(parcel, ring); + + ArrayList onlyA = new ArrayList(); + ArrayList onlyB = new ArrayList(); + + Assert.assertTrue("keyring must differ from original", KeyringTestingHelper.diffKeyrings( + ring.getEncoded(), modified.getEncoded(), onlyA, onlyB)); + + Assert.assertEquals("no extra packets in original", 0, onlyA.size()); + Assert.assertEquals("exactly one extra packet in modified", 1, onlyB.size()); + + Iterator it = onlyB.iterator(); + Packet p; + + p = new BCPGInputStream(new ByteArrayInputStream(it.next().buf)).readPacket(); + Assert.assertTrue("first new packet must be secret subkey", p instanceof SignaturePacket); + Assert.assertEquals("signature type must be subkey binding certificate", + PGPSignature.SUBKEY_REVOCATION, ((SignaturePacket) p).getSignatureType()); + Assert.assertEquals("signature must have been created by master key", + ring.getMasterKeyId(), ((SignaturePacket) p).getKeyID()); + + } + @Test public void testUserIdAdd() throws Exception {