james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adup...@apache.org
Subject [05/19] james-project git commit: JAMES-2214 Fix mailbox not found invalid lambda in SetMessages::create
Date Wed, 15 Nov 2017 11:15:46 GMT
JAMES-2214 Fix mailbox not found invalid lambda in SetMessages::create


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/f85b5c6b
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/f85b5c6b
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/f85b5c6b

Branch: refs/heads/master
Commit: f85b5c6b4c47af63c66c09adce121506277a56ab
Parents: 903ead0
Author: benwa <btellier@linagora.com>
Authored: Mon Nov 13 11:43:03 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Wed Nov 15 17:59:49 2017 +0700

----------------------------------------------------------------------
 .../integration/SetMessagesMethodTest.java      | 45 ++++++++++++++++++--
 .../methods/SetMessagesCreationProcessor.java   |  6 ++-
 .../SetMessagesCreationProcessorTest.java       |  4 ++
 3 files changed, 50 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/f85b5c6b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
index 54cf67b..3508e65 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
@@ -120,10 +120,13 @@ public abstract class SetMessagesMethodTest {
     private static final String USERS_DOMAIN = "domain.tld";
     private static final String USERNAME = "username@" + USERS_DOMAIN;
     private static final String PASSWORD = "password";
+    private static final String BOB = "bob@" + USERS_DOMAIN;
+    private static final String BOB_PASSWORD = "bobPassword";
     private static final MailboxPath USER_MAILBOX = MailboxPath.forUser(USERNAME, "mailbox");
     private static final String NOT_UPDATED = ARGUMENTS + ".notUpdated";
 
     private ConditionFactory calmlyAwait;
+    private AccessToken bobAccessToken;
 
     protected abstract GuiceJamesServer createJmapServer();
 
@@ -158,8 +161,10 @@ public abstract class SetMessagesMethodTest {
 
         dataProbe.addDomain(USERS_DOMAIN);
         dataProbe.addUser(USERNAME, PASSWORD);
+        dataProbe.addUser(BOB, BOB_PASSWORD);
         mailboxProbe.createMailbox("#private", USERNAME, DefaultMailboxes.INBOX);
         accessToken = HttpJmapAuthentication.authenticateJamesUser(baseUri(), USERNAME, PASSWORD);
+        bobAccessToken = HttpJmapAuthentication.authenticateJamesUser(baseUri(), BOB, BOB_PASSWORD);
 
         mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, DefaultMailboxes.OUTBOX);
         mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, DefaultMailboxes.TRASH);
@@ -1182,6 +1187,40 @@ public abstract class SetMessagesMethodTest {
     }
 
     @Test
+    public void setMessagesShouldReturnValidErrorWhenMailboxNotFound() {
+        String messageCreationId = "creationId1337";
+        String fromAddress = USERNAME;
+        String requestBody = "[" +
+            "  [" +
+            "    \"setMessages\","+
+            "    {" +
+            "      \"create\": { \"" + messageCreationId  + "\" : {" +
+            "        \"from\": { \"name\": \"Me\", \"email\": \"" + fromAddress + "\"},"
+
+            "        \"to\": [{ \"name\": \"BOB\", \"email\": \"someone@example.com\"}],"
+
+            "        \"subject\": \"\"," +
+            "        \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" +
+            "      }}" +
+            "    }," +
+            "    \"#0\"" +
+            "  ]" +
+            "]";
+
+        given()
+            .header("Authorization", bobAccessToken.serialize())
+            .body(requestBody)
+        .when()
+            .post("/jmap")
+        .then()
+            .log().ifValidationFails()
+            .statusCode(200)
+            .body(NAME, equalTo("messagesSet"))
+            .body(ARGUMENTS + ".created", aMapWithSize(0))
+            .body(ARGUMENTS + ".notCreated", aMapWithSize(1))
+            .body(ARGUMENTS + ".notCreated." + messageCreationId + ".type", equalTo("error"))
+            .body(ARGUMENTS + ".notCreated." + messageCreationId + ".description", endsWith("can
not be found"));
+    }
+
+    @Test
     public void setMessagesShouldReturnCreatedMessageWithNonASCIICharactersInSubjectWhenPresent()
{
         String messageCreationId = "creationId1337";
         String fromAddress = USERNAME;
@@ -1325,6 +1364,7 @@ public abstract class SetMessagesMethodTest {
             .body(ARGUMENTS + ".created[\""+messageCreationId+"\"].keywords.$Flagged", equalTo(true))
             ;
     }
+
     @Test
     public void setMessagesShouldSupportArbitraryMessageId() {
         String messageCreationId = "1717fcd1-603e-44a5-b2a6-1234dbcd5723";
@@ -1890,11 +1930,10 @@ public abstract class SetMessagesMethodTest {
         dataProbe.addUser(recipientAddress, password);
         mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, recipientAddress, DefaultMailboxes.INBOX);
 
-        String bccAddress = "bob" + "@" + USERS_DOMAIN;
-        dataProbe.addUser(bccAddress, password);
+        String bccAddress = BOB;
         mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, bccAddress, DefaultMailboxes.INBOX);
         await();
-        AccessToken bccToken = HttpJmapAuthentication.authenticateJamesUser(baseUri(), bccAddress,
password);
+        AccessToken bccToken = HttpJmapAuthentication.authenticateJamesUser(baseUri(), BOB,
BOB_PASSWORD);
 
         String messageCreationId = "creationId1337";
         String fromAddress = USERNAME;

http://git-wip-us.apache.org/repos/asf/james-project/blob/f85b5c6b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
index 50407a2..870235c 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
@@ -57,6 +57,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.github.fge.lambdas.Throwing;
+import com.github.fge.lambdas.functions.FunctionChainer;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Joiner;
 import com.google.common.base.Splitter;
@@ -105,9 +106,9 @@ public class SetMessagesCreationProcessor implements SetMessagesProcessor
{
 
     private void handleCreate(CreationMessageEntry create, Builder responseBuilder, MailboxSession
mailboxSession) {
         try {
+            validateIsUserOwnerOfMailboxes(create, mailboxSession);
             validateImplementedFeature(create, mailboxSession);
             validateArguments(create, mailboxSession);
-            validateIsUserOwnerOfMailboxes(create, mailboxSession);
             MessageWithId created = handleOutboxMessages(create, mailboxSession);
             responseBuilder.created(created.getCreationId(), created.getValue());
 
@@ -190,9 +191,10 @@ public class SetMessagesCreationProcessor implements SetMessagesProcessor
{
     }
 
     private boolean containsMailboxNotOwn(List<String> mailboxIds, MailboxSession session)
{
+        FunctionChainer<MailboxId, MessageManager> findMailbox = Throwing.function(mailboxId
-> mailboxManager.getMailbox(mailboxId, session));
         return mailboxIds.stream()
             .map(mailboxIdFactory::fromString)
-            .map(Throwing.function(mailboxId -> mailboxManager.getMailbox(mailboxId, session)))
+            .map(findMailbox.sneakyThrow())
             .map(Throwing.function(MessageManager::getMailboxPath))
             .anyMatch(path -> !session.getUser().isSameUser(path.getUser()));
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/f85b5c6b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesCreationProcessorTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesCreationProcessorTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesCreationProcessorTest.java
index 2857b1e..1ef68ea 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesCreationProcessorTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesCreationProcessorTest.java
@@ -62,6 +62,7 @@ import org.apache.james.mailbox.exception.MailboxNotFoundException;
 import org.apache.james.mailbox.inmemory.InMemoryId;
 import org.apache.james.mailbox.mock.MockMailboxSession;
 import org.apache.james.mailbox.model.ComposedMessageId;
+import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxId.Factory;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.MessageId;
@@ -286,6 +287,8 @@ public class SetMessagesCreationProcessorTest {
                             creationMessageBuilder.mailboxId("any-id-but-outbox-id")
                         .build())
                     .build();
+        when(mockedMailboxManager.getMailbox(any(MailboxId.class), any()))
+            .thenReturn(outbox);
 
         sut.process(notInOutboxCreationRequest, session);
 
@@ -320,6 +323,7 @@ public class SetMessagesCreationProcessorTest {
                 .create(
                         creationMessageId, creationMessageBuilder.mailboxId(DRAFTS_ID.serialize()).build())
                 .build();
+        when(mockedMailboxManager.getMailbox(any(MailboxId.class), any())).thenReturn(drafts);
         sut.process(createMessageInDrafts, session);
 
         // Then


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


Mime
View raw message