From 0321a6170cac50862d5fb22902b337f3e34a6d3b Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Sat, 3 Jul 2021 12:56:42 +0200 Subject: [PATCH] Execute signature related tests on all implementations --- .../signature/KeyRevocationTest.java | 18 ++++-- .../SignatureChainValidatorTest.java | 57 +++++++++++++------ 2 files changed, 53 insertions(+), 22 deletions(-) diff --git a/pgpainless-core/src/test/java/org/pgpainless/signature/KeyRevocationTest.java b/pgpainless-core/src/test/java/org/pgpainless/signature/KeyRevocationTest.java index a70c5921..bd93b183 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/signature/KeyRevocationTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/signature/KeyRevocationTest.java @@ -25,16 +25,21 @@ import java.util.Date; import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPPublicKeyRing; import org.bouncycastle.openpgp.PGPSignature; -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.exception.SignatureValidationException; +import org.pgpainless.implementation.ImplementationFactory; public class KeyRevocationTest { private static final String data = "Hello, World"; - @Test - public void subkeySignsPrimaryKeyRevokedNoReason() throws IOException, PGPException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + public void subkeySignsPrimaryKeyRevokedNoReason(ImplementationFactory implementationFactory) throws IOException, PGPException { + ImplementationFactory.setFactoryImplementation(implementationFactory); + String key = "-----BEGIN PGP ARMORED FILE-----\n" + "Comment: ASCII Armor added by openpgp-interoperability-test-suite\n" + "\n" + @@ -178,8 +183,11 @@ public class KeyRevocationTest { * * @see Sequoia Test-Suite */ - @Test - public void subkeySignsPrimaryKeyNotRevoked() throws IOException, PGPException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + public void subkeySignsPrimaryKeyNotRevoked(ImplementationFactory implementationFactory) throws IOException, PGPException { + ImplementationFactory.setFactoryImplementation(implementationFactory); + String key = "-----BEGIN PGP ARMORED FILE-----\n" + "Comment: ASCII Armor added by openpgp-interoperability-test-suite\n" + "\n" + diff --git a/pgpainless-core/src/test/java/org/pgpainless/signature/SignatureChainValidatorTest.java b/pgpainless-core/src/test/java/org/pgpainless/signature/SignatureChainValidatorTest.java index 849f202a..60da5ac4 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/signature/SignatureChainValidatorTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/signature/SignatureChainValidatorTest.java @@ -27,9 +27,11 @@ import java.util.Date; import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPPublicKeyRing; import org.bouncycastle.openpgp.PGPSignature; -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.exception.SignatureValidationException; +import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.policy.Policy; public class SignatureChainValidatorTest { @@ -39,8 +41,11 @@ public class SignatureChainValidatorTest { * * @see Sequoia Test Suite */ - @Test - public void testPrimaryKeySignsAndIsHardRevokedUnknown() throws IOException, PGPException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + public void testPrimaryKeySignsAndIsHardRevokedUnknown(ImplementationFactory implementationFactory) throws IOException, PGPException { + ImplementationFactory.setFactoryImplementation(implementationFactory); + String key = "-----BEGIN PGP ARMORED FILE-----\n" + "Comment: ASCII Armor added by openpgp-interoperability-test-suite\n" + "\n" + @@ -188,8 +193,11 @@ public class SignatureChainValidatorTest { * Subkey signs, primary key is hard revoked with reason: unknown. * @see Sequoia Test Suite */ - @Test - public void testSubkeySignsPrimaryKeyIsHardRevokedUnknown() throws IOException, PGPException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + public void testSubkeySignsPrimaryKeyIsHardRevokedUnknown(ImplementationFactory implementationFactory) throws IOException, PGPException { + ImplementationFactory.setFactoryImplementation(implementationFactory); + String key = "-----BEGIN PGP ARMORED FILE-----\n" + "Comment: ASCII Armor added by openpgp-interoperability-test-suite\n" + "\n" + @@ -338,8 +346,11 @@ public class SignatureChainValidatorTest { * * @see Sequoia Test Suite */ - @Test - public void testSubkeySignsAndIsHardRevokedUnknown() throws IOException, PGPException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + public void testSubkeySignsAndIsHardRevokedUnknown(ImplementationFactory implementationFactory) throws IOException, PGPException { + ImplementationFactory.setFactoryImplementation(implementationFactory); + String keyWithHardRev = "-----BEGIN PGP ARMORED FILE-----\n" + "Comment: ASCII Armor added by openpgp-interoperability-test-suite\n" + "\n" + @@ -488,8 +499,11 @@ public class SignatureChainValidatorTest { * * @see Sequoia Test Suite */ - @Test - public void testPrimaryKeySignsAndIsSoftRevokedSuperseded() throws IOException, PGPException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + public void testPrimaryKeySignsAndIsSoftRevokedSuperseded(ImplementationFactory implementationFactory) throws IOException, PGPException { + ImplementationFactory.setFactoryImplementation(implementationFactory); + String keyWithSoftRev = "-----BEGIN PGP ARMORED FILE-----\n" + "Comment: ASCII Armor added by openpgp-interoperability-test-suite\n" + "\n" + @@ -643,8 +657,11 @@ public class SignatureChainValidatorTest { * * @see Sequoia Test Suite */ - @Test - public void testSubkeySignsPrimaryKeyIsSoftRevokedSuperseded() throws IOException, PGPException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + public void testSubkeySignsPrimaryKeyIsSoftRevokedSuperseded(ImplementationFactory implementationFactory) throws IOException, PGPException { + ImplementationFactory.setFactoryImplementation(implementationFactory); + String key = "-----BEGIN PGP ARMORED FILE-----\n" + "Comment: ASCII Armor added by openpgp-interoperability-test-suite\n" + "\n" + @@ -785,7 +802,7 @@ public class SignatureChainValidatorTest { "Signing key is revoked at this point"); assertDoesNotThrow(() -> SignatureChainValidator.validateSignatureChain( - valid, getSignedData(data), publicKeys, policy, validationDate), + valid, getSignedData(data), publicKeys, policy, validationDate), "Signing key is revalidated"); } @@ -794,8 +811,11 @@ public class SignatureChainValidatorTest { * * @see Sequoia Test Suite */ - @Test - public void testPrimaryKeySignsAndIsSoftRevokedRetired() throws IOException, PGPException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + public void testPrimaryKeySignsAndIsSoftRevokedRetired(ImplementationFactory implementationFactory) throws IOException, PGPException { + ImplementationFactory.setFactoryImplementation(implementationFactory); + String key = "-----BEGIN PGP ARMORED FILE-----\n" + "Comment: ASCII Armor added by openpgp-interoperability-test-suite\n" + "\n" + @@ -945,8 +965,11 @@ public class SignatureChainValidatorTest { * * @see Sequoia Test Suite */ - @Test - public void testTemporaryValidity() throws IOException, PGPException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + public void testTemporaryValidity(ImplementationFactory implementationFactory) throws IOException, PGPException { + ImplementationFactory.setFactoryImplementation(implementationFactory); + String keyA = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" + "Comment: D1A6 6E1A 23B1 82C9 980F 788C FBFC C82A 015E 7330\n" + "Comment: Bob Babbage \n" + @@ -1271,7 +1294,7 @@ public class SignatureChainValidatorTest { "Key valid"); assertThrows(SignatureValidationException.class, () -> SignatureChainValidator.validateSignatureChain( - sigAT2_T3, getSignedData(data), keysA, policy, validationDate), + sigAT2_T3, getSignedData(data), keysA, policy, validationDate), "Key is not valid, as subkey binding expired"); assertDoesNotThrow(() -> SignatureChainValidator.validateSignatureChain( sigAT3_now, getSignedData(data), keysA, policy, validationDate),