This is an automated email from the ASF dual-hosted git repository. gnodet pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit 008a6f07b68c501b0ef1d9a02c691bb40ba9bc12 Author: Guillaume Nodet <[email protected]> AuthorDate: Wed Jun 24 10:33:27 2020 +0200 [CAMEL-11807] Upgrade camel-crypto-jms to junit5 --- components/camel-crypto-cms/pom.xml | 6 +- .../camel/component/crypto/cms/ComponentTest.java | 12 +- .../component/crypto/cms/EnvelopedDataTest.java | 163 +++++++++++---------- .../camel/component/crypto/cms/ProcessorsTest.java | 8 +- .../camel/component/crypto/cms/SignedDataTest.java | 112 +++++++------- .../util/TestOriginatorInformationProvider.java | 2 +- 6 files changed, 160 insertions(+), 143 deletions(-) diff --git a/components/camel-crypto-cms/pom.xml b/components/camel-crypto-cms/pom.xml index 5582280..1660ccc 100644 --- a/components/camel-crypto-cms/pom.xml +++ b/components/camel-crypto-cms/pom.xml @@ -58,12 +58,12 @@ <!-- for testing --> <dependency> <groupId>org.apache.camel</groupId> - <artifactId>camel-test-spring</artifactId> + <artifactId>camel-test-spring-junit5</artifactId> <scope>test</scope> </dependency> <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter</artifactId> <scope>test</scope> </dependency> <dependency> diff --git a/components/camel-crypto-cms/src/test/java/org/apache/camel/component/crypto/cms/ComponentTest.java b/components/camel-crypto-cms/src/test/java/org/apache/camel/component/crypto/cms/ComponentTest.java index 3158d2f..f70127b 100644 --- a/components/camel-crypto-cms/src/test/java/org/apache/camel/component/crypto/cms/ComponentTest.java +++ b/components/camel-crypto-cms/src/test/java/org/apache/camel/component/crypto/cms/ComponentTest.java @@ -30,8 +30,11 @@ import org.apache.camel.component.mock.MockEndpoint; import org.apache.camel.impl.DefaultCamelContext; import org.apache.camel.support.SimpleRegistry; import org.apache.camel.support.jsse.KeyStoreParameters; -import org.apache.camel.test.junit4.CamelTestSupport; -import org.junit.Test; +import org.apache.camel.test.junit5.CamelTestSupport; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; public class ComponentTest extends CamelTestSupport { @@ -160,9 +163,10 @@ public class ComponentTest extends CamelTestSupport { }; } - @Test(expected = IllegalStateException.class) + @Test public void wrongOperation() throws Exception { CryptoCmsComponent c = new CryptoCmsComponent(new DefaultCamelContext()); - c.createEndpoint("uri", "wrongoperation", null); + assertThrows(IllegalStateException.class, + () -> c.createEndpoint("uri", "wrongoperation", null)); } } diff --git a/components/camel-crypto-cms/src/test/java/org/apache/camel/component/crypto/cms/EnvelopedDataTest.java b/components/camel-crypto-cms/src/test/java/org/apache/camel/component/crypto/cms/EnvelopedDataTest.java index fa7313c..aae618d 100644 --- a/components/camel-crypto-cms/src/test/java/org/apache/camel/component/crypto/cms/EnvelopedDataTest.java +++ b/components/camel-crypto-cms/src/test/java/org/apache/camel/component/crypto/cms/EnvelopedDataTest.java @@ -38,14 +38,16 @@ import org.apache.camel.component.crypto.cms.util.ExchangeUtil; import org.apache.camel.component.crypto.cms.util.KeystoreUtil; import org.apache.camel.support.jsse.KeyStoreParameters; import org.bouncycastle.jce.provider.BouncyCastleProvider; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; public class EnvelopedDataTest { - @BeforeClass + @BeforeAll public static void setUpProvider() { Security.addProvider(new BouncyCastleProvider()); } @@ -196,41 +198,47 @@ public class EnvelopedDataTest { } /** Works if strong encryption policy jars are installed. */ - @Ignore - @Test(expected = CryptoCmsException.class) + @Disabled + @Test public void executeCamelliaCBCKeySize256() throws Exception { - encryptDecrypt("system.jks", "rsa", "Camellia/CBC/PKCS5Padding", 256); + assertThrows(CryptoCmsException.class, + () -> encryptDecrypt("system.jks", "rsa", "Camellia/CBC/PKCS5Padding", 256)); } /** Works if strong encryption policy jars are installed. */ - @Ignore - @Test(expected = CryptoCmsException.class) + @Disabled + @Test public void executeCamelliaCBCKeySize192() throws Exception { - encryptDecrypt("system.jks", "rsa", "Camellia/CBC/PKCS5Padding", 192); + assertThrows(CryptoCmsException.class, + () -> encryptDecrypt("system.jks", "rsa", "Camellia/CBC/PKCS5Padding", 192)); } - @Test(expected = CryptoCmsException.class) + @Test public void executeNoInWhiteListCamellia256CBC() throws Exception { - encryptDecrypt("system.jks", "rsa", "Camellia256/CBC/PKCS5Padding", 256); + assertThrows(CryptoCmsException.class, + () -> encryptDecrypt("system.jks", "rsa", "Camellia256/CBC/PKCS5Padding", 256)); } - @Test(expected = CryptoCmsException.class) + @Test public void executeNotInWhiteListCamellia192CBC() throws Exception { - encryptDecrypt("system.jks", "rsa", "Camellia192/CBC/PKCS5Padding", 192); + assertThrows(CryptoCmsException.class, + () -> encryptDecrypt("system.jks", "rsa", "Camellia192/CBC/PKCS5Padding", 192)); } /** Works if strong encryption policy jars are installed. */ - @Ignore - @Test(expected = CryptoCmsException.class) + @Disabled + @Test public void executeAESCBCKeySize256() throws Exception { - encryptDecrypt("system.jks", "rsa", "AES/CBC/PKCS5Padding", 256); + assertThrows(CryptoCmsException.class, + () -> encryptDecrypt("system.jks", "rsa", "AES/CBC/PKCS5Padding", 256)); } /** Works if strong encryption policy jars are installed. */ - @Ignore - @Test(expected = CryptoCmsException.class) + @Disabled + @Test public void executeAESCBCKeySize192() throws Exception { - encryptDecrypt("system.jks", "rsa", "AES/CBC/PKCS5Padding", 192); + assertThrows(CryptoCmsException.class, + () -> encryptDecrypt("system.jks", "rsa", "AES/CBC/PKCS5Padding", 192)); } @Test @@ -238,84 +246,100 @@ public class EnvelopedDataTest { encryptDecrypt("system.jks", "rsa", "AES/CBC/PKCS5Padding", 128); } - @Test(expected = CryptoCmsException.class) + @Test public void executeNotInWhiteListAES256CBC() throws Exception { - encryptDecrypt("system.jks", "rsa", "AES256/CBC/PKCS5Padding", 256); + assertThrows(CryptoCmsException.class, + () -> encryptDecrypt("system.jks", "rsa", "AES256/CBC/PKCS5Padding", 256)); } - @Test(expected = CryptoCmsException.class) + @Test public void executeNotInWhiteListAES192CBC() throws Exception { - encryptDecrypt("system.jks", "rsa", "AES192/CBC/PKCS5Padding", 192); + assertThrows(CryptoCmsException.class, + () -> encryptDecrypt("system.jks", "rsa", "AES192/CBC/PKCS5Padding", 192)); } - @Test(expected = CryptoCmsException.class) + @Test public void executerNoImplRSAECB() throws Exception { - encryptDecrypt("system.jks", "rsa", "RSA/ECB/OAEP", 0); + assertThrows(CryptoCmsException.class, + () -> encryptDecrypt("system.jks", "rsa", "RSA/ECB/OAEP", 0)); } - @Test(expected = CryptoCmsException.class) + @Test public void executeNotInWhiteListAESGCM() throws Exception { - encryptDecrypt("system.jks", "rsa", "AES/GCM/NoPadding", 128); + assertThrows(CryptoCmsException.class, + () -> encryptDecrypt("system.jks", "rsa", "AES/GCM/NoPadding", 128)); } - @Test(expected = CryptoCmsException.class) + @Test public void executeNotInWhiteListAES192GCM() throws Exception { - encryptDecrypt("system.jks", "rsa", "AES192/GCM/NoPadding", 192); + assertThrows(CryptoCmsException.class, + () -> encryptDecrypt("system.jks", "rsa", "AES192/GCM/NoPadding", 192)); } - @Test(expected = CryptoCmsException.class) + @Test public void executeNotInWhiteListAES256GCM() throws Exception { - encryptDecrypt("system.jks", "rsa", "AES256/GCM/NoPadding", 256); + assertThrows(CryptoCmsException.class, + () -> encryptDecrypt("system.jks", "rsa", "AES256/GCM/NoPadding", 256)); } - @Test(expected = CryptoCmsException.class) + @Test public void executeNotInWhiteListAES256CCM() throws Exception { - encryptDecrypt("system.jks", "rsa", "AES256/CCM/NoPadding", 256); + assertThrows(CryptoCmsException.class, + () -> encryptDecrypt("system.jks", "rsa", "AES256/CCM/NoPadding", 256)); } - @Test(expected = CryptoCmsException.class) + @Test public void executeNotInWhiteListIDEACBC() throws Exception { - encryptDecrypt("system.jks", "rsa", "IDEA/CBC/PKCS5Padding", 128); + assertThrows(CryptoCmsException.class, + () -> encryptDecrypt("system.jks", "rsa", "IDEA/CBC/PKCS5Padding", 128)); } - @Test(expected = CryptoCmsException.class) + @Test public void executeNotInWhiteListAESCCM() throws Exception { - encryptDecrypt("system.jks", "rsa", "AES/CCM/NoPadding", 128); + assertThrows(CryptoCmsException.class, + () -> encryptDecrypt("system.jks", "rsa", "AES/CCM/NoPadding", 128)); } - @Test(expected = CryptoCmsException.class) + @Test public void executeNotInWhiteListAES192CCM() throws Exception { - encryptDecrypt("system.jks", "rsa", "AES192/CCM/NoPadding", 192); + assertThrows(CryptoCmsException.class, + () -> encryptDecrypt("system.jks", "rsa", "AES192/CCM/NoPadding", 192)); } - @Test(expected = CryptoCmsException.class) + @Test public void executeNotInWhiteListRC5CBC() throws Exception { - encryptDecrypt("system.jks", "rsa", "RC5/CBC/PKCS5Padding", 0); + assertThrows(CryptoCmsException.class, + () -> encryptDecrypt("system.jks", "rsa", "RC5/CBC/PKCS5Padding", 0)); } - @Test(expected = CryptoCmsException.class) + @Test public void wrongSecretKeyLength() throws Exception { - encrypt("system.jks", "DESede/CBC/PKCS5Padding", 200, "testMessage", "rsa"); + assertThrows(CryptoCmsException.class, + () -> encrypt("system.jks", "DESede/CBC/PKCS5Padding", 200, "testMessage", "rsa")); } - @Test(expected = CryptoCmsException.class) + @Test public void wrongContentEncryptionAlgorithm() throws Exception { - encryptDecrypt("system.jks", "rsa", "WrongDESede/CBC/PKCS5Padding", 200); + assertThrows(CryptoCmsException.class, + () -> encryptDecrypt("system.jks", "rsa", "WrongDESede/CBC/PKCS5Padding", 200)); } - @Test(expected = CryptoCmsNoKeyOrCertificateForAliasException.class) + @Test public void wrongEncryptAlias() throws Exception { - encrypt("system.jks", "DESede/CBC/PKCS5Padding", 128, "testMessage", "wrongAlias"); + assertThrows(CryptoCmsNoKeyOrCertificateForAliasException.class, + () -> encrypt("system.jks", "DESede/CBC/PKCS5Padding", 128, "testMessage", "wrongAlias")); } - @Test(expected = CryptoCmsNoKeyOrCertificateForAliasException.class) + @Test public void encryptWrongAliasAndCorrectAlias() throws Exception { - encrypt("system.jks", "DESede/CBC/PKCS5Padding", 128, "testMessage", "wrongAlias", "rsa"); + assertThrows(CryptoCmsNoKeyOrCertificateForAliasException.class, + () -> encrypt("system.jks", "DESede/CBC/PKCS5Padding", 128, "testMessage", "wrongAlias", "rsa")); } - @Test(expected = CryptoCmsNoKeyOrCertificateForAliasException.class) + @Test public void encryptTwoWrongAliases() throws Exception { - encrypt("system.jks", "DESede/CBC/PKCS5Padding", 128, "testMessage", "wrongAlias", "wrongAlias2"); + assertThrows(CryptoCmsNoKeyOrCertificateForAliasException.class, + () -> encrypt("system.jks", "DESede/CBC/PKCS5Padding", 128, "testMessage", "wrongAlias", "wrongAlias2")); } @Test @@ -323,38 +347,29 @@ public class EnvelopedDataTest { encrypt("system.jks", "DESede/CBC/PKCS5Padding", 128, "testMessage", "rsa2", "rsa"); } - @Test(expected = CryptoCmsFormatException.class) + @Test public void wrongEncryptedMessage() throws Exception { - decrypt("system.jks", "TestMessage".getBytes()); + assertThrows(CryptoCmsFormatException.class, + () -> decrypt("system.jks", "TestMessage".getBytes())); } - @Test(expected = CryptoCmsFormatException.class) + @Test public void wrongEncryptedEmptyMessage() throws Exception { - decrypt("system.jks", new byte[0]); + assertThrows(CryptoCmsException.class, + () -> decrypt("system.jks", new byte[0])); } @Test public void decryptionWithEmptyAlias() throws Exception { - - byte[] bytes = null; - try { - bytes = encrypt("system.jks", "DESede/CBC/PKCS5Padding", 192, "Test Message", "rsa"); - } catch (Exception e) { - Assert.fail("Unexpected exception: " + e.getMessage()); - } + byte[] bytes = encrypt("system.jks", "DESede/CBC/PKCS5Padding", 192, "Test Message", "rsa"); decrypt("system.jks", bytes); } - @Test(expected = CryptoCmsNoCertificateForRecipientsException.class) + @Test public void decryptionWithNullAliasWrongKeystore() throws Exception { - - byte[] bytes = null; - try { - bytes = encrypt("system.jks", "DESede/CBC/PKCS5Padding", 192, "Test Message", "rsa"); - } catch (Exception e) { - Assert.fail("Unexpected exception: " + e.getMessage()); - } - decrypt("test.jks", bytes); + byte[] bytes = encrypt("system.jks", "DESede/CBC/PKCS5Padding", 192, "Test Message", "rsa"); + assertThrows(CryptoCmsNoCertificateForRecipientsException.class, + () -> decrypt("test.jks", bytes)); } // @Test @@ -377,7 +392,7 @@ public class EnvelopedDataTest { byte[] decrypted = decrypt(keystoreName, encrypted); String actual = new String(decrypted, "UTF-8"); - Assert.assertEquals(message, actual); + assertEquals(message, actual); } private byte[] encrypt(String keystoreName, String contentEncryptionAlgorithm, int secretKeyLength, String message, String... aliases) diff --git a/components/camel-crypto-cms/src/test/java/org/apache/camel/component/crypto/cms/ProcessorsTest.java b/components/camel-crypto-cms/src/test/java/org/apache/camel/component/crypto/cms/ProcessorsTest.java index c5213f7..a975ac6 100644 --- a/components/camel-crypto-cms/src/test/java/org/apache/camel/component/crypto/cms/ProcessorsTest.java +++ b/components/camel-crypto-cms/src/test/java/org/apache/camel/component/crypto/cms/ProcessorsTest.java @@ -35,16 +35,16 @@ import org.apache.camel.component.mock.MockEndpoint; import org.apache.camel.impl.DefaultCamelContext; import org.apache.camel.support.SimpleRegistry; import org.apache.camel.support.jsse.KeyStoreParameters; -import org.apache.camel.test.junit4.CamelTestSupport; +import org.apache.camel.test.junit5.CamelTestSupport; import org.bouncycastle.jce.provider.BouncyCastleProvider; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class ProcessorsTest extends CamelTestSupport { private SimpleRegistry simpleReg; - @BeforeClass + @BeforeAll public static void setUpProvider() { Security.addProvider(new BouncyCastleProvider()); } diff --git a/components/camel-crypto-cms/src/test/java/org/apache/camel/component/crypto/cms/SignedDataTest.java b/components/camel-crypto-cms/src/test/java/org/apache/camel/component/crypto/cms/SignedDataTest.java index 0dda513..30a59f7 100644 --- a/components/camel-crypto-cms/src/test/java/org/apache/camel/component/crypto/cms/SignedDataTest.java +++ b/components/camel-crypto-cms/src/test/java/org/apache/camel/component/crypto/cms/SignedDataTest.java @@ -59,17 +59,16 @@ import org.apache.camel.impl.DefaultCamelContext; import org.apache.camel.support.jsse.KeyStoreParameters; import org.apache.camel.util.IOHelper; import org.bouncycastle.jce.provider.BouncyCastleProvider; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; public class SignedDataTest { - @BeforeClass + @BeforeAll public static void setUpProvider() { Security.addProvider(new BouncyCastleProvider()); } @@ -105,7 +104,7 @@ public class SignedDataTest { byte[] signed = sign(message, keystoreName, signatureAlgorithm, includeContent, includeCertificates, alias); byte[] result = verify(keystoreName, alias, signed, false); - Assert.assertEquals(message, new String(result, "UTF-8")); + assertEquals(message, new String(result, "UTF-8")); } private byte[] sign(String message, String keystoreName, String signatureAlgorithm, boolean includeContent, boolean includeCertificates, String... aliases) @@ -183,15 +182,16 @@ public class SignedDataTest { sign("", "system.jks", "SHA1withRSA", true, false, "rsa", "rsa2"); } - @Test(expected = CryptoCmsNoKeyOrCertificateForAliasException.class) + @Test public void signWithTwoAliasesOneWithNoPrivateKeyInKeystore() throws Exception { - sign("Test Message", "system.jks", "SHA1withDSA", true, false, "dsa", "noEntry"); + assertThrows(CryptoCmsNoKeyOrCertificateForAliasException.class, + () -> sign("Test Message", "system.jks", "SHA1withDSA", true, false, "dsa", "noEntry")); } - @Test(expected = CryptoCmsNoKeyOrCertificateForAliasException.class) + @Test public void signWrongAlias() throws Exception { - sign("Test Message", "system.jks", "SHA1withDSA", true, false, "wrong"); - + assertThrows(CryptoCmsNoKeyOrCertificateForAliasException.class, + () -> sign("Test Message", "system.jks", "SHA1withDSA", true, false, "wrong")); } @Test @@ -199,14 +199,16 @@ public class SignedDataTest { sign("", "system.jks", "SHA1withDSA", true, false, "dsa"); } - @Test(expected = CryptoCmsInvalidKeyException.class) + @Test public void signSignatureAlgorithmNotCorrespondingToPrivateKey() throws Exception { - sign("testMessage", "system.jks", "MD5withRSA", true, false, "dsa"); + assertThrows(CryptoCmsInvalidKeyException.class, + () -> sign("testMessage", "system.jks", "MD5withRSA", true, false, "dsa")); } - @Test(expected = IllegalArgumentException.class) + @Test public void signWrongSignatureAlgorithm() throws Exception { - sign("testMessage", "system.jks", "wrongRSA", true, false, "rsa"); + assertThrows(IllegalArgumentException.class, + () -> sign("testMessage", "system.jks", "wrongRSA", true, false, "rsa")); } @Test @@ -215,44 +217,36 @@ public class SignedDataTest { ByteArrayOutputStream os = new ByteArrayOutputStream(); IOHelper.copy(is, os); byte[] signed = os.toByteArray(); - try { - verify("system.jks", "rsa", signed, false); - } catch (CryptoCmsException e) { - String message = e.getMessage(); - assertEquals("PKCS7/CMS signature validation not possible: The content for which the hash-value must be calculated is missing in the PKCS7/CMS signed data instance. " - + "Please check the configuration of the sender of the PKCS7/CMS signature.", message); - return; - } - fail("Exception expected"); + CryptoCmsException e = assertThrows(CryptoCmsException.class, + () -> verify("system.jks", "rsa", signed, false)); + String message = e.getMessage(); + assertEquals("PKCS7/CMS signature validation not possible: The content for which the hash-value must be calculated is missing in the PKCS7/CMS signed data instance. " + + "Please check the configuration of the sender of the PKCS7/CMS signature.", message); } - @Test(expected = CryptoCmsNoCertificateForSignerInfosException.class) + @Test public void verifyNoVerifierCerts() throws Exception { - byte[] signed = sign("Test Message", "system.jks", "SHA1withRSA", true, true, "rsa"); - verify("system.jks", "wrongAlias", signed, false); // wrongAlias means - // that no - // certificates are - // added to the - // verifier keystore + // wrongAlias means that no certificates are added to the verifier keystore + assertThrows(CryptoCmsException.class, + () -> verify("system.jks", "wrongAlias", signed, false)); } - @Test(expected = CryptoCmsFormatException.class) + @Test public void verifyWrongFormat() throws Exception { - - verify("system.jks", "rsa", "test".getBytes(), false); + assertThrows(CryptoCmsFormatException.class, + () -> verify("system.jks", "rsa", "test".getBytes(), false)); } - @Test(expected = CryptoCmsFormatException.class) + @Test public void verifyWrongFormatInHeader() throws Exception { - - verifyContentWithSeparateSignature(new ByteArrayInputStream("ABCDEFG1ABCDEFG1ABCDEFG1".getBytes()), new ByteArrayInputStream("ABCDEFG1ABCDEFG1ABCDEFG1".getBytes()), "rsa"); + assertThrows(CryptoCmsFormatException.class, + () -> verifyContentWithSeparateSignature(new ByteArrayInputStream("ABCDEFG1ABCDEFG1ABCDEFG1".getBytes()), new ByteArrayInputStream("ABCDEFG1ABCDEFG1ABCDEFG1".getBytes()), "rsa")); } @Test public void verifyContentWithSeparateSignature() throws Exception { - InputStream message = new ByteArrayInputStream("Test Message".getBytes(StandardCharsets.UTF_8)); InputStream signature = this.getClass().getClassLoader().getResourceAsStream("detached_signature.binary"); @@ -261,20 +255,18 @@ public class SignedDataTest { verifyContentWithSeparateSignature(message, signature, "rsa"); } - @Test(expected = CryptoCmsSignatureInvalidContentHashException.class) + @Test public void verifyContentWithSeparateSignatureWrongContent() throws Exception { - InputStream message = new ByteArrayInputStream("Wrong Message".getBytes()); InputStream signature = this.getClass().getClassLoader().getResourceAsStream("detached_signature.binary"); assertNotNull(signature); - verifyContentWithSeparateSignature(message, signature, "rsa"); - + assertThrows(CryptoCmsSignatureInvalidContentHashException.class, + () -> verifyContentWithSeparateSignature(message, signature, "rsa")); } private void verifyContentWithSeparateSignature(InputStream content, InputStream signature, String alias) throws Exception { - DefaultSignedDataVerifierConfiguration verifierConf = getCryptoCmsSignedDataVerifierConf("system.jks", Collections.singletonList(alias), Boolean.FALSE); SignedDataVerifier verifier = new SignedDataVerifierFromHeader(verifierConf); @@ -294,19 +286,22 @@ public class SignedDataTest { verifyDetachedSignatureWithKeystore("system.jks", "noEntry", "rsa"); } - @Test(expected = CryptoCmsException.class) + @Test public void verifyWithEmptyAlias() throws Exception { - verifyDetachedSignatureWithKeystore("system.jks", ""); + assertThrows(CryptoCmsException.class, + () -> verifyDetachedSignatureWithKeystore("system.jks", "")); } - @Test(expected = CryptoCmsNoCertificateForSignerInfoException.class) + @Test public void verifyDetachedSignatureWithAliasNotFittingToSigner() throws Exception { - verifyDetachedSignatureWithKeystore("system.jks", "rsa2"); + assertThrows(CryptoCmsNoCertificateForSignerInfoException.class, + () -> verifyDetachedSignatureWithKeystore("system.jks", "rsa2")); } - @Test(expected = CryptoCmsNoCertificateForSignerInfosException.class) + @Test public void verifyDetachedSignatureWithAliasNotFittingToSignerWithVerifiyAllSignaturesFalse() throws Exception { - verifyDetachedSignatureWithKeystore("system.jks", Boolean.FALSE, "rsa2"); + assertThrows(CryptoCmsNoCertificateForSignerInfosException.class, + () -> verifyDetachedSignatureWithKeystore("system.jks", Boolean.FALSE, "rsa2")); } private void verifyDetachedSignatureWithKeystore(String keystoreName, String... aliases) throws FileNotFoundException, CryptoCmsException, Exception { @@ -405,9 +400,10 @@ public class SignedDataTest { } // SHA1withECDSA // ECSDSA keys not supported - @Test(expected = CryptoCmsException.class) + @Test public void testSigAlgorithmSHA1withECDSA() throws Exception { - signAndVerifyByDSASigAlgorithm("SHA1withECDSA"); + assertThrows(CryptoCmsException.class, + () -> signAndVerifyByDSASigAlgorithm("SHA1withECDSA")); } // MD2withRSA @@ -471,13 +467,15 @@ public class SignedDataTest { signAndVerifyByRSASigAlgorithm("RIPEMD256withRSA"); } - @Test(expected = CryptoCmsInvalidKeyException.class) + @Test public void testSigAlgorithmDoesnotFitToDSAPrivateKey() throws Exception { - signAndVerifyByDSASigAlgorithm("RIPEMD128withRSA"); + assertThrows(CryptoCmsInvalidKeyException.class, + () -> signAndVerifyByDSASigAlgorithm("RIPEMD128withRSA")); } - @Test(expected = CryptoCmsInvalidKeyException.class) + @Test public void testSigAlgorithmDoesnotFitToRSAPrivateKey() throws Exception { - signAndVerifyByRSASigAlgorithm("SHA224withDSA"); + assertThrows(CryptoCmsInvalidKeyException.class, + () -> signAndVerifyByRSASigAlgorithm("SHA224withDSA")); } } diff --git a/components/camel-crypto-cms/src/test/java/org/apache/camel/component/crypto/cms/util/TestOriginatorInformationProvider.java b/components/camel-crypto-cms/src/test/java/org/apache/camel/component/crypto/cms/util/TestOriginatorInformationProvider.java index 43b5c2a..e59b715 100644 --- a/components/camel-crypto-cms/src/test/java/org/apache/camel/component/crypto/cms/util/TestOriginatorInformationProvider.java +++ b/components/camel-crypto-cms/src/test/java/org/apache/camel/component/crypto/cms/util/TestOriginatorInformationProvider.java @@ -26,7 +26,7 @@ import org.bouncycastle.cert.X509CertificateHolder; import org.bouncycastle.cms.OriginatorInfoGenerator; import org.bouncycastle.cms.OriginatorInformation; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; public class TestOriginatorInformationProvider implements OriginatorInformationProvider {
