Skip to content

Commit a3d8d60

Browse files
committed
Fix build and switched test assertions to AssertJ
1 parent ae3507b commit a3d8d60

File tree

3 files changed

+27
-69
lines changed

3 files changed

+27
-69
lines changed

pom.xml

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,28 @@
33
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
44
<modelVersion>4.0.0</modelVersion>
55

6-
<!-- <parent>-->
7-
<!-- <groupId>com.github.bbottema</groupId>-->
8-
<!-- <artifactId>standard-project-parent</artifactId>-->
9-
<!-- <version>1.0.24</version>-->
10-
<!-- </parent>-->
6+
<parent>
7+
<groupId>com.github.bbottema</groupId>
8+
<artifactId>standard-project-parent</artifactId>
9+
<version>1.0.24</version>
10+
</parent>
1111

1212
<groupId>org.simplejavamail</groupId>
1313
<artifactId>utils-mail-smime</artifactId>
1414
<packaging>jar</packaging>
1515
<name>utils-mail-smime</name>
16-
<version>2.1.0-SNAPSHOT</version>
16+
<version>2.0.1</version>
1717
<description>An S/MIME library for JavaMail</description>
1818
<url>http:///github.com/bbottema/java-utils-mail-smime</url>
1919
<inceptionYear>2021</inceptionYear>
2020

2121
<properties>
22-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23-
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
2422
<automaticModuleName>com.github.bbottema.java-utils-mail-smime</automaticModuleName>
2523
<!-- license plugin, see possible types here: -->
2624
<!-- https://github.com/mathieucarbou/license-maven-plugin/tree/master/license-maven-plugin/src/main/resources/com/mycila/maven/plugin/license/templates -->
2725
<license.type>com/mycila/maven/plugin/license/templates/APACHE-2.txt</license.type>
2826
<license.owner.name>Benny Bottema</license.owner.name>
2927
<license.owner.email>[email protected]</license.owner.email>
30-
<junit.version>5.8.2</junit.version>
31-
<maven.compiler.source>17</maven.compiler.source>
32-
<maven.compiler.target>17</maven.compiler.target>
3328
</properties>
3429

3530
<scm>
@@ -77,18 +72,6 @@
7772
<url>https://github.com/bbottema/java-utils-mail-smime/issues</url>
7873
</issueManagement>
7974

80-
<dependencyManagement>
81-
<dependencies>
82-
<dependency>
83-
<groupId>org.junit</groupId>
84-
<artifactId>junit-bom</artifactId>
85-
<version>${junit.version}</version>
86-
<type>pom</type>
87-
<scope>import</scope>
88-
</dependency>
89-
</dependencies>
90-
</dependencyManagement>
91-
9275
<dependencies>
9376
<dependency><!-- Gives us @NotNull and @Nullable -->
9477
<groupId>org.jetbrains</groupId>
@@ -122,17 +105,5 @@
122105
<artifactId>jakarta.mail</artifactId>
123106
<version>2.0.1</version>
124107
</dependency>
125-
126-
<dependency>
127-
<groupId>org.junit.jupiter</groupId>
128-
<artifactId>junit-jupiter-api</artifactId>
129-
<scope>test</scope>
130-
</dependency>
131-
<dependency>
132-
<groupId>org.junit.jupiter</groupId>
133-
<artifactId>junit-jupiter-engine</artifactId>
134-
<scope>test</scope>
135-
</dependency>
136108
</dependencies>
137-
138109
</project>

src/main/java/org/simplejavamail/utils/mail/smime/KeyEncapsulationAlgorithm.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
/*
2-
* Copyright (c) 2022. Ulrich Schuster, 10827 Berlin, Germany
3-
*/
4-
51
package org.simplejavamail.utils.mail.smime;
62

73
public enum KeyEncapsulationAlgorithm {

src/test/java/org/simplejavamail/utils/mail/smime/SmimeUtilTest.java

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
import jakarta.mail.internet.MimeMultipart;
88
import org.bouncycastle.cms.CMSAlgorithm;
99
import org.bouncycastle.jce.provider.BouncyCastleProvider;
10-
import org.junit.jupiter.api.BeforeAll;
11-
import org.junit.jupiter.api.Test;
12-
import org.junit.jupiter.api.TestInstance;
10+
import org.junit.Before;
11+
import org.junit.Test;
1312

1413
import java.io.IOException;
1514
import java.io.InputStream;
@@ -21,20 +20,17 @@
2120
import java.security.cert.X509Certificate;
2221
import java.util.Properties;
2322

24-
import static org.junit.jupiter.api.Assertions.assertEquals;
25-
import static org.junit.jupiter.api.Assertions.assertTrue;
23+
import static org.assertj.core.api.Assertions.assertThat;
2624

27-
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
28-
class SmimeUtilTest {
25+
public class SmimeUtilTest {
2926

30-
private static final String SignatureAlgorithmRsa = "SHA256withRSA";
3127
private static final String SignatureAlgorithmRsaPss = "SHA256WITHRSAANDMGF1";
3228
private SmimeKeyStore alicesKeyStore;
3329
private SmimeKeyStore bobsKeyStore;
3430
private Session mailSession;
3531

36-
@BeforeAll
37-
void setup() throws MessagingException, KeyStoreException, NoSuchProviderException, CertificateException, IOException, NoSuchAlgorithmException {
32+
@Before
33+
public void setup() throws MessagingException, KeyStoreException, NoSuchProviderException, CertificateException, IOException, NoSuchAlgorithmException {
3834
Security.addProvider(new BouncyCastleProvider());
3935
InputStream alicesKeystoreStream = this.getClass().getClassLoader().getResourceAsStream("alice.p12");
4036
this.alicesKeyStore = new SmimeKeyStore(alicesKeystoreStream, "alice".toCharArray());
@@ -55,71 +51,66 @@ private MimeMessage createTestMessage(String from, String to) throws MessagingEx
5551
}
5652

5753
@Test
58-
void SuccessfullySignAndValidate() throws MessagingException, IOException {
54+
public void SuccessfullySignAndValidate() throws MessagingException, IOException {
5955
MimeMessage testMessage = createTestMessage("[email protected]", "[email protected]");
6056
SmimeKey alicesKey = this.alicesKeyStore.getPrivateKey("alice", "alice".toCharArray());
6157
MimeMessage signedMessage = SmimeUtil.sign(this.mailSession, testMessage, alicesKey);
6258
MimeMultipart multipartContent = (MimeMultipart) signedMessage.getContent();
63-
assertEquals(SmimeState.SIGNED, SmimeUtil.getStatus(multipartContent));
64-
boolean isSignatureValid = SmimeUtil.checkSignature(multipartContent);
65-
assertTrue(isSignatureValid);
59+
assertThat(SmimeUtil.getStatus(multipartContent)).isEqualTo(SmimeState.SIGNED);
60+
assertThat(SmimeUtil.checkSignature(multipartContent)).isTrue();
6661
}
6762

6863
@Test
69-
void SuccessfullyEnvelopeAndDecryptDefault() throws MessagingException {
64+
public void SuccessfullyEnvelopeAndDecryptDefault() throws MessagingException {
7065
MimeMessage testMessage = createTestMessage("[email protected]", "[email protected]");
7166
SmimeKey alicesKey = this.alicesKeyStore.getPrivateKey("alice", "alice".toCharArray());
7267
X509Certificate alicesCert = alicesKey.getCertificate();
7368
MimeMessage encryptedMessage = SmimeUtil.encrypt(this.mailSession,
7469
SmimeUtil.sign(this.mailSession, testMessage, alicesKey),
7570
alicesCert);
76-
assertEquals(SmimeState.ENCRYPTED, SmimeUtil.getStatus((encryptedMessage)));
71+
assertThat(SmimeUtil.getStatus((encryptedMessage))).isEqualTo(SmimeState.ENCRYPTED);
7772
MimeMessage decryptedMessage = SmimeUtil.decrypt(this.mailSession, encryptedMessage, alicesKey);
78-
boolean isSignatureValid = SmimeUtil.checkSignature(decryptedMessage);
79-
assertTrue(isSignatureValid);
73+
assertThat(SmimeUtil.checkSignature(decryptedMessage)).isTrue();
8074
}
8175

8276
@Test
83-
void SuccessfullyEnvelopeAndDecrypt() throws MessagingException {
77+
public void SuccessfullyEnvelopeAndDecrypt() throws MessagingException {
8478
MimeMessage testMessage = createTestMessage("[email protected]", "[email protected]");
8579
SmimeKey alicesKey = this.alicesKeyStore.getPrivateKey("alice", "alice".toCharArray());
8680
X509Certificate alicesCert = alicesKey.getCertificate();
8781
MimeMessage encryptedMessage = SmimeUtil.encrypt(this.mailSession,
8882
SmimeUtil.sign(this.mailSession, testMessage, alicesKey, SignatureAlgorithmRsaPss),
8983
alicesCert, KeyEncapsulationAlgorithm.RSA_OAEP_SHA256, CMSAlgorithm.AES256_CBC);
90-
assertEquals(SmimeState.ENCRYPTED, SmimeUtil.getStatus((encryptedMessage)));
84+
assertThat(SmimeUtil.getStatus((encryptedMessage))).isEqualTo(SmimeState.ENCRYPTED);
9185
MimeMessage decryptedMessage = SmimeUtil.decrypt(this.mailSession, encryptedMessage, alicesKey);
92-
boolean isSignatureValid = SmimeUtil.checkSignature(decryptedMessage);
93-
assertTrue(isSignatureValid);
86+
assertThat(SmimeUtil.checkSignature(decryptedMessage)).isTrue();
9487
}
9588

9689
@Test
97-
void AliceToBoEnvelopeAndDecrypt() throws MessagingException {
90+
public void AliceToBoEnvelopeAndDecrypt() throws MessagingException {
9891
MimeMessage testMessage = createTestMessage("[email protected]", "[email protected]");
9992
SmimeKey alicesKey = this.alicesKeyStore.getPrivateKey("alice", "alice".toCharArray());
10093
SmimeKey bobsKey = this.bobsKeyStore.getPrivateKey("bob", "bob".toCharArray());
10194
X509Certificate bobsCert = bobsKey.getCertificate();
10295
MimeMessage encryptedMessage = SmimeUtil.encrypt(this.mailSession,
10396
SmimeUtil.sign(this.mailSession, testMessage, alicesKey, SignatureAlgorithmRsaPss),
10497
bobsCert, KeyEncapsulationAlgorithm.RSA_OAEP_SHA512, CMSAlgorithm.AES256_GCM);
105-
assertEquals(SmimeState.ENCRYPTED, SmimeUtil.getStatus((encryptedMessage)));
98+
assertThat(SmimeUtil.getStatus((encryptedMessage))).isEqualTo(SmimeState.ENCRYPTED);
10699
MimeMessage decryptedMessage = SmimeUtil.decrypt(this.mailSession, encryptedMessage, bobsKey);
107-
boolean isSignatureValid = SmimeUtil.checkSignature(decryptedMessage);
108-
assertTrue(isSignatureValid);
100+
assertThat(SmimeUtil.checkSignature(decryptedMessage)).isTrue();
109101
}
110102

111103
@Test
112-
void BobToAliceEnvelopeAndDecrypt() throws MessagingException {
104+
public void BobToAliceEnvelopeAndDecrypt() throws MessagingException {
113105
MimeMessage testMessage = createTestMessage("[email protected]", "[email protected]");
114106
SmimeKey bobsKey = this.bobsKeyStore.getPrivateKey("bob", "bob".toCharArray());
115107
SmimeKey alicesKey = this.alicesKeyStore.getPrivateKey("alice", "alice".toCharArray());
116108
X509Certificate alicesCert = alicesKey.getCertificate();
117109
MimeMessage encryptedMessage = SmimeUtil.encrypt(this.mailSession,
118110
SmimeUtil.sign(this.mailSession, testMessage, bobsKey, SignatureAlgorithmRsaPss),
119111
alicesCert, KeyEncapsulationAlgorithm.RSA_OAEP_SHA384, CMSAlgorithm.AES192_CCM);
120-
assertEquals(SmimeState.ENCRYPTED, SmimeUtil.getStatus((encryptedMessage)));
112+
assertThat(SmimeUtil.getStatus((encryptedMessage))).isEqualTo(SmimeState.ENCRYPTED);
121113
MimeMessage decryptedMessage = SmimeUtil.decrypt(this.mailSession, encryptedMessage, alicesKey);
122-
boolean isSignatureValid = SmimeUtil.checkSignature(decryptedMessage);
123-
assertTrue(isSignatureValid);
114+
assertThat(SmimeUtil.checkSignature(decryptedMessage)).isTrue();
124115
}
125116
}

0 commit comments

Comments
 (0)