Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JAMES-3715 Add tests for IMAP COMPRESS transport layer #896

Merged
merged 1 commit into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions server/protocols/protocols-imap4/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@
<groupId>org.mock-server</groupId>
<artifactId>mockserver-netty</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>com.jcraft</groupId>
<artifactId>jzlib</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.apache.james.imapserver.netty;

import static javax.mail.Folder.READ_WRITE;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
Expand All @@ -29,6 +30,7 @@
import java.nio.charset.StandardCharsets;
import java.util.Properties;

import javax.mail.FetchProfile;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.Session;
Expand Down Expand Up @@ -79,6 +81,8 @@
import org.mockserver.model.HttpRequest;
import org.mockserver.model.HttpResponse;

import com.sun.mail.imap.IMAPFolder;

import nl.altindag.ssl.exception.GenericKeyStoreException;
import nl.altindag.ssl.exception.PrivateKeyParseException;

Expand Down Expand Up @@ -215,6 +219,50 @@ void largeAppendsShouldWork() throws Exception {
}
}

@Nested
class Compress {
IMAPServer imapServer;
private int port;

@BeforeEach
void beforeEach() throws Exception {
imapServer = createImapServer("imapServerCompress.xml");
port = imapServer.getListenAddresses().get(0).getPort();
}

@AfterEach
void tearDown() {
imapServer.destroy();
}

@Test
void shouldNotThrowWhenCompressionEnabled() throws Exception {
InMemoryMailboxManager mailboxManager = memoryIntegrationResources.getMailboxManager();
MailboxSession mailboxSession = mailboxManager.createSystemSession(USER);
mailboxManager.createMailbox(
MailboxPath.inbox(USER),
mailboxSession);
mailboxManager.getMailbox(MailboxPath.inbox(USER), mailboxSession)
.appendMessage(MessageManager.AppendCommand.builder().build("header: value\r\n\r\nbody"), mailboxSession);

Properties props = new Properties();
props.put("mail.imap.user", USER.asString());
props.put("mail.imap.host", "127.0.0.1");
props.put("mail.imap.auth.mechanisms", "LOGIN");
props.put("mail.imap.compress.enable", true);
final Session session = Session.getInstance(props);
final Store store = session.getStore("imap");
store.connect("127.0.0.1", port, USER.asString(), USER_PASS);
final FetchProfile fetchProfile = new FetchProfile();
fetchProfile.add(FetchProfile.Item.ENVELOPE);
final IMAPFolder inbox = (IMAPFolder) store.getFolder("INBOX");
inbox.open(READ_WRITE);

inbox.getMessageByUID(1);
}

}

@Nested
class StartTLS {
IMAPServer imapServer;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

<imapserver enabled="true">
<jmxName>imapserver</jmxName>
<bind>0.0.0.0:0</bind>
<compress>true</compress>
<connectionBacklog>200</connectionBacklog>
<connectionLimit>0</connectionLimit>
<connectionLimitPerIP>0</connectionLimitPerIP>
<idleTimeInterval>120</idleTimeInterval>
<idleTimeIntervalUnit>SECONDS</idleTimeIntervalUnit>
<enableIdle>true</enableIdle>
<inMemorySizeLimit>65536</inMemorySizeLimit> <!-- 64 KB -->
<plainAuthDisallowed>false</plainAuthDisallowed>
</imapserver>