diff options
author | Vincent Breitmoser <valodim@mugenguild.com> | 2014-09-02 12:36:04 +0200 |
---|---|---|
committer | Vincent Breitmoser <valodim@mugenguild.com> | 2014-09-02 12:36:04 +0200 |
commit | 84d16bd1f756f5c3317280d4d26ac3216b11b8af (patch) | |
tree | e5040f29d9518d67f863ed245cc233cbcc433e72 /OpenKeychain-Test/src/test/java/org/sufficientlysecure | |
parent | b547258df6a66a0e4d0830f5c10662a3a7095b0c (diff) | |
download | open-keychain-84d16bd1f756f5c3317280d4d26ac3216b11b8af.tar.gz open-keychain-84d16bd1f756f5c3317280d4d26ac3216b11b8af.tar.bz2 open-keychain-84d16bd1f756f5c3317280d4d26ac3216b11b8af.zip |
add test for divert-to-card
Diffstat (limited to 'OpenKeychain-Test/src/test/java/org/sufficientlysecure')
-rw-r--r-- | OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/provider/ProviderHelperSaveTest.java | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/provider/ProviderHelperSaveTest.java b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/provider/ProviderHelperSaveTest.java index b5d950f59..d117f2103 100644 --- a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/provider/ProviderHelperSaveTest.java +++ b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/provider/ProviderHelperSaveTest.java @@ -25,8 +25,12 @@ import org.junit.runner.RunWith; import org.robolectric.Robolectric; import org.robolectric.RobolectricTestRunner; import org.robolectric.shadows.ShadowLog; +import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey; +import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType; +import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.service.OperationResults.SaveKeyringResult; +import org.sufficientlysecure.keychain.util.ProgressScaler; import java.io.IOException; import java.util.Iterator; @@ -40,13 +44,13 @@ public class ProviderHelperSaveTest { ShadowLog.stream = System.out; } - @Test - public void testLongKeyIdCollision() throws Exception { + @Test public void testImportCooperPair() throws Exception { + // insert two keys with same long key id, make sure the second one gets rejected either way! UncachedKeyRing first = - readRingFromResource("/cooperpair/9E669861368BCA0BE42DAF7DDDA252EBB8EBE1AF.asc"); + readRingFromResource("/test-keys/cooperpair/9E669861368BCA0BE42DAF7DDDA252EBB8EBE1AF.asc"); UncachedKeyRing second = - readRingFromResource("/cooperpair/A55120427374F3F7AA5F1166DDA252EBB8EBE1AF.asc"); + readRingFromResource("/test-keys/cooperpair/A55120427374F3F7AA5F1166DDA252EBB8EBE1AF.asc"); SaveKeyringResult result; @@ -66,6 +70,41 @@ public class ProviderHelperSaveTest { } + @Test public void testImportDivertToCard() throws Exception { + + UncachedKeyRing pub = + readRingFromResource("/test-keys/divert_to_card_pub.asc"); + UncachedKeyRing sec = + readRingFromResource("/test-keys/divert_to_card_sec.asc"); + long keyId = sec.getMasterKeyId(); + + SaveKeyringResult result; + + // insert both keys, second should fail + result = new ProviderHelper(Robolectric.application).savePublicKeyRing(pub); + Assert.assertTrue("import of public keyring should succeed", result.success()); + result = new ProviderHelper(Robolectric.application).saveSecretKeyRing(sec, + new ProgressScaler()); + Assert.assertTrue("import of secret keyring should succeed", result.success()); + + CanonicalizedSecretKeyRing secRing = + new ProviderHelper(Robolectric.application).getCanonicalizedSecretKeyRing(keyId); + for (CanonicalizedSecretKey key : secRing.secretKeyIterator()) { + Assert.assertEquals("all subkeys should be divert-to-key", + SecretKeyType.DIVERT_TO_CARD, key.getSecretKeyType()); + } + + /* + CachedPublicKeyRing cachedRing = + new ProviderHelper(Robolectric.application).getCachedPublicKeyRing(keyId); + for (CanonicalizedSecretKey key : cachedRing.()) { + Assert.assertEquals("all subkeys should be divert-to-key", + SecretKeyType.DIVERT_TO_CARD, key.getSecretKeyType()); + } + */ + + } + UncachedKeyRing readRingFromResource(String name) throws Exception { return UncachedKeyRing.fromStream(ProviderHelperSaveTest.class.getResourceAsStream(name)).next(); } |