This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 9094ca6685e4c6441222accfbd77d9102872f271
Author: Benoit Tellier <[email protected]>
AuthorDate: Tue Jan 25 14:53:00 2022 +0700

    JAMES-3708 Invalid mail address: Demonstrate NPE in RemoteDelivery
---
 .../org/apache/james/core/MailAddressTest.java     | 18 +++++++++++++
 ...ectResolutionRemoteDeliveryIntegrationTest.java | 31 ++++++++++++++++++++++
 2 files changed, 49 insertions(+)

diff --git a/core/src/test/java/org/apache/james/core/MailAddressTest.java 
b/core/src/test/java/org/apache/james/core/MailAddressTest.java
index 6ab51bd..91abe63 100644
--- a/core/src/test/java/org/apache/james/core/MailAddressTest.java
+++ b/core/src/test/java/org/apache/james/core/MailAddressTest.java
@@ -28,6 +28,7 @@ import javax.mail.internet.AddressException;
 import javax.mail.internet.InternetAddress;
 
 import org.assertj.core.api.Assertions;
+import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.Arguments;
@@ -47,6 +48,7 @@ class MailAddressTest {
                 GOOD_ADDRESS,
                 GOOD_QUOTED_LOCAL_PART,
                 "[email protected]",
+                "[email protected]",
                 "server-dev@[127.0.0.1]",
                 "server-dev@#123",
                 "server-dev@#123.apache.org",
@@ -95,6 +97,22 @@ class MailAddressTest {
             .doesNotThrowAnyException();
     }
 
+    @Disabled("JAMES-3708 Fails on the following values:" +
+        "" +
+        "[email protected] -> javax.mail.internet.AddressException: Local 
address contains dot-dot in string ``[email protected]''" +
+        "server-dev@#123 -> javax.mail.internet.AddressException: Domain 
contains illegal character in string ``server-dev@#123''" +
+        "server-dev@#123.apache.org -> javax.mail.internet.AddressException: 
Domain contains illegal character in string ``server-dev@#123.apache.org'''" +
+        "server-dev\\[email protected]' -> 
javax.mail.internet.AddressException: Local address ends with dot in string 
``server-dev\\[email protected]''" +
+        "" +
+        "Impact: potential NPEs (bouncing, remoteDelivery)" +
+        "Those values should likely be rejected")
+    @ParameterizedTest
+    @MethodSource("goodAddresses")
+    void toInternetAddressShouldNoop(String mailAddress) throws Exception {
+        assertThat(new MailAddress(mailAddress).toInternetAddress())
+            .isNotNull();
+    }
+
     @ParameterizedTest
     @MethodSource("badAddresses")
     void testBadMailAddressString(String mailAddress) {
diff --git 
a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/DirectResolutionRemoteDeliveryIntegrationTest.java
 
b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/DirectResolutionRemoteDeliveryIntegrationTest.java
index 6def318..7e03f9c 100644
--- 
a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/DirectResolutionRemoteDeliveryIntegrationTest.java
+++ 
b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/DirectResolutionRemoteDeliveryIntegrationTest.java
@@ -26,10 +26,12 @@ import static 
org.apache.james.mailets.configuration.Constants.LOCALHOST_IP;
 import static org.apache.james.mailets.configuration.Constants.PASSWORD;
 import static 
org.apache.james.mailets.configuration.Constants.awaitAtMostOneMinute;
 import static 
org.apache.james.mailets.configuration.MailetConfiguration.LOCAL_DELIVERY;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.hamcrest.Matchers.equalTo;
 import static org.hamcrest.Matchers.hasSize;
 
 import java.io.File;
+import java.io.IOException;
 import java.net.InetAddress;
 import java.util.List;
 
@@ -115,6 +117,35 @@ public class DirectResolutionRemoteDeliveryIntegrationTest 
{
             .untilAsserted(this::assertMessageReceivedByTheSmtpServer);
     }
 
+    @Disabled("JAMES-3708 [email protected] triggers a parsing error within 
javax.mail, the exception is ingnored and substituted with null," +
+        "resulting in a NPE in RemoteDelivery. Instead we should reject as 
part of SMTP reception emails we cannot handle." +
+        "This can be used to make the delivery of all remote recipients fail 
while local recipient succeeds.")
+    @Test
+    void test(@TempDir File temporaryFolder) throws Exception {
+        InMemoryDNSService inMemoryDNSService = new InMemoryDNSService()
+            .registerMxRecord(JAMES_ANOTHER_DOMAIN, 
fakeSmtp.getContainer().getContainerIp());
+
+        jamesServer = TemporaryJamesServer.builder()
+            .withBase(SMTP_ONLY_MODULE)
+            .withOverrides(binder -> 
binder.bind(DNSService.class).toInstance(inMemoryDNSService))
+            
.withMailetContainer(TemporaryJamesServer.simpleMailetContainerConfiguration()
+                .putProcessor(directResolutionTransport())
+                .putProcessor(CommonProcessors.bounces()))
+            .withSmtpConfiguration(SmtpConfiguration.builder()
+                .doNotVerifyIdentity()
+                .withAutorizedAddresses("0.0.0.0/0.0.0.0"))
+            .build(temporaryFolder);
+        jamesServer.start();
+
+        dataProbe = jamesServer.getProbe(DataProbeImpl.class);
+        dataProbe.addDomain(DEFAULT_DOMAIN);
+        dataProbe.addUser(FROM, PASSWORD);
+
+        assertThatThrownBy(() -> messageSender.connect(LOCALHOST_IP, 
jamesServer.getProbe(SmtpGuiceProbe.class).getSmtpPort())
+            .sendMessage(FROM, "to..user@" + JAMES_ANOTHER_DOMAIN))
+            .isInstanceOf(IOException.class);
+    }
+
     @Test
     void directResolutionShouldFailoverOnSecondMxWhenFirstMxFailed(@TempDir 
File temporaryFolder) throws Exception {
         InMemoryDNSService inMemoryDNSService = new InMemoryDNSService()

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to