Arsnael commented on code in PR #1856:
URL: https://github.com/apache/james-project/pull/1856#discussion_r1430867117


##########
server/mailet/integration-testing/src/test/java/org/apache/james/mailets/ForwardLoopIntegrationTest.java:
##########
@@ -186,19 +200,89 @@ void regularForwardShouldNotCreateLoopError() throws 
Exception {
         Awaitility.await().until(() -> 
mailRepositoryProbe.getRepositoryMailCount(CUSTOM_REPOSITORY) == 1L);
 
         SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
-            List<Mail> mails = mailRepositoryProbe.listMails(CUSTOM_REPOSITORY)
-                .collect(ImmutableList.toImmutableList());
-
-            
softly.assertThat(mails.get(0).getRecipients()).containsOnly(CEDRIC.asMailAddress());
+            Mail mail = 
mailRepositoryProbe.listMails(CUSTOM_REPOSITORY).findAny().get();
+            
softly.assertThat(mail.getRecipients()).containsOnly(SENDER.asMailAddress());
+            
softly.assertThat(mail.getMaybeSender().asOptional()).contains(CEDRIC.asMailAddress());
         }));
     }
 
     @Test
-    void 
regularForwardShouldNotCreateLoopErrorAndSendEmailToAppropriateReceivers() 
throws Exception {
+    void loopShouldLeadToRrtError() throws Exception {
         dataProbe.addMapping(MappingSource.fromUser(ALICE), 
Mapping.forward(BOB.asString()));
         dataProbe.addMapping(MappingSource.fromUser(BOB), 
Mapping.forward(CEDRIC.asString()));
         dataProbe.addMapping(MappingSource.fromUser(CEDRIC), 
Mapping.forward(ALICE.asString()));
-        dataProbe.addMapping(MappingSource.fromUser(CEDRIC), 
Mapping.forward(SENDER.asString()));
+
+        messageSender.connect(LOCALHOST_IP, 
jamesServer.getProbe(SmtpGuiceProbe.class).getSmtpPort())
+            .authenticate(SENDER.asString(), PASSWORD)
+            .sendMessage(SENDER.asString(), ALICE.asString());
+
+        Awaitility.await().until(() -> 
jamesServer.getProbe(SpoolerProbe.class).processingFinished());
+
+        
assertThat(mailRepositoryProbe.getRepositoryMailCount(RRT_ERROR_REPOSITORY)).isEqualTo(1);
+    }
+
+    @Test
+    void loopWithRuleShouldLeadToRrtError() throws Exception {
+        filteringManagementProbe.defineRulesForUser(ALICE, 
asRule(Forward.to(BOB.asMailAddress()).withoutACopy()));
+        filteringManagementProbe.defineRulesForUser(BOB, 
asRule(Forward.to(CEDRIC.asMailAddress()).withoutACopy()));
+        filteringManagementProbe.defineRulesForUser(CEDRIC, 
asRule(Forward.to(ALICE.asMailAddress()).withoutACopy()));
+
+        messageSender.connect(LOCALHOST_IP, 
jamesServer.getProbe(SmtpGuiceProbe.class).getSmtpPort())
+            .authenticate(SENDER.asString(), PASSWORD)
+            .sendMessage(SENDER.asString(), ALICE.asString());
+
+        Awaitility.await().until(() -> 
jamesServer.getProbe(SpoolerProbe.class).processingFinished());
+
+        
assertThat(mailRepositoryProbe.getRepositoryMailCount(RRT_ERROR_REPOSITORY)).isEqualTo(1);
+    }
+
+    @Test
+    void loopWithLocalCopyShouldLeadToRrtError() throws Exception {
+        filteringManagementProbe.defineRulesForUser(ALICE, 
asRule(Forward.to(BOB.asMailAddress()).keepACopy()));
+        filteringManagementProbe.defineRulesForUser(BOB, 
asRule(Forward.to(CEDRIC.asMailAddress()).withoutACopy()));
+        filteringManagementProbe.defineRulesForUser(CEDRIC, 
asRule(Forward.to(ALICE.asMailAddress()).withoutACopy()));
+
+        messageSender.connect(LOCALHOST_IP, 
jamesServer.getProbe(SmtpGuiceProbe.class).getSmtpPort())
+            .authenticate(SENDER.asString(), PASSWORD)
+            .sendMessage(SENDER.asString(), ALICE.asString());
+
+        Awaitility.await().until(() -> 
jamesServer.getProbe(SpoolerProbe.class).processingFinished());
+
+        
assertThat(mailRepositoryProbe.getRepositoryMailCount(RRT_ERROR_REPOSITORY)).isEqualTo(1);
+    }
+
+    @Test
+    void mixedLoopShouldLeadToRrtError() throws Exception {
+        dataProbe.addMapping(MappingSource.fromUser(ALICE), 
Mapping.forward(BOB.asString()));
+        filteringManagementProbe.defineRulesForUser(BOB, 
asRule(Forward.to(CEDRIC.asMailAddress()).withoutACopy()));
+        filteringManagementProbe.defineRulesForUser(CEDRIC, 
asRule(Forward.to(ALICE.asMailAddress()).withoutACopy()));
+
+        messageSender.connect(LOCALHOST_IP, 
jamesServer.getProbe(SmtpGuiceProbe.class).getSmtpPort())
+            .authenticate(SENDER.asString(), PASSWORD)
+            .sendMessage(SENDER.asString(), ALICE.asString());
+
+        Awaitility.await().until(() -> 
jamesServer.getProbe(SpoolerProbe.class).processingFinished());
+
+        
assertThat(mailRepositoryProbe.getRepositoryMailCount(RRT_ERROR_REPOSITORY)).isEqualTo(1);
+    }
+
+    @Test
+    void 
forwardShouldNotCreateLoopErrorWhenFilterForwardAndRegularForwardWorkTogether() 
throws Exception {
+        filteringManagementProbe.defineRulesForUser(ALICE, 
asRule(Forward.to(BOB.asMailAddress()).withoutACopy()));
+        dataProbe.addMapping(MappingSource.fromUser(BOB), 
Mapping.forward(CEDRIC.asString()));
+        filteringManagementProbe.defineRulesForUser(CEDRIC, 
asRule(Forward.to(ALICE.asMailAddress()).withoutACopy()));
+
+        messageSender.connect(LOCALHOST_IP, 
jamesServer.getProbe(SmtpGuiceProbe.class).getSmtpPort())
+            .authenticate(SENDER.asString(), PASSWORD)
+            .sendMessage(SENDER.asString(), ALICE.asString());
+
+        Awaitility.await().until(() -> 
jamesServer.getProbe(SpoolerProbe.class).processingFinished());
+        Awaitility.await().until(() -> 
mailRepositoryProbe.getRepositoryMailCount(CUSTOM_REPOSITORY) == 0L);

Review Comment:
   I think this test leads to rrt error?



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