You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2021/02/09 04:29:53 UTC
[james-project] 25/33: JAMES-3491 WebSocket PUSH should support
delegation
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 9691e2efe358a8e85c95781136982cc392f63cc7
Author: LanKhuat <dl...@linagora.com>
AuthorDate: Fri Feb 5 11:38:54 2021 +0700
JAMES-3491 WebSocket PUSH should support delegation
---
.../jmap/rfc8621/contract/WebSocketContract.scala | 69 +++++++++++++++++++++-
1 file changed, 67 insertions(+), 2 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/WebSocketContract.scala b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/WebSocketContract.scala
index e1fcb87..750c12f 100644
--- a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/WebSocketContract.scala
+++ b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/WebSocketContract.scala
@@ -19,14 +19,18 @@
package org.apache.james.jmap.rfc8621.contract
import java.net.{ProtocolException, URI}
+import java.nio.charset.StandardCharsets
import net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson
import org.apache.james.GuiceJamesServer
import org.apache.james.jmap.api.model.AccountId
import org.apache.james.jmap.draft.JmapGuiceProbe
import org.apache.james.jmap.rfc8621.contract.Fixture._
-import org.apache.james.mailbox.model.MailboxPath
-import org.apache.james.modules.MailboxProbeImpl
+import org.apache.james.mailbox.MessageManager.AppendCommand
+import org.apache.james.mailbox.model.MailboxACL.Right
+import org.apache.james.mailbox.model.{MailboxACL, MailboxPath}
+import org.apache.james.mime4j.dom.Message
+import org.apache.james.modules.{ACLProbeImpl, MailboxProbeImpl}
import org.apache.james.utils.DataProbeImpl
import org.assertj.core.api.Assertions.{assertThat, assertThatThrownBy}
import org.junit.jupiter.api.{BeforeEach, Test}
@@ -51,6 +55,7 @@ trait WebSocketContract {
server.getProbe(classOf[DataProbeImpl])
.fluent()
.addDomain(DOMAIN.asString())
+ .addUser(ANDRE.asString(), ANDRE_PASSWORD)
.addUser(BOB.asString(), BOB_PASSWORD)
}
@@ -636,6 +641,66 @@ trait WebSocketContract {
.doesNotContain(emailStateChange)
}
+ @Test
+ def pushShouldSupportDelegation(server: GuiceJamesServer): Unit = {
+ val mailboxProbe: MailboxProbeImpl = server.getProbe(classOf[MailboxProbeImpl])
+ val andrePath = MailboxPath.inbox(ANDRE)
+ mailboxProbe.createMailbox(andrePath)
+
+ server.getProbe(classOf[ACLProbeImpl])
+ .replaceRights(andrePath, BOB.asString, new MailboxACL.Rfc4314Rights(Right.Lookup, Right.Read))
+
+ Thread.sleep(100)
+
+ val response: Either[String, List[String]] =
+ authenticatedRequest(server)
+ .response(asWebSocket[Identity, List[String]] {
+ ws =>
+ ws.send(WebSocketFrame.text(
+ """{
+ | "@type": "WebSocketPushEnable",
+ | "dataTypes": ["Mailbox", "Email"]
+ |}""".stripMargin))
+
+ Thread.sleep(100)
+
+ val message: Message = Message.Builder
+ .of
+ .setSubject("test")
+ .setBody("testmail", StandardCharsets.UTF_8)
+ .build
+ mailboxProbe.appendMessage(ANDRE.asString(), andrePath, AppendCommand.from(message))
+
+ Thread.sleep(100)
+
+ List(
+ ws.receive()
+ .map { case t: Text =>
+ t.payload
+ },
+ ws.receive()
+ .map { case t: Text =>
+ t.payload
+ })
+ })
+ .send(backend)
+ .body
+
+ Thread.sleep(100)
+
+ val jmapGuiceProbe: JmapGuiceProbe = server.getProbe(classOf[JmapGuiceProbe])
+ val accountId: AccountId = AccountId.fromUsername(BOB)
+ val emailState: String = jmapGuiceProbe.getLatestEmailStateWithDelegation(accountId).getValue.toString
+ val mailboxState: String = jmapGuiceProbe.getLatestMailboxStateWithDelegation(accountId).getValue.toString
+
+ val mailboxStateChange: String = s"""{"@type":"StateChange","changed":{"$ACCOUNT_ID":{"Mailbox":"$mailboxState"}}}"""
+ val emailStateChange: String = s"""{"@type":"StateChange","changed":{"$ACCOUNT_ID":{"Email":"$emailState"}}}"""
+
+ assertThat(response.toOption.get.asJava)
+ .hasSize(2) // email notification + mailbox notification
+ .contains(mailboxStateChange, emailStateChange)
+ }
+
private def authenticatedRequest(server: GuiceJamesServer): RequestT[Identity, Either[String, String], Any] = {
val port = server.getProbe(classOf[JmapGuiceProbe])
.getJmapPort
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org