From 8f6b7e27f1bda9606da35afee05b675f55b25a8e Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Thu, 11 Sep 2014 22:49:39 +0200 Subject: [PATCH] editKey: add test case for previous commit --- .../keychain/pgp/PgpKeyOperationTest.java | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperationTest.java b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperationTest.java index d80a674e0..1992c40ca 100644 --- a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperationTest.java +++ b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperationTest.java @@ -30,6 +30,8 @@ import org.robolectric.shadows.ShadowLog; import org.spongycastle.bcpg.BCPGInputStream; import org.spongycastle.bcpg.Packet; import org.spongycastle.bcpg.PacketTags; +import org.spongycastle.bcpg.S2K; +import org.spongycastle.bcpg.SecretKeyPacket; import org.spongycastle.bcpg.SecretSubkeyPacket; import org.spongycastle.bcpg.SignaturePacket; import org.spongycastle.bcpg.UserIDPacket; @@ -687,6 +689,58 @@ public class PgpKeyOperationTest { } } + @Test + public void testSubkeyStrip() throws Exception { + + long keyId = KeyringTestingHelper.getSubkeyId(ring, 1); + parcel.mStripSubKeys.add(keyId); + applyModificationWithChecks(parcel, ring, onlyA, onlyB); + + Assert.assertEquals("one extra packet in original", 1, onlyA.size()); + Assert.assertEquals("one extra packet in modified", 1, onlyB.size()); + + Assert.assertEquals("old packet must be secret subkey", + PacketTags.SECRET_SUBKEY, onlyA.get(0).tag); + Assert.assertEquals("new packet must be secret subkey", + PacketTags.SECRET_SUBKEY, onlyB.get(0).tag); + + Packet p = new BCPGInputStream(new ByteArrayInputStream(onlyB.get(0).buf)).readPacket(); + Assert.assertEquals("new packet should have GNU_DUMMY S2K type", + S2K.GNU_DUMMY_S2K, ((SecretSubkeyPacket) p).getS2K().getType()); + Assert.assertEquals("new packet should have GNU_DUMMY protection mode 0x1", + 0x1, ((SecretSubkeyPacket) p).getS2K().getProtectionMode()); + Assert.assertEquals("new packet secret key data should have length zero", + 0, ((SecretSubkeyPacket) p).getSecretKeyData().length); + Assert.assertNull("new packet should have no iv data", ((SecretSubkeyPacket) p).getIV()); + + } + + @Test + public void testMasterStrip() throws Exception { + + long keyId = ring.getMasterKeyId(); + parcel.mStripSubKeys.add(keyId); + applyModificationWithChecks(parcel, ring, onlyA, onlyB); + + Assert.assertEquals("one extra packet in original", 1, onlyA.size()); + Assert.assertEquals("one extra packet in modified", 1, onlyB.size()); + + Assert.assertEquals("old packet must be secret key", + PacketTags.SECRET_KEY, onlyA.get(0).tag); + Assert.assertEquals("new packet must be secret key", + PacketTags.SECRET_KEY, onlyB.get(0).tag); + + Packet p = new BCPGInputStream(new ByteArrayInputStream(onlyB.get(0).buf)).readPacket(); + Assert.assertEquals("new packet should have GNU_DUMMY S2K type", + S2K.GNU_DUMMY_S2K, ((SecretKeyPacket) p).getS2K().getType()); + Assert.assertEquals("new packet should have GNU_DUMMY protection mode 0x1", + 0x1, ((SecretKeyPacket) p).getS2K().getProtectionMode()); + Assert.assertEquals("new packet secret key data should have length zero", + 0, ((SecretKeyPacket) p).getSecretKeyData().length); + Assert.assertNull("new packet should have no iv data", ((SecretKeyPacket) p).getIV()); + + } + @Test public void testUserIdRevoke() throws Exception {