mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-12-23 23:48:51 -05:00
fix test for new PgpDecryptVerify
This commit is contained in:
parent
e58ba0f4bb
commit
7af0219857
@ -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());
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
|
@ -145,7 +145,8 @@ public class PassphraseCacheService extends Service {
|
||||
* @return passphrase or null (if no passphrase is cached for this keyId)
|
||||
*/
|
||||
public static String getCachedPassphrase(Context context, long masterKeyId, long subKeyId) throws KeyNotFoundException {
|
||||
Log.d(Constants.TAG, "PassphraseCacheService.getCachedPassphrase() get masterKeyId for " + masterKeyId);
|
||||
Log.d(Constants.TAG, "PassphraseCacheService.getCachedPassphrase() for masterKeyId "
|
||||
+ masterKeyId + ", subKeyId " + subKeyId);
|
||||
|
||||
Intent intent = new Intent(context, PassphraseCacheService.class);
|
||||
intent.setAction(ACTION_PASSPHRASE_CACHE_GET);
|
||||
@ -194,6 +195,7 @@ public class PassphraseCacheService extends Service {
|
||||
case MSG_PASSPHRASE_CACHE_GET_KEY_NOT_FOUND:
|
||||
throw new KeyNotFoundException();
|
||||
default:
|
||||
Log.e(Constants.TAG, "timeout case!");
|
||||
throw new KeyNotFoundException("should not happen!");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user