performance: fix unit tests
This commit is contained in:
@@ -145,7 +145,7 @@ public class PromoteKeyOperationTest {
|
|||||||
|
|
||||||
for (CanonicalizedSecretKey key : ring.secretKeyIterator()) {
|
for (CanonicalizedSecretKey key : ring.secretKeyIterator()) {
|
||||||
Assert.assertEquals("all subkeys must be divert-to-card",
|
Assert.assertEquals("all subkeys must be divert-to-card",
|
||||||
SecretKeyType.DIVERT_TO_CARD, key.getSecretKeyType());
|
SecretKeyType.DIVERT_TO_CARD, key.getSecretKeyTypeSuperExpensive());
|
||||||
Assert.assertArrayEquals("all subkeys must have correct iv",
|
Assert.assertArrayEquals("all subkeys must have correct iv",
|
||||||
aid, key.getIv());
|
aid, key.getIv());
|
||||||
}
|
}
|
||||||
@@ -176,12 +176,12 @@ public class PromoteKeyOperationTest {
|
|||||||
for (CanonicalizedSecretKey key : ring.secretKeyIterator()) {
|
for (CanonicalizedSecretKey key : ring.secretKeyIterator()) {
|
||||||
if (key.getKeyId() == keyId) {
|
if (key.getKeyId() == keyId) {
|
||||||
Assert.assertEquals("subkey must be divert-to-card",
|
Assert.assertEquals("subkey must be divert-to-card",
|
||||||
SecretKeyType.DIVERT_TO_CARD, key.getSecretKeyType());
|
SecretKeyType.DIVERT_TO_CARD, key.getSecretKeyTypeSuperExpensive());
|
||||||
Assert.assertArrayEquals("subkey must have correct iv",
|
Assert.assertArrayEquals("subkey must have correct iv",
|
||||||
aid, key.getIv());
|
aid, key.getIv());
|
||||||
} else {
|
} else {
|
||||||
Assert.assertEquals("some subkeys must be gnu dummy",
|
Assert.assertEquals("some subkeys must be gnu dummy",
|
||||||
SecretKeyType.GNU_DUMMY, key.getSecretKeyType());
|
SecretKeyType.GNU_DUMMY, key.getSecretKeyTypeSuperExpensive());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1254,7 +1254,7 @@ public class PgpKeyOperationTest {
|
|||||||
modified.getEncoded(), false, 0);
|
modified.getEncoded(), false, 0);
|
||||||
Assert.assertEquals("secret key type should be 'pin' after this",
|
Assert.assertEquals("secret key type should be 'pin' after this",
|
||||||
SecretKeyType.PIN,
|
SecretKeyType.PIN,
|
||||||
secretRing.getSecretKey().getSecretKeyType());
|
secretRing.getSecretKey().getSecretKeyTypeSuperExpensive());
|
||||||
|
|
||||||
// need to sleep for a sec, so the timestamp changes for notation data
|
// need to sleep for a sec, so the timestamp changes for notation data
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import org.openintents.openpgp.OpenPgpSignatureResult;
|
|||||||
import org.robolectric.RobolectricGradleTestRunner;
|
import org.robolectric.RobolectricGradleTestRunner;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
|
import org.robolectric.shadows.ShadowLog;
|
||||||
import org.spongycastle.jce.provider.BouncyCastleProvider;
|
import org.spongycastle.jce.provider.BouncyCastleProvider;
|
||||||
import org.sufficientlysecure.keychain.WorkaroundBuildConfig;
|
import org.sufficientlysecure.keychain.WorkaroundBuildConfig;
|
||||||
import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult;
|
import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult;
|
||||||
@@ -37,10 +38,12 @@ import org.sufficientlysecure.keychain.operations.results.OperationResult.Operat
|
|||||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedKeyRing;
|
import org.sufficientlysecure.keychain.pgp.CanonicalizedKeyRing;
|
||||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKey;
|
import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKey;
|
||||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing;
|
import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing;
|
||||||
|
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType;
|
||||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing;
|
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing;
|
||||||
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyInputParcel;
|
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyInputParcel;
|
||||||
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyOperation;
|
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyOperation;
|
||||||
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
|
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
|
||||||
|
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
||||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||||
@@ -64,6 +67,7 @@ public class InteropTest {
|
|||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUpOnce() throws Exception {
|
public static void setUpOnce() throws Exception {
|
||||||
Security.insertProviderAt(new BouncyCastleProvider(), 1);
|
Security.insertProviderAt(new BouncyCastleProvider(), 1);
|
||||||
|
ShadowLog.stream = System.out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -243,21 +247,45 @@ public class InteropTest {
|
|||||||
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(verify.getMasterKeyId()) : null;
|
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(verify.getMasterKeyId()) : null;
|
||||||
|
|
||||||
ProviderHelper helper = new ProviderHelper(RuntimeEnvironment.application) {
|
ProviderHelper helper = new ProviderHelper(RuntimeEnvironment.application) {
|
||||||
@Override
|
|
||||||
public CanonicalizedPublicKeyRing getCanonicalizedPublicKeyRing(Uri q)
|
@Override
|
||||||
throws NotFoundException {
|
public CachedPublicKeyRing getCachedPublicKeyRing(Uri queryUri) throws PgpKeyNotFoundException {
|
||||||
Assert.assertEquals(msg + ": query should be for verification key",
|
Assert.assertEquals(msg + ": query should be for the decryption key", queryUri, decryptUri);
|
||||||
q, verifyUri);
|
return new CachedPublicKeyRing(this, queryUri) {
|
||||||
return verify;
|
@Override
|
||||||
}
|
public long getMasterKeyId() throws PgpKeyNotFoundException {
|
||||||
@Override
|
return decrypt.getMasterKeyId();
|
||||||
public CanonicalizedSecretKeyRing getCanonicalizedSecretKeyRing(Uri q)
|
}
|
||||||
throws NotFoundException {
|
|
||||||
Assert.assertEquals(msg + ": query should be for the decryption key",
|
@Override
|
||||||
q, decryptUri);
|
public SecretKeyType getSecretKeyType(long keyId) throws NotFoundException {
|
||||||
return decrypt;
|
return decrypt.getSecretKey(keyId).getSecretKeyTypeSuperExpensive();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CanonicalizedPublicKeyRing getCanonicalizedPublicKeyRing(Uri q)
|
||||||
|
throws NotFoundException {
|
||||||
|
Assert.assertEquals(msg + ": query should be for verification key", q, verifyUri);
|
||||||
|
return verify;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CanonicalizedSecretKeyRing getCanonicalizedSecretKeyRing(Uri q)
|
||||||
|
throws NotFoundException {
|
||||||
|
Assert.assertEquals(msg + ": query should be for the decryption key", q, decryptUri);
|
||||||
|
return decrypt;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CanonicalizedSecretKeyRing getCanonicalizedSecretKeyRing(long masterKeyId)
|
||||||
|
throws NotFoundException {
|
||||||
|
Assert.assertEquals(msg + ": query should be for the decryption key",
|
||||||
|
masterKeyId, decrypt.getMasterKeyId());
|
||||||
|
return decrypt;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return new PgpDecryptVerifyOperation(RuntimeEnvironment.application, helper, null) {
|
return new PgpDecryptVerifyOperation(RuntimeEnvironment.application, helper, null) {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ public class ProviderHelperSaveTest {
|
|||||||
Assert.assertEquals("first subkey should be of type sign+certify",
|
Assert.assertEquals("first subkey should be of type sign+certify",
|
||||||
KeyFlags.CERTIFY_OTHER | KeyFlags.SIGN_DATA, (int) key.getKeyUsage());
|
KeyFlags.CERTIFY_OTHER | KeyFlags.SIGN_DATA, (int) key.getKeyUsage());
|
||||||
Assert.assertEquals("first subkey should be divert-to-card",
|
Assert.assertEquals("first subkey should be divert-to-card",
|
||||||
SecretKeyType.DIVERT_TO_CARD, key.getSecretKeyType());
|
SecretKeyType.DIVERT_TO_CARD, key.getSecretKeyTypeSuperExpensive());
|
||||||
Assert.assertTrue("canCertify() should be true", key.canCertify());
|
Assert.assertTrue("canCertify() should be true", key.canCertify());
|
||||||
Assert.assertTrue("canSign() should be true", key.canSign());
|
Assert.assertTrue("canSign() should be true", key.canSign());
|
||||||
|
|
||||||
@@ -168,7 +168,7 @@ public class ProviderHelperSaveTest {
|
|||||||
Assert.assertEquals("second subkey should be of type authenticate",
|
Assert.assertEquals("second subkey should be of type authenticate",
|
||||||
KeyFlags.AUTHENTICATION, (int) key.getKeyUsage());
|
KeyFlags.AUTHENTICATION, (int) key.getKeyUsage());
|
||||||
Assert.assertEquals("second subkey should be divert-to-card",
|
Assert.assertEquals("second subkey should be divert-to-card",
|
||||||
SecretKeyType.DIVERT_TO_CARD, key.getSecretKeyType());
|
SecretKeyType.DIVERT_TO_CARD, key.getSecretKeyTypeSuperExpensive());
|
||||||
Assert.assertTrue("canAuthenticate() should be true", key.canAuthenticate());
|
Assert.assertTrue("canAuthenticate() should be true", key.canAuthenticate());
|
||||||
|
|
||||||
// cached
|
// cached
|
||||||
@@ -182,7 +182,7 @@ public class ProviderHelperSaveTest {
|
|||||||
Assert.assertEquals("first subkey should be of type encrypt (both types)",
|
Assert.assertEquals("first subkey should be of type encrypt (both types)",
|
||||||
KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE, (int) key.getKeyUsage());
|
KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE, (int) key.getKeyUsage());
|
||||||
Assert.assertEquals("third subkey should be divert-to-card",
|
Assert.assertEquals("third subkey should be divert-to-card",
|
||||||
SecretKeyType.DIVERT_TO_CARD, key.getSecretKeyType());
|
SecretKeyType.DIVERT_TO_CARD, key.getSecretKeyTypeSuperExpensive());
|
||||||
Assert.assertTrue("canEncrypt() should be true", key.canEncrypt());
|
Assert.assertTrue("canEncrypt() should be true", key.canEncrypt());
|
||||||
|
|
||||||
// cached
|
// cached
|
||||||
@@ -237,7 +237,7 @@ public class ProviderHelperSaveTest {
|
|||||||
Assert.assertTrue("master key should have sign flag", ring.getPublicKey().canSign());
|
Assert.assertTrue("master key should have sign flag", ring.getPublicKey().canSign());
|
||||||
Assert.assertTrue("master key should have encrypt flag", ring.getPublicKey().canEncrypt());
|
Assert.assertTrue("master key should have encrypt flag", ring.getPublicKey().canEncrypt());
|
||||||
|
|
||||||
signId = ring.getSecretSignId();
|
signId = mProviderHelper.getCachedPublicKeyRing(masterKeyId).getSecretSignId();
|
||||||
Assert.assertNotEquals("encrypt id should not be 0", 0, signId);
|
Assert.assertNotEquals("encrypt id should not be 0", 0, signId);
|
||||||
Assert.assertNotEquals("encrypt key should be different from master key", masterKeyId, signId);
|
Assert.assertNotEquals("encrypt key should be different from master key", masterKeyId, signId);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user