florentos17 commented on code in PR #2405:
URL: https://github.com/apache/james-project/pull/2405#discussion_r1764555858


##########
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 {

Review Comment:
   fair point ! 
   the only thing is that initializing the ACLCommand throws an exception so i 
cannot initialize it as a static final constant directly. so i used a 
@BeforeAll method to initialize the different commands i will have to use, is 
that ok ?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to