You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ad...@apache.org on 2017/09/13 10:57:50 UTC

[24/24] james-project git commit: JAMES-2139 Add IT so that group does not support external address

JAMES-2139 Add IT so that group does not support external address


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/81bf0a3c
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/81bf0a3c
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/81bf0a3c

Branch: refs/heads/master
Commit: 81bf0a3c8c009b49a8c9bb4effd7a9af391b6469
Parents: d42ec7f
Author: quynhn <qn...@linagora.com>
Authored: Tue Sep 12 16:11:01 2017 +0700
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Wed Sep 13 10:23:34 2017 +0200

----------------------------------------------------------------------
 server/mailet/integration-testing/pom.xml       |  6 ++
 .../transport/mailets/GroupMappingTest.java     | 79 +++++++++++++++++++-
 .../src/test/resources/domainlist.xml           |  4 +-
 3 files changed, 85 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/81bf0a3c/server/mailet/integration-testing/pom.xml
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/pom.xml b/server/mailet/integration-testing/pom.xml
index 147b510..02858f8 100644
--- a/server/mailet/integration-testing/pom.xml
+++ b/server/mailet/integration-testing/pom.xml
@@ -55,6 +55,12 @@
         </dependency>
         <dependency>
             <groupId>${project.groupId}</groupId>
+            <artifactId>james-server-dnsservice-api</artifactId>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
             <artifactId>james-server-guice-common</artifactId>
             <type>test-jar</type>
             <scope>test</scope>

http://git-wip-us.apache.org/repos/asf/james-project/blob/81bf0a3c/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/GroupMappingTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/GroupMappingTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/GroupMappingTest.java
index f391fff..db99d55 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/GroupMappingTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/GroupMappingTest.java
@@ -19,14 +19,19 @@
 
 package org.apache.james.transport.mailets;
 
+import static com.jayway.restassured.RestAssured.with;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.isEmptyOrNullString;
 
+import java.net.InetAddress;
 import java.util.concurrent.TimeUnit;
 
 import javax.mail.internet.MimeMessage;
 
 import org.apache.james.core.MailAddress;
+import org.apache.james.dnsservice.api.DNSService;
+import org.apache.james.dnsservice.api.InMemoryDNSService;
 import org.apache.james.mailbox.model.MailboxConstants;
 import org.apache.james.mailets.TemporaryJamesServer;
 import org.apache.james.mailets.configuration.CommonProcessors;
@@ -35,6 +40,7 @@ import org.apache.james.mailets.configuration.MailetContainer;
 import org.apache.james.mailets.configuration.ProcessorConfiguration;
 import org.apache.james.modules.MailboxProbeImpl;
 import org.apache.james.probe.DataProbe;
+import org.apache.james.util.streams.SwarmGenericContainer;
 import org.apache.james.utils.DataProbeImpl;
 import org.apache.james.utils.IMAPMessageReader;
 import org.apache.james.utils.SMTPMessageSender;
@@ -79,13 +85,45 @@ public class GroupMappingTest {
     private RequestSpecification restApiRequest;
 
     @Rule
+    public final SwarmGenericContainer fakeSmtp = new SwarmGenericContainer("weave/rest-smtp-sink:latest")
+        .withExposedPorts(25);
+
+    private final InMemoryDNSService inMemoryDNSService = new InMemoryDNSService();
+    @Rule
     public TemporaryFolder temporaryFolder = new TemporaryFolder();
+
+    private InetAddress containerIp;
     @Before
     public void setup() throws Exception {
+
+        containerIp = InetAddress.getByName(fakeSmtp.getContainerIp());
+        inMemoryDNSService.registerRecord("yopmail.com", containerIp, "yopmail.com");
+
         MailetContainer mailetContainer = MailetContainer.builder()
             .postmaster("postmaster@" + DOMAIN1)
             .threads(5)
-            .addProcessor(CommonProcessors.root())
+            .addProcessor(ProcessorConfiguration.builder()
+                .state("root")
+                .enableJmx(true)
+                .addMailet(MailetConfiguration.builder()
+                    .match("All")
+                    .clazz("PostmasterAlias")
+                    .build())
+                .addMailet(MailetConfiguration.builder()
+                    .match("RelayLimit=30")
+                    .clazz("Null")
+                    .build())
+                .addMailet(MailetConfiguration.builder()
+                    .match("SMTPAuthSuccessful")
+                    .clazz("ToProcessor")
+                    .addProperty("processor", "transport")
+                    .build())
+                .addMailet(MailetConfiguration.builder()
+                    .match("All")
+                    .clazz("ToProcessor")
+                    .addProperty("processor", "transport")
+                    .build())
+                .build())
             .addProcessor(CommonProcessors.error())
             .addProcessor(ProcessorConfiguration.transport()
                 .enableJmx(true)
@@ -120,7 +158,8 @@ public class GroupMappingTest {
                 .build())
             .build();
 
-        jamesServer = new TemporaryJamesServer(temporaryFolder, mailetContainer);
+        jamesServer = new TemporaryJamesServer(temporaryFolder, mailetContainer, (binder) -> binder.bind(DNSService.class).toInstance(inMemoryDNSService));
+
         Duration slowPacedPollInterval = Duration.FIVE_HUNDRED_MILLISECONDS;
         calmlyAwait = Awaitility.with().pollInterval(slowPacedPollInterval).and().with().pollDelay(slowPacedPollInterval).await();
 
@@ -388,4 +427,40 @@ public class GroupMappingTest {
             calmlyAwait.atMost(Duration.ONE_MINUTE).until(() -> imapMessageReader.userReceivedMessage(USER_DOMAIN2, PASSWORD));
         }
     }
+
+    @Test
+    public void externalGroupMemberAreNotSupported() throws Exception {
+        String externalMail = "ray@yopmail.com";
+        restApiRequest.put(GroupsRoutes.ROOT_PATH + "/" + GROUP_ON_DOMAIN1 + "/" + externalMail);
+
+        Mail mail = FakeMail.builder()
+            .mimeMessage(message)
+            .sender(new MailAddress(SENDER))
+            .recipient(new MailAddress(GROUP_ON_DOMAIN1))
+            .build();
+
+        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, DOMAIN1);) {
+            messageSender.sendMessage(mail);
+            calmlyAwait.atMost(Duration.ONE_MINUTE).until(messageSender::messageHasBeenSent);
+
+            calmlyAwait.atMost(1, TimeUnit.MINUTES)
+                .until(() -> {
+                    try {
+                        with()
+                            .baseUri("http://" + containerIp.getHostAddress())
+                            .port(80)
+                            .get("/api/email")
+                        .then()
+                            .statusCode(200)
+                            .body("[0].from", equalTo(SENDER))
+                            .body("[0].to[0]", equalTo(externalMail))
+                            .body("[0].text", equalTo(MESSAGE_CONTENT));
+
+                        return true;
+                    } catch(AssertionError e) {
+                        return false;
+                    }
+                });
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/81bf0a3c/server/mailet/integration-testing/src/test/resources/domainlist.xml
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/resources/domainlist.xml b/server/mailet/integration-testing/src/test/resources/domainlist.xml
index d9040c0..fc3d912 100644
--- a/server/mailet/integration-testing/src/test/resources/domainlist.xml
+++ b/server/mailet/integration-testing/src/test/resources/domainlist.xml
@@ -21,7 +21,7 @@
 <!-- See http://james.apache.org/server/3/config.html for usage -->
 
 <domainlist>
-  <autodetect>true</autodetect>
-  <autodetectIP>true</autodetectIP>
+  <autodetect>false</autodetect>
+  <autodetectIP>false</autodetectIP>
   <defaultDomain>localhost</defaultDomain>
 </domainlist>


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org