This is an automated email from the ASF dual-hosted git repository.
rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
The following commit(s) were added to refs/heads/master by this push:
new d8d8fc4010 JAMES-4054 Update SMIMECheckSignatureIntegrationTest to
include IsSMIMESigned matcher (#2409)
d8d8fc4010 is described below
commit d8d8fc40100f4a4cc42de06abf325b0d77fce063
Author: hungphan227 <[email protected]>
AuthorDate: Tue Sep 17 14:35:15 2024 +0700
JAMES-4054 Update SMIMECheckSignatureIntegrationTest to include
IsSMIMESigned matcher (#2409)
---
mailet/crypto/pom.xml | 5 ++
.../james/transport/matcher/IsSMIMESigned.java | 3 +-
.../james/transport/matcher/IsSMIMESignedTest.java | 80 ++++++++++++++++++++++
.../main/resources/eml/mail_with_no_signature.eml | 1 +
...il_with_no_signature.eml => non_smime_mail.eml} | 0
.../crypto/SMIMECheckSignatureIntegrationTest.java | 14 ++++
...ckSignatureWithKeyStoreFileIntegrationTest.java | 4 +-
...MECheckSignatureWithPemFileIntegrationTest.java | 4 +-
8 files changed, 105 insertions(+), 6 deletions(-)
diff --git a/mailet/crypto/pom.xml b/mailet/crypto/pom.xml
index bc7c11e2e5..62ff793454 100644
--- a/mailet/crypto/pom.xml
+++ b/mailet/crypto/pom.xml
@@ -41,6 +41,11 @@
<groupId>${james.groupId}</groupId>
<artifactId>apache-mailet-base</artifactId>
</dependency>
+ <dependency>
+ <groupId>${james.groupId}</groupId>
+ <artifactId>apache-mailet-test</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>${james.groupId}</groupId>
<artifactId>james-server-core</artifactId>
diff --git
a/mailet/crypto/src/main/java/org/apache/james/transport/matcher/IsSMIMESigned.java
b/mailet/crypto/src/main/java/org/apache/james/transport/matcher/IsSMIMESigned.java
index 26a19eaa42..343d87f909 100644
---
a/mailet/crypto/src/main/java/org/apache/james/transport/matcher/IsSMIMESigned.java
+++
b/mailet/crypto/src/main/java/org/apache/james/transport/matcher/IsSMIMESigned.java
@@ -45,8 +45,7 @@ public class IsSMIMESigned extends GenericMatcher {
if (message == null) {
return null;
}
-
-
+
if (message.isMimeType("multipart/signed")
|| message.isMimeType("application/pkcs7-signature")
|| message.isMimeType("application/x-pkcs7-signature")
diff --git
a/mailet/crypto/src/test/java/org/apache/james/transport/matcher/IsSMIMESignedTest.java
b/mailet/crypto/src/test/java/org/apache/james/transport/matcher/IsSMIMESignedTest.java
new file mode 100644
index 0000000000..58f068a14e
--- /dev/null
+++
b/mailet/crypto/src/test/java/org/apache/james/transport/matcher/IsSMIMESignedTest.java
@@ -0,0 +1,80 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.transport.matcher;
+
+import static org.apache.mailet.base.MailAddressFixture.RECIPIENT1;
+import static org.apache.mailet.base.MailAddressFixture.SENDER;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.james.core.builder.MimeMessageBuilder;
+import org.apache.mailet.base.test.FakeMail;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+public class IsSMIMESignedTest {
+ private IsSMIMESigned isSMIMESigned;
+
+ @BeforeEach
+ void beforeEach() {
+ isSMIMESigned = new IsSMIMESigned();
+ }
+
+ @ParameterizedTest
+ @ValueSource(strings = {"multipart/signed",
+ "application/pkcs7-signature",
+ "application/x-pkcs7-signature",
+ "application/pkcs7-mime; smime-type=signed-data; name=\"smime.p7m\"",
+ "application/x-pkcs7-mime; smime-type=signed-data;
name=\"smime.p7m\""})
+ void
matchShouldReturnNonEmptyListWhenMessageContentTypeIsSMIMERelated(String
contentType) throws Exception {
+ FakeMail mail = FakeMail.builder()
+ .name("mail")
+
.mimeMessage(MimeMessageBuilder.mimeMessageBuilder().addHeader("Content-Type",
contentType))
+ .sender(SENDER)
+ .recipient(RECIPIENT1)
+ .build();
+ assertThat(isSMIMESigned.match(mail)).isNotEmpty();
+ }
+
+ @Test
+ void matchShouldReturnNullWhenMessageContentTypeIsNotSMIMERelated() throws
Exception {
+ FakeMail mail = FakeMail.builder()
+ .name("mail")
+
.mimeMessage(MimeMessageBuilder.mimeMessageBuilder().addHeader("Content-Type",
"text/plain"))
+ .sender(SENDER)
+ .recipient(RECIPIENT1)
+ .build();
+ assertThat(isSMIMESigned.match(mail)).isNull();
+ }
+
+ @Test
+ void matchShouldReturnNullWhenMailIsNull() throws Exception {
+ assertThat(isSMIMESigned.match(null)).isNull();
+ }
+
+ @Test
+ void matchShouldReturnNullWhenMessageIsNull() throws Exception {
+ FakeMail mail = FakeMail.builder()
+ .name("mail")
+ .build();
+ assertThat(isSMIMESigned.match(mail)).isNull();
+ }
+}
diff --git
a/server/mailet/integration-testing/src/main/resources/eml/mail_with_no_signature.eml
b/server/mailet/integration-testing/src/main/resources/eml/mail_with_no_signature.eml
index 7787b0b1f1..d9eac7ca34 100644
---
a/server/mailet/integration-testing/src/main/resources/eml/mail_with_no_signature.eml
+++
b/server/mailet/integration-testing/src/main/resources/eml/mail_with_no_signature.eml
@@ -3,5 +3,6 @@ To: [email protected]
Subject: test
Message-ID: <[email protected]>
Date: Fri, 1 Nov 2019 10:21:39 +0700
+Content-Type: application/x-pkcs7-mime; smime-type=signed-data;
name="smime.p7m"
test SMIME
\ No newline at end of file
diff --git
a/server/mailet/integration-testing/src/main/resources/eml/mail_with_no_signature.eml
b/server/mailet/integration-testing/src/main/resources/eml/non_smime_mail.eml
similarity index 100%
copy from
server/mailet/integration-testing/src/main/resources/eml/mail_with_no_signature.eml
copy to
server/mailet/integration-testing/src/main/resources/eml/non_smime_mail.eml
diff --git
a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/crypto/SMIMECheckSignatureIntegrationTest.java
b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/crypto/SMIMECheckSignatureIntegrationTest.java
index 8d02701f06..e759d31374 100644
---
a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/crypto/SMIMECheckSignatureIntegrationTest.java
+++
b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/crypto/SMIMECheckSignatureIntegrationTest.java
@@ -115,4 +115,18 @@ public abstract class SMIMECheckSignatureIntegrationTest {
.awaitMessage(awaitAtMostOneMinute);
assertThat(testIMAPClient().readFirstMessage()).containsSequence("X-SMIME-Status:
Not signed");
}
+
+ @Test
+ public void checkSMIMESignatureShouldDoNothingWhenItIsNonSMIMEMail()
throws Exception {
+ messageSender().connect(LOCALHOST_IP,
jamesServer().getProbe(SmtpGuiceProbe.class).getSmtpAuthRequiredPort())
+ .authenticate(FROM, PASSWORD)
+ .sendMessageWithHeaders(FROM, RECIPIENT,
+
ClassLoaderUtils.getSystemResourceAsString("eml/non_smime_mail.eml"));
+
+ testIMAPClient().connect(LOCALHOST_IP,
jamesServer().getProbe(ImapGuiceProbe.class).getImapPort())
+ .login(RECIPIENT, PASSWORD)
+ .select(TestIMAPClient.INBOX)
+ .awaitMessage(awaitAtMostOneMinute);
+
assertThat(testIMAPClient().readFirstMessage()).doesNotContain("X-SMIME-Status");
+ }
}
diff --git
a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/crypto/SMIMECheckSignatureWithKeyStoreFileIntegrationTest.java
b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/crypto/SMIMECheckSignatureWithKeyStoreFileIntegrationTest.java
index 1e0bdc0806..7f2a392b88 100644
---
a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/crypto/SMIMECheckSignatureWithKeyStoreFileIntegrationTest.java
+++
b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/crypto/SMIMECheckSignatureWithKeyStoreFileIntegrationTest.java
@@ -31,7 +31,7 @@ import
org.apache.james.mailets.configuration.MailetConfiguration;
import org.apache.james.mailets.configuration.MailetContainer;
import org.apache.james.mailets.configuration.ProcessorConfiguration;
import org.apache.james.transport.mailets.SMIMECheckSignature;
-import org.apache.james.transport.matchers.All;
+import org.apache.james.transport.matcher.IsSMIMESigned;
import org.apache.james.util.date.ZonedDateTimeProvider;
import org.apache.james.utils.DataProbeImpl;
import org.apache.james.utils.SMTPMessageSender;
@@ -58,7 +58,7 @@ public class
SMIMECheckSignatureWithKeyStoreFileIntegrationTest extends SMIMEChe
.addMailet(MailetConfiguration.BCC_STRIPPER)
.addMailet(MailetConfiguration.builder()
.mailet(SMIMECheckSignature.class)
- .matcher(All.class)
+ .matcher(IsSMIMESigned.class)
.addProperty("fileType", "keystore")
.addProperty("keyStoreFileName",
FileSystem.CLASSPATH_PROTOCOL + "trusted_cert_keystore")
.addProperty("keyStorePassword", "secret")
diff --git
a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/crypto/SMIMECheckSignatureWithPemFileIntegrationTest.java
b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/crypto/SMIMECheckSignatureWithPemFileIntegrationTest.java
index 1c33661c59..fc4503afd9 100644
---
a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/crypto/SMIMECheckSignatureWithPemFileIntegrationTest.java
+++
b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/crypto/SMIMECheckSignatureWithPemFileIntegrationTest.java
@@ -31,7 +31,7 @@ import
org.apache.james.mailets.configuration.MailetConfiguration;
import org.apache.james.mailets.configuration.MailetContainer;
import org.apache.james.mailets.configuration.ProcessorConfiguration;
import org.apache.james.transport.mailets.SMIMECheckSignature;
-import org.apache.james.transport.matchers.All;
+import org.apache.james.transport.matcher.IsSMIMESigned;
import org.apache.james.util.date.ZonedDateTimeProvider;
import org.apache.james.utils.DataProbeImpl;
import org.apache.james.utils.SMTPMessageSender;
@@ -58,7 +58,7 @@ public class SMIMECheckSignatureWithPemFileIntegrationTest
extends SMIMECheckSig
.addMailet(MailetConfiguration.BCC_STRIPPER)
.addMailet(MailetConfiguration.builder()
.mailet(SMIMECheckSignature.class)
- .matcher(All.class)
+ .matcher(IsSMIMESigned.class)
.addProperty("fileType", "pem")
.addProperty("pemFileName", FileSystem.CLASSPATH_PROTOCOL
+ "trusted_certificate.pem")
.addProperty("debug", "true"))
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]