You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by rc...@apache.org on 2020/02/12 04:14:27 UTC

[james-project] branch master updated (63363dc -> d8bcd44)

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

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


    from 63363dc  Merge remote-tracking branch 'mine/split-blobstore-cassandra'
     new e0d1d67  JAMES-3028 enhancements to DeleteDumbBlobStoreContract
     new 4fd7029  JAMES-3028 enhancement to BucketDumbBlobStoreContract
     new 29faf2c  JAMES-3044 Unify Jsoup version in James
     new 2958ee9  JAMES-3044 Test to prove JsoupTextExtractor fails on null characters
     new 1006530  JAMES-3044 Upgrading Jsoup from 1.21.1 to 1.12.2
     new 9fcda1e  [Fix] Disable unstable test on concurrent webadmin start up
     new d95f16a  JAMES-3042 ImapRequestFrameDecoder should be more resilient
     new 365dd4a  JAMES-3042 ImapRequestFrameDecoder::newCumulationBuffer should sanitize negative size
     new d8bcd44  JAMES-3043 IMAP selected mailbox checks should rely on mailboxId

The 9 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 mailbox/store/pom.xml                              |  1 -
 .../store/extractor/JsoupTextExtractorTest.java    | 24 ++++++-
 pom.xml                                            |  5 ++
 .../imap/processor/AbstractSelectionProcessor.java |  2 +-
 .../james/imap/processor/AppendProcessor.java      |  2 +-
 .../blob/api/BucketDumbBlobStoreContract.java      |  2 +-
 .../blob/api/DeleteDumbBlobStoreContract.java      | 22 +++---
 server/protocols/jmap-draft/pom.xml                |  1 -
 server/protocols/protocols-imap4/pom.xml           |  5 ++
 .../imapserver/netty/ImapRequestFrameDecoder.java  | 22 +++---
 .../netty/ImapRequestFrameDecoderTest.java         | 80 ++++++++++++++++++++++
 .../apache/james/webadmin/WebAdminUtilsTest.java   |  5 +-
 12 files changed, 145 insertions(+), 26 deletions(-)
 create mode 100644 server/protocols/protocols-imap4/src/test/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoderTest.java


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


[james-project] 09/09: JAMES-3043 IMAP selected mailbox checks should rely on mailboxId

Posted by rc...@apache.org.
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

commit d8bcd447a579f658c9377b178c01608a577c5fc0
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Feb 7 11:58:07 2020 +0700

    JAMES-3043 IMAP selected mailbox checks should rely on mailboxId
    
     Currently they rely on mailboxPath...
    
     Doing them by mailboxId will:
      - avoid a mailboxPath lookup
      - avoid rename concurrency issues
    
     Concerned processors: Append, Select, Examine
---
 .../org/apache/james/imap/processor/AbstractSelectionProcessor.java     | 2 +-
 .../src/main/java/org/apache/james/imap/processor/AppendProcessor.java  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractSelectionProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractSelectionProcessor.java
index e7a1184..f00345e 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractSelectionProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractSelectionProcessor.java
@@ -387,7 +387,7 @@ abstract class AbstractSelectionProcessor<R extends AbstractMailboxSelectionRequ
 
         final SelectedMailbox sessionMailbox;
         final SelectedMailbox currentMailbox = session.getSelected();
-        if (currentMailbox == null || !currentMailbox.getPath().equals(mailboxPath)) {
+        if (currentMailbox == null || !currentMailbox.getMailboxId().equals(mailbox.getId())) {
             
             // QRESYNC EXTENSION
             //
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/AppendProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/AppendProcessor.java
index 114281b..707a356 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/AppendProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/AppendProcessor.java
@@ -126,7 +126,7 @@ public class AppendProcessor extends AbstractMailboxProcessor<AppendRequest> {
             final MailboxSession mailboxSession = session.getMailboxSession();
             final SelectedMailbox selectedMailbox = session.getSelected();
             final MailboxManager mailboxManager = getMailboxManager();
-            final boolean isSelectedMailbox = selectedMailbox != null && selectedMailbox.getPath().equals(mailboxPath);
+            final boolean isSelectedMailbox = selectedMailbox != null && selectedMailbox.getMailboxId().equals(mailbox.getId());
             final ComposedMessageId messageId = mailbox.appendMessage(message, datetime, mailboxSession, !isSelectedMailbox, flagsToBeSet);
             if (isSelectedMailbox) {
                 selectedMailbox.addRecent(messageId.getUid());


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


[james-project] 03/09: JAMES-3044 Unify Jsoup version in James

Posted by rc...@apache.org.
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

commit 29faf2c50ff489814f3dbfebacf6151d3de21029
Author: Tran Tien Duc <dt...@linagora.com>
AuthorDate: Fri Feb 7 13:12:18 2020 +0700

    JAMES-3044 Unify Jsoup version in James
---
 mailbox/store/pom.xml               | 1 -
 pom.xml                             | 5 +++++
 server/protocols/jmap-draft/pom.xml | 1 -
 3 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/mailbox/store/pom.xml b/mailbox/store/pom.xml
index 291c43c..4bcb239 100644
--- a/mailbox/store/pom.xml
+++ b/mailbox/store/pom.xml
@@ -126,7 +126,6 @@
         <dependency>
             <groupId>org.jsoup</groupId>
             <artifactId>jsoup</artifactId>
-            <version>1.11.3</version>
         </dependency>
         <dependency>
             <groupId>org.mockito</groupId>
diff --git a/pom.xml b/pom.xml
index 1b387a6..5757f9b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -2536,6 +2536,11 @@
                 <version>${junit.vintage.version}</version>
             </dependency>
             <dependency>
+                <groupId>org.jsoup</groupId>
+                <artifactId>jsoup</artifactId>
+                <version>1.12.1</version>
+            </dependency>
+            <dependency>
                 <groupId>org.mockito</groupId>
                 <artifactId>mockito-core</artifactId>
                 <version>3.0.0</version>
diff --git a/server/protocols/jmap-draft/pom.xml b/server/protocols/jmap-draft/pom.xml
index 6da8ee3..3167500 100644
--- a/server/protocols/jmap-draft/pom.xml
+++ b/server/protocols/jmap-draft/pom.xml
@@ -236,7 +236,6 @@
         <dependency>
             <groupId>org.jsoup</groupId>
             <artifactId>jsoup</artifactId>
-            <version>1.12.1</version>
         </dependency>
         <dependency>
             <groupId>org.mockito</groupId>


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


[james-project] 01/09: JAMES-3028 enhancements to DeleteDumbBlobStoreContract

Posted by rc...@apache.org.
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

commit e0d1d673252c676255d112b03be46df1bb0dba3e
Author: Matthieu Baechler <ma...@apache.org>
AuthorDate: Mon Jan 20 10:36:32 2020 +0100

    JAMES-3028 enhancements to DeleteDumbBlobStoreContract
---
 .../blob/api/DeleteDumbBlobStoreContract.java      | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/server/blob/blob-api/src/test/java/org/apache/james/blob/api/DeleteDumbBlobStoreContract.java b/server/blob/blob-api/src/test/java/org/apache/james/blob/api/DeleteDumbBlobStoreContract.java
index 5f1b0fa..e537774 100644
--- a/server/blob/blob-api/src/test/java/org/apache/james/blob/api/DeleteDumbBlobStoreContract.java
+++ b/server/blob/blob-api/src/test/java/org/apache/james/blob/api/DeleteDumbBlobStoreContract.java
@@ -35,6 +35,7 @@ import java.io.ByteArrayInputStream;
 import java.io.InputStream;
 import java.nio.charset.StandardCharsets;
 import java.time.Duration;
+import java.util.Arrays;
 import java.util.concurrent.ExecutionException;
 
 import org.apache.commons.io.IOUtils;
@@ -200,10 +201,12 @@ public interface DeleteDumbBlobStoreContract  {
 
     @Test
     default void mixingSaveReadAndDeleteShouldReturnConsistentState() throws ExecutionException, InterruptedException {
+        DumbBlobStore store = testee();
+        store.save(TEST_BUCKET_NAME, TEST_BLOB_ID, TWELVE_MEGABYTES).block();
         ConcurrentTestRunner.builder()
             .randomlyDistributedReactorOperations(
-                (thread, iteration) -> testee().save(TEST_BUCKET_NAME, TEST_BLOB_ID, TWELVE_MEGABYTES),
-                (thread, iteration) -> testee().delete(TEST_BUCKET_NAME, TEST_BLOB_ID),
+                (thread, iteration) -> store.save(TEST_BUCKET_NAME, TEST_BLOB_ID, TWELVE_MEGABYTES),
+                (thread, iteration) -> store.delete(TEST_BUCKET_NAME, TEST_BLOB_ID),
                 (thread, iteration) -> checkConcurrentMixedOperation()
             )
             .threadCount(10)
@@ -212,12 +215,13 @@ public interface DeleteDumbBlobStoreContract  {
     }
 
     default Mono<Void> checkConcurrentMixedOperation() {
-        return Mono
-            .fromCallable(() ->
-                testee().read(TEST_BUCKET_NAME, TEST_BLOB_ID))
-            .doOnNext(inputStream -> assertThat(inputStream).hasSameContentAs(new ByteArrayInputStream(TWELVE_MEGABYTES)))
-            .doOnError(throwable -> assertThat(throwable).isInstanceOf(ObjectNotFoundException.class))
-            .onErrorResume(throwable -> Mono.empty())
-            .then();
+        return
+            testee().readBytes(TEST_BUCKET_NAME, TEST_BLOB_ID)
+                //assertj is very cpu-intensive, let's compute the assertion only when arrays are different
+                .filter(bytes -> !Arrays.equals(bytes, TWELVE_MEGABYTES))
+                .doOnNext(bytes -> assertThat(bytes).isEqualTo(TWELVE_MEGABYTES))
+                .onErrorResume(ObjectNotFoundException.class, throwable -> Mono.empty())
+                .then();
     }
+
 }


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


[james-project] 06/09: [Fix] Disable unstable test on concurrent webadmin start up

Posted by rc...@apache.org.
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

commit 9fcda1ee2d013f0db1b8efe05788dc7805dca29b
Author: Tran Tien Duc <dt...@linagora.com>
AuthorDate: Fri Feb 7 15:51:38 2020 +0700

    [Fix] Disable unstable test on concurrent webadmin start up
---
 .../src/test/java/org/apache/james/webadmin/WebAdminUtilsTest.java   | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/server/protocols/webadmin/webadmin-core/src/test/java/org/apache/james/webadmin/WebAdminUtilsTest.java b/server/protocols/webadmin/webadmin-core/src/test/java/org/apache/james/webadmin/WebAdminUtilsTest.java
index f5e61d6..3cdfe09 100644
--- a/server/protocols/webadmin/webadmin-core/src/test/java/org/apache/james/webadmin/WebAdminUtilsTest.java
+++ b/server/protocols/webadmin/webadmin-core/src/test/java/org/apache/james/webadmin/WebAdminUtilsTest.java
@@ -22,11 +22,14 @@ package org.apache.james.webadmin;
 import java.time.Duration;
 
 import org.apache.james.util.concurrency.ConcurrentTestRunner;
+import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 
 class WebAdminUtilsTest {
+
+    @Disabled("JAMES-3046 the concurrent webadmin server fails on a high concurrent level")
     @Test
-    void serverShouldBeAbletoStartConcurrently() throws Exception {
+    void serverShouldBeAbleToStartConcurrently() throws Exception {
         ConcurrentTestRunner.builder()
             .operation((a, b) -> {
                 WebAdminServer webAdminServer = WebAdminUtils.createWebAdminServer();


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


[james-project] 04/09: JAMES-3044 Test to prove JsoupTextExtractor fails on null characters

Posted by rc...@apache.org.
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

commit 2958ee9f6f0d34f61f91950cb907156d7f39dc32
Author: Tran Tien Duc <dt...@linagora.com>
AuthorDate: Fri Feb 7 15:31:31 2020 +0700

    JAMES-3044 Test to prove JsoupTextExtractor fails on null characters
---
 .../store/extractor/JsoupTextExtractorTest.java    | 30 ++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)

diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/extractor/JsoupTextExtractorTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/extractor/JsoupTextExtractorTest.java
index 64bd9b9..2a8ec70 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/extractor/JsoupTextExtractorTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/extractor/JsoupTextExtractorTest.java
@@ -20,6 +20,7 @@
 package org.apache.james.mailbox.store.extractor;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatCode;
 
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
@@ -28,9 +29,13 @@ import java.nio.charset.StandardCharsets;
 import org.apache.james.mailbox.extractor.ParsedContent;
 import org.apache.james.mailbox.extractor.TextExtractor;
 import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 
 class JsoupTextExtractorTest {
+
+    private static final String TEXT_HTML_CONTENT_TYPE = "text/html";
+
     TextExtractor textExtractor;
 
     @BeforeEach
@@ -42,7 +47,7 @@ class JsoupTextExtractorTest {
     void extractedTextFromHtmlShouldNotContainTheContentOfTitleTag() throws Exception {
         InputStream inputStream = ClassLoader.getSystemResourceAsStream("documents/html.txt");
 
-        assertThat(textExtractor.extractContent(inputStream, "text/html").getTextualContent().get())
+        assertThat(textExtractor.extractContent(inputStream, TEXT_HTML_CONTENT_TYPE).getTextualContent().get())
                 .doesNotContain("*|MC:SUBJECT|*");
     }
 
@@ -64,7 +69,7 @@ class JsoupTextExtractorTest {
 
     @Test
     void extractContentShouldReturnEmptyWhenNullData() throws Exception {
-        assertThat(textExtractor.extractContent(null, "text/html"))
+        assertThat(textExtractor.extractContent(null, TEXT_HTML_CONTENT_TYPE))
             .isEqualTo(ParsedContent.empty());
     }
 
@@ -76,4 +81,25 @@ class JsoupTextExtractorTest {
             .isEqualTo(ParsedContent.empty());
     }
 
+    @Disabled("JAMES-3044 java.io.IOException: Input is binary and unsupported")
+    @Test
+    void extractContentShouldNotThrowWhenContainingNullCharacters() {
+        InputStream inputStream = textContentWithManyNullCharacters();
+
+        assertThatCode(() -> textExtractor.extractContent(inputStream, TEXT_HTML_CONTENT_TYPE))
+            .doesNotThrowAnyException();
+    }
+
+    private InputStream textContentWithManyNullCharacters() {
+        String htmlTextContent = "HTML pages can include a lot of null '\0' character. But still expecting the content can be parsed." +
+            "Jsoup 1.21.1 thinks a file containing more than 10 null characters can be a binary file";
+        byte[] htmlBytesContent = htmlTextContent.getBytes(StandardCharsets.UTF_8);
+        byte[] nullCharacters = {'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'};
+
+        byte[] fullContent = new byte[htmlBytesContent.length + nullCharacters.length];
+        System.arraycopy(htmlBytesContent, 0, fullContent, 0, htmlBytesContent.length);
+        System.arraycopy(nullCharacters, 0, fullContent, htmlBytesContent.length, nullCharacters.length);
+
+        return new ByteArrayInputStream(fullContent);
+    }
 }
\ No newline at end of file


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


[james-project] 08/09: JAMES-3042 ImapRequestFrameDecoder::newCumulationBuffer should sanitize negative size

Posted by rc...@apache.org.
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

commit 365dd4a9dc7c6e0034438d64ef7f81a54575760b
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Mon Feb 10 10:44:40 2020 +0700

    JAMES-3042 ImapRequestFrameDecoder::newCumulationBuffer should sanitize negative size
    
    NotEnoughDataException is using -1 as a "unknown" marker, making this code path
    potentially buggy.
---
 .../james/imapserver/netty/ImapRequestFrameDecoder.java | 15 ++++++++-------
 .../imapserver/netty/ImapRequestFrameDecoderTest.java   | 17 +++++++++++++++++
 2 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java
index 801f6d7..c8e35de 100644
--- a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java
+++ b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java
@@ -42,6 +42,8 @@ import org.jboss.netty.channel.ChannelPipeline;
 import org.jboss.netty.channel.ChannelStateEvent;
 import org.jboss.netty.handler.codec.frame.FrameDecoder;
 
+import com.google.common.annotations.VisibleForTesting;
+
 /**
  * {@link FrameDecoder} which will decode via and {@link ImapDecoder} instance
  */
@@ -50,7 +52,8 @@ public class ImapRequestFrameDecoder extends FrameDecoder implements NettyConsta
     private final ImapDecoder decoder;
     private final int inMemorySizeLimit;
     private final int literalSizeLimit;
-    private static final String NEEDED_DATA = "NEEDED_DATA";
+    @VisibleForTesting
+    static final String NEEDED_DATA = "NEEDED_DATA";
     private static final String STORED_DATA = "STORED_DATA";
     private static final String WRITTEN_DATA = "WRITTEN_DATA";
     private static final String OUTPUT_STREAM = "OUTPUT_STREAM";
@@ -227,13 +230,11 @@ public class ImapRequestFrameDecoder extends FrameDecoder implements NettyConsta
             @SuppressWarnings("unchecked")
             int size = (Integer) sizeAsObject;
 
-            if (inMemorySizeLimit > 0) {
-                return ChannelBuffers.dynamicBuffer(Math.min(size, inMemorySizeLimit), ctx.getChannel().getConfig().getBufferFactory());
-            } else {
+            if (size > 0) {
+                int sanitizedInMemorySizeLimit = Math.max(0, inMemorySizeLimit);
+                int sanitizedSize = Math.min(sanitizedInMemorySizeLimit, size);
 
-                if (size > 0) {
-                    return ChannelBuffers.dynamicBuffer(size, ctx.getChannel().getConfig().getBufferFactory());
-                }
+                return ChannelBuffers.dynamicBuffer(sanitizedSize, ctx.getChannel().getConfig().getBufferFactory());
             }
         }
         return super.newCumulationBuffer(ctx, minimumCapacity);
diff --git a/server/protocols/protocols-imap4/src/test/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoderTest.java b/server/protocols/protocols-imap4/src/test/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoderTest.java
index 1c66c83..8dffa0b 100644
--- a/server/protocols/protocols-imap4/src/test/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoderTest.java
+++ b/server/protocols/protocols-imap4/src/test/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoderTest.java
@@ -20,6 +20,7 @@
 package org.apache.james.imapserver.netty;
 
 
+import static org.apache.james.imapserver.netty.ImapRequestFrameDecoder.NEEDED_DATA;
 import static org.assertj.core.api.Assertions.assertThatCode;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
@@ -60,4 +61,20 @@ class ImapRequestFrameDecoderTest {
         assertThatCode(() -> testee.newCumulationBuffer(channelHandler, 36))
             .doesNotThrowAnyException();
     }
+
+    @Test
+    void newCumulationBufferShouldNotThrowOnNegativeSize() {
+        ChannelHandlerContext channelHandler = mock(ChannelHandlerContext.class);
+        Channel channel = mock(Channel.class);
+        ChannelConfig channelConfig = mock(ChannelConfig.class);
+
+        when(channelConfig.getBufferFactory()).thenReturn(mock(ChannelBufferFactory.class));
+        when(channelHandler.getChannel()).thenReturn(channel);
+        when(channel.getConfig()).thenReturn(channelConfig);
+
+        when(channelHandler.getAttachment()).thenReturn(ImmutableMap.<String, Object>of(NEEDED_DATA, -1));
+
+        assertThatCode(() -> testee.newCumulationBuffer(channelHandler, 36))
+            .doesNotThrowAnyException();
+    }
 }
\ No newline at end of file


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


[james-project] 02/09: JAMES-3028 enhancement to BucketDumbBlobStoreContract

Posted by rc...@apache.org.
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

commit 4fd70296e167422f658dea46340ba36ae9a7b88a
Author: Matthieu Baechler <ma...@apache.org>
AuthorDate: Mon Jan 20 10:35:49 2020 +0100

    JAMES-3028 enhancement to BucketDumbBlobStoreContract
---
 .../java/org/apache/james/blob/api/BucketDumbBlobStoreContract.java     | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/server/blob/blob-api/src/test/java/org/apache/james/blob/api/BucketDumbBlobStoreContract.java b/server/blob/blob-api/src/test/java/org/apache/james/blob/api/BucketDumbBlobStoreContract.java
index 2a7fbae..49e2a7e 100644
--- a/server/blob/blob-api/src/test/java/org/apache/james/blob/api/BucketDumbBlobStoreContract.java
+++ b/server/blob/blob-api/src/test/java/org/apache/james/blob/api/BucketDumbBlobStoreContract.java
@@ -165,7 +165,7 @@ public interface BucketDumbBlobStoreContract {
         store.save(TEST_BUCKET_NAME, TEST_BLOB_ID, SHORT_BYTEARRAY).block();
 
         ConcurrentTestRunner.builder()
-            .operation(((threadNumber, step) -> store.deleteBucket(TEST_BUCKET_NAME).block()))
+            .reactorOperation(((threadNumber, step) -> store.deleteBucket(TEST_BUCKET_NAME)))
             .threadCount(10)
             .operationCount(10)
             .runSuccessfullyWithin(Duration.ofMinutes(1));


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


[james-project] 05/09: JAMES-3044 Upgrading Jsoup from 1.21.1 to 1.12.2

Posted by rc...@apache.org.
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

commit 1006530a9307569152f7b8f5c9f177999d183bc6
Author: Tran Tien Duc <dt...@linagora.com>
AuthorDate: Fri Feb 7 15:35:43 2020 +0700

    JAMES-3044 Upgrading Jsoup from 1.21.1 to 1.12.2
---
 .../store/extractor/JsoupTextExtractorTest.java    | 26 +++++++++-------------
 pom.xml                                            |  2 +-
 2 files changed, 11 insertions(+), 17 deletions(-)

diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/extractor/JsoupTextExtractorTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/extractor/JsoupTextExtractorTest.java
index 2a8ec70..cfdd362 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/extractor/JsoupTextExtractorTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/extractor/JsoupTextExtractorTest.java
@@ -20,7 +20,6 @@
 package org.apache.james.mailbox.store.extractor;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatCode;
 
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
@@ -29,12 +28,15 @@ import java.nio.charset.StandardCharsets;
 import org.apache.james.mailbox.extractor.ParsedContent;
 import org.apache.james.mailbox.extractor.TextExtractor;
 import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 
 class JsoupTextExtractorTest {
 
     private static final String TEXT_HTML_CONTENT_TYPE = "text/html";
+    private static final String HTML_TEXT_CONTENT = "HTML pages can include a lot of null '\0' character. But still expecting the content can be parsed." +
+        "Jsoup 1.12.1 thinks a file containing more than 10 null characters can be a binary file";
+    private static final String NULL_CHARACTERS = "\0\0\0\0\0\0\0\0\0\0";
+    private static final String FULL_CONTENT = HTML_TEXT_CONTENT + NULL_CHARACTERS;
 
     TextExtractor textExtractor;
 
@@ -81,25 +83,17 @@ class JsoupTextExtractorTest {
             .isEqualTo(ParsedContent.empty());
     }
 
-    @Disabled("JAMES-3044 java.io.IOException: Input is binary and unsupported")
     @Test
-    void extractContentShouldNotThrowWhenContainingNullCharacters() {
+    void extractContentShouldNotThrowWhenContainingNullCharacters() throws Exception {
         InputStream inputStream = textContentWithManyNullCharacters();
 
-        assertThatCode(() -> textExtractor.extractContent(inputStream, TEXT_HTML_CONTENT_TYPE))
-            .doesNotThrowAnyException();
+        assertThat(textExtractor.extractContent(inputStream, TEXT_HTML_CONTENT_TYPE)
+                .getTextualContent())
+            .hasValueSatisfying(text -> assertThat(text)
+                .contains(HTML_TEXT_CONTENT));
     }
 
     private InputStream textContentWithManyNullCharacters() {
-        String htmlTextContent = "HTML pages can include a lot of null '\0' character. But still expecting the content can be parsed." +
-            "Jsoup 1.21.1 thinks a file containing more than 10 null characters can be a binary file";
-        byte[] htmlBytesContent = htmlTextContent.getBytes(StandardCharsets.UTF_8);
-        byte[] nullCharacters = {'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'};
-
-        byte[] fullContent = new byte[htmlBytesContent.length + nullCharacters.length];
-        System.arraycopy(htmlBytesContent, 0, fullContent, 0, htmlBytesContent.length);
-        System.arraycopy(nullCharacters, 0, fullContent, htmlBytesContent.length, nullCharacters.length);
-
-        return new ByteArrayInputStream(fullContent);
+        return new ByteArrayInputStream(FULL_CONTENT.getBytes(StandardCharsets.UTF_8));
     }
 }
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 5757f9b..1018e28 100644
--- a/pom.xml
+++ b/pom.xml
@@ -2538,7 +2538,7 @@
             <dependency>
                 <groupId>org.jsoup</groupId>
                 <artifactId>jsoup</artifactId>
-                <version>1.12.1</version>
+                <version>1.12.2</version>
             </dependency>
             <dependency>
                 <groupId>org.mockito</groupId>


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


[james-project] 07/09: JAMES-3042 ImapRequestFrameDecoder should be more resilient

Posted by rc...@apache.org.
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

commit d95f16a3f02238491bc7ceb786be886e3b61b0a9
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Feb 7 10:13:27 2020 +0700

    JAMES-3042 ImapRequestFrameDecoder should be more resilient
    
    `newCumulationBuffer` ended up throwing nullPointer exceptions when NEEDED_DATA
    attachment was not well positioned.
    
    We can call super method when this attachment is not here in order to be more resilient
    (as only the sizing of a buffer is chosen).
---
 server/protocols/protocols-imap4/pom.xml           |  5 ++
 .../imapserver/netty/ImapRequestFrameDecoder.java  | 21 ++++----
 .../netty/ImapRequestFrameDecoderTest.java         | 63 ++++++++++++++++++++++
 3 files changed, 80 insertions(+), 9 deletions(-)

diff --git a/server/protocols/protocols-imap4/pom.xml b/server/protocols/protocols-imap4/pom.xml
index 521e0d9..635d0d4 100644
--- a/server/protocols/protocols-imap4/pom.xml
+++ b/server/protocols/protocols-imap4/pom.xml
@@ -80,6 +80,11 @@
             <artifactId>commons-configuration2</artifactId>
         </dependency>
         <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>jcl-over-slf4j</artifactId>
         </dependency>
diff --git a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java
index 7a631f3..801f6d7 100644
--- a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java
+++ b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java
@@ -221,19 +221,22 @@ public class ImapRequestFrameDecoder extends FrameDecoder implements NettyConsta
 
     @Override
     protected synchronized ChannelBuffer newCumulationBuffer(ChannelHandlerContext ctx, int minimumCapacity) {
-        @SuppressWarnings("unchecked")
         Map<String, Object> attachment = (Map<String, Object>) ctx.getAttachment();
-        int size = (Integer) attachment.get(NEEDED_DATA);
-        
-        if (inMemorySizeLimit > 0) {
-            return ChannelBuffers.dynamicBuffer(Math.min(size, inMemorySizeLimit), ctx.getChannel().getConfig().getBufferFactory());
-        } else {
+        Object sizeAsObject = attachment.get(NEEDED_DATA);
+        if (sizeAsObject != null) {
+            @SuppressWarnings("unchecked")
+            int size = (Integer) sizeAsObject;
+
+            if (inMemorySizeLimit > 0) {
+                return ChannelBuffers.dynamicBuffer(Math.min(size, inMemorySizeLimit), ctx.getChannel().getConfig().getBufferFactory());
+            } else {
 
-            if (size > 0) {
-                return ChannelBuffers.dynamicBuffer(size, ctx.getChannel().getConfig().getBufferFactory());
+                if (size > 0) {
+                    return ChannelBuffers.dynamicBuffer(size, ctx.getChannel().getConfig().getBufferFactory());
+                }
             }
-            return super.newCumulationBuffer(ctx, minimumCapacity);
         }
+        return super.newCumulationBuffer(ctx, minimumCapacity);
     }
 
 }
diff --git a/server/protocols/protocols-imap4/src/test/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoderTest.java b/server/protocols/protocols-imap4/src/test/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoderTest.java
new file mode 100644
index 0000000..1c66c83
--- /dev/null
+++ b/server/protocols/protocols-imap4/src/test/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoderTest.java
@@ -0,0 +1,63 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.imapserver.netty;
+
+
+import static org.assertj.core.api.Assertions.assertThatCode;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.apache.james.imap.decode.ImapDecoder;
+import org.jboss.netty.buffer.ChannelBufferFactory;
+import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelConfig;
+import org.jboss.netty.channel.ChannelHandlerContext;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.google.common.collect.ImmutableMap;
+
+class ImapRequestFrameDecoderTest {
+    ImapRequestFrameDecoder testee;
+
+    @BeforeEach
+    void setUp() {
+        testee = new ImapRequestFrameDecoder(
+            mock(ImapDecoder.class),
+            12,
+            18);
+    }
+
+    @Test
+    void newCumulationBufferShouldNotThrowWhenNoAttachments() {
+        ChannelHandlerContext channelHandler = mock(ChannelHandlerContext.class);
+        Channel channel = mock(Channel.class);
+        ChannelConfig channelConfig = mock(ChannelConfig.class);
+
+        when(channelConfig.getBufferFactory()).thenReturn(mock(ChannelBufferFactory.class));
+        when(channelHandler.getChannel()).thenReturn(channel);
+        when(channel.getConfig()).thenReturn(channelConfig);
+
+        when(channelHandler.getAttachment()).thenReturn(ImmutableMap.<String, Object>of());
+
+        assertThatCode(() -> testee.newCumulationBuffer(channelHandler, 36))
+            .doesNotThrowAnyException();
+    }
+}
\ No newline at end of file


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