From 7af02198573a820f308faf675bdf01b4792be015 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Tue, 14 Oct 2014 16:35:48 +0200 Subject: fix test for new PgpDecryptVerify --- .../keychain/pgp/PgpEncryptDecryptTest.java | 47 +++++++++++++++------- 1 file changed, 32 insertions(+), 15 deletions(-) (limited to 'OpenKeychain-Test/src') diff --git a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java index c5136b5cb..9dc8f8934 100644 --- a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java +++ b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java @@ -105,7 +105,6 @@ public class PgpEncryptDecryptTest { providerHelper.saveSecretKeyRing(mStaticRing1, new ProgressScaler()); } - /* @Test public void testSymmetricEncryptDecrypt() { @@ -117,9 +116,9 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); InputData data = new InputData(in, in.available()); - Builder b = new PgpSignEncrypt.Builder( + Builder b = new PgpSignEncrypt.Builder(Robolectric.application, new ProviderHelper(Robolectric.application), - new DummyPassphraseCache(mPassphrase, 0L), + null, // new DummyPassphraseCache(mPassphrase, 0L) data, out); b.setSymmetricPassphrase(mPassphrase); @@ -136,9 +135,10 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(ciphertext); InputData data = new InputData(in, in.available()); - PgpDecryptVerify.Builder b = new PgpDecryptVerify.Builder( + PgpDecryptVerify.Builder b = new PgpDecryptVerify.Builder(Robolectric.application, new ProviderHelper(Robolectric.application), - new DummyPassphraseCache(mPassphrase, 0L), data, out); + null, // new DummyPassphraseCache(mPassphrase, 0L), + data, out); b.setPassphrase(mPassphrase); DecryptVerifyResult result = b.build().execute(); Assert.assertTrue("decryption must succeed", result.success()); @@ -154,8 +154,10 @@ public class PgpEncryptDecryptTest { InputData data = new InputData(in, in.available()); PgpDecryptVerify.Builder b = new PgpDecryptVerify.Builder( + Robolectric.application, new ProviderHelper(Robolectric.application), - new DummyPassphraseCache(mPassphrase, 0L), data, out); + null, // new DummyPassphraseCache(mPassphrase, 0L), + data, out); b.setPassphrase(mPassphrase + "x"); DecryptVerifyResult result = b.build().execute(); Assert.assertFalse("decryption must succeed", result.success()); @@ -170,8 +172,10 @@ public class PgpEncryptDecryptTest { InputData data = new InputData(in, in.available()); PgpDecryptVerify.Builder b = new PgpDecryptVerify.Builder( + Robolectric.application, new ProviderHelper(Robolectric.application), - new DummyPassphraseCache(mPassphrase, 0L), data, out); + null, // new DummyPassphraseCache(mPassphrase, 0L), + data, out); DecryptVerifyResult result = b.build().execute(); Assert.assertFalse("decryption must succeed", result.success()); Assert.assertEquals("decrypted plaintext should be empty", 0, out.size()); @@ -192,8 +196,9 @@ public class PgpEncryptDecryptTest { InputData data = new InputData(in, in.available()); Builder b = new PgpSignEncrypt.Builder( + Robolectric.application, new ProviderHelper(Robolectric.application), - new DummyPassphraseCache(mPassphrase, 0L), + null, // new DummyPassphraseCache(mPassphrase, 0L), data, out); b.setEncryptionMasterKeyIds(new long[]{ mStaticRing1.getMasterKeyId() }); @@ -211,8 +216,10 @@ public class PgpEncryptDecryptTest { InputData data = new InputData(in, in.available()); PgpDecryptVerify.Builder b = new PgpDecryptVerify.Builder( + Robolectric.application, new ProviderHelper(Robolectric.application), - new DummyPassphraseCache(null, null), data, out); + null, // new DummyPassphraseCache(null, null), + data, out); b.setPassphrase(mKeyPhrase1); DecryptVerifyResult result = b.build().execute(); Assert.assertTrue("decryption with provided passphrase must succeed", result.success()); @@ -221,37 +228,47 @@ public class PgpEncryptDecryptTest { Assert.assertNull("signature be empty", result.getSignatureResult()); } - { // decryption with passphrase cached should succeed + // TODO how to test passphrase cache? + + /*{ // decryption with passphrase cached should succeed ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayInputStream in = new ByteArrayInputStream(ciphertext); InputData data = new InputData(in, in.available()); + PassphraseCacheService.addCachedPassphrase( + Robolectric.application, mStaticRing1.getMasterKeyId(), + mStaticRing1.getMasterKeyId(), mKeyPhrase1, "dummy"); + PgpDecryptVerify.Builder b = new PgpDecryptVerify.Builder( + Robolectric.application, new ProviderHelper(Robolectric.application), - new DummyPassphraseCache(mKeyPhrase1, null), data, out); + null, // new DummyPassphraseCache(mKeyPhrase1, null), + data, out); DecryptVerifyResult result = b.build().execute(); Assert.assertTrue("decryption with cached passphrase must succeed", result.success()); Assert.assertArrayEquals("decrypted ciphertext with cached passphrase should equal plaintext", out.toByteArray(), plaintext.getBytes()); Assert.assertNull("signature should be empty", result.getSignatureResult()); - } + }*/ - { // decryption with no passphrase provided should return status pending + /*{ // decryption with no passphrase provided should return status pending ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayInputStream in = new ByteArrayInputStream(ciphertext); InputData data = new InputData(in, in.available()); PgpDecryptVerify.Builder b = new PgpDecryptVerify.Builder( + Robolectric.application, new ProviderHelper(Robolectric.application), - new DummyPassphraseCache(null, null), data, out); + null, // new DummyPassphraseCache(null, null), + data, out); DecryptVerifyResult result = b.build().execute(); Assert.assertFalse("decryption with no passphrase must return pending", result.success()); Assert.assertTrue("decryption with no passphrase should return pending", result.isPending()); Assert.assertEquals("decryption with no passphrase should return pending passphrase", DecryptVerifyResult.RESULT_PENDING_ASYM_PASSPHRASE, result.getResult()); - } + }*/ } -- cgit v1.2.3