From 9f76d16a34da60077dcf7ab63cb5514dc349fbb1 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Thu, 1 Jul 2021 19:11:55 +0200 Subject: [PATCH] Execute more tests on both implementation providers --- .../pgpainless/key/info/KeyRingInfoTest.java | 20 +++++++++++++------ .../key/modification/AddUserIdTest.java | 15 +++++++++----- .../modification/ChangeExpirationTest.java | 7 ++++--- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/info/KeyRingInfoTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/info/KeyRingInfoTest.java index 2e5d3bd4..18ce27d4 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/info/KeyRingInfoTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/info/KeyRingInfoTest.java @@ -36,6 +36,8 @@ import org.bouncycastle.openpgp.PGPPublicKeyRing; import org.bouncycastle.openpgp.PGPSecretKey; import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.pgpainless.PGPainless; import org.pgpainless.algorithm.KeyFlag; import org.pgpainless.algorithm.PublicKeyAlgorithm; @@ -54,8 +56,10 @@ import org.pgpainless.util.Passphrase; public class KeyRingInfoTest { - @Test - public void testWithEmilsKeys() throws IOException, PGPException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void testWithEmilsKeys(ImplementationFactory implementationFactory) throws IOException, PGPException { + ImplementationFactory.setFactoryImplementation(implementationFactory); PGPSecretKeyRing secretKeys = TestKeys.getEmilSecretKeyRing(); PGPPublicKeyRing publicKeys = TestKeys.getEmilPublicKeyRing(); KeyRingInfo sInfo = PGPainless.inspectKeyRing(secretKeys); @@ -161,8 +165,10 @@ public class KeyRingInfoTest { KeyRingUtils.requireSecretKeyFrom(secretKeys, secretKeys.getPublicKey().getKeyID())); } - @Test - public void dummyS2KTest() throws PGPException, IOException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void dummyS2KTest(ImplementationFactory implementationFactory) throws PGPException, IOException { + ImplementationFactory.setFactoryImplementation(implementationFactory); String withDummyS2K = "-----BEGIN PGP PRIVATE KEY BLOCK-----\n" + "\n" + "lQCVBFZuSwwBBAC04VdUUq2REb7+IF/x21yOV3kIn798XRl7A7RiGcE9VpBjT5xM\n" + @@ -197,8 +203,10 @@ public class KeyRingInfoTest { assertTrue(new KeyInfo(secretKeys.getSecretKey()).hasDummyS2K()); } - @Test - public void testGetKeysWithFlagsAndExpiry() throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void testGetKeysWithFlagsAndExpiry(ImplementationFactory implementationFactory) throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException { + ImplementationFactory.setFactoryImplementation(implementationFactory); PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing() .withSubKey(KeySpec.getBuilder(KeyType.ECDH(EllipticCurve._BRAINPOOLP384R1)).withKeyFlags(KeyFlag.ENCRYPT_STORAGE).withDefaultAlgorithms()) .withSubKey(KeySpec.getBuilder(KeyType.ECDSA(EllipticCurve._BRAINPOOLP384R1)).withKeyFlags(KeyFlag.SIGN_DATA).withDefaultAlgorithms()) diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/modification/AddUserIdTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/modification/AddUserIdTest.java index 3872efbb..82c92305 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/modification/AddUserIdTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/modification/AddUserIdTest.java @@ -27,7 +27,6 @@ import java.util.NoSuchElementException; import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPSecretKeyRing; -import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; import org.pgpainless.PGPainless; @@ -69,15 +68,21 @@ public class AddUserIdTest { assertFalse(userIds.hasNext()); } - @Test - public void deleteUserId_noSuchElementExceptionForMissingUserId() throws IOException, PGPException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void deleteUserId_noSuchElementExceptionForMissingUserId(ImplementationFactory implementationFactory) throws IOException, PGPException { + ImplementationFactory.setFactoryImplementation(implementationFactory); + PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing(); assertThrows(NoSuchElementException.class, () -> PGPainless.modifyKeyRing(secretKeys) .deleteUserId("invalid@user.id", new UnprotectedKeysProtector())); } - @Test - public void deleteExistingAndAddNewUserIdToExistingKeyRing() throws PGPException, IOException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void deleteExistingAndAddNewUserIdToExistingKeyRing(ImplementationFactory implementationFactory) throws PGPException, IOException { + ImplementationFactory.setFactoryImplementation(implementationFactory); + final String ARMORED_PRIVATE_KEY = "-----BEGIN PGP PRIVATE KEY BLOCK-----\r\n\r\n" + "xVgEX6UIExYJKwYBBAHaRw8BAQdAMfHf64wPQ2LC9In5AKYU/KT1qWvI7e7a\r\n" + diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/modification/ChangeExpirationTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/modification/ChangeExpirationTest.java index bb3371ff..67076255 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/modification/ChangeExpirationTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/modification/ChangeExpirationTest.java @@ -24,7 +24,6 @@ import java.util.Date; import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPSecretKeyRing; -import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; import org.pgpainless.PGPainless; @@ -70,8 +69,10 @@ public class ChangeExpirationTest { assertNull(sInfo.getSubkeyExpirationDate(subKeyFingerprint)); } - @Test - public void setExpirationDateAndThenUnsetIt_OnSubkey() throws PGPException, IOException, InterruptedException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void setExpirationDateAndThenUnsetIt_OnSubkey(ImplementationFactory implementationFactory) throws PGPException, IOException, InterruptedException { + ImplementationFactory.setFactoryImplementation(implementationFactory); PGPSecretKeyRing secretKeys = TestKeys.getEmilSecretKeyRing(); KeyRingInfo sInfo = PGPainless.inspectKeyRing(secretKeys);