diff options
author | Vincent Breitmoser <valodim@mugenguild.com> | 2014-09-11 22:49:39 +0200 |
---|---|---|
committer | Vincent Breitmoser <valodim@mugenguild.com> | 2014-09-11 22:49:39 +0200 |
commit | 8f6b7e27f1bda9606da35afee05b675f55b25a8e (patch) | |
tree | 547770441815e5d3e98be5cd751064dbcdac1763 /OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain | |
parent | f7444880171064377636cd11b5e9fe0ce7c2a827 (diff) | |
download | open-keychain-8f6b7e27f1bda9606da35afee05b675f55b25a8e.tar.gz open-keychain-8f6b7e27f1bda9606da35afee05b675f55b25a8e.tar.bz2 open-keychain-8f6b7e27f1bda9606da35afee05b675f55b25a8e.zip |
editKey: add test case for previous commit
Diffstat (limited to 'OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain')
-rw-r--r-- | OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperationTest.java | 54 |
1 files changed, 54 insertions, 0 deletions
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; @@ -688,6 +690,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 { UncachedKeyRing modified; |