aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain-Test
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2014-07-11 13:29:13 +0200
committerVincent Breitmoser <valodim@mugenguild.com>2014-07-11 13:29:13 +0200
commit4345e0309d0863267bbcad5089f141dd290ac65e (patch)
tree47e1939728c2a3c55343cf28d1cc999202ac59f2 /OpenKeychain-Test
parent9bae53f1019ec0114bfad6ad2b7d61c15f3f7480 (diff)
downloadopen-keychain-4345e0309d0863267bbcad5089f141dd290ac65e.tar.gz
open-keychain-4345e0309d0863267bbcad5089f141dd290ac65e.tar.bz2
open-keychain-4345e0309d0863267bbcad5089f141dd290ac65e.zip
test: add more user id tests
Diffstat (limited to 'OpenKeychain-Test')
-rw-r--r--OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/tests/PgpKeyOperationTest.java87
1 files changed, 85 insertions, 2 deletions
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 8bdde021a..b8aa1328f 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
@@ -197,6 +197,74 @@ public class PgpKeyOperationTest {
}
@Test
+ public void testUserIdRevokeReadd() throws Exception {
+
+ UncachedKeyRing modified;
+ String uid = ring.getPublicKey().getUnorderedUserIds().get(1);
+
+ { // revoke second user id
+
+ SaveKeyringParcel parcel = new SaveKeyringParcel();
+ parcel.mMasterKeyId = ring.getMasterKeyId();
+ parcel.mFingerprint = ring.getFingerprint();
+ parcel.revokeUserIds.add(uid);
+
+ modified = applyModificationWithChecks(parcel, ring, onlyA, onlyB);
+
+ Assert.assertEquals("no extra packets in original", 0, onlyA.size());
+ Assert.assertEquals("exactly one extra packet in modified", 1, onlyB.size());
+
+ Iterator<RawPacket> 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.CERTIFICATION_REVOCATION, ((SignaturePacket) p).getSignatureType());
+ Assert.assertEquals("signature must have been created by master key",
+ ring.getMasterKeyId(), ((SignaturePacket) p).getKeyID());
+
+ }
+
+ { // re-add second user id
+ SaveKeyringParcel parcel = new SaveKeyringParcel();
+ parcel.mMasterKeyId = ring.getMasterKeyId();
+ parcel.mFingerprint = ring.getFingerprint();
+ parcel.addUserIds.add(uid);
+
+ modified = applyModificationWithChecks(
+ parcel, modified, onlyA, onlyB, true, false);
+
+ Assert.assertEquals("exactly two outdated packets in original", 2, onlyA.size());
+ Assert.assertEquals("exactly one extra packet in modified", 1, onlyB.size());
+
+ Packet p;
+
+ p = new BCPGInputStream(new ByteArrayInputStream(onlyA.get(0).buf)).readPacket();
+ Assert.assertTrue("first outdated packet must be signature", p instanceof SignaturePacket);
+ Assert.assertEquals("first outdated signature type must be positive certification",
+ PGPSignature.POSITIVE_CERTIFICATION, ((SignaturePacket) p).getSignatureType());
+ Assert.assertEquals("first outdated signature must have been created by master key",
+ ring.getMasterKeyId(), ((SignaturePacket) p).getKeyID());
+
+ p = new BCPGInputStream(new ByteArrayInputStream(onlyA.get(1).buf)).readPacket();
+ Assert.assertTrue("second outdated packet must be signature", p instanceof SignaturePacket);
+ Assert.assertEquals("second outdated signature type must be certificate revocation",
+ PGPSignature.CERTIFICATION_REVOCATION, ((SignaturePacket) p).getSignatureType());
+ Assert.assertEquals("second outdated signature must have been created by master key",
+ ring.getMasterKeyId(), ((SignaturePacket) p).getKeyID());
+
+ p = new BCPGInputStream(new ByteArrayInputStream(onlyB.get(0).buf)).readPacket();
+ Assert.assertTrue("new packet must be signature ", p instanceof SignaturePacket);
+ Assert.assertEquals("new signature type must be positive certification",
+ PGPSignature.POSITIVE_CERTIFICATION, ((SignaturePacket) p).getSignatureType());
+ Assert.assertEquals("signature must have been created by master key",
+ ring.getMasterKeyId(), ((SignaturePacket) p).getKeyID());
+ }
+
+ }
+
+ @Test
public void testUserIdAdd() throws Exception {
SaveKeyringParcel parcel = new SaveKeyringParcel();
@@ -235,6 +303,7 @@ public class PgpKeyOperationTest {
public void testUserIdPrimary() throws Exception {
UncachedKeyRing modified = ring;
+ String uid = ring.getPublicKey().getUnorderedUserIds().get(1);
{ // first part, add new user id which is also primary
SaveKeyringParcel parcel = new SaveKeyringParcel();
@@ -243,7 +312,7 @@ public class PgpKeyOperationTest {
parcel.addUserIds.add("jack");
parcel.changePrimaryUserId = "jack";
- modified = applyModificationWithChecks(parcel, modified);
+ modified = applyModificationWithChecks(parcel, modified, onlyA, onlyB);
Assert.assertEquals("primary user id must be the one added",
"jack", modified.getPublicKey().getPrimaryUserId());
@@ -253,7 +322,7 @@ public class PgpKeyOperationTest {
SaveKeyringParcel parcel = new SaveKeyringParcel();
parcel.mMasterKeyId = ring.getMasterKeyId();
parcel.mFingerprint = ring.getFingerprint();
- parcel.changePrimaryUserId = "pink";
+ parcel.changePrimaryUserId = uid;
modified = applyModificationWithChecks(parcel, modified, onlyA, onlyB);
@@ -264,6 +333,20 @@ public class PgpKeyOperationTest {
"pink", modified.getPublicKey().getPrimaryUserId());
}
+ { // third part, change primary to a non-existent one
+ SaveKeyringParcel parcel = new SaveKeyringParcel();
+ parcel.mMasterKeyId = ring.getMasterKeyId();
+ parcel.mFingerprint = ring.getFingerprint();
+ //noinspection SpellCheckingInspection
+ parcel.changePrimaryUserId = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
+
+ WrappedSecretKeyRing secretRing = new WrappedSecretKeyRing(ring.getEncoded(), false, 0);
+ OperationResultParcel.OperationLog log = new OperationResultParcel.OperationLog();
+ modified = op.modifySecretKeyRing(secretRing, parcel, "swag", log, 0);
+
+ Assert.assertNull("changing primary user id to a non-existent one should fail", modified);
+ }
+
}