You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by rc...@apache.org on 2024/11/13 02:12:36 UTC
(james-project) branch master updated: IMAP - IDLE Command - Add test cases when authenticated state (#2498)
This is an automated email from the ASF dual-hosted git repository.
rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
The following commit(s) were added to refs/heads/master by this push:
new bfab4540d1 IMAP - IDLE Command - Add test cases when authenticated state (#2498)
bfab4540d1 is described below
commit bfab4540d1155d8f00f0d91e6f129587ddb917d1
Author: vttran <vt...@linagora.com>
AuthorDate: Wed Nov 13 09:12:30 2024 +0700
IMAP - IDLE Command - Add test cases when authenticated state (#2498)
---
.../james/imapserver/netty/IMAPServerTest.java | 57 ++++++++++++++++++++++
1 file changed, 57 insertions(+)
diff --git a/server/protocols/protocols-imap4/src/test/java/org/apache/james/imapserver/netty/IMAPServerTest.java b/server/protocols/protocols-imap4/src/test/java/org/apache/james/imapserver/netty/IMAPServerTest.java
index 10b5d24ebb..8e9cb2245e 100644
--- a/server/protocols/protocols-imap4/src/test/java/org/apache/james/imapserver/netty/IMAPServerTest.java
+++ b/server/protocols/protocols-imap4/src/test/java/org/apache/james/imapserver/netty/IMAPServerTest.java
@@ -2197,6 +2197,63 @@ class IMAPServerTest {
imapServer.destroy();
}
+ @Test
+ void idleShouldBeAllowedWhenAuthenticatedState() throws Exception {
+ // Given an authenticated user
+ clientConnection.write(ByteBuffer.wrap(String.format("a0 LOGIN %s %s\r\n", USER.asString(), USER_PASS).getBytes(StandardCharsets.UTF_8)));
+ readBytes(clientConnection);
+
+ // When IDLE command is issued (Authenticated state)
+ clientConnection.write(ByteBuffer.wrap(("a3 IDLE\r\n").getBytes(StandardCharsets.UTF_8)));
+
+ // Then the server should respond Idling response
+ Awaitility.await().atMost(Duration.ofSeconds(2)).untilAsserted(() ->
+ assertThat(readStringUntil(clientConnection, s -> s.contains("+ Idling")))
+ .isNotNull());
+ }
+
+ @Test
+ void idleShouldDoNothingResponseWhenAuthenticatedStateAndHasNewMessages() throws Exception {
+ // Given an authenticated user
+ clientConnection.write(ByteBuffer.wrap(String.format("a0 LOGIN %s %s\r\n", USER.asString(), USER_PASS).getBytes(StandardCharsets.UTF_8)));
+ readBytes(clientConnection);
+
+ // When IDLE command is issued (Authenticated state)
+ clientConnection.write(ByteBuffer.wrap(("a3 IDLE\r\n").getBytes(StandardCharsets.UTF_8)));
+ readStringUntil(clientConnection, s -> s.contains("+ Idling"));
+
+ // And a new message is appended
+ inbox.appendMessage(MessageManager.AppendCommand.builder().build("h: value\r\n\r\nbody".getBytes()), mailboxSession);
+
+ ImmutableList.Builder<String> listenerResult = ImmutableList.builder();
+ Mono.fromCallable(() -> new String(readBytes(clientConnection), StandardCharsets.US_ASCII))
+ .doOnNext(listenerResult::add)
+ .subscribeOn(Schedulers.boundedElastic()).subscribe();
+
+ Thread.sleep(200);
+ // Then the server should not send any response
+ assertThat(listenerResult.build()).isEmpty();
+ }
+
+ @Test
+ void idleShouldBeInterruptibleWhenAuthenticatedState() throws Exception {
+ // Given an authenticated user
+ clientConnection.write(ByteBuffer.wrap(String.format("a0 LOGIN %s %s\r\n", USER.asString(), USER_PASS).getBytes(StandardCharsets.UTF_8)));
+ readBytes(clientConnection);
+
+ // When IDLE command is issued (Authenticated state)
+ clientConnection.write(ByteBuffer.wrap(("a3 IDLE\r\n").getBytes(StandardCharsets.UTF_8)));
+ readStringUntil(clientConnection, s -> s.contains("+ Idling"));
+
+ // And DONE command is issued
+ clientConnection.write(ByteBuffer.wrap(("DONE\r\n").getBytes(StandardCharsets.UTF_8)));
+
+ // Then the server should respond IDLE completed
+ Awaitility.await().atMost(Duration.ofSeconds(2)).untilAsserted(() ->
+ assertThat(readStringUntil(clientConnection, s -> s.contains("a3 OK IDLE completed.")))
+ .isNotNull());
+ }
+
@Test
void idleShouldSendInitialContinuation() throws Exception {
clientConnection.write(ByteBuffer.wrap(String.format("a0 LOGIN %s %s\r\n", USER.asString(), USER_PASS).getBytes(StandardCharsets.UTF_8)));
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org