JAMES-2366 Check explicitly SMTP RCPT command upon RRT loop Should be rejected with 550 code
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/025a0c3d Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/025a0c3d Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/025a0c3d Branch: refs/heads/master Commit: 025a0c3dbd1f69ae08ca7512880758a32d3df7c0 Parents: b676aa9 Author: benwa <btell...@linagora.com> Authored: Mon Apr 16 15:32:46 2018 +0700 Committer: benwa <btell...@linagora.com> Committed: Fri Apr 20 09:12:02 2018 +0700 ---------------------------------------------------------------------- .../transport/mailets/GroupMappingTest.java | 5 ++-- .../apache/james/utils/SMTPMessageSender.java | 29 +++++++++++++++++++- 2 files changed, 31 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/025a0c3d/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 d1c71a8..2339ca5 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 @@ -41,6 +41,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.protocols.smtp.SMTPRetCode; import org.apache.james.transport.matchers.All; import org.apache.james.transport.matchers.RecipientIsLocal; import org.apache.james.utils.DataProbeImpl; @@ -288,11 +289,11 @@ public class GroupMappingTest { webAdminApi.put(GroupsRoutes.ROOT_PATH + "/" + GROUP_ON_DOMAIN2 + "/" + GROUP_ON_DOMAIN1); messageSender.connect(LOCALHOST_IP, SMTP_PORT) - .sendMessage(FakeMail.builder() + .sendEnvelope(FakeMail.builder() .mimeMessage(message) .sender(SENDER) .recipient(GROUP_ON_DOMAIN1)) - .awaitSentFail(awaitAtMostOneMinute); + .awaitSentFail(SMTPRetCode.MAILBOX_PERM_UNAVAILABLE, awaitAtMostOneMinute); imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT) .login(USER_DOMAIN1, PASSWORD) http://git-wip-us.apache.org/repos/asf/james-project/blob/025a0c3d/server/testing/src/main/java/org/apache/james/utils/SMTPMessageSender.java ---------------------------------------------------------------------- diff --git a/server/testing/src/main/java/org/apache/james/utils/SMTPMessageSender.java b/server/testing/src/main/java/org/apache/james/utils/SMTPMessageSender.java index cc35a0a..723f4e1 100644 --- a/server/testing/src/main/java/org/apache/james/utils/SMTPMessageSender.java +++ b/server/testing/src/main/java/org/apache/james/utils/SMTPMessageSender.java @@ -149,6 +149,24 @@ public class SMTPMessageSender extends ExternalResource implements Closeable { return this; } + public SMTPMessageSender sendEnvelope(Mail mail) throws MessagingException { + try { + String from = mail.getSender().asString(); + smtpClient.helo(senderDomain); + smtpClient.setSender(from); + mail.getRecipients().stream() + .map(MailAddress::asString) + .forEach(Throwing.consumer(smtpClient::addRecipient)); + } catch (IOException e) { + throw Throwables.propagate(e); + } + return this; + } + + public SMTPMessageSender sendEnvelope(FakeMail.Builder mail) throws MessagingException { + return sendEnvelope(mail.build()); + } + public SMTPMessageSender sendMessage(FakeMail.Builder mail) throws MessagingException { return sendMessage(mail.build()); } @@ -173,11 +191,20 @@ public class SMTPMessageSender extends ExternalResource implements Closeable { conditionFactory.until(this::messageSendingFailed); } - public boolean messageSendingFailed() throws IOException { + public void awaitSentFail(String code, ConditionFactory conditionFactory) { + conditionFactory.until(() -> messageSendingFailedWithCode(code)); + } + + public boolean messageSendingFailed() { String replyString = smtpClient.getReplyString().trim(); return replyString.startsWith("4") || replyString.startsWith("5"); } + public boolean messageSendingFailedWithCode(String code) { + String replyString = smtpClient.getReplyString().trim(); + return replyString.startsWith(code); + } + public boolean messageHaveNotBeenSent() throws IOException { return !messageHasBeenSent(); } --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org