diff --git a/pgpainless-core/src/test/java/org/bouncycastle/PGPUtilWrapperTest.java b/pgpainless-core/src/test/java/org/bouncycastle/PGPUtilWrapperTest.java
index fd1ec62a..8c2b432b 100644
--- a/pgpainless-core/src/test/java/org/bouncycastle/PGPUtilWrapperTest.java
+++ b/pgpainless-core/src/test/java/org/bouncycastle/PGPUtilWrapperTest.java
@@ -19,18 +19,17 @@ import org.bouncycastle.openpgp.PGPLiteralData;
import org.bouncycastle.openpgp.PGPLiteralDataGenerator;
import org.bouncycastle.openpgp.PGPObjectFactory;
import org.bouncycastle.util.io.Streams;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.ArgumentsSource;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.implementation.ImplementationFactory;
+import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
import org.pgpainless.util.PGPUtilWrapper;
-import org.pgpainless.util.TestImplementationFactoryProvider;
public class PGPUtilWrapperTest {
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void testGetDecoderStream(ImplementationFactory implementationFactory) throws IOException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void testGetDecoderStream() throws IOException {
ByteArrayInputStream msg = new ByteArrayInputStream("Foo\nBar".getBytes(StandardCharsets.UTF_8));
PGPLiteralDataGenerator literalDataGenerator = new PGPLiteralDataGenerator();
diff --git a/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/DecryptAndVerifyMessageTest.java b/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/DecryptAndVerifyMessageTest.java
index 76426582..79e6fae0 100644
--- a/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/DecryptAndVerifyMessageTest.java
+++ b/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/DecryptAndVerifyMessageTest.java
@@ -17,16 +17,15 @@ import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.util.io.Streams;
import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.ArgumentsSource;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.PGPainless;
import org.pgpainless.algorithm.CompressionAlgorithm;
import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
-import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.SubkeyIdentifier;
import org.pgpainless.key.TestKeys;
import org.pgpainless.key.util.KeyRingUtils;
-import org.pgpainless.util.TestImplementationFactoryProvider;
+import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
public class DecryptAndVerifyMessageTest {
@@ -42,10 +41,9 @@ public class DecryptAndVerifyMessageTest {
romeo = TestKeys.getRomeoSecretKeyRing();
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void decryptMessageAndVerifySignatureTest(ImplementationFactory implementationFactory) throws Exception {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void decryptMessageAndVerifySignatureTest() throws Exception {
String encryptedMessage = TestKeys.MSG_SIGN_CRYPT_JULIET_JULIET;
ConsumerOptions options = new ConsumerOptions()
diff --git a/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/DecryptHiddenRecipientMessage.java b/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/DecryptHiddenRecipientMessage.java
index 060435ff..3ea67b62 100644
--- a/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/DecryptHiddenRecipientMessage.java
+++ b/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/DecryptHiddenRecipientMessage.java
@@ -16,21 +16,19 @@ import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPPublicKey;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.util.io.Streams;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.ArgumentsSource;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.PGPainless;
import org.pgpainless.algorithm.EncryptionPurpose;
-import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.SubkeyIdentifier;
import org.pgpainless.key.info.KeyRingInfo;
-import org.pgpainless.util.TestImplementationFactoryProvider;
+import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
public class DecryptHiddenRecipientMessage {
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void testDecryptionWithWildcardRecipient(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void testDecryptionWithWildcardRecipient() throws IOException, PGPException {
String secretKeyAscii = "-----BEGIN PGP PRIVATE KEY BLOCK-----\n" +
"Comment: Bob's OpenPGP Transferable Secret Key\n" +
"\n" +
diff --git a/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/ModificationDetectionTests.java b/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/ModificationDetectionTests.java
index 03f6165e..db6fb9f3 100644
--- a/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/ModificationDetectionTests.java
+++ b/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/ModificationDetectionTests.java
@@ -18,15 +18,14 @@ import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
import org.bouncycastle.util.io.Streams;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.ArgumentsSource;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.PGPainless;
import org.pgpainless.exception.MessageNotIntegrityProtectedException;
import org.pgpainless.exception.ModificationDetectionException;
-import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.protection.SecretKeyRingProtector;
+import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
import org.pgpainless.util.Passphrase;
-import org.pgpainless.util.TestImplementationFactoryProvider;
public class ModificationDetectionTests {
@@ -205,14 +204,12 @@ public class ModificationDetectionTests {
/**
* Messages containing a missing MDC shall fail to decrypt.
- * @param implementationFactory implementation factory
* @throws IOException in case of an io-error
* @throws PGPException in case of a pgp error
*/
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void testMissingMDCThrowsByDefault(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void testMissingMDCThrowsByDefault() throws IOException, PGPException {
PGPSecretKeyRingCollection secretKeyRings = getDecryptionKey();
@@ -230,10 +227,9 @@ public class ModificationDetectionTests {
});
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void testTamperedCiphertextThrows(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void testTamperedCiphertextThrows() throws IOException, PGPException {
ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_TAMPERED_CIPHERTEXT.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(in)
@@ -246,10 +242,9 @@ public class ModificationDetectionTests {
assertThrows(ModificationDetectionException.class, decryptionStream::close);
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void testIgnoreTamperedCiphertext(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void testIgnoreTamperedCiphertext() throws IOException, PGPException {
ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_TAMPERED_CIPHERTEXT.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(in)
@@ -263,10 +258,9 @@ public class ModificationDetectionTests {
decryptionStream.close();
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void testTamperedMDCThrowsByDefault(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void testTamperedMDCThrowsByDefault() throws IOException, PGPException {
ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_TAMPERED_MDC.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(in)
@@ -279,10 +273,9 @@ public class ModificationDetectionTests {
assertThrows(ModificationDetectionException.class, decryptionStream::close);
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void testIgnoreTamperedMDC(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void testIgnoreTamperedMDC() throws IOException, PGPException {
ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_TAMPERED_MDC.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(in)
@@ -295,10 +288,9 @@ public class ModificationDetectionTests {
Streams.pipeAll(decryptionStream, out);
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void testTruncatedMDCThrows(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void testTruncatedMDCThrows() throws IOException, PGPException {
ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_TRUNCATED_MDC.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(in)
@@ -310,10 +302,9 @@ public class ModificationDetectionTests {
assertThrows(EOFException.class, () -> Streams.pipeAll(decryptionStream, out));
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void testMDCWithBadCTBThrows(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void testMDCWithBadCTBThrows() throws IOException, PGPException {
ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_MDC_WITH_BAD_CTB.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(in)
@@ -326,10 +317,9 @@ public class ModificationDetectionTests {
assertThrows(ModificationDetectionException.class, decryptionStream::close);
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void testIgnoreMDCWithBadCTB(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void testIgnoreMDCWithBadCTB() throws IOException, PGPException {
ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_MDC_WITH_BAD_CTB.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(in)
@@ -343,10 +333,9 @@ public class ModificationDetectionTests {
decryptionStream.close();
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void testMDCWithBadLengthThrows(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void testMDCWithBadLengthThrows() throws IOException, PGPException {
ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_MDC_WITH_BAD_LENGTH.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(in)
@@ -359,10 +348,9 @@ public class ModificationDetectionTests {
assertThrows(ModificationDetectionException.class, decryptionStream::close);
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void testIgnoreMDCWithBadLength(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void testIgnoreMDCWithBadLength() throws IOException, PGPException {
ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_MDC_WITH_BAD_LENGTH.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(in)
@@ -376,10 +364,9 @@ public class ModificationDetectionTests {
decryptionStream.close();
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void decryptMessageWithSEDPacket(ImplementationFactory implementationFactory) throws IOException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void decryptMessageWithSEDPacket() throws IOException {
Passphrase passphrase = Passphrase.fromPassword("flowcrypt compatibility tests");
String key = "-----BEGIN PGP PRIVATE KEY BLOCK-----\r\n" +
"Version: FlowCrypt 6.9.1 Gmail Encryption\r\n" +
diff --git a/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/RecursionDepthTest.java b/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/RecursionDepthTest.java
index 73ff3f71..343feb7b 100644
--- a/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/RecursionDepthTest.java
+++ b/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/RecursionDepthTest.java
@@ -14,11 +14,10 @@ import java.nio.charset.StandardCharsets;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.util.io.Streams;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.ArgumentsSource;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.PGPainless;
-import org.pgpainless.implementation.ImplementationFactory;
-import org.pgpainless.util.TestImplementationFactoryProvider;
+import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
public class RecursionDepthTest {
@@ -27,11 +26,10 @@ public class RecursionDepthTest {
*
* @see Sequoia-PGP Test Suite
*/
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void decryptionAbortsWhenMaximumRecursionDepthReachedTest(ImplementationFactory implementationFactory)
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void decryptionAbortsWhenMaximumRecursionDepthReachedTest()
throws IOException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
String key = "-----BEGIN PGP PRIVATE KEY BLOCK-----\n" +
"Comment: Bob's OpenPGP Transferable Secret Key\n" +
"\n" +
diff --git a/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/EncryptDecryptTest.java b/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/EncryptDecryptTest.java
index 09a58695..c6075853 100644
--- a/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/EncryptDecryptTest.java
+++ b/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/EncryptDecryptTest.java
@@ -25,8 +25,8 @@ import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.PGPSignature;
import org.bouncycastle.util.io.Streams;
import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.ArgumentsSource;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.PGPainless;
import org.pgpainless.algorithm.DocumentSignatureType;
import org.pgpainless.algorithm.KeyFlag;
@@ -34,7 +34,6 @@ import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
import org.pgpainless.decryption_verification.ConsumerOptions;
import org.pgpainless.decryption_verification.DecryptionStream;
import org.pgpainless.decryption_verification.OpenPgpMetadata;
-import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.SubkeyIdentifier;
import org.pgpainless.key.TestKeys;
import org.pgpainless.key.generation.KeySpec;
@@ -47,7 +46,7 @@ import org.pgpainless.key.protection.UnprotectedKeysProtector;
import org.pgpainless.key.util.KeyRingUtils;
import org.pgpainless.policy.Policy;
import org.pgpainless.util.ArmoredOutputStreamFactory;
-import org.pgpainless.util.TestImplementationFactoryProvider;
+import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
public class EncryptDecryptTest {
@@ -70,11 +69,10 @@ public class EncryptDecryptTest {
Policy.SymmetricKeyAlgorithmPolicy.defaultSymmetricKeyDecryptionAlgorithmPolicy());
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void freshKeysRsaToElGamalTest(ImplementationFactory implementationFactory)
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void freshKeysRsaToElGamalTest()
throws PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, IOException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing sender = PGPainless.generateKeyRing().simpleRsaKeyRing("romeo@montague.lit", RsaLength._3072);
PGPSecretKeyRing recipient = PGPainless.buildKeyRing()
.setPrimaryKey(KeySpec.getBuilder(
@@ -88,54 +86,49 @@ public class EncryptDecryptTest {
encryptDecryptForSecretKeyRings(sender, recipient);
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void freshKeysRsaToRsaTest(ImplementationFactory implementationFactory)
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void freshKeysRsaToRsaTest()
throws PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, IOException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing sender = PGPainless.generateKeyRing().simpleRsaKeyRing("romeo@montague.lit", RsaLength._3072);
PGPSecretKeyRing recipient = PGPainless.generateKeyRing().simpleRsaKeyRing("juliet@capulet.lit", RsaLength._3072);
encryptDecryptForSecretKeyRings(sender, recipient);
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void freshKeysEcToEcTest(ImplementationFactory implementationFactory)
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void freshKeysEcToEcTest()
throws IOException, PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing sender = PGPainless.generateKeyRing().simpleEcKeyRing("romeo@montague.lit");
PGPSecretKeyRing recipient = PGPainless.generateKeyRing().simpleEcKeyRing("juliet@capulet.lit");
encryptDecryptForSecretKeyRings(sender, recipient);
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void freshKeysEcToRsaTest(ImplementationFactory implementationFactory)
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void freshKeysEcToRsaTest()
throws PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, IOException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing sender = PGPainless.generateKeyRing().simpleEcKeyRing("romeo@montague.lit");
PGPSecretKeyRing recipient = PGPainless.generateKeyRing().simpleRsaKeyRing("juliet@capulet.lit", RsaLength._3072);
encryptDecryptForSecretKeyRings(sender, recipient);
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void freshKeysRsaToEcTest(ImplementationFactory implementationFactory)
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void freshKeysRsaToEcTest()
throws PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, IOException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing sender = PGPainless.generateKeyRing().simpleRsaKeyRing("romeo@montague.lit", RsaLength._3072);
PGPSecretKeyRing recipient = PGPainless.generateKeyRing().simpleEcKeyRing("juliet@capulet.lit");
encryptDecryptForSecretKeyRings(sender, recipient);
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void existingRsaKeysTest(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void existingRsaKeysTest() throws IOException, PGPException {
PGPSecretKeyRing sender = TestKeys.getJulietSecretKeyRing();
PGPSecretKeyRing recipient = TestKeys.getRomeoSecretKeyRing();
@@ -197,10 +190,9 @@ public class EncryptDecryptTest {
assertTrue(result.isVerified());
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void testDetachedSignatureCreationAndVerification(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void testDetachedSignatureCreationAndVerification() throws IOException, PGPException {
PGPSecretKeyRing signingKeys = TestKeys.getJulietSecretKeyRing();
SecretKeyRingProtector keyRingProtector = new UnprotectedKeysProtector();
@@ -243,10 +235,9 @@ public class EncryptDecryptTest {
assertFalse(decryptionResult.getVerifiedSignatures().isEmpty());
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void testOnePassSignatureCreationAndVerification(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void testOnePassSignatureCreationAndVerification() throws IOException, PGPException {
PGPSecretKeyRing signingKeys = TestKeys.getJulietSecretKeyRing();
SecretKeyRingProtector keyRingProtector = new UnprotectedKeysProtector();
byte[] data = testMessage.getBytes();
@@ -274,10 +265,9 @@ public class EncryptDecryptTest {
assertFalse(metadata.getVerifiedSignatures().isEmpty());
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void expiredSubkeyBacksigTest(ImplementationFactory implementationFactory) throws IOException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void expiredSubkeyBacksigTest() throws IOException {
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" +
"xsDNBF2lnPIBDAC5cL9PQoQLTMuhjbYvb4Ncuuo0bfmgPRFywX53jPhoFf4Zg6mv\n" +
diff --git a/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/EncryptionStreamClosedTest.java b/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/EncryptionStreamClosedTest.java
index e3b31967..4f0f05d2 100644
--- a/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/EncryptionStreamClosedTest.java
+++ b/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/EncryptionStreamClosedTest.java
@@ -11,19 +11,17 @@ import java.io.IOException;
import java.io.OutputStream;
import org.bouncycastle.openpgp.PGPException;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.ArgumentsSource;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.PGPainless;
-import org.pgpainless.implementation.ImplementationFactory;
+import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
import org.pgpainless.util.Passphrase;
-import org.pgpainless.util.TestImplementationFactoryProvider;
public class EncryptionStreamClosedTest {
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void testStreamHasToBeClosedBeforeGetResultCanBeCalled(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void testStreamHasToBeClosedBeforeGetResultCanBeCalled() throws IOException, PGPException {
OutputStream out = new ByteArrayOutputStream();
EncryptionStream stream = PGPainless.encryptAndOrSign()
.onOutputStream(out)
diff --git a/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/SigningTest.java b/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/SigningTest.java
index 27860088..aaaa09db 100644
--- a/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/SigningTest.java
+++ b/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/SigningTest.java
@@ -26,8 +26,8 @@ import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
import org.bouncycastle.openpgp.PGPSignature;
import org.bouncycastle.util.io.Streams;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.ArgumentsSource;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.PGPainless;
import org.pgpainless.algorithm.DocumentSignatureType;
import org.pgpainless.algorithm.HashAlgorithm;
@@ -37,7 +37,6 @@ import org.pgpainless.decryption_verification.DecryptionStream;
import org.pgpainless.decryption_verification.OpenPgpMetadata;
import org.pgpainless.exception.KeyCannotSignException;
import org.pgpainless.exception.KeyValidationError;
-import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.SubkeyIdentifier;
import org.pgpainless.key.TestKeys;
import org.pgpainless.key.generation.KeySpec;
@@ -46,17 +45,16 @@ import org.pgpainless.key.generation.type.eddsa.EdDSACurve;
import org.pgpainless.key.info.KeyRingInfo;
import org.pgpainless.key.protection.SecretKeyRingProtector;
import org.pgpainless.key.util.KeyRingUtils;
+import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
import org.pgpainless.util.MultiMap;
import org.pgpainless.util.Passphrase;
-import org.pgpainless.util.TestImplementationFactoryProvider;
public class SigningTest {
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void testEncryptionAndSignatureVerification(ImplementationFactory implementationFactory)
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void testEncryptionAndSignatureVerification()
throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPPublicKeyRing julietKeys = TestKeys.getJulietPublicKeyRing();
PGPPublicKeyRing romeoKeys = TestKeys.getRomeoPublicKeyRing();
@@ -117,11 +115,10 @@ public class SigningTest {
assertFalse(metadata.containsVerifiedSignatureFrom(julietKeys));
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void testSignWithInvalidUserIdFails(ImplementationFactory implementationFactory)
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void testSignWithInvalidUserIdFails()
throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
.modernKeyRing("alice", "password123");
SecretKeyRingProtector protector = SecretKeyRingProtector.unlockAnyKeyWith(Passphrase.fromPassword("password123"));
@@ -133,11 +130,10 @@ public class SigningTest {
DocumentSignatureType.CANONICAL_TEXT_DOCUMENT));
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void testSignWithRevokedUserIdFails(ImplementationFactory implementationFactory)
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void testSignWithRevokedUserIdFails()
throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
.modernKeyRing("alice", "password123");
SecretKeyRingProtector protector = SecretKeyRingProtector.unlockAnyKeyWith(
@@ -155,10 +151,9 @@ public class SigningTest {
DocumentSignatureType.CANONICAL_TEXT_DOCUMENT));
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void signWithHashAlgorithmOverride(ImplementationFactory implementationFactory) throws PGPException, IOException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void signWithHashAlgorithmOverride() throws PGPException, IOException {
PGPSecretKeyRing secretKeys = TestKeys.getEmilSecretKeyRing();
SecretKeyRingProtector protector = SecretKeyRingProtector.unprotectedKeys();
@@ -188,11 +183,10 @@ public class SigningTest {
assertEquals(HashAlgorithm.SHA224.getAlgorithmId(), signature.getHashAlgorithm());
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void negotiateHashAlgorithmChoseFallbackIfEmptyPreferences(ImplementationFactory implementationFactory)
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void negotiateHashAlgorithmChoseFallbackIfEmptyPreferences()
throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IOException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing secretKeys = PGPainless.buildKeyRing()
.setPrimaryKey(KeySpec.getBuilder(
KeyType.EDDSA(EdDSACurve._Ed25519), KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA)
@@ -219,11 +213,10 @@ public class SigningTest {
signature.getHashAlgorithm());
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void negotiateHashAlgorithmChoseFallbackIfUnacceptablePreferences(ImplementationFactory implementationFactory)
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void negotiateHashAlgorithmChoseFallbackIfUnacceptablePreferences()
throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IOException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing secretKeys = PGPainless.buildKeyRing()
.setPrimaryKey(
KeySpec.getBuilder(KeyType.EDDSA(EdDSACurve._Ed25519), KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA)
@@ -250,11 +243,10 @@ public class SigningTest {
signature.getHashAlgorithm());
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void signingWithNonCapableKeyThrowsKeyCannotSignException(ImplementationFactory implementationFactory)
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void signingWithNonCapableKeyThrowsKeyCannotSignException()
throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing secretKeys = PGPainless.buildKeyRing()
.setPrimaryKey(KeySpec.getBuilder(KeyType.EDDSA(EdDSACurve._Ed25519), KeyFlag.CERTIFY_OTHER))
.addUserId("Alice")
@@ -267,11 +259,10 @@ public class SigningTest {
SecretKeyRingProtector.unprotectedKeys(), secretKeys, DocumentSignatureType.BINARY_DOCUMENT));
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void signWithInvalidUserIdThrowsKeyValidationError(ImplementationFactory implementationFactory)
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void signWithInvalidUserIdThrowsKeyValidationError()
throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing secretKeys = PGPainless.buildKeyRing()
.setPrimaryKey(KeySpec.getBuilder(KeyType.EDDSA(EdDSACurve._Ed25519),
KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA))
diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/BouncycastleExportSubkeys.java b/pgpainless-core/src/test/java/org/pgpainless/key/BouncycastleExportSubkeys.java
index e651eb2d..74f02dcf 100644
--- a/pgpainless-core/src/test/java/org/pgpainless/key/BouncycastleExportSubkeys.java
+++ b/pgpainless-core/src/test/java/org/pgpainless/key/BouncycastleExportSubkeys.java
@@ -29,18 +29,16 @@ import org.bouncycastle.openpgp.operator.PGPDigestCalculator;
import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder;
import org.bouncycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder;
import org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyPair;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.ArgumentsSource;
-import org.pgpainless.implementation.ImplementationFactory;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.provider.ProviderFactory;
-import org.pgpainless.util.TestImplementationFactoryProvider;
+import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
public class BouncycastleExportSubkeys {
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void testExportImport(ImplementationFactory implementationFactory) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void testExportImport() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, PGPException {
KeyPairGenerator generator;
KeyPair pair;
diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/ImportExportKeyTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/ImportExportKeyTest.java
index d12963cd..fc05a3ca 100644
--- a/pgpainless-core/src/test/java/org/pgpainless/key/ImportExportKeyTest.java
+++ b/pgpainless-core/src/test/java/org/pgpainless/key/ImportExportKeyTest.java
@@ -13,10 +13,10 @@ import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPPublicKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.operator.KeyFingerPrintCalculator;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.ArgumentsSource;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.implementation.ImplementationFactory;
-import org.pgpainless.util.TestImplementationFactoryProvider;
+import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
public class ImportExportKeyTest {
@@ -24,10 +24,9 @@ public class ImportExportKeyTest {
* Test the export and import of a key ring with sub keys.
* @throws IOException in case of a IO error
*/
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void testExportImportPublicKeyRing(ImplementationFactory implementationFactory) throws IOException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void testExportImportPublicKeyRing() throws IOException {
PGPPublicKeyRing publicKeys = TestKeys.getJulietPublicKeyRing();
KeyFingerPrintCalculator calc = ImplementationFactory.getInstance().getKeyFingerprintCalculator();
@@ -36,10 +35,9 @@ public class ImportExportKeyTest {
assertArrayEquals(publicKeys.getEncoded(), parsed.getEncoded());
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void testExportImportSecretKeyRing(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void testExportImportSecretKeyRing() throws IOException, PGPException {
PGPSecretKeyRing secretKeys = TestKeys.getRomeoSecretKeyRing();
KeyFingerPrintCalculator calc = ImplementationFactory.getInstance().getKeyFingerprintCalculator();
diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/generation/BrainpoolKeyGenerationTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/generation/BrainpoolKeyGenerationTest.java
index 376777a2..f5b3cf73 100644
--- a/pgpainless-core/src/test/java/org/pgpainless/key/generation/BrainpoolKeyGenerationTest.java
+++ b/pgpainless-core/src/test/java/org/pgpainless/key/generation/BrainpoolKeyGenerationTest.java
@@ -17,12 +17,11 @@ import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPPublicKey;
import org.bouncycastle.openpgp.PGPSecretKey;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.ArgumentsSource;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.PGPainless;
import org.pgpainless.algorithm.KeyFlag;
import org.pgpainless.algorithm.PublicKeyAlgorithm;
-import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.generation.type.KeyType;
import org.pgpainless.key.generation.type.ecc.EllipticCurve;
import org.pgpainless.key.generation.type.eddsa.EdDSACurve;
@@ -31,16 +30,15 @@ import org.pgpainless.key.generation.type.xdh.XDHSpec;
import org.pgpainless.key.info.KeyInfo;
import org.pgpainless.key.util.UserId;
import org.pgpainless.util.BCUtil;
+import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
import org.pgpainless.util.Passphrase;
-import org.pgpainless.util.TestImplementationFactoryProvider;
public class BrainpoolKeyGenerationTest {
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void generateEcKeysTest(ImplementationFactory implementationFactory)
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void generateEcKeysTest()
throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
for (EllipticCurve curve : EllipticCurve.values()) {
PGPSecretKeyRing secretKeys = generateKey(
@@ -66,11 +64,10 @@ public class BrainpoolKeyGenerationTest {
}
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void generateEdDSAKeyTest(ImplementationFactory implementationFactory)
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void generateEdDSAKeyTest()
throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing secretKeys = PGPainless.buildKeyRing()
.setPrimaryKey(KeySpec.getBuilder(
diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/generation/CertificationKeyMustBeAbleToCertifyTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/generation/CertificationKeyMustBeAbleToCertifyTest.java
index fecde6c7..1c74d321 100644
--- a/pgpainless-core/src/test/java/org/pgpainless/key/generation/CertificationKeyMustBeAbleToCertifyTest.java
+++ b/pgpainless-core/src/test/java/org/pgpainless/key/generation/CertificationKeyMustBeAbleToCertifyTest.java
@@ -6,15 +6,14 @@ package org.pgpainless.key.generation;
import static org.junit.jupiter.api.Assertions.assertThrows;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.ArgumentsSource;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.PGPainless;
import org.pgpainless.algorithm.KeyFlag;
-import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.generation.type.KeyType;
import org.pgpainless.key.generation.type.ecc.EllipticCurve;
import org.pgpainless.key.generation.type.xdh.XDHSpec;
-import org.pgpainless.util.TestImplementationFactoryProvider;
+import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
public class CertificationKeyMustBeAbleToCertifyTest {
@@ -23,10 +22,9 @@ public class CertificationKeyMustBeAbleToCertifyTest {
* would result in an invalid key.
* This test therefore verifies that generating such keys fails.
*/
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void testCertificationIncapableKeyTypesThrow(ImplementationFactory implementationFactory) {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void testCertificationIncapableKeyTypesThrow() {
KeyType[] typesIncapableOfCreatingVerifications = new KeyType[] {
KeyType.ECDH(EllipticCurve._P256),
KeyType.ECDH(EllipticCurve._P384),
diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateEllipticCurveKeyTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateEllipticCurveKeyTest.java
index 36a987f9..9102092b 100644
--- a/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateEllipticCurveKeyTest.java
+++ b/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateEllipticCurveKeyTest.java
@@ -6,32 +6,30 @@ package org.pgpainless.key.generation;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import java.io.IOException;
import java.security.InvalidAlgorithmParameterException;
import java.security.NoSuchAlgorithmException;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.ArgumentsSource;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.PGPainless;
import org.pgpainless.algorithm.KeyFlag;
import org.pgpainless.algorithm.PublicKeyAlgorithm;
-import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.generation.type.KeyType;
import org.pgpainless.key.generation.type.eddsa.EdDSACurve;
import org.pgpainless.key.generation.type.xdh.XDHSpec;
import org.pgpainless.key.protection.SecretKeyRingProtector;
import org.pgpainless.key.protection.UnlockSecretKey;
import org.pgpainless.key.util.UserId;
-import org.pgpainless.util.TestImplementationFactoryProvider;
+import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
public class GenerateEllipticCurveKeyTest {
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void generateEllipticCurveKeys(ImplementationFactory implementationFactory) throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void generateEllipticCurveKeys()
+ throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException {
PGPSecretKeyRing keyRing = PGPainless.buildKeyRing()
.setPrimaryKey(KeySpec.getBuilder(
KeyType.EDDSA(EdDSACurve._Ed25519),
diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateKeyWithAdditionalUserIdTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateKeyWithAdditionalUserIdTest.java
index 4505662a..ab79b171 100644
--- a/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateKeyWithAdditionalUserIdTest.java
+++ b/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateKeyWithAdditionalUserIdTest.java
@@ -17,24 +17,22 @@ import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPPublicKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.junit.JUtils;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.ArgumentsSource;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.PGPainless;
import org.pgpainless.algorithm.KeyFlag;
-import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.generation.type.KeyType;
import org.pgpainless.key.generation.type.rsa.RsaLength;
import org.pgpainless.key.util.KeyRingUtils;
import org.pgpainless.key.util.UserId;
import org.pgpainless.util.DateUtil;
-import org.pgpainless.util.TestImplementationFactoryProvider;
+import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
public class GenerateKeyWithAdditionalUserIdTest {
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void test(ImplementationFactory implementationFactory) throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void test() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException {
Date expiration = new Date(DateUtil.now().getTime() + 60 * 1000);
PGPSecretKeyRing secretKeys = PGPainless.buildKeyRing()
.setPrimaryKey(KeySpec.getBuilder(
diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateWithEmptyPassphraseTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateWithEmptyPassphraseTest.java
index 6233e59e..6ac8ffb7 100644
--- a/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateWithEmptyPassphraseTest.java
+++ b/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateWithEmptyPassphraseTest.java
@@ -6,20 +6,18 @@ package org.pgpainless.key.generation;
import static org.junit.jupiter.api.Assertions.assertNotNull;
-import java.io.IOException;
import java.security.InvalidAlgorithmParameterException;
import java.security.NoSuchAlgorithmException;
import org.bouncycastle.openpgp.PGPException;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.ArgumentsSource;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.PGPainless;
import org.pgpainless.algorithm.KeyFlag;
-import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.generation.type.KeyType;
import org.pgpainless.key.generation.type.rsa.RsaLength;
+import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
import org.pgpainless.util.Passphrase;
-import org.pgpainless.util.TestImplementationFactoryProvider;
/**
* Reproduce behavior of https://github.com/pgpainless/pgpainless/issues/16
@@ -30,10 +28,10 @@ import org.pgpainless.util.TestImplementationFactoryProvider;
*/
public class GenerateWithEmptyPassphraseTest {
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void testGeneratingKeyWithEmptyPassphraseDoesNotThrow(ImplementationFactory implementationFactory) throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void testGeneratingKeyWithEmptyPassphraseDoesNotThrow()
+ throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException {
assertNotNull(PGPainless.buildKeyRing()
.setPrimaryKey(KeySpec.getBuilder(
diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/generation/IllegalKeyFlagsTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/generation/IllegalKeyFlagsTest.java
index 3477e189..adb0c10e 100644
--- a/pgpainless-core/src/test/java/org/pgpainless/key/generation/IllegalKeyFlagsTest.java
+++ b/pgpainless-core/src/test/java/org/pgpainless/key/generation/IllegalKeyFlagsTest.java
@@ -6,21 +6,19 @@ package org.pgpainless.key.generation;
import static org.junit.jupiter.api.Assertions.assertThrows;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.ArgumentsSource;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.algorithm.KeyFlag;
-import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.generation.type.KeyType;
import org.pgpainless.key.generation.type.eddsa.EdDSACurve;
import org.pgpainless.key.generation.type.xdh.XDHSpec;
-import org.pgpainless.util.TestImplementationFactoryProvider;
+import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
public class IllegalKeyFlagsTest {
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void testKeyCannotCarryFlagsTest(ImplementationFactory implementationFactory) {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void testKeyCannotCarryFlagsTest() {
assertThrows(IllegalArgumentException.class, () -> KeySpec.getBuilder(
KeyType.XDH(XDHSpec._X25519), KeyFlag.SIGN_DATA));
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 8f07d33f..335c7959 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
@@ -31,8 +31,8 @@ import org.bouncycastle.openpgp.PGPSecretKey;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.junit.JUtils;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.ArgumentsSource;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.PGPainless;
import org.pgpainless.algorithm.CompressionAlgorithm;
import org.pgpainless.algorithm.EncryptionPurpose;
@@ -40,7 +40,6 @@ import org.pgpainless.algorithm.HashAlgorithm;
import org.pgpainless.algorithm.KeyFlag;
import org.pgpainless.algorithm.PublicKeyAlgorithm;
import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
-import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.OpenPgpV4Fingerprint;
import org.pgpainless.key.TestKeys;
import org.pgpainless.key.generation.KeySpec;
@@ -52,15 +51,14 @@ import org.pgpainless.key.protection.UnprotectedKeysProtector;
import org.pgpainless.key.util.KeyRingUtils;
import org.pgpainless.key.util.UserId;
import org.pgpainless.util.DateUtil;
+import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
import org.pgpainless.util.Passphrase;
-import org.pgpainless.util.TestImplementationFactoryProvider;
public class KeyRingInfoTest {
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void testWithEmilsKeys(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void testWithEmilsKeys() throws IOException, PGPException {
PGPSecretKeyRing secretKeys = TestKeys.getEmilSecretKeyRing();
PGPPublicKeyRing publicKeys = TestKeys.getEmilPublicKeyRing();
@@ -175,10 +173,9 @@ public class KeyRingInfoTest {
KeyRingUtils.requireSecretKeyFrom(secretKeys, secretKeys.getPublicKey().getKeyID()));
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void dummyS2KTest(ImplementationFactory implementationFactory) throws IOException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void dummyS2KTest() throws IOException {
String withDummyS2K = "-----BEGIN PGP PRIVATE KEY BLOCK-----\n" +
"\n" +
@@ -214,10 +211,9 @@ public class KeyRingInfoTest {
assertTrue(new KeyInfo(secretKeys.getSecretKey()).hasDummyS2K());
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void testGetKeysWithFlagsAndExpiry(ImplementationFactory implementationFactory) throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void testGetKeysWithFlagsAndExpiry() throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException {
PGPSecretKeyRing secretKeys = PGPainless.buildKeyRing()
.setPrimaryKey(KeySpec.getBuilder(
diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/modification/AddSubKeyTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/modification/AddSubKeyTest.java
index 1b97cd1a..0ac53d58 100644
--- a/pgpainless-core/src/test/java/org/pgpainless/key/modification/AddSubKeyTest.java
+++ b/pgpainless-core/src/test/java/org/pgpainless/key/modification/AddSubKeyTest.java
@@ -20,11 +20,10 @@ import org.bouncycastle.openpgp.PGPPrivateKey;
import org.bouncycastle.openpgp.PGPPublicKey;
import org.bouncycastle.openpgp.PGPSecretKey;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.ArgumentsSource;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.PGPainless;
import org.pgpainless.algorithm.KeyFlag;
-import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.TestKeys;
import org.pgpainless.key.generation.KeySpec;
import org.pgpainless.key.generation.type.ecc.EllipticCurve;
@@ -33,15 +32,15 @@ import org.pgpainless.key.info.KeyRingInfo;
import org.pgpainless.key.protection.PasswordBasedSecretKeyRingProtector;
import org.pgpainless.key.protection.SecretKeyRingProtector;
import org.pgpainless.key.protection.UnlockSecretKey;
+import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
import org.pgpainless.util.Passphrase;
-import org.pgpainless.util.TestImplementationFactoryProvider;
public class AddSubKeyTest {
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void testAddSubKey(ImplementationFactory implementationFactory) throws IOException, PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void testAddSubKey()
+ throws IOException, PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException {
PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing();
List keyIdsBefore = new ArrayList<>();
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 77c1383b..5caa99e1 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
@@ -18,26 +18,24 @@ 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.ArgumentsSource;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.PGPainless;
-import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.TestKeys;
import org.pgpainless.key.info.KeyRingInfo;
import org.pgpainless.key.protection.PasswordBasedSecretKeyRingProtector;
import org.pgpainless.key.protection.SecretKeyRingProtector;
import org.pgpainless.key.protection.UnprotectedKeysProtector;
import org.pgpainless.key.util.UserId;
+import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
import org.pgpainless.util.Passphrase;
-import org.pgpainless.util.TestImplementationFactoryProvider;
public class AddUserIdTest {
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void addUserIdToExistingKeyRing(ImplementationFactory implementationFactory)
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void addUserIdToExistingKeyRing()
throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().simpleEcKeyRing("alice@wonderland.lit", "rabb1th0le");
KeyRingInfo info = PGPainless.inspectKeyRing(secretKeys);
@@ -66,20 +64,18 @@ public class AddUserIdTest {
assertFalse(userIds.hasNext());
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void deleteUserId_noSuchElementExceptionForMissingUserId(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void deleteUserId_noSuchElementExceptionForMissingUserId() throws IOException, PGPException {
PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing();
assertThrows(NoSuchElementException.class, () -> PGPainless.modifyKeyRing(secretKeys)
.revokeUserId("invalid@user.id", new UnprotectedKeysProtector()));
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void deleteExistingAndAddNewUserIdToExistingKeyRing(ImplementationFactory implementationFactory) throws PGPException, IOException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void deleteExistingAndAddNewUserIdToExistingKeyRing() throws PGPException, IOException {
final String ARMORED_PRIVATE_KEY =
"-----BEGIN PGP PRIVATE KEY BLOCK-----\r\n\r\n" +
diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/modification/ChangeExpirationOnKeyWithDifferentSignatureTypesTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/modification/ChangeExpirationOnKeyWithDifferentSignatureTypesTest.java
index aa8b0589..dd6d03d8 100644
--- a/pgpainless-core/src/test/java/org/pgpainless/key/modification/ChangeExpirationOnKeyWithDifferentSignatureTypesTest.java
+++ b/pgpainless-core/src/test/java/org/pgpainless/key/modification/ChangeExpirationOnKeyWithDifferentSignatureTypesTest.java
@@ -10,13 +10,12 @@ import java.util.Date;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.junit.JUtils;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.ArgumentsSource;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.PGPainless;
-import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.protection.SecretKeyRingProtector;
import org.pgpainless.util.DateUtil;
-import org.pgpainless.util.TestImplementationFactoryProvider;
+import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
public class ChangeExpirationOnKeyWithDifferentSignatureTypesTest {
@@ -136,21 +135,19 @@ public class ChangeExpirationOnKeyWithDifferentSignatureTypesTest {
"=GIQn\n" +
"-----END PGP PRIVATE KEY BLOCK-----";
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void setExpirationDate_keyHasSigClass10(ImplementationFactory implementationFactory)
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void setExpirationDate_keyHasSigClass10()
throws PGPException, IOException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing keys = PGPainless.readKeyRing().secretKeyRing(keyWithGenericCertification);
SecretKeyRingProtector protector = SecretKeyRingProtector.unprotectedKeys();
executeTestForKeys(keys, protector);
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void setExpirationDate_keyHasSigClass12(ImplementationFactory implementationFactory)
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void setExpirationDate_keyHasSigClass12()
throws PGPException, IOException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing keys = PGPainless.readKeyRing().secretKeyRing(keyWithCasualCertification);
SecretKeyRingProtector protector = SecretKeyRingProtector.unprotectedKeys();
executeTestForKeys(keys, protector);
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 b728016a..d9ddd44e 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
@@ -13,26 +13,24 @@ import java.util.Date;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.ArgumentsSource;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.PGPainless;
-import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.OpenPgpV4Fingerprint;
import org.pgpainless.key.TestKeys;
import org.pgpainless.key.info.KeyRingInfo;
import org.pgpainless.key.protection.UnprotectedKeysProtector;
import org.pgpainless.util.DateUtil;
-import org.pgpainless.util.TestImplementationFactoryProvider;
+import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
public class ChangeExpirationTest {
private final OpenPgpV4Fingerprint subKeyFingerprint = new OpenPgpV4Fingerprint("F73FDE6439ABE210B1AF4EDD273EF7A0C749807B");
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void setExpirationDateAndThenUnsetIt_OnPrimaryKey(ImplementationFactory implementationFactory)
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void setExpirationDateAndThenUnsetIt_OnPrimaryKey()
throws PGPException, IOException, InterruptedException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing secretKeys = TestKeys.getEmilSecretKeyRing();
KeyRingInfo sInfo = PGPainless.inspectKeyRing(secretKeys);
@@ -62,11 +60,10 @@ public class ChangeExpirationTest {
assertNull(sInfo.getSubkeyExpirationDate(subKeyFingerprint));
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void setExpirationDateAndThenUnsetIt_OnSubkey(ImplementationFactory implementationFactory)
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void setExpirationDateAndThenUnsetIt_OnSubkey()
throws PGPException, IOException, InterruptedException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing secretKeys = TestKeys.getEmilSecretKeyRing();
KeyRingInfo sInfo = PGPainless.inspectKeyRing(secretKeys);
diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/modification/ChangeSecretKeyRingPassphraseTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/modification/ChangeSecretKeyRingPassphraseTest.java
index 283d74cc..0e81d6a2 100644
--- a/pgpainless-core/src/test/java/org/pgpainless/key/modification/ChangeSecretKeyRingPassphraseTest.java
+++ b/pgpainless-core/src/test/java/org/pgpainless/key/modification/ChangeSecretKeyRingPassphraseTest.java
@@ -20,8 +20,8 @@ import org.bouncycastle.openpgp.PGPSecretKey;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor;
import org.bouncycastle.util.io.Streams;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.ArgumentsSource;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.PGPainless;
import org.pgpainless.algorithm.DocumentSignatureType;
import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
@@ -32,8 +32,8 @@ import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.protection.KeyRingProtectionSettings;
import org.pgpainless.key.protection.PasswordBasedSecretKeyRingProtector;
import org.pgpainless.key.protection.UnlockSecretKey;
+import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
import org.pgpainless.util.Passphrase;
-import org.pgpainless.util.TestImplementationFactoryProvider;
public class ChangeSecretKeyRingPassphraseTest {
@@ -42,10 +42,9 @@ public class ChangeSecretKeyRingPassphraseTest {
public ChangeSecretKeyRingPassphraseTest() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException {
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void changePassphraseOfWholeKeyRingTest(ImplementationFactory implementationFactory) throws PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void changePassphraseOfWholeKeyRingTest() throws PGPException {
PGPSecretKeyRing secretKeys = PGPainless.modifyKeyRing(keyRing)
.changePassphraseFromOldPassphrase(Passphrase.fromPassword("weakPassphrase"))
@@ -70,10 +69,9 @@ public class ChangeSecretKeyRingPassphraseTest {
"Unlocking the secret key ring with the new passphrase MUST succeed.");
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void changePassphraseOfWholeKeyRingToEmptyPassphrase(ImplementationFactory implementationFactory) throws PGPException, IOException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void changePassphraseOfWholeKeyRingToEmptyPassphrase() throws PGPException, IOException {
PGPSecretKeyRing secretKeys = PGPainless.modifyKeyRing(keyRing)
.changePassphraseFromOldPassphrase(Passphrase.fromPassword("weakPassphrase"))
.withSecureDefaultSettings()
@@ -88,10 +86,9 @@ public class ChangeSecretKeyRingPassphraseTest {
signDummyMessageWithKeysAndPassphrase(changedPassphraseKeyRing, Passphrase.emptyPassphrase());
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void changePassphraseOfSingleSubkeyToNewPassphrase(ImplementationFactory implementationFactory) throws PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void changePassphraseOfSingleSubkeyToNewPassphrase() throws PGPException {
Iterator keys = keyRing.getSecretKeys();
PGPSecretKey primaryKey = keys.next();
@@ -125,10 +122,9 @@ public class ChangeSecretKeyRingPassphraseTest {
"Unlocking the subkey with the primary key passphrase must fail.");
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void changePassphraseOfSingleSubkeyToEmptyPassphrase(ImplementationFactory implementationFactory) throws PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void changePassphraseOfSingleSubkeyToEmptyPassphrase() throws PGPException {
Iterator keys = keyRing.getSecretKeys();
PGPSecretKey primaryKey = keys.next();
diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/modification/OldSignatureSubpacketsArePreservedOnNewSig.java b/pgpainless-core/src/test/java/org/pgpainless/key/modification/OldSignatureSubpacketsArePreservedOnNewSig.java
index b9a00cd6..bdead096 100644
--- a/pgpainless-core/src/test/java/org/pgpainless/key/modification/OldSignatureSubpacketsArePreservedOnNewSig.java
+++ b/pgpainless-core/src/test/java/org/pgpainless/key/modification/OldSignatureSubpacketsArePreservedOnNewSig.java
@@ -16,21 +16,19 @@ import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.PGPSignature;
import org.bouncycastle.openpgp.PGPSignatureSubpacketVector;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.ArgumentsSource;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.PGPainless;
-import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.OpenPgpV4Fingerprint;
import org.pgpainless.key.protection.UnprotectedKeysProtector;
-import org.pgpainless.util.TestImplementationFactoryProvider;
+import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
public class OldSignatureSubpacketsArePreservedOnNewSig {
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void verifyOldSignatureSubpacketsArePreservedOnNewExpirationDateSig(ImplementationFactory implementationFactory)
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void verifyOldSignatureSubpacketsArePreservedOnNewExpirationDateSig()
throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, InterruptedException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
.simpleEcKeyRing("Alice ");
diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/modification/RevokeKeyWithGenericCertificationSignatureTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/modification/RevokeKeyWithGenericCertificationSignatureTest.java
index a9b1f0a8..b6a4d435 100644
--- a/pgpainless-core/src/test/java/org/pgpainless/key/modification/RevokeKeyWithGenericCertificationSignatureTest.java
+++ b/pgpainless-core/src/test/java/org/pgpainless/key/modification/RevokeKeyWithGenericCertificationSignatureTest.java
@@ -14,13 +14,12 @@ import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPPublicKey;
import org.bouncycastle.openpgp.PGPSecretKey;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.ArgumentsSource;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.PGPainless;
-import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.protection.UnprotectedKeysProtector;
import org.pgpainless.util.ArmoredOutputStreamFactory;
-import org.pgpainless.util.TestImplementationFactoryProvider;
+import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
/**
* Test that makes sure that PGPainless can deal with keys that carry a key
@@ -64,10 +63,9 @@ public class RevokeKeyWithGenericCertificationSignatureTest {
}
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void test(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void test() throws IOException, PGPException {
revokeKey(SAMPLE_PRIVATE_KEY); // would crash previously
}
diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/modification/RevokeKeyWithoutPreferredAlgorithmsOnPrimaryKey.java b/pgpainless-core/src/test/java/org/pgpainless/key/modification/RevokeKeyWithoutPreferredAlgorithmsOnPrimaryKey.java
index 1cce7290..68c9ddaa 100644
--- a/pgpainless-core/src/test/java/org/pgpainless/key/modification/RevokeKeyWithoutPreferredAlgorithmsOnPrimaryKey.java
+++ b/pgpainless-core/src/test/java/org/pgpainless/key/modification/RevokeKeyWithoutPreferredAlgorithmsOnPrimaryKey.java
@@ -13,17 +13,16 @@ import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPSecretKey;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.junit.JUtils;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.ArgumentsSource;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.PGPainless;
-import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.OpenPgpV4Fingerprint;
import org.pgpainless.key.info.KeyRingInfo;
import org.pgpainless.key.modification.secretkeyring.SecretKeyRingEditorInterface;
import org.pgpainless.key.protection.SecretKeyRingProtector;
import org.pgpainless.key.protection.UnprotectedKeysProtector;
import org.pgpainless.util.DateUtil;
-import org.pgpainless.util.TestImplementationFactoryProvider;
+import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
public class RevokeKeyWithoutPreferredAlgorithmsOnPrimaryKey {
@@ -101,11 +100,10 @@ public class RevokeKeyWithoutPreferredAlgorithmsOnPrimaryKey {
"=3Zyp\n" +
"-----END PGP PRIVATE KEY BLOCK-----";
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void testChangingExpirationTimeWithKeyWithoutPrefAlgos(ImplementationFactory implementationFactory)
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void testChangingExpirationTimeWithKeyWithoutPrefAlgos()
throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
Date expirationDate = DateUtil.parseUTCDate(DateUtil.formatUTCDate(new Date()));
PGPSecretKeyRing secretKeys = PGPainless.readKeyRing().secretKeyRing(KEY);
List fingerprintList = new ArrayList<>();
diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/modification/RevokeSubKeyTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/modification/RevokeSubKeyTest.java
index 861002f0..4f612c50 100644
--- a/pgpainless-core/src/test/java/org/pgpainless/key/modification/RevokeSubKeyTest.java
+++ b/pgpainless-core/src/test/java/org/pgpainless/key/modification/RevokeSubKeyTest.java
@@ -24,12 +24,11 @@ import org.bouncycastle.openpgp.PGPSecretKey;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.PGPSignature;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.ArgumentsSource;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.PGPainless;
import org.pgpainless.algorithm.EncryptionPurpose;
import org.pgpainless.algorithm.SignatureType;
-import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.OpenPgpV4Fingerprint;
import org.pgpainless.key.TestKeys;
import org.pgpainless.key.modification.secretkeyring.SecretKeyRingEditorInterface;
@@ -39,15 +38,14 @@ import org.pgpainless.key.util.RevocationAttributes;
import org.pgpainless.signature.SignatureUtils;
import org.pgpainless.signature.subpackets.RevocationSignatureSubpackets;
import org.pgpainless.signature.subpackets.SignatureSubpacketsUtil;
+import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
import org.pgpainless.util.Passphrase;
-import org.pgpainless.util.TestImplementationFactoryProvider;
public class RevokeSubKeyTest {
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void revokeSukeyTest(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void revokeSukeyTest() throws IOException, PGPException {
PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing();
Iterator keysIterator = secretKeys.iterator();
@@ -69,10 +67,9 @@ public class RevokeSubKeyTest {
assertTrue(subKey.getPublicKey().hasRevocation());
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void detachedRevokeSubkeyTest(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void detachedRevokeSubkeyTest() throws IOException, PGPException {
PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing();
OpenPgpV4Fingerprint fingerprint = new OpenPgpV4Fingerprint(secretKeys);
SecretKeyRingProtector protector = PasswordBasedSecretKeyRingProtector.forKey(secretKeys, Passphrase.fromPassword("password123"));
@@ -90,10 +87,9 @@ public class RevokeSubKeyTest {
assertTrue(publicKey.hasRevocation());
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void testRevocationSignatureTypeCorrect(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void testRevocationSignatureTypeCorrect() throws IOException, PGPException {
PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing();
Iterator keysIterator = secretKeys.getPublicKeys();
PGPPublicKey primaryKey = keysIterator.next();
diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/protection/PassphraseTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/protection/PassphraseTest.java
index 94eb5863..83477b28 100644
--- a/pgpainless-core/src/test/java/org/pgpainless/key/protection/PassphraseTest.java
+++ b/pgpainless-core/src/test/java/org/pgpainless/key/protection/PassphraseTest.java
@@ -13,6 +13,8 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
import org.pgpainless.util.Passphrase;
public class PassphraseTest {
@@ -49,15 +51,13 @@ public class PassphraseTest {
assertTrue(fromEmptyChars.isEmpty());
}
- @Test
- public void testEmptyPassphrase() {
- Passphrase empty = Passphrase.emptyPassphrase();
- assertNull(empty.getChars());
- assertTrue(empty.isEmpty());
+ @ParameterizedTest
+ @ValueSource(strings = {"", " ", " ", "\t", "\t\t"})
+ public void testEmptyPassphrases(String empty) {
+ Passphrase passphrase = Passphrase.fromPassword(empty);
+ assertTrue(passphrase.isEmpty());
- Passphrase trimmedEmpty = Passphrase.fromPassword(" ");
- assertNull(trimmedEmpty.getChars());
- assertTrue(trimmedEmpty.isEmpty());
+ assertEquals(Passphrase.emptyPassphrase(), passphrase);
}
@Test
diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/protection/SecretKeyRingProtectorTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/protection/SecretKeyRingProtectorTest.java
index b641af56..3fd0e1eb 100644
--- a/pgpainless-core/src/test/java/org/pgpainless/key/protection/SecretKeyRingProtectorTest.java
+++ b/pgpainless-core/src/test/java/org/pgpainless/key/protection/SecretKeyRingProtectorTest.java
@@ -23,22 +23,20 @@ import org.bouncycastle.openpgp.PGPSecretKey;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.ArgumentsSource;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.PGPainless;
-import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.TestKeys;
import org.pgpainless.key.protection.passphrase_provider.SecretKeyPassphraseProvider;
+import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
import org.pgpainless.util.Passphrase;
-import org.pgpainless.util.TestImplementationFactoryProvider;
public class SecretKeyRingProtectorTest {
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void testUnlockAllKeysWithSamePassword(ImplementationFactory implementationFactory)
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void testUnlockAllKeysWithSamePassword()
throws IOException, PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing();
SecretKeyRingProtector protector =
@@ -69,11 +67,10 @@ public class SecretKeyRingProtectorTest {
}
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void testUnlockSingleKeyWithPassphrase(ImplementationFactory implementationFactory)
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void testUnlockSingleKeyWithPassphrase()
throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing();
Iterator iterator = secretKeys.iterator();
diff --git a/pgpainless-core/src/test/java/org/pgpainless/signature/BindingSignatureSubpacketsTest.java b/pgpainless-core/src/test/java/org/pgpainless/signature/BindingSignatureSubpacketsTest.java
index f94380cd..e158b958 100644
--- a/pgpainless-core/src/test/java/org/pgpainless/signature/BindingSignatureSubpacketsTest.java
+++ b/pgpainless-core/src/test/java/org/pgpainless/signature/BindingSignatureSubpacketsTest.java
@@ -16,14 +16,13 @@ import java.util.Date;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPPublicKeyRing;
import org.bouncycastle.openpgp.PGPSignature;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.ArgumentsSource;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.PGPainless;
import org.pgpainless.exception.SignatureValidationException;
-import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.policy.Policy;
import org.pgpainless.signature.consumer.CertificateValidator;
-import org.pgpainless.util.TestImplementationFactoryProvider;
+import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
/**
* Explores how subpackets on binding sigs are handled.
@@ -52,10 +51,9 @@ public class BindingSignatureSubpacketsTest {
private Date validationDate = new Date();
private Policy policy = PGPainless.getPolicy();
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void baseCase(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void baseCase() throws IOException, PGPException {
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" +
@@ -114,10 +112,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "Base case. Is valid.");
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void subkeyBindingIssuerFpOnly(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void subkeyBindingIssuerFpOnly() throws IOException, PGPException {
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" +
@@ -176,10 +173,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "Interoperability concern.");
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void subkeyBindingIssuerV6IssuerFp(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void subkeyBindingIssuerV6IssuerFp() throws IOException, PGPException {
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" +
@@ -238,10 +234,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "Interoperability concern");
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void subkeyBindingIssuerFakeIssuer(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void subkeyBindingIssuerFakeIssuer() throws IOException, PGPException {
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" +
@@ -300,10 +295,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "Interoperability concern.");
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void subkeyBindingFakeIssuerIssuer(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void subkeyBindingFakeIssuerIssuer() throws IOException, PGPException {
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" +
@@ -362,10 +356,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "Interop concern");
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void subkeyBindingFakeIssuer(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void subkeyBindingFakeIssuer() throws IOException, PGPException {
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" +
@@ -424,10 +417,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "fake issuers do not throw us off here.");
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void subkeyBindingNoIssuer(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void subkeyBindingNoIssuer() throws IOException, PGPException {
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" +
@@ -485,10 +477,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "subkey binding sig does not need issuer");
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void unknownSubpacketHashed(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void unknownSubpacketHashed() throws IOException, PGPException {
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" +
@@ -547,10 +538,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "Unknown subpackets are okay in hashed area");
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void subkeyBindingUnknownCriticalSubpacket(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void subkeyBindingUnknownCriticalSubpacket() throws IOException, PGPException {
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" +
@@ -609,10 +599,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationFails(key, "Unknown critical subpacket in hashed area invalidates signature");
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void subkeyBindingUnknownSubpacketUnhashed(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void subkeyBindingUnknownSubpacketUnhashed() throws IOException, PGPException {
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" +
@@ -671,10 +660,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "Unknown subpackets may be allowed in unhashed area.");
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void subkeyBindingUnknownCriticalSubpacketUnhashed(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void subkeyBindingUnknownCriticalSubpacketUnhashed() throws IOException, PGPException {
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" +
@@ -733,10 +721,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "Critical unknown subpacket is okay in unhashed area.");
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void subkeyBindingUnknownNotationHashed(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void subkeyBindingUnknownNotationHashed() throws IOException, PGPException {
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" +
@@ -796,10 +783,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "Unknown notation is okay in subkey binding sig.");
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void subkeyBindingCriticalUnknownNotationHashed(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void subkeyBindingCriticalUnknownNotationHashed() throws IOException, PGPException {
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" +
@@ -859,10 +845,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationFails(key, "Critical unknown notation invalidates subkey binding sig.");
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void subkeyBindingUnknownNotationUnhashed(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void subkeyBindingUnknownNotationUnhashed() throws IOException, PGPException {
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" +
@@ -922,10 +907,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "Unknown notation is okay in unhashed area.");
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void subkeyBindingCriticalUnknownNotationUnhashed(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void subkeyBindingCriticalUnknownNotationUnhashed() throws IOException, PGPException {
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" +
@@ -985,10 +969,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "Critical unknown notation is okay in unhashed area.");
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void subkeyBindingBackSigFakeBackSig(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void subkeyBindingBackSigFakeBackSig() throws IOException, PGPException {
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" +
@@ -1058,10 +1041,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "Back-sig, fake back-sig should succeed to verify");
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void subkeyBindingFakeBackSigBackSig(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void subkeyBindingFakeBackSigBackSig() throws IOException, PGPException {
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" +
@@ -1131,10 +1113,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "Fake back-sig, back-sig should succeed to verify.");
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void primaryBindingIssuerFpOnly(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void primaryBindingIssuerFpOnly() throws IOException, PGPException {
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" +
@@ -1193,10 +1174,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "issuer fp is enough");
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void primaryBindingIssuerV6IssuerFp(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void primaryBindingIssuerV6IssuerFp() throws IOException, PGPException {
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" +
@@ -1255,10 +1235,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "interop");
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void primaryBindingIssuerFakeIssuer(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void primaryBindingIssuerFakeIssuer() throws IOException, PGPException {
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" +
@@ -1317,10 +1296,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "interop");
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void primaryBindingFakeIssuerIssuer(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void primaryBindingFakeIssuerIssuer() throws IOException, PGPException {
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" +
@@ -1379,10 +1357,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "interop");
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void primaryBindingFakeIssuer(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void primaryBindingFakeIssuer() throws IOException, PGPException {
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" +
@@ -1441,10 +1418,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "Fake issuer on primary key binding sig is not an issue.");
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void primaryBindingNoIssuer(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void primaryBindingNoIssuer() throws IOException, PGPException {
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" +
@@ -1502,10 +1478,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "Missing issuer on primary key binding sig is not an issue");
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void primaryBindingUnknownSubpacketHashed(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void primaryBindingUnknownSubpacketHashed() throws IOException, PGPException {
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" +
@@ -1564,10 +1539,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "Unknown subpacket in hashed area is not a problem.");
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void primaryBindingCriticalUnknownSubpacketHashed(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void primaryBindingCriticalUnknownSubpacketHashed() throws IOException, PGPException {
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" +
@@ -1626,10 +1600,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationFails(key, "Critical unknown subpacket in hashed area invalidates signature.");
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void primaryBindingUnknownSubpacketUnhashed(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void primaryBindingUnknownSubpacketUnhashed() throws IOException, PGPException {
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" +
@@ -1688,10 +1661,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "Unknown subpacket is not an issue in the unhashed area");
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void primaryBindingCriticalUnknownSubpacketUnhashed(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void primaryBindingCriticalUnknownSubpacketUnhashed() throws IOException, PGPException {
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" +
@@ -1750,10 +1722,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "Critical unknown subpacket is acceptable in unhashed area of primary binding sig");
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void primaryBindingUnknownNotationHashed(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void primaryBindingUnknownNotationHashed() throws IOException, PGPException {
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" +
@@ -1813,10 +1784,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "Unknown notation is acceptable in hashed area of primary binding sig.");
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void primaryBindingCriticalUnknownNotationHashed(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void primaryBindingCriticalUnknownNotationHashed() throws IOException, PGPException {
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" +
@@ -1876,10 +1846,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationFails(key, "Critical unknown notation in hashed area invalidates primary binding sig");
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void primaryBindingUnknownNotationUnhashed(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void primaryBindingUnknownNotationUnhashed() throws IOException, PGPException {
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" +
@@ -1939,10 +1908,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "Unknown notation in unhashed area of primary key binding is okay.");
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void primaryBindingCriticalUnknownNotationUnhashed(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void primaryBindingCriticalUnknownNotationUnhashed() throws IOException, PGPException {
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" +
diff --git a/pgpainless-core/src/test/java/org/pgpainless/signature/CertificateValidatorTest.java b/pgpainless-core/src/test/java/org/pgpainless/signature/CertificateValidatorTest.java
index 5eb98aa7..cf7e07ed 100644
--- a/pgpainless-core/src/test/java/org/pgpainless/signature/CertificateValidatorTest.java
+++ b/pgpainless-core/src/test/java/org/pgpainless/signature/CertificateValidatorTest.java
@@ -19,17 +19,16 @@ import org.bouncycastle.openpgp.PGPPublicKeyRing;
import org.bouncycastle.openpgp.PGPSignature;
import org.bouncycastle.util.io.Streams;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.ArgumentsSource;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.PGPainless;
import org.pgpainless.decryption_verification.ConsumerOptions;
import org.pgpainless.decryption_verification.DecryptionStream;
import org.pgpainless.decryption_verification.OpenPgpMetadata;
import org.pgpainless.exception.SignatureValidationException;
-import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.policy.Policy;
import org.pgpainless.signature.consumer.CertificateValidator;
-import org.pgpainless.util.TestImplementationFactoryProvider;
+import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
public class CertificateValidatorTest {
@@ -38,10 +37,9 @@ public class CertificateValidatorTest {
*
* @see Sequoia Test Suite
*/
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void testPrimaryKeySignsAndIsHardRevokedUnknown(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void testPrimaryKeySignsAndIsHardRevokedUnknown() throws IOException, PGPException {
String key = "-----BEGIN PGP ARMORED FILE-----\n" +
"Comment: ASCII Armor added by openpgp-interoperability-test-suite\n" +
@@ -190,10 +188,9 @@ public class CertificateValidatorTest {
* Subkey signs, primary key is hard revoked with reason: unknown.
* @see Sequoia Test Suite
*/
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void testSubkeySignsPrimaryKeyIsHardRevokedUnknown(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void testSubkeySignsPrimaryKeyIsHardRevokedUnknown() throws IOException, PGPException {
String key = "-----BEGIN PGP ARMORED FILE-----\n" +
"Comment: ASCII Armor added by openpgp-interoperability-test-suite\n" +
@@ -343,10 +340,9 @@ public class CertificateValidatorTest {
*
* @see Sequoia Test Suite
*/
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void testSubkeySignsAndIsHardRevokedUnknown(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void testSubkeySignsAndIsHardRevokedUnknown() throws IOException, PGPException {
String keyWithHardRev = "-----BEGIN PGP ARMORED FILE-----\n" +
"Comment: ASCII Armor added by openpgp-interoperability-test-suite\n" +
@@ -496,10 +492,9 @@ public class CertificateValidatorTest {
*
* @see Sequoia Test Suite
*/
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void testPrimaryKeySignsAndIsSoftRevokedSuperseded(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void testPrimaryKeySignsAndIsSoftRevokedSuperseded() throws IOException, PGPException {
String keyWithSoftRev = "-----BEGIN PGP ARMORED FILE-----\n" +
"Comment: ASCII Armor added by openpgp-interoperability-test-suite\n" +
@@ -654,10 +649,9 @@ public class CertificateValidatorTest {
*
* @see Sequoia Test Suite
*/
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void testSubkeySignsPrimaryKeyIsSoftRevokedSuperseded(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void testSubkeySignsPrimaryKeyIsSoftRevokedSuperseded() throws IOException, PGPException {
String key = "-----BEGIN PGP ARMORED FILE-----\n" +
"Comment: ASCII Armor added by openpgp-interoperability-test-suite\n" +
@@ -808,10 +802,9 @@ public class CertificateValidatorTest {
*
* @see Sequoia Test Suite
*/
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void testPrimaryKeySignsAndIsSoftRevokedRetired(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void testPrimaryKeySignsAndIsSoftRevokedRetired() throws IOException, PGPException {
String key = "-----BEGIN PGP ARMORED FILE-----\n" +
"Comment: ASCII Armor added by openpgp-interoperability-test-suite\n" +
@@ -962,10 +955,9 @@ public class CertificateValidatorTest {
*
* @see Sequoia Test Suite
*/
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void testTemporaryValidity(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void testTemporaryValidity() throws IOException, PGPException {
String keyA = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"Comment: D1A6 6E1A 23B1 82C9 980F 788C FBFC C82A 015E 7330\n" +
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 95728fb0..3db8096d 100644
--- a/pgpainless-core/src/test/java/org/pgpainless/signature/KeyRevocationTest.java
+++ b/pgpainless-core/src/test/java/org/pgpainless/signature/KeyRevocationTest.java
@@ -14,22 +14,20 @@ import java.util.Date;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPPublicKeyRing;
import org.bouncycastle.openpgp.PGPSignature;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.ArgumentsSource;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.PGPainless;
import org.pgpainless.exception.SignatureValidationException;
-import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.signature.consumer.CertificateValidator;
-import org.pgpainless.util.TestImplementationFactoryProvider;
+import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
public class KeyRevocationTest {
private static final String data = "Hello, World";
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void subkeySignsPrimaryKeyRevokedNoReason(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void subkeySignsPrimaryKeyRevokedNoReason() throws IOException, PGPException {
String key = "-----BEGIN PGP ARMORED FILE-----\n" +
"Comment: ASCII Armor added by openpgp-interoperability-test-suite\n" +
@@ -174,10 +172,9 @@ public class KeyRevocationTest {
*
* @see Sequoia Test-Suite
*/
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void subkeySignsPrimaryKeyNotRevoked(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void subkeySignsPrimaryKeyNotRevoked() throws IOException, PGPException {
String key = "-----BEGIN PGP ARMORED FILE-----\n" +
"Comment: ASCII Armor added by openpgp-interoperability-test-suite\n" +
diff --git a/pgpainless-core/src/test/java/org/pgpainless/signature/OnePassSignatureBracketingTest.java b/pgpainless-core/src/test/java/org/pgpainless/signature/OnePassSignatureBracketingTest.java
index 20fb598a..00f39144 100644
--- a/pgpainless-core/src/test/java/org/pgpainless/signature/OnePassSignatureBracketingTest.java
+++ b/pgpainless-core/src/test/java/org/pgpainless/signature/OnePassSignatureBracketingTest.java
@@ -33,8 +33,8 @@ import org.bouncycastle.openpgp.PGPSignatureList;
import org.bouncycastle.openpgp.PGPUtil;
import org.bouncycastle.openpgp.operator.PublicKeyDataDecryptorFactory;
import org.bouncycastle.util.io.Streams;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.ArgumentsSource;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.PGPainless;
import org.pgpainless.algorithm.DocumentSignatureType;
import org.pgpainless.algorithm.HashAlgorithm;
@@ -47,14 +47,14 @@ import org.pgpainless.encryption_signing.SigningOptions;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.protection.SecretKeyRingProtector;
import org.pgpainless.key.protection.UnlockSecretKey;
-import org.pgpainless.util.TestImplementationFactoryProvider;
+import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
public class OnePassSignatureBracketingTest {
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void onePassSignaturePacketsAndSignaturesAreBracketedTest(ImplementationFactory implementationFactory) throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IOException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void onePassSignaturePacketsAndSignaturesAreBracketedTest()
+ throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IOException {
PGPSecretKeyRing key1 = PGPainless.generateKeyRing().modernKeyRing("Alice", null);
PGPSecretKeyRing key2 = PGPainless.generateKeyRing().modernKeyRing("Bob", null);
diff --git a/pgpainless-core/src/test/java/org/pgpainless/symmetric_encryption/MultiPassphraseSymmetricEncryptionTest.java b/pgpainless-core/src/test/java/org/pgpainless/symmetric_encryption/MultiPassphraseSymmetricEncryptionTest.java
index 7ab00868..efcef2ec 100644
--- a/pgpainless-core/src/test/java/org/pgpainless/symmetric_encryption/MultiPassphraseSymmetricEncryptionTest.java
+++ b/pgpainless-core/src/test/java/org/pgpainless/symmetric_encryption/MultiPassphraseSymmetricEncryptionTest.java
@@ -11,24 +11,22 @@ import java.nio.charset.StandardCharsets;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.util.io.Streams;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.ArgumentsSource;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.PGPainless;
import org.pgpainless.decryption_verification.ConsumerOptions;
import org.pgpainless.decryption_verification.DecryptionStream;
import org.pgpainless.encryption_signing.EncryptionOptions;
import org.pgpainless.encryption_signing.EncryptionStream;
import org.pgpainless.encryption_signing.ProducerOptions;
-import org.pgpainless.implementation.ImplementationFactory;
+import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
import org.pgpainless.util.Passphrase;
-import org.pgpainless.util.TestImplementationFactoryProvider;
public class MultiPassphraseSymmetricEncryptionTest {
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void encryptDecryptWithMultiplePassphrases(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void encryptDecryptWithMultiplePassphrases() throws IOException, PGPException {
String message = "Here we test if during decryption of a message that was encrypted with two passphrases, " +
"the decryptor finds the session key encrypted for the right passphrase.";
ByteArrayInputStream plaintextIn = new ByteArrayInputStream(message.getBytes(StandardCharsets.UTF_8));
diff --git a/pgpainless-core/src/test/java/org/pgpainless/symmetric_encryption/SymmetricEncryptionTest.java b/pgpainless-core/src/test/java/org/pgpainless/symmetric_encryption/SymmetricEncryptionTest.java
index aa14394c..2a2de35a 100644
--- a/pgpainless-core/src/test/java/org/pgpainless/symmetric_encryption/SymmetricEncryptionTest.java
+++ b/pgpainless-core/src/test/java/org/pgpainless/symmetric_encryption/SymmetricEncryptionTest.java
@@ -17,8 +17,9 @@ import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPPublicKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
import org.bouncycastle.util.io.Streams;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.ArgumentsSource;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
import org.pgpainless.PGPainless;
import org.pgpainless.decryption_verification.ConsumerOptions;
import org.pgpainless.decryption_verification.DecryptionStream;
@@ -27,24 +28,21 @@ import org.pgpainless.encryption_signing.EncryptionOptions;
import org.pgpainless.encryption_signing.EncryptionStream;
import org.pgpainless.encryption_signing.ProducerOptions;
import org.pgpainless.exception.MissingDecryptionMethodException;
-import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.TestKeys;
import org.pgpainless.key.protection.KeyRingProtectionSettings;
import org.pgpainless.key.protection.PasswordBasedSecretKeyRingProtector;
import org.pgpainless.key.protection.SecretKeyRingProtector;
import org.pgpainless.key.protection.passphrase_provider.SolitaryPassphraseProvider;
import org.pgpainless.util.Passphrase;
-import org.pgpainless.util.TestImplementationFactoryProvider;
/**
* Test parallel symmetric and public key encryption/decryption.
*/
public class SymmetricEncryptionTest {
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void encryptWithKeyAndPassphrase_DecryptWithKey(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void encryptWithKeyAndPassphrase_DecryptWithKey() throws IOException, PGPException {
byte[] plaintext = "This is a secret message".getBytes(StandardCharsets.UTF_8);
ByteArrayInputStream plaintextIn = new ByteArrayInputStream(plaintext);
PGPPublicKeyRing encryptionKey = TestKeys.getCryptiePublicKeyRing();
@@ -95,11 +93,9 @@ public class SymmetricEncryptionTest {
assertArrayEquals(plaintext, decrypted.toByteArray());
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void testMismatchPassphraseFails(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
-
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void testMismatchPassphraseFails() throws IOException, PGPException {
byte[] bytes = new byte[5000];
new Random().nextBytes(bytes);
diff --git a/pgpainless-core/src/test/java/org/pgpainless/util/ArmorUtilsTest.java b/pgpainless-core/src/test/java/org/pgpainless/util/ArmorUtilsTest.java
index 6a8a6a64..116c18cd 100644
--- a/pgpainless-core/src/test/java/org/pgpainless/util/ArmorUtilsTest.java
+++ b/pgpainless-core/src/test/java/org/pgpainless/util/ArmorUtilsTest.java
@@ -26,8 +26,8 @@ import org.bouncycastle.openpgp.PGPUtil;
import org.bouncycastle.util.io.Streams;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.ArgumentsSource;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.algorithm.HashAlgorithm;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.TestKeys;
@@ -144,10 +144,9 @@ public class ArmorUtilsTest {
"-----END PGP MESSAGE-----\n", out.toString());
}
- @ParameterizedTest
- @ArgumentsSource(TestImplementationFactoryProvider.class)
- public void decodeExampleTest(ImplementationFactory implementationFactory) throws IOException, PGPException {
- ImplementationFactory.setFactoryImplementation(implementationFactory);
+ @TestTemplate
+ @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ public void decodeExampleTest() throws IOException, PGPException {
String armored = "-----BEGIN PGP MESSAGE-----\n" +
"Version: OpenPrivacy 0.99\n" +
"\n" +
diff --git a/pgpainless-core/src/test/java/org/pgpainless/util/ImplementationFactoryTestInvocationContextProvider.java b/pgpainless-core/src/test/java/org/pgpainless/util/ImplementationFactoryTestInvocationContextProvider.java
new file mode 100644
index 00000000..430290e5
--- /dev/null
+++ b/pgpainless-core/src/test/java/org/pgpainless/util/ImplementationFactoryTestInvocationContextProvider.java
@@ -0,0 +1,66 @@
+// SPDX-FileCopyrightText: 2021 Paul Schaub
+//
+// SPDX-License-Identifier: Apache-2.0
+
+package org.pgpainless.util;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Stream;
+
+import org.junit.jupiter.api.extension.BeforeTestExecutionCallback;
+import org.junit.jupiter.api.extension.Extension;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.api.extension.TestTemplateInvocationContext;
+import org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider;
+import org.pgpainless.implementation.BcImplementationFactory;
+import org.pgpainless.implementation.ImplementationFactory;
+import org.pgpainless.implementation.JceImplementationFactory;
+
+/**
+ * InvocationContextProvider that sets different {@link ImplementationFactory} implementations before running annotated
+ * tests.
+ *
+ * Example test annotation:
+ * {@code
+ * @TestTemplate
+ * @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
+ * public void testAllImplementationFactories() {
+ * ...
+ * }
+ * }
+ *
+ * @see Baeldung: Writing Templates for Test Cases Using JUnit 5
+ */
+public class ImplementationFactoryTestInvocationContextProvider implements TestTemplateInvocationContextProvider {
+
+ private static final List IMPLEMENTATIONS = Arrays.asList(
+ new BcImplementationFactory(),
+ new JceImplementationFactory()
+ );
+
+ @Override
+ public boolean supportsTestTemplate(ExtensionContext context) {
+ return true;
+ }
+
+ @Override
+ public Stream provideTestTemplateInvocationContexts(ExtensionContext context) {
+
+ return IMPLEMENTATIONS.stream()
+ .map(implementationFactory -> new TestTemplateInvocationContext() {
+ @Override
+ public String getDisplayName(int invocationIndex) {
+ return context.getDisplayName() + " with " + implementationFactory.getClass().getSimpleName();
+ }
+
+ @Override
+ public List getAdditionalExtensions() {
+ return Collections.singletonList(
+ (BeforeTestExecutionCallback) ctx -> ImplementationFactory.setFactoryImplementation(implementationFactory)
+ );
+ }
+ });
+ }
+}
diff --git a/pgpainless-core/src/test/java/org/pgpainless/util/TestImplementationFactoryProvider.java b/pgpainless-core/src/test/java/org/pgpainless/util/TestImplementationFactoryProvider.java
index 63dc386c..bb9b0feb 100644
--- a/pgpainless-core/src/test/java/org/pgpainless/util/TestImplementationFactoryProvider.java
+++ b/pgpainless-core/src/test/java/org/pgpainless/util/TestImplementationFactoryProvider.java
@@ -17,6 +17,8 @@ import java.util.stream.Stream;
/**
* Utility class used to provide all available implementations of {@link ImplementationFactory} for parametrized tests.
+ *
+ * @deprecated in favor of {@link ImplementationFactoryTestInvocationContextProvider}.
*/
public class TestImplementationFactoryProvider implements ArgumentsProvider {