You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by hq...@apache.org on 2026/08/10 02:47:59 UTC

(james-project) 01/04: JAMES-4210 POP3: add a test to verify SASL exchange closure upon client disconnection

This is an automated email from the ASF dual-hosted git repository.

quantranhong1999 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit a5465b3219fb6eec80a931190441cfe952340b80
Author: Quan Tran <hq...@linagora.com>
AuthorDate: Mon Jul 27 16:42:41 2026 +0700

    JAMES-4210 POP3: add a test to verify SASL exchange closure upon client disconnection
    
    For POP3, the SASL exchange is well closed upon client disconnection, as `AuthCmdHandler` already implement `DisconnectHandler` to close the SASL exchange.
    Dropping that piece of code indeed would make the test fail.
---
 .../apache/james/pop3server/POP3ServerTest.java    | 37 ++++++++++++++++++++--
 1 file changed, 34 insertions(+), 3 deletions(-)

diff --git a/server/protocols/protocols-pop3/src/test/java/org/apache/james/pop3server/POP3ServerTest.java b/server/protocols/protocols-pop3/src/test/java/org/apache/james/pop3server/POP3ServerTest.java
index 932f907a71..3fa4009236 100644
--- a/server/protocols/protocols-pop3/src/test/java/org/apache/james/pop3server/POP3ServerTest.java
+++ b/server/protocols/protocols-pop3/src/test/java/org/apache/james/pop3server/POP3ServerTest.java
@@ -40,6 +40,7 @@ import java.util.Optional;
 import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import jakarta.mail.util.SharedByteArrayInputStream;
 
@@ -127,17 +128,25 @@ public class POP3ServerTest {
         private static final byte[] SERVER_DATA = "server-data".getBytes(StandardCharsets.US_ASCII);
 
         private final Username username;
-        private final AtomicBoolean closed;
+        private final Runnable closeAction;
         private final String name;
 
         private ServerDataSaslMechanism(Username username, AtomicBoolean closed) {
             this("TEST", username, closed);
         }
 
+        private ServerDataSaslMechanism(Username username, AtomicInteger closeCount) {
+            this("TEST", username, closeCount::incrementAndGet);
+        }
+
         private ServerDataSaslMechanism(String name, Username username, AtomicBoolean closed) {
+            this(name, username, () -> closed.set(true));
+        }
+
+        private ServerDataSaslMechanism(String name, Username username, Runnable closeAction) {
             this.name = name;
             this.username = username;
-            this.closed = closed;
+            this.closeAction = closeAction;
         }
 
         @Override
@@ -160,7 +169,7 @@ public class POP3ServerTest {
 
                 @Override
                 public void close() {
-                    closed.set(true);
+                    closeAction.run();
                 }
             };
         }
@@ -1215,6 +1224,28 @@ public class POP3ServerTest {
         }
     }
 
+    @Test
+    void disconnectDuringSaslContinuationShouldCloseExchange() throws Exception {
+        Username username = Username.of("auth-user");
+        AtomicInteger closeCount = new AtomicInteger();
+        pop3Server.setSaslMechanisms(ImmutableList.of(new ServerDataSaslMechanism(username, closeCount)));
+        finishSetUp(pop3Configuration);
+
+        try (Socket socket = connectToPop3Server();
+             BufferedReader reader = reader(socket);
+             BufferedWriter writer = writer(socket)) {
+            assertThat(reader.readLine()).startsWith("+OK");
+
+            send(writer, "AUTH TEST");
+            assertThat(reader.readLine()).isEqualTo("+ " + encoded("challenge"));
+            socket.close();
+
+            // Disconnect cleanup closes the pending SASL exchange.
+            Awaitility.await().atMost(Duration.ofSeconds(2))
+                .untilAsserted(() -> assertThat(closeCount.get()).isEqualTo(1));
+        }
+    }
+
     @Test
     void authShouldEnforceInitialCommandLength() throws Exception {
         Username username = Username.of("auth-user");


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org