This is an automated email from the ASF dual-hosted git repository. btellier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 3a3d0b1790f854a5d5b3c0becf99614593706c88 Author: Benoit Tellier <[email protected]> AuthorDate: Fri Sep 11 16:17:12 2020 +0700 JAMES-3373 Tests for delegation & download --- .../jmap/rfc8621/contract/DownloadContract.scala | 107 ++++++++++++++++++++- 1 file changed, 104 insertions(+), 3 deletions(-) diff --git a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/DownloadContract.scala b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/DownloadContract.scala index 729107c..df56eb6 100644 --- a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/DownloadContract.scala +++ b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/DownloadContract.scala @@ -29,10 +29,11 @@ import org.apache.http.HttpStatus.{SC_NOT_FOUND, SC_OK} import org.apache.james.GuiceJamesServer import org.apache.james.jmap.http.UserCredential import org.apache.james.jmap.rfc8621.contract.DownloadContract.accountId -import org.apache.james.jmap.rfc8621.contract.Fixture.{ACCEPT_RFC8621_VERSION_HEADER, BOB, BOB_PASSWORD, DOMAIN, authScheme, baseRequestSpecBuilder} +import org.apache.james.jmap.rfc8621.contract.Fixture.{ACCEPT_RFC8621_VERSION_HEADER, ANDRE, BOB, BOB_PASSWORD, DOMAIN, authScheme, baseRequestSpecBuilder} import org.apache.james.mailbox.MessageManager.AppendCommand -import org.apache.james.mailbox.model.{MailboxPath, MessageId} -import org.apache.james.modules.MailboxProbeImpl +import org.apache.james.mailbox.model.MailboxACL.Right +import org.apache.james.mailbox.model.{MailboxACL, MailboxPath, MessageId} +import org.apache.james.modules.{ACLProbeImpl, MailboxProbeImpl} import org.apache.james.utils.DataProbeImpl import org.assertj.core.api.Assertions.assertThat import org.hamcrest.Matchers.{containsString, emptyOrNullString} @@ -85,6 +86,106 @@ trait DownloadContract { .hasContent(expectedResponse) } + + @Test + def downloadMessageShouldSucceedWhenDelegated(server: GuiceJamesServer): Unit = { + val path = MailboxPath.inbox(ANDRE) + server.getProbe(classOf[MailboxProbeImpl]).createMailbox(path) + val messageId: MessageId = server.getProbe(classOf[MailboxProbeImpl]) + .appendMessage(ANDRE.asString, path, AppendCommand.from( + ClassLoader.getSystemResourceAsStream("eml/multipart_simple.eml"))) + .getMessageId + server.getProbe(classOf[ACLProbeImpl]) + .replaceRights(path, BOB.asString(), new MailboxACL.Rfc4314Rights(Right.Read, Right.Lookup)) + + val response = `given` + .basePath("") + .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER) + .when + .get(s"/download/$accountId/${messageId.serialize()}") + .`then` + .statusCode(SC_OK) + .contentType("message/rfc822") + .extract + .body + .asString + + val expectedResponse: String = IOUtils.toString(ClassLoader.getSystemResourceAsStream("eml/multipart_simple.eml"), + StandardCharsets.UTF_8) + assertThat(new ByteArrayInputStream(response.getBytes(StandardCharsets.UTF_8))) + .hasContent(expectedResponse) + } + + @Test + def downloadingOtherPeopleMessageShouldFail(server: GuiceJamesServer): Unit = { + val path = MailboxPath.inbox(ANDRE) + server.getProbe(classOf[MailboxProbeImpl]).createMailbox(path) + val messageId: MessageId = server.getProbe(classOf[MailboxProbeImpl]) + .appendMessage(ANDRE.asString, path, AppendCommand.from( + ClassLoader.getSystemResourceAsStream("eml/multipart_simple.eml"))) + .getMessageId + + `given` + .basePath("") + .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER) + .when + .get(s"/download/$accountId/${messageId.serialize()}") + .`then` + .statusCode(SC_NOT_FOUND) + } + + @Test + def downloadPartShouldSucceedWhenDelegated(server: GuiceJamesServer): Unit = { + val path = MailboxPath.inbox(ANDRE) + server.getProbe(classOf[MailboxProbeImpl]).createMailbox(path) + val messageId: MessageId = server.getProbe(classOf[MailboxProbeImpl]) + .appendMessage(ANDRE.asString, path, AppendCommand.from( + ClassLoader.getSystemResourceAsStream("eml/multipart_simple.eml"))) + .getMessageId + server.getProbe(classOf[ACLProbeImpl]) + .replaceRights(path, BOB.asString(), new MailboxACL.Rfc4314Rights(Right.Read, Right.Lookup)) + + val response = `given` + .basePath("") + .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER) + .when + .get(s"/download/$accountId/${messageId.serialize()}_3").prettyPeek() + .`then` + .statusCode(SC_OK) + .contentType("text/plain") + .extract + .body + .asString + + val expectedResponse: String = + """-----BEGIN RSA PRIVATE KEY----- + |MIIEogIBAAKCAQEAx7PG0+E//EMpm7IgI5Q9TMDSFya/1hE+vvTJrk0iGFllPeHL + |A5/VlTM0YWgG6X50qiMfE3VLazf2c19iXrT0mq/21PZ1wFnogv4zxUNaih+Bng62 + |F0SyruE/O/Njqxh/Ccq6K/e05TV4T643USxAeG0KppmYW9x8HA/GvV832apZuxkV + |i6NVkDBrfzaUCwu4zH+HwOv/pI87E7KccHYC++Biaj3 + |""".stripMargin + assertThat(new ByteArrayInputStream(response.getBytes(StandardCharsets.UTF_8))) + .hasContent(expectedResponse) + } + + @Test + def downloadingOtherPeopleMessagePartShouldFail(server: GuiceJamesServer): Unit = { + val path = MailboxPath.inbox(ANDRE) + server.getProbe(classOf[MailboxProbeImpl]).createMailbox(path) + val messageId: MessageId = server.getProbe(classOf[MailboxProbeImpl]) + .appendMessage(ANDRE.asString, path, AppendCommand.from( + ClassLoader.getSystemResourceAsStream("eml/multipart_simple.eml"))) + .getMessageId + + `given` + .basePath("") + .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER) + .when + .get(s"/download/$accountId/${messageId.serialize()}_3") + .`then` + .statusCode(SC_NOT_FOUND) + } + @Test def downloadPart(server: GuiceJamesServer): Unit = { val path = MailboxPath.inbox(BOB) --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
