chibenwa commented on code in PR #2405: URL: https://github.com/apache/james-project/pull/2405#discussion_r1764063508
########## server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/SubAddressingTest.java: ########## @@ -96,40 +97,79 @@ void shouldNotAddStorageDirectiveWhenNoRight() throws Exception { @Test void shouldAddStorageDirectiveMatchingDetailsWhenRight() throws Exception { - MailboxSession session = mailboxManager.createSystemSession(Username.of("recipient")); + Username username = Username.of("recipient"); + MailboxSession session = mailboxManager.createSystemSession(username); // create Mailbox MailboxId mailboxId = mailboxManager.createMailbox( - MailboxPath.forUser(Username.of("recipient"), "any"), session) - .get(); + MailboxPath.forUser(username, "any"), session).get(); - // give right to post - MailboxACL.ACLCommand command = MailboxACL.command() - .key(MailboxACL.ANYBODY_KEY) - .rights(MailboxACL.Right.Post) - .asAddition(); + giveRightToPost(mailboxId, session); - mailboxManager.applyRightsCommand(mailboxId, command, session); + Mail mail = sendSubAddressedMail(true); + + AttributeName recipient = AttributeName.of("DeliveryPaths_recipient@localhost"); + assertThat(mail.attributes().map(this::unbox)) + .doesNotContain(Pair.of(recipient, "any")); + } + + @Test + void shouldAddStorageDirectiveWhenEveryoneHasRightAndSenderIsUnknown() throws Exception { + + Username username = Username.of("recipient"); + MailboxSession session = mailboxManager.createSystemSession(username); + + // create Mailbox + MailboxId mailboxId = mailboxManager.createMailbox( + MailboxPath.forUser(username, "any"), session).get(); + + giveRightToPost(mailboxId, session); + Mail mail = sendSubAddressedMail(false); + + AttributeName recipient = AttributeName.of("DeliveryPaths_recipient@localhost"); + assertThat(mail.attributes().map(this::unbox)) + .doesNotContain(Pair.of(recipient, "any")); + } + + @Test + void shouldNotAddStorageDirectiveWhenNooneHasRightAndSenderIsUnknown() throws Exception { + + Username username = Username.of("recipient"); + MailboxSession session = mailboxManager.createSystemSession(username); + + // create Mailbox + MailboxId mailboxId = mailboxManager.createMailbox( + MailboxPath.forUser(username, "any"), session).get(); - Mail mail = sendSubAddressedMail(); + giveRightToPost(mailboxId, session); + Mail mail = sendSubAddressedMail(false); AttributeName recipient = AttributeName.of("DeliveryPaths_recipient@localhost"); assertThat(mail.attributes().map(this::unbox)) .doesNotContain(Pair.of(recipient, "any")); } - private Mail sendSubAddressedMail() throws MessagingException, IOException { + private void giveRightToPost(MailboxId mailboxId, MailboxSession session) throws MailboxException { + MailboxACL.ACLCommand command = MailboxACL.command() + .key(MailboxACL.ANYBODY_KEY) + .rights(MailboxACL.Right.Post) + .asAddition(); + + mailboxManager.applyRightsCommand(mailboxId, command, session); + } + + private Mail sendSubAddressedMail(boolean knownSender) throws MessagingException, IOException { Review Comment: Protip: just return a FakeMail.Builder without the sender, and let caller decide if he wants sender or not and let him build the mail then execute the mailbet on it. Caller code: ``` Mail mail = mailBuilder().sender(...).build(); testee.service(mail); ``` Which is more readable (tests shall be as straightforward as possible and avoid ccidental indirection that obfuscate them... -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@james.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@james.apache.org For additional commands, e-mail: notifications-h...@james.apache.org