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 ma...@apache.org on 2016/04/25 16:15:46 UTC
[2/4] james-project git commit: JAMES-1721 SetMailboxes can't modify
system mailboxes
JAMES-1721 SetMailboxes can't modify system mailboxes
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/f476cbaf
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/f476cbaf
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/f476cbaf
Branch: refs/heads/master
Commit: f476cbafaf86c6554be5bebf51b864e97ab4063d
Parents: 223dd81
Author: Laura Royet <lr...@linagora.com>
Authored: Thu Apr 14 16:15:14 2016 +0200
Committer: Laura Royet <lr...@linagora.com>
Committed: Mon Apr 25 14:50:28 2016 +0200
----------------------------------------------------------------------
.../integration/SetMailboxesMethodTest.java | 35 ++++++++++++++++++++
.../jmap/exceptions/SystemMailboxException.java | 23 -------------
.../SystemMailboxNotUpdatableException.java | 23 +++++++++++++
.../SetMailboxesDestructionProcessor.java | 10 +++---
.../methods/SetMailboxesUpdateProcessor.java | 12 +++++++
.../SetMailboxesUpdateProcessorTest.java | 2 +-
6 files changed, 76 insertions(+), 29 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/f476cbaf/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMailboxesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMailboxesMethodTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMailboxesMethodTest.java
index 07718f8..2c0316c 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMailboxesMethodTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMailboxesMethodTest.java
@@ -1441,4 +1441,39 @@ public abstract class SetMailboxesMethodTest {
.body(ARGUMENTS + ".list", hasSize(1))
.body(ARGUMENTS + ".list[0].name", equalTo("mySecondBox"));
}
+
+ @Test
+ public void setMailboxesShouldReturnNotUpdatedWhenRenamingSystemMailbox() {
+
+ Mailbox<?> mailbox = jmapServer.serverProbe().getMailbox("#private", username, "inbox");
+ String mailboxId = mailbox.getMailboxId().serialize();
+
+ String requestBody =
+ "[" +
+ " [ \"setMailboxes\"," +
+ " {" +
+ " \"update\": {" +
+ " \"" + mailboxId + "\" : {" +
+ " \"name\" : \"renamed\"" +
+ " }" +
+ " }" +
+ " }," +
+ " \"#0\"" +
+ " ]" +
+ "]";
+
+ given()
+ .accept(ContentType.JSON)
+ .contentType(ContentType.JSON)
+ .header("Authorization", this.accessToken.serialize())
+ .body(requestBody)
+ .when()
+ .post("/jmap")
+ .then()
+ .statusCode(200)
+ .body(NAME, equalTo("mailboxesSet"))
+ .body(ARGUMENTS + ".notUpdated", hasEntry(equalTo(mailboxId), Matchers.allOf(
+ hasEntry(equalTo("type"), equalTo("invalidArguments")),
+ hasEntry(equalTo("description"), equalTo("Cannot update a system mailbox.")))));
+ }
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f476cbaf/server/protocols/jmap/src/main/java/org/apache/james/jmap/exceptions/SystemMailboxException.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/exceptions/SystemMailboxException.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/exceptions/SystemMailboxException.java
deleted file mode 100644
index f82cfa1..0000000
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/exceptions/SystemMailboxException.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/****************************************************************
- * 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.jmap.exceptions;
-
-public class SystemMailboxException extends Exception {
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f476cbaf/server/protocols/jmap/src/main/java/org/apache/james/jmap/exceptions/SystemMailboxNotUpdatableException.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/exceptions/SystemMailboxNotUpdatableException.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/exceptions/SystemMailboxNotUpdatableException.java
new file mode 100644
index 0000000..6ecebf7
--- /dev/null
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/exceptions/SystemMailboxNotUpdatableException.java
@@ -0,0 +1,23 @@
+/****************************************************************
+ * 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.jmap.exceptions;
+
+public class SystemMailboxNotUpdatableException extends RuntimeException {
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f476cbaf/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesDestructionProcessor.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesDestructionProcessor.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesDestructionProcessor.java
index 6076fb8..5fdc8d9 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesDestructionProcessor.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesDestructionProcessor.java
@@ -26,7 +26,7 @@ import java.util.Optional;
import javax.inject.Inject;
import org.apache.james.jmap.exceptions.MailboxHasChildException;
-import org.apache.james.jmap.exceptions.SystemMailboxException;
+import org.apache.james.jmap.exceptions.SystemMailboxNotUpdatableException;
import org.apache.james.jmap.model.SetError;
import org.apache.james.jmap.model.SetMailboxesRequest;
import org.apache.james.jmap.model.SetMailboxesResponse;
@@ -103,7 +103,7 @@ public class SetMailboxesDestructionProcessor<Id extends MailboxId> implements S
.type("mailboxHasChild")
.description(String.format("The mailbox '%s' has a child.", entry.getKey()))
.build());
- } catch (SystemMailboxException e) {
+ } catch (SystemMailboxNotUpdatableException e) {
builder.notDestroyed(entry.getKey(), SetError.builder()
.type("invalidArguments")
.description(String.format("The mailbox '%s' is a system mailbox.", entry.getKey()))
@@ -118,7 +118,7 @@ public class SetMailboxesDestructionProcessor<Id extends MailboxId> implements S
}
}
- private void preconditions(Mailbox mailbox, MailboxSession mailboxSession) throws MailboxHasChildException, SystemMailboxException, MailboxException {
+ private void preconditions(Mailbox mailbox, MailboxSession mailboxSession) throws MailboxHasChildException, SystemMailboxNotUpdatableException, MailboxException {
checkForChild(mailbox.getId(), mailboxSession);
checkRole(mailbox.getRole());
}
@@ -129,9 +129,9 @@ public class SetMailboxesDestructionProcessor<Id extends MailboxId> implements S
}
}
- private void checkRole(Optional<Role> role) throws SystemMailboxException {
+ private void checkRole(Optional<Role> role) throws SystemMailboxNotUpdatableException {
if (role.map(Role::isSystemRole).orElse(false)) {
- throw new SystemMailboxException();
+ throw new SystemMailboxNotUpdatableException();
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f476cbaf/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java
index bf4d4ac..b079b64 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java
@@ -26,12 +26,14 @@ import javax.inject.Inject;
import org.apache.james.jmap.exceptions.MailboxHasChildException;
import org.apache.james.jmap.exceptions.MailboxNameException;
import org.apache.james.jmap.exceptions.MailboxParentNotFoundException;
+import org.apache.james.jmap.exceptions.SystemMailboxNotUpdatableException;
import org.apache.james.jmap.model.SetError;
import org.apache.james.jmap.model.SetMailboxesRequest;
import org.apache.james.jmap.model.SetMailboxesResponse;
import org.apache.james.jmap.model.SetMailboxesResponse.Builder;
import org.apache.james.jmap.model.mailbox.Mailbox;
import org.apache.james.jmap.model.mailbox.MailboxUpdateRequest;
+import org.apache.james.jmap.model.mailbox.Role;
import org.apache.james.jmap.utils.MailboxUtils;
import org.apache.james.mailbox.MailboxManager;
import org.apache.james.mailbox.MailboxSession;
@@ -71,10 +73,14 @@ public class SetMailboxesUpdateProcessor<Id extends MailboxId> implements SetMai
try {
validateMailboxName(updateRequest, mailboxSession);
Mailbox mailbox = getMailbox(mailboxId, mailboxSession);
+ checkRole(mailbox.getRole());
validateParent(mailbox, updateRequest, mailboxSession);
updateMailbox(mailbox, updateRequest, mailboxSession);
responseBuilder.updated(mailboxId);
+
+ } catch (SystemMailboxNotUpdatableException e) {
+ notUpdated(mailboxId, "invalidArguments", "Cannot update a system mailbox.", responseBuilder);
} catch (MailboxNameException e) {
notUpdated(mailboxId, "invalidArguments",
e.getMessage(), responseBuilder);
@@ -94,6 +100,12 @@ public class SetMailboxesUpdateProcessor<Id extends MailboxId> implements SetMai
notUpdated(mailboxId, "anErrorOccurred",
"An error occurred when updating the mailbox", responseBuilder);
}
+ }
+
+ private void checkRole(Optional<Role> role) throws SystemMailboxNotUpdatableException {
+ if (role.map(Role::isSystemRole).orElse(false)) {
+ throw new SystemMailboxNotUpdatableException();
+ }
}
private Builder notUpdated(String mailboxId, String type, String message, Builder responseBuilder) {
http://git-wip-us.apache.org/repos/asf/james-project/blob/f476cbaf/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessorTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessorTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessorTest.java
index 73e2146..6fc0f9e 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessorTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessorTest.java
@@ -64,7 +64,7 @@ public class SetMailboxesUpdateProcessorTest {
SetMailboxesRequest request = SetMailboxesRequest.builder()
.update(mailboxId, MailboxUpdateRequest.builder().parentId(newParentId).build())
.build();
- Mailbox mailbox = Mailbox.builder().id(mailboxId).name("name").build();
+ Mailbox mailbox = Mailbox.builder().id(mailboxId).name("name").role(Optional.empty()).build();
when(mockedMailboxUtils.mailboxFromMailboxId(mailboxId, mockedMailboxSession))
.thenReturn(Optional.of(mailbox));
when(mockedMailboxUtils.mailboxPathFromMailboxId(newParentId, mockedMailboxSession))
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org