JAMES-1814 Special filenames integration test
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/c07b64b7 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/c07b64b7 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/c07b64b7 Branch: refs/heads/master Commit: c07b64b752d684fc38861b8db3b9a07f1abcd74c Parents: abb21de Author: Laura Royet <lro...@linagora.com> Authored: Wed Sep 21 12:21:40 2016 +0200 Committer: Laura Royet <lro...@linagora.com> Committed: Wed Sep 21 12:21:40 2016 +0200 ---------------------------------------------------------------------- .../integration/SetMessagesMethodTest.java | 188 ++++++++++++++++++- 1 file changed, 187 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/c07b64b7/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 d85c1bc..58e2609 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 @@ -37,7 +37,6 @@ import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.collection.IsMapWithSize.aMapWithSize; import static org.hamcrest.collection.IsMapWithSize.anEmptyMap; - import java.io.ByteArrayInputStream; import java.io.IOException; import java.time.ZonedDateTime; @@ -1775,6 +1774,193 @@ public abstract class SetMessagesMethodTest { .body(secondAttachment + ".isInline", equalTo(true)); } + @Test + public void setMessagesShouldReturnAttachmentsWithNonASCIINames() throws Exception { + jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "sent"); + + Attachment attachment = Attachment.builder() + .bytes("attachment".getBytes(Charsets.UTF_8)) + .type("application/octet-stream") + .build(); + uploadAttachment(attachment); + Attachment attachment2 = Attachment.builder() + .bytes("attachment2".getBytes(Charsets.UTF_8)) + .type("application/octet-stream") + .build(); + uploadAttachment(attachment2); + Attachment attachment3 = Attachment.builder() + .bytes("attachment3".getBytes(Charsets.UTF_8)) + .type("application/octet-stream") + .build(); + uploadAttachment(attachment3); + + String messageCreationId = "creationId"; + String fromAddress = username; + String outboxId = getOutboxId(accessToken); + String requestBody = "[" + + " [" + + " \"setMessages\","+ + " {" + + " \"create\":" + + " {" + + " \"" + messageCreationId + "\" : "+ + " {" + + " \"from\": { \"name\": \"Me\", \"email\": \"" + fromAddress + "\"}," + + " \"to\": [{ \"name\": \"BOB\", \"email\": \"some...@example.com\"}]," + + " \"subject\": \"Message with three attachments with non ASCII name\"," + + " \"textBody\": \"Test body\"," + + " \"mailboxIds\": [\"" + outboxId + "\"], " + + " \"attachments\":" + + " [" + + " {" + + " \"blobId\" : \"" + attachment.getAttachmentId().getId() + "\", " + + " \"type\" : \"" + attachment.getType() + "\", " + + " \"size\" : " + attachment.getSize() + "," + + " \"name\" : \"دÙÙاصÙر.png\", " + + " \"isInline\" : false" + + " }," + + " {" + + " \"blobId\" : \"" + attachment2.getAttachmentId().getId() + "\", " + + " \"type\" : \"" + attachment2.getType() + "\", " + + " \"size\" : " + attachment2.getSize() + "," + + " \"name\" : \"ÑволÑÑиониÑоваÑÑ.png\", " + + " \"isInline\" : false" + + " }," + + " {" + + " \"blobId\" : \"" + attachment3.getAttachmentId().getId() + "\", " + + " \"type\" : \"" + attachment3.getType() + "\", " + + " \"size\" : " + attachment3.getSize() + "," + + " \"name\" : \"è¿åè¿æ¯ä¸.png\"," + + " \"isInline\" : false" + + " }" + + " ]" + + " }" + + " }" + + " }," + + " \"#0\"" + + " ]" + + "]"; + + String createdPath = ARGUMENTS + ".created[\""+messageCreationId+"\"]"; + String firstAttachment = createdPath + ".attachments[0]"; + String secondAttachment = createdPath + ".attachments[1]"; + String thirdAttachment = createdPath + ".attachments[2]"; + + given() + .header("Authorization", accessToken.serialize()) + .body(requestBody) + .when() + .post("/jmap") + .then() + .statusCode(200) + .body(NAME, equalTo("messagesSet")) + .body(ARGUMENTS + ".notCreated", aMapWithSize(0)) + .body(ARGUMENTS + ".created", aMapWithSize(1)) + .body(createdPath + ".attachments", hasSize(3)) + .body(firstAttachment + ".name", equalTo("دÙÙاصÙر.png")) + .body(secondAttachment + ".name", equalTo("ÑволÑÑиониÑоваÑÑ.png")) + .body(thirdAttachment + ".name", equalTo("è¿åè¿æ¯ä¸.png")); + } + + @Test + public void filenamesAttachmentsWithNonASCIICharactersShouldBeRetrievedWhenChainingSetMessagesAndGetMessages() throws Exception { + jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "sent"); + + Attachment attachment = Attachment.builder() + .bytes("attachment".getBytes(Charsets.UTF_8)) + .type("application/octet-stream") + .build(); + uploadAttachment(attachment); + + Attachment attachment2 = Attachment.builder() + .bytes("attachment2".getBytes(Charsets.UTF_8)) + .type("application/octet-stream") + .build(); + uploadAttachment(attachment2); + + Attachment attachment3 = Attachment.builder() + .bytes("attachment3".getBytes(Charsets.UTF_8)) + .type("application/octet-stream") + .build(); + uploadAttachment(attachment3); + + String messageCreationId = "creationId"; + String fromAddress = username; + String outboxId = getOutboxId(accessToken); + String requestBody = "[" + + " [" + + " \"setMessages\","+ + " {" + + " \"create\":" + + " {" + + " \"" + messageCreationId + "\" : "+ + " {" + + " \"from\": { \"name\": \"Me\", \"email\": \"" + fromAddress + "\"}," + + " \"to\": [{ \"name\": \"BOB\", \"email\": \"" + fromAddress + "\"}]," + + " \"subject\": \"Message with three attachments with non ASCII name\"," + + " \"textBody\": \"Test body\"," + + " \"mailboxIds\": [\"" + outboxId + "\"], " + + " \"attachments\":" + + " [" + + " {" + + " \"blobId\" : \"" + attachment.getAttachmentId().getId() + "\", " + + " \"type\" : \"" + attachment.getType() + "\", " + + " \"size\" : " + attachment.getSize() + "," + + " \"name\" : \"دÙÙاصÙر.png\", " + + " \"isInline\" : false" + + " }," + + " {" + + " \"blobId\" : \"" + attachment2.getAttachmentId().getId() + "\", " + + " \"type\" : \"" + attachment2.getType() + "\", " + + " \"size\" : " + attachment2.getSize() + "," + + " \"name\" : \"ÑволÑÑиониÑоваÑÑ.png\", " + + " \"isInline\" : false" + + " }," + + " {" + + " \"blobId\" : \"" + attachment3.getAttachmentId().getId() + "\", " + + " \"type\" : \"" + attachment3.getType() + "\", " + + " \"size\" : " + attachment3.getSize() + "," + + " \"name\" : \"è¿åè¿æ¯ä¸.png\"," + + " \"isInline\" : false" + + " }" + + " ]" + + " }" + + " }" + + " }," + + " \"#0\"" + + " ]" + + "]"; + + given() + .header("Authorization", accessToken.serialize()) + .body(requestBody) + .when() + .post("/jmap").then(); + + calmlyAwait.atMost(30, TimeUnit.SECONDS).until( () -> isAnyMessageFoundInInbox(accessToken)); + + String message = ARGUMENTS + ".list[0]"; + String firstAttachment = message + ".attachments[0]"; + String secondAttachment = message + ".attachments[1]"; + String thirdAttachment = message + ".attachments[2]"; + String presumedMessageId = "usern...@domain.tld|INBOX|1"; + + given() + .header("Authorization", accessToken.serialize()) + .body("[[\"getMessages\", {\"ids\": [\"" + presumedMessageId + "\"]}, \"#0\"]]") + .when() + .post("/jmap") + .then() + .statusCode(200) + .log().ifValidationFails() + .body(NAME, equalTo("messages")) + .body(ARGUMENTS + ".list", hasSize(1)) + .body(message + ".attachments", hasSize(3)) + .body(firstAttachment + ".name", equalTo("دÙÙاصÙر.png")) + .body(secondAttachment + ".name", equalTo("ÑволÑÑиониÑоваÑÑ.png")) + .body(thirdAttachment + ".name", equalTo("è¿åè¿æ¯ä¸.png")); + } + private void uploadAttachment(Attachment attachment) throws IOException { with() .header("Authorization", accessToken.serialize()) --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org