chibenwa commented on code in PR #3130:
URL: https://github.com/apache/james-project/pull/3130#discussion_r3959155181


##########
server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SmtpUtf8AnnounceTest.java:
##########
@@ -49,30 +58,87 @@ void tearDown() {
 
     @Test
     void ehloShouldAnnounceSmtpUtf8() throws Exception {
-        SMTPClient smtpProtocol = new SMTPClient();
-        InetSocketAddress bindedAddress = testSystem.getBindedAddress();
-        smtpProtocol.connect(bindedAddress.getAddress().getHostAddress(), 
bindedAddress.getPort());
+        SMTPClient smtpProtocol = connect();
         smtpProtocol.sendCommand("EHLO localhost");
 
         SoftAssertions.assertSoftly(softly -> {
             softly.assertThat(smtpProtocol.getReplyCode()).isEqualTo(250);
-            softly.assertThat(smtpProtocol.getReplyString())
-                .contains("250-SMTPUTF8");
+            
softly.assertThat(smtpProtocol.getReplyString()).contains("SMTPUTF8");
         });
     }
 
     @Test
-    void trivialEmailWithSmtpUtf8ShouldBeReceived() throws Exception {
-        SMTPClient smtpProtocol = new SMTPClient();
-        InetSocketAddress bindedAddress = testSystem.getBindedAddress();
-        smtpProtocol.connect(bindedAddress.getAddress().getHostAddress(), 
bindedAddress.getPort());
+    void ehloShouldAnnounceSmtpUtf8Once() throws Exception {
+        SMTPClient smtpProtocol = connect();
+        smtpProtocol.sendCommand("EHLO localhost");
+
+        // EhloCmdHandler appends one line per EhloExtension without
+        // deduplicating, so a second handler advertising the keyword would
+        // silently produce a duplicate 250- line.
+        assertThat(smtpProtocol.getReplyString().split("SMTPUTF8", 
-1)).hasSize(2);
+    }
 
+    @Test
+    void unicodeAddressesShouldBeAcceptedWhenSmtpUtf8IsRequested() throws 
Exception {
+        SMTPClient smtpProtocol = connect();
         smtpProtocol.sendCommand("EHLO remote.org");
-        smtpProtocol.sendCommand("MAIL FROM: <[email protected]> SMTPUTF8");
-        smtpProtocol.sendCommand("RCPT TO:<rcpt@localhost> SMTPUTF8");
-        smtpProtocol.sendShortMessageData("From: bob@localhost\r\n\r\nSubject: 
test mail\r\n\r\nTest body testSimpleMailSendWithDSN\r\n.\r\n");
+        smtpProtocol.sendCommand("MAIL FROM: <" + UTF8_SENDER + "> SMTPUTF8");
+        assertThat(smtpProtocol.getReplyCode()).isEqualTo(250);
+        smtpProtocol.sendCommand("RCPT TO:<" + UTF8_RECIPIENT + ">");
+        assertThat(smtpProtocol.getReplyCode()).isEqualTo(250);
+        smtpProtocol.sendShortMessageData("From: " + UTF8_SENDER + 
"\r\nSubject: test\r\n\r\nbody\r\n.\r\n");
 
         Mail lastMail = testSystem.queue.getLastMail();
         assertThat(lastMail).isNotNull();
+        SoftAssertions.assertSoftly(softly -> {
+            
softly.assertThat(lastMail.getMaybeSender().asString()).isEqualTo(UTF8_SENDER);
+            softly.assertThat(lastMail.getRecipients())
+                .extracting(rcpt -> rcpt.asString())
+                .containsExactly(UTF8_RECIPIENT);
+        });
+    }
+
+    @Test
+    void nonAsciiSenderShouldBeRejectedWithoutSmtpUtf8() throws Exception {
+        SMTPClient smtpProtocol = connect();
+        smtpProtocol.sendCommand("EHLO remote.org");
+        smtpProtocol.sendCommand("MAIL FROM: <" + UTF8_SENDER + ">");
+
+        SoftAssertions.assertSoftly(softly -> {
+            softly.assertThat(smtpProtocol.getReplyCode()).isEqualTo(553);
+            
softly.assertThat(smtpProtocol.getReplyString()).contains(NON_ASCII_WITHOUT_SMTPUTF8);
+        });
+    }
+
+    @Test
+    void nonAsciiRecipientShouldBeRejectedWithoutSmtpUtf8() throws Exception {
+        SMTPClient smtpProtocol = connect();
+        smtpProtocol.sendCommand("EHLO remote.org");
+        smtpProtocol.sendCommand("MAIL FROM: <[email protected]>");
+        assertThat(smtpProtocol.getReplyCode()).isEqualTo(250);
+        smtpProtocol.sendCommand("RCPT TO:<" + UTF8_RECIPIENT + ">");
+
+        SoftAssertions.assertSoftly(softly -> {
+            softly.assertThat(smtpProtocol.getReplyCode()).isEqualTo(553);
+            
softly.assertThat(smtpProtocol.getReplyString()).contains(NON_ASCII_WITHOUT_SMTPUTF8);
+        });
+    }
+
+    @Test
+    void asciiEmailWithSmtpUtf8ShouldBeReceived() throws Exception {

Review Comment:
   Simply that we can use ascii addresses with SMTPUTF8
   
   Maybe not the most useful of a test but defnitly harmless.



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