You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by GitBox <gi...@apache.org> on 2021/10/28 10:28:14 UTC

[GitHub] [james-project] vttranlina opened a new pull request #716: JAMES-3539 PushSubscriptionSetCreateProcessor - pushVerification

vttranlina opened a new pull request #716:
URL: https://github.com/apache/james-project/pull/716


   Jira: https://issues.apache.org/jira/browse/JAMES-3539


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [james-project] chibenwa commented on a change in pull request #716: JAMES-3539 PushSubscriptionSetCreateProcessor - pushVerification

Posted by GitBox <gi...@apache.org>.
chibenwa commented on a change in pull request #716:
URL: https://github.com/apache/james-project/pull/716#discussion_r740752574



##########
File path: server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/PushSubscriptionSetMethodContract.scala
##########
@@ -820,4 +836,100 @@ trait PushSubscriptionSetMethodContract {
            |    ]
            |}""".stripMargin)
   }
+
+  @Test
+  def setMethodCreateShouldCallVerificationToPushServer(pushServer: ClientAndServer): Unit = {
+    val request: String =
+      s"""{
+         |    "using": ["urn:ietf:params:jmap:core"],
+         |    "methodCalls": [
+         |      [
+         |        "PushSubscription/set",
+         |        {
+         |            "create": {
+         |                "4f29": {
+         |                  "deviceClientId": "a889-ffea-910",
+         |                  "url": "${getPushServerUrl(pushServer)}",
+         |                  "types": ["Mailbox"]
+         |                }
+         |              }
+         |        },
+         |        "c1"
+         |      ]
+         |    ]
+         |  }""".stripMargin
+
+    `given`
+      .body(request)
+    .when
+      .post
+    .`then`
+      .statusCode(SC_OK)
+
+    pushServer.verify(HttpRequest.request()
+      .withPath("/subscribe"),

Review comment:
       Can we verify the format of the message sent?
   
   cf: https://jmap.io/spec-core.html#pushsubscription
   
   ```
   The server also immediately makes a POST request to https://example.com/push/?device=X8980fc&client=12c6d086 with the data:
   
   {
     "@type": "PushVerification",
     "pushSubscriptionId": "P43dcfa4-1dd4-41ef-9156-2c89b3b19c60",
     "verificationCode": "da1f097b11ca17f06424e30bf02bfa67"
   }
   ```

##########
File path: server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/PushSubscriptionSetCreatePerformer.scala
##########
@@ -87,3 +95,20 @@ class PushSubscriptionSetCreatePerformer @Inject()(pushSubscriptionRepository: P
       case (path, _) => SetError.invalidArguments(SetErrorDescription(s"Unknown error on property '$path'"))
     }
 }
+
+object PushSubscriptionSetCreateProcessor {
+  val PUSH_VERIFICATION_TO_PUSH_SERVER_TTL_DEFAULT: PushTTL = PushTTL.validate(15).toOption.get

Review comment:
       Why a TTL so low? Can't we keep the default?

##########
File path: server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/PushSubscriptionSetCreatePerformer.scala
##########
@@ -87,3 +95,20 @@ class PushSubscriptionSetCreatePerformer @Inject()(pushSubscriptionRepository: P
       case (path, _) => SetError.invalidArguments(SetErrorDescription(s"Unknown error on property '$path'"))
     }
 }
+
+object PushSubscriptionSetCreateProcessor {
+  val PUSH_VERIFICATION_TO_PUSH_SERVER_TTL_DEFAULT: PushTTL = PushTTL.validate(15).toOption.get
+}
+
+class PushSubscriptionSetCreateProcessor @Inject()(webPushClient: WebPushClient) {
+
+  def pushVerificationToPushServer(pushSubscriptionServerURL: PushSubscriptionServerURL, pushVerification: PushVerification): SMono[Unit] = {
+    SMono.fromPublisher(webPushClient.push(pushSubscriptionServerURL,
+      PushRequest(
+        ttl = PUSH_VERIFICATION_TO_PUSH_SERVER_TTL_DEFAULT,
+        payload = Json.stringify(PushSerializer.serializePushVerification(pushVerification)).getBytes(StandardCharsets.UTF_8))))

Review comment:
       Please encrypt the payload if the subscription have encryption keys.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [james-project] Arsnael commented on pull request #716: JAMES-3539 PushSubscriptionSetCreateProcessor - pushVerification

Posted by GitBox <gi...@apache.org>.
Arsnael commented on pull request #716:
URL: https://github.com/apache/james-project/pull/716#issuecomment-957331098


   A little squash? :)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [james-project] Arsnael commented on pull request #716: JAMES-3539 PushSubscriptionSetCreateProcessor - pushVerification

Posted by GitBox <gi...@apache.org>.
Arsnael commented on pull request #716:
URL: https://github.com/apache/james-project/pull/716#issuecomment-957331098


   A little squash? :)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [james-project] vttranlina commented on a change in pull request #716: JAMES-3539 PushSubscriptionSetCreateProcessor - pushVerification

Posted by GitBox <gi...@apache.org>.
vttranlina commented on a change in pull request #716:
URL: https://github.com/apache/james-project/pull/716#discussion_r740720314



##########
File path: server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/PushSubscriptionSetCreatePerformer.scala
##########
@@ -87,3 +95,20 @@ class PushSubscriptionSetCreatePerformer @Inject()(pushSubscriptionRepository: P
       case (path, _) => SetError.invalidArguments(SetErrorDescription(s"Unknown error on property '$path'"))
     }
 }
+
+object PushSubscriptionSetCreateProcessor {

Review comment:
       I don't like this name, I used it because the issue wrote that (https://github.com/linagora/james-project/issues/4411)
   Should we rename it to "PushVerificationProcessor" ? or move it directly inside the `PushSubscriptionSetCreatePerformer` class.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [james-project] vttranlina commented on a change in pull request #716: JAMES-3539 PushSubscriptionSetCreateProcessor - pushVerification

Posted by GitBox <gi...@apache.org>.
vttranlina commented on a change in pull request #716:
URL: https://github.com/apache/james-project/pull/716#discussion_r740720314



##########
File path: server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/PushSubscriptionSetCreatePerformer.scala
##########
@@ -87,3 +95,20 @@ class PushSubscriptionSetCreatePerformer @Inject()(pushSubscriptionRepository: P
       case (path, _) => SetError.invalidArguments(SetErrorDescription(s"Unknown error on property '$path'"))
     }
 }
+
+object PushSubscriptionSetCreateProcessor {

Review comment:
       I don't like this name, I used it because the issue wrote that (https://github.com/linagora/james-project/issues/4411)
   Should we rename it to "PushVerificationProcessor" ? or move it directly inside the `PushSubscriptionSetCreatePerformer` class.

##########
File path: server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/PushSubscriptionSetCreatePerformer.scala
##########
@@ -70,6 +75,9 @@ class PushSubscriptionSetCreatePerformer @Inject()(pushSubscriptionRepository: P
 
   private def create(clientId: PushSubscriptionCreationId, request: PushSubscriptionCreationRequest, mailboxSession: MailboxSession): SMono[CreationResult] =
     SMono.fromPublisher(pushSubscriptionRepository.save(mailboxSession.getUser, request))
+      .flatMap(subscription => verificationCreateProcessor.pushVerificationToPushServer(subscription.url,

Review comment:
       Should we handler the `pushVerificationToPushServer` error case? Then we will remove the entry saved before?
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [james-project] vttranlina commented on a change in pull request #716: JAMES-3539 PushSubscriptionSetCreateProcessor - pushVerification

Posted by GitBox <gi...@apache.org>.
vttranlina commented on a change in pull request #716:
URL: https://github.com/apache/james-project/pull/716#discussion_r740760323



##########
File path: server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/PushSubscriptionSetMethodContract.scala
##########
@@ -820,4 +836,100 @@ trait PushSubscriptionSetMethodContract {
            |    ]
            |}""".stripMargin)
   }
+
+  @Test
+  def setMethodCreateShouldCallVerificationToPushServer(pushServer: ClientAndServer): Unit = {
+    val request: String =
+      s"""{
+         |    "using": ["urn:ietf:params:jmap:core"],
+         |    "methodCalls": [
+         |      [
+         |        "PushSubscription/set",
+         |        {
+         |            "create": {
+         |                "4f29": {
+         |                  "deviceClientId": "a889-ffea-910",
+         |                  "url": "${getPushServerUrl(pushServer)}",
+         |                  "types": ["Mailbox"]
+         |                }
+         |              }
+         |        },
+         |        "c1"
+         |      ]
+         |    ]
+         |  }""".stripMargin
+
+    `given`
+      .body(request)
+    .when
+      .post
+    .`then`
+      .statusCode(SC_OK)
+
+    pushServer.verify(HttpRequest.request()
+      .withPath("/subscribe"),

Review comment:
       For validate body request, It already at  `org.apache.james.jmap.pushsubscription.PushSubscriptionSetCreateProcessorTest#pushVerificationShouldSuccess` 
   
   In `PushSubscriptionSetMethodContract`, we don't have a guiceProbe (or something) for get "verificationCode".




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [james-project] chibenwa commented on a change in pull request #716: JAMES-3539 PushSubscriptionSetCreateProcessor - pushVerification

Posted by GitBox <gi...@apache.org>.
chibenwa commented on a change in pull request #716:
URL: https://github.com/apache/james-project/pull/716#discussion_r740752574



##########
File path: server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/PushSubscriptionSetMethodContract.scala
##########
@@ -820,4 +836,100 @@ trait PushSubscriptionSetMethodContract {
            |    ]
            |}""".stripMargin)
   }
+
+  @Test
+  def setMethodCreateShouldCallVerificationToPushServer(pushServer: ClientAndServer): Unit = {
+    val request: String =
+      s"""{
+         |    "using": ["urn:ietf:params:jmap:core"],
+         |    "methodCalls": [
+         |      [
+         |        "PushSubscription/set",
+         |        {
+         |            "create": {
+         |                "4f29": {
+         |                  "deviceClientId": "a889-ffea-910",
+         |                  "url": "${getPushServerUrl(pushServer)}",
+         |                  "types": ["Mailbox"]
+         |                }
+         |              }
+         |        },
+         |        "c1"
+         |      ]
+         |    ]
+         |  }""".stripMargin
+
+    `given`
+      .body(request)
+    .when
+      .post
+    .`then`
+      .statusCode(SC_OK)
+
+    pushServer.verify(HttpRequest.request()
+      .withPath("/subscribe"),

Review comment:
       Can we verify the format of the message sent?
   
   cf: https://jmap.io/spec-core.html#pushsubscription
   
   ```
   The server also immediately makes a POST request to https://example.com/push/?device=X8980fc&client=12c6d086 with the data:
   
   {
     "@type": "PushVerification",
     "pushSubscriptionId": "P43dcfa4-1dd4-41ef-9156-2c89b3b19c60",
     "verificationCode": "da1f097b11ca17f06424e30bf02bfa67"
   }
   ```

##########
File path: server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/PushSubscriptionSetCreatePerformer.scala
##########
@@ -87,3 +95,20 @@ class PushSubscriptionSetCreatePerformer @Inject()(pushSubscriptionRepository: P
       case (path, _) => SetError.invalidArguments(SetErrorDescription(s"Unknown error on property '$path'"))
     }
 }
+
+object PushSubscriptionSetCreateProcessor {
+  val PUSH_VERIFICATION_TO_PUSH_SERVER_TTL_DEFAULT: PushTTL = PushTTL.validate(15).toOption.get

Review comment:
       Why a TTL so low? Can't we keep the default?

##########
File path: server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/PushSubscriptionSetCreatePerformer.scala
##########
@@ -87,3 +95,20 @@ class PushSubscriptionSetCreatePerformer @Inject()(pushSubscriptionRepository: P
       case (path, _) => SetError.invalidArguments(SetErrorDescription(s"Unknown error on property '$path'"))
     }
 }
+
+object PushSubscriptionSetCreateProcessor {
+  val PUSH_VERIFICATION_TO_PUSH_SERVER_TTL_DEFAULT: PushTTL = PushTTL.validate(15).toOption.get
+}
+
+class PushSubscriptionSetCreateProcessor @Inject()(webPushClient: WebPushClient) {
+
+  def pushVerificationToPushServer(pushSubscriptionServerURL: PushSubscriptionServerURL, pushVerification: PushVerification): SMono[Unit] = {
+    SMono.fromPublisher(webPushClient.push(pushSubscriptionServerURL,
+      PushRequest(
+        ttl = PUSH_VERIFICATION_TO_PUSH_SERVER_TTL_DEFAULT,
+        payload = Json.stringify(PushSerializer.serializePushVerification(pushVerification)).getBytes(StandardCharsets.UTF_8))))

Review comment:
       Please encrypt the payload if the subscription have encryption keys.

##########
File path: server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/PushSubscriptionSetMethodContract.scala
##########
@@ -820,4 +836,100 @@ trait PushSubscriptionSetMethodContract {
            |    ]
            |}""".stripMargin)
   }
+
+  @Test
+  def setMethodCreateShouldCallVerificationToPushServer(pushServer: ClientAndServer): Unit = {
+    val request: String =
+      s"""{
+         |    "using": ["urn:ietf:params:jmap:core"],
+         |    "methodCalls": [
+         |      [
+         |        "PushSubscription/set",
+         |        {
+         |            "create": {
+         |                "4f29": {
+         |                  "deviceClientId": "a889-ffea-910",
+         |                  "url": "${getPushServerUrl(pushServer)}",
+         |                  "types": ["Mailbox"]
+         |                }
+         |              }
+         |        },
+         |        "c1"
+         |      ]
+         |    ]
+         |  }""".stripMargin
+
+    `given`
+      .body(request)
+    .when
+      .post
+    .`then`
+      .statusCode(SC_OK)
+
+    pushServer.verify(HttpRequest.request()
+      .withPath("/subscribe"),

Review comment:
       > For validate body request, It already at org.apache.james.jmap.pushsubscription.PushSubscriptionSetCreateProcessorTest#pushVerificationShouldSuccess
   
   I would love to see it in an integration test

##########
File path: server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/pushsubscription/PushSubscriptionSetCreateProcessorTest.scala
##########
@@ -0,0 +1,73 @@
+/****************************************************************
+ * 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.pushsubscription
+
+import org.apache.james.jmap.api.model.{PushSubscriptionId, PushSubscriptionServerURL, VerificationCode}
+import org.apache.james.jmap.json.PushSerializer
+import org.apache.james.jmap.method.{PushSubscriptionSetCreateProcessor, PushVerification}
+import org.apache.james.jmap.pushsubscription.PushSubscriptionSetCreateProcessorTest.PUSH_VERIFICATION_SAMPLE
+import org.junit.jupiter.api.extension.ExtendWith
+import org.junit.jupiter.api.{BeforeEach, Test}
+import org.mockserver.integration.ClientAndServer
+import org.mockserver.model.HttpRequest.request
+import org.mockserver.model.HttpResponse.response
+import org.mockserver.model.NottableString.string
+import org.mockserver.verify.VerificationTimes
+import play.api.libs.json.Json
+
+import java.net.URL
+import java.util.UUID
+
+object PushSubscriptionSetCreateProcessorTest {
+  val PUSH_VERIFICATION_SAMPLE: PushVerification = PushVerification(
+    PushSubscriptionId(UUID.fromString("44111166-affc-4187-b974-0672e312b72e")),
+    VerificationCode("2b295d19-b37a-4865-b93e-bbb59f76ffc0"))
+}
+
+@ExtendWith(Array(classOf[PushServerExtension]))
+class PushSubscriptionSetCreateProcessorTest {
+
+  var testee: PushSubscriptionSetCreateProcessor = _
+  var pushServerUrl: PushSubscriptionServerURL = _
+
+  @BeforeEach
+  def setup(pushServer: ClientAndServer): Unit = {
+    val webPushClient: WebPushClient = new DefaultWebPushClient(WebPushClientTestFixture.PUSH_CLIENT_CONFIGURATION)
+    testee = new PushSubscriptionSetCreateProcessor(webPushClient)
+    pushServerUrl = PushSubscriptionServerURL(new URL(s"http://127.0.0.1:${pushServer.getLocalPort}/subscribe"))
+
+    pushServer
+      .when(request
+        .withPath("/subscribe")
+        .withMethod("POST")
+        .withHeader(string("Content-type"), string("application/json charset=utf-8")))
+      .respond(response
+        .withStatusCode(201))
+  }
+
+  @Test
+  def pushVerificationShouldSuccess(pushServer: ClientAndServer): Unit = {
+    testee.pushVerificationToPushServer(pushServerUrl, PUSH_VERIFICATION_SAMPLE, None).block()
+    pushServer.verify(request()
+      .withPath("/subscribe")
+      .withBody(Json.stringify(PushSerializer.serializePushVerification(PUSH_VERIFICATION_SAMPLE))),

Review comment:
       ```suggestion
         .withBody("json string"),
   ```

##########
File path: server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/pushsubscription/PushSubscriptionSetCreateProcessorTest.scala
##########
@@ -65,9 +71,35 @@ class PushSubscriptionSetCreateProcessorTest {
   @Test
   def pushVerificationShouldSuccess(pushServer: ClientAndServer): Unit = {
     testee.pushVerificationToPushServer(pushServerUrl, PUSH_VERIFICATION_SAMPLE, None).block()
+    print(Json.stringify(PushSerializer.serializePushVerification(PUSH_VERIFICATION_SAMPLE)))
     pushServer.verify(request()
       .withPath("/subscribe")
-      .withBody(Json.stringify(PushSerializer.serializePushVerification(PUSH_VERIFICATION_SAMPLE))),
+      .withBody(json("""{
+                       |    "@type": "PushVerification",
+                       |    "pushSubscriptionId": "44111166-affc-4187-b974-0672e312b72e",
+                       |    "verificationCode": "2b295d19-b37a-4865-b93e-bbb59f76ffc0"
+                       |}""".stripMargin)),
+      VerificationTimes.atLeast(1))
+  }
+
+  @Test
+  def pushVerificationShouldEncryptedPayloadWhenAssignKeys(pushServer: ClientAndServer): Unit = {
+    val uaKeyPair: KeyPair = EllipticCurves.generateKeyPair(CurveType.NIST_P256)
+    val uaPublicKey: ECPublicKey = uaKeyPair.getPublic.asInstanceOf[ECPublicKey]
+    val authSecret: Array[Byte] = "secret123secret1".getBytes
+
+    val p256dh: String = Base64.getEncoder.encodeToString(uaPublicKey.getEncoded)
+    val auth: String = Base64.getEncoder.encodeToString(authSecret)
+
+    testee.pushVerificationToPushServer(pushServerUrl, PUSH_VERIFICATION_SAMPLE, Some(PushSubscriptionKeys(p256dh, auth))).block()
+    print(Json.stringify(PushSerializer.serializePushVerification(PUSH_VERIFICATION_SAMPLE)))

Review comment:
       ```suggestion
   
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [james-project] chibenwa merged pull request #716: JAMES-3539 PushSubscriptionSetCreateProcessor - pushVerification

Posted by GitBox <gi...@apache.org>.
chibenwa merged pull request #716:
URL: https://github.com/apache/james-project/pull/716


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [james-project] vttranlina commented on a change in pull request #716: JAMES-3539 PushSubscriptionSetCreateProcessor - pushVerification

Posted by GitBox <gi...@apache.org>.
vttranlina commented on a change in pull request #716:
URL: https://github.com/apache/james-project/pull/716#discussion_r740720314



##########
File path: server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/PushSubscriptionSetCreatePerformer.scala
##########
@@ -87,3 +95,20 @@ class PushSubscriptionSetCreatePerformer @Inject()(pushSubscriptionRepository: P
       case (path, _) => SetError.invalidArguments(SetErrorDescription(s"Unknown error on property '$path'"))
     }
 }
+
+object PushSubscriptionSetCreateProcessor {

Review comment:
       I don't like this name, I used it because the issue wrote that (https://github.com/linagora/james-project/issues/4411)
   Should we rename it to "PushVerificationProcessor" ? or move it directly inside the `PushSubscriptionSetCreatePerformer` class.

##########
File path: server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/PushSubscriptionSetCreatePerformer.scala
##########
@@ -70,6 +75,9 @@ class PushSubscriptionSetCreatePerformer @Inject()(pushSubscriptionRepository: P
 
   private def create(clientId: PushSubscriptionCreationId, request: PushSubscriptionCreationRequest, mailboxSession: MailboxSession): SMono[CreationResult] =
     SMono.fromPublisher(pushSubscriptionRepository.save(mailboxSession.getUser, request))
+      .flatMap(subscription => verificationCreateProcessor.pushVerificationToPushServer(subscription.url,

Review comment:
       Should we handler the `pushVerificationToPushServer` error case? Then we will remove the entry saved before?
   

##########
File path: server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/PushSubscriptionSetMethodContract.scala
##########
@@ -820,4 +836,100 @@ trait PushSubscriptionSetMethodContract {
            |    ]
            |}""".stripMargin)
   }
+
+  @Test
+  def setMethodCreateShouldCallVerificationToPushServer(pushServer: ClientAndServer): Unit = {
+    val request: String =
+      s"""{
+         |    "using": ["urn:ietf:params:jmap:core"],
+         |    "methodCalls": [
+         |      [
+         |        "PushSubscription/set",
+         |        {
+         |            "create": {
+         |                "4f29": {
+         |                  "deviceClientId": "a889-ffea-910",
+         |                  "url": "${getPushServerUrl(pushServer)}",
+         |                  "types": ["Mailbox"]
+         |                }
+         |              }
+         |        },
+         |        "c1"
+         |      ]
+         |    ]
+         |  }""".stripMargin
+
+    `given`
+      .body(request)
+    .when
+      .post
+    .`then`
+      .statusCode(SC_OK)
+
+    pushServer.verify(HttpRequest.request()
+      .withPath("/subscribe"),

Review comment:
       For validate body request, It already at  `org.apache.james.jmap.pushsubscription.PushSubscriptionSetCreateProcessorTest#pushVerificationShouldSuccess` 
   
   In `PushSubscriptionSetMethodContract`, we don't have a guiceProbe (or something) for get "verificationCode".

##########
File path: server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/PushSubscriptionSetCreatePerformer.scala
##########
@@ -87,3 +95,20 @@ class PushSubscriptionSetCreatePerformer @Inject()(pushSubscriptionRepository: P
       case (path, _) => SetError.invalidArguments(SetErrorDescription(s"Unknown error on property '$path'"))
     }
 }
+
+object PushSubscriptionSetCreateProcessor {
+  val PUSH_VERIFICATION_TO_PUSH_SERVER_TTL_DEFAULT: PushTTL = PushTTL.validate(15).toOption.get

Review comment:
       your mean is `PushTTL.MAX`? 

##########
File path: server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/PushSubscriptionSetCreatePerformer.scala
##########
@@ -87,3 +95,20 @@ class PushSubscriptionSetCreatePerformer @Inject()(pushSubscriptionRepository: P
       case (path, _) => SetError.invalidArguments(SetErrorDescription(s"Unknown error on property '$path'"))
     }
 }
+
+object PushSubscriptionSetCreateProcessor {

Review comment:
       I don't like this name, I used it because the issue wrote that (https://github.com/linagora/james-project/issues/4411)
   Should we rename it to "PushVerificationProcessor" ? or move it directly inside the `PushSubscriptionSetCreatePerformer` class.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [james-project] chibenwa merged pull request #716: JAMES-3539 PushSubscriptionSetCreateProcessor - pushVerification

Posted by GitBox <gi...@apache.org>.
chibenwa merged pull request #716:
URL: https://github.com/apache/james-project/pull/716


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [james-project] chibenwa commented on a change in pull request #716: JAMES-3539 PushSubscriptionSetCreateProcessor - pushVerification

Posted by GitBox <gi...@apache.org>.
chibenwa commented on a change in pull request #716:
URL: https://github.com/apache/james-project/pull/716#discussion_r740869987



##########
File path: server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/pushsubscription/PushSubscriptionSetCreateProcessorTest.scala
##########
@@ -65,9 +71,35 @@ class PushSubscriptionSetCreateProcessorTest {
   @Test
   def pushVerificationShouldSuccess(pushServer: ClientAndServer): Unit = {
     testee.pushVerificationToPushServer(pushServerUrl, PUSH_VERIFICATION_SAMPLE, None).block()
+    print(Json.stringify(PushSerializer.serializePushVerification(PUSH_VERIFICATION_SAMPLE)))
     pushServer.verify(request()
       .withPath("/subscribe")
-      .withBody(Json.stringify(PushSerializer.serializePushVerification(PUSH_VERIFICATION_SAMPLE))),
+      .withBody(json("""{
+                       |    "@type": "PushVerification",
+                       |    "pushSubscriptionId": "44111166-affc-4187-b974-0672e312b72e",
+                       |    "verificationCode": "2b295d19-b37a-4865-b93e-bbb59f76ffc0"
+                       |}""".stripMargin)),
+      VerificationTimes.atLeast(1))
+  }
+
+  @Test
+  def pushVerificationShouldEncryptedPayloadWhenAssignKeys(pushServer: ClientAndServer): Unit = {
+    val uaKeyPair: KeyPair = EllipticCurves.generateKeyPair(CurveType.NIST_P256)
+    val uaPublicKey: ECPublicKey = uaKeyPair.getPublic.asInstanceOf[ECPublicKey]
+    val authSecret: Array[Byte] = "secret123secret1".getBytes
+
+    val p256dh: String = Base64.getEncoder.encodeToString(uaPublicKey.getEncoded)
+    val auth: String = Base64.getEncoder.encodeToString(authSecret)
+
+    testee.pushVerificationToPushServer(pushServerUrl, PUSH_VERIFICATION_SAMPLE, Some(PushSubscriptionKeys(p256dh, auth))).block()
+    print(Json.stringify(PushSerializer.serializePushVerification(PUSH_VERIFICATION_SAMPLE)))

Review comment:
       ```suggestion
   
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [james-project] vttranlina commented on a change in pull request #716: JAMES-3539 PushSubscriptionSetCreateProcessor - pushVerification

Posted by GitBox <gi...@apache.org>.
vttranlina commented on a change in pull request #716:
URL: https://github.com/apache/james-project/pull/716#discussion_r740760841



##########
File path: server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/PushSubscriptionSetCreatePerformer.scala
##########
@@ -87,3 +95,20 @@ class PushSubscriptionSetCreatePerformer @Inject()(pushSubscriptionRepository: P
       case (path, _) => SetError.invalidArguments(SetErrorDescription(s"Unknown error on property '$path'"))
     }
 }
+
+object PushSubscriptionSetCreateProcessor {
+  val PUSH_VERIFICATION_TO_PUSH_SERVER_TTL_DEFAULT: PushTTL = PushTTL.validate(15).toOption.get

Review comment:
       your mean is `PushTTL.MAX`? 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [james-project] Arsnael commented on pull request #716: JAMES-3539 PushSubscriptionSetCreateProcessor - pushVerification

Posted by GitBox <gi...@apache.org>.
Arsnael commented on pull request #716:
URL: https://github.com/apache/james-project/pull/716#issuecomment-957331098


   A little squash? :)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [james-project] chibenwa commented on a change in pull request #716: JAMES-3539 PushSubscriptionSetCreateProcessor - pushVerification

Posted by GitBox <gi...@apache.org>.
chibenwa commented on a change in pull request #716:
URL: https://github.com/apache/james-project/pull/716#discussion_r738268439



##########
File path: server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/PushVerificationSerializer.scala
##########
@@ -0,0 +1,34 @@
+/****************************************************************
+ * 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.json
+
+import org.apache.james.jmap.push_subscription.PushVerification
+import play.api.libs.json.{JsValue, Json, Writes}
+
+object PushVerificationSerializer {

Review comment:
       Can we use the existing PushSerializer class?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [james-project] vttranlina commented on a change in pull request #716: JAMES-3539 PushSubscriptionSetCreateProcessor - pushVerification

Posted by GitBox <gi...@apache.org>.
vttranlina commented on a change in pull request #716:
URL: https://github.com/apache/james-project/pull/716#discussion_r740720314



##########
File path: server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/PushSubscriptionSetCreatePerformer.scala
##########
@@ -87,3 +95,20 @@ class PushSubscriptionSetCreatePerformer @Inject()(pushSubscriptionRepository: P
       case (path, _) => SetError.invalidArguments(SetErrorDescription(s"Unknown error on property '$path'"))
     }
 }
+
+object PushSubscriptionSetCreateProcessor {

Review comment:
       I don't like this name, I used it because the issue wrote that (https://github.com/linagora/james-project/issues/4411)
   Should we rename it to "PushVerificationProcessor" ? or move it directly inside the `PushSubscriptionSetCreatePerformer` class.

##########
File path: server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/PushSubscriptionSetCreatePerformer.scala
##########
@@ -70,6 +75,9 @@ class PushSubscriptionSetCreatePerformer @Inject()(pushSubscriptionRepository: P
 
   private def create(clientId: PushSubscriptionCreationId, request: PushSubscriptionCreationRequest, mailboxSession: MailboxSession): SMono[CreationResult] =
     SMono.fromPublisher(pushSubscriptionRepository.save(mailboxSession.getUser, request))
+      .flatMap(subscription => verificationCreateProcessor.pushVerificationToPushServer(subscription.url,

Review comment:
       Should we handler the `pushVerificationToPushServer` error case? Then we will remove the entry saved before?
   

##########
File path: server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/PushSubscriptionSetMethodContract.scala
##########
@@ -820,4 +836,100 @@ trait PushSubscriptionSetMethodContract {
            |    ]
            |}""".stripMargin)
   }
+
+  @Test
+  def setMethodCreateShouldCallVerificationToPushServer(pushServer: ClientAndServer): Unit = {
+    val request: String =
+      s"""{
+         |    "using": ["urn:ietf:params:jmap:core"],
+         |    "methodCalls": [
+         |      [
+         |        "PushSubscription/set",
+         |        {
+         |            "create": {
+         |                "4f29": {
+         |                  "deviceClientId": "a889-ffea-910",
+         |                  "url": "${getPushServerUrl(pushServer)}",
+         |                  "types": ["Mailbox"]
+         |                }
+         |              }
+         |        },
+         |        "c1"
+         |      ]
+         |    ]
+         |  }""".stripMargin
+
+    `given`
+      .body(request)
+    .when
+      .post
+    .`then`
+      .statusCode(SC_OK)
+
+    pushServer.verify(HttpRequest.request()
+      .withPath("/subscribe"),

Review comment:
       For validate body request, It already at  `org.apache.james.jmap.pushsubscription.PushSubscriptionSetCreateProcessorTest#pushVerificationShouldSuccess` 
   
   In `PushSubscriptionSetMethodContract`, we don't have a guiceProbe (or something) for get "verificationCode".

##########
File path: server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/PushSubscriptionSetCreatePerformer.scala
##########
@@ -87,3 +95,20 @@ class PushSubscriptionSetCreatePerformer @Inject()(pushSubscriptionRepository: P
       case (path, _) => SetError.invalidArguments(SetErrorDescription(s"Unknown error on property '$path'"))
     }
 }
+
+object PushSubscriptionSetCreateProcessor {
+  val PUSH_VERIFICATION_TO_PUSH_SERVER_TTL_DEFAULT: PushTTL = PushTTL.validate(15).toOption.get

Review comment:
       your mean is `PushTTL.MAX`? 

##########
File path: server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/PushSubscriptionSetCreatePerformer.scala
##########
@@ -87,3 +95,20 @@ class PushSubscriptionSetCreatePerformer @Inject()(pushSubscriptionRepository: P
       case (path, _) => SetError.invalidArguments(SetErrorDescription(s"Unknown error on property '$path'"))
     }
 }
+
+object PushSubscriptionSetCreateProcessor {

Review comment:
       I don't like this name, I used it because the issue wrote that (https://github.com/linagora/james-project/issues/4411)
   Should we rename it to "PushVerificationProcessor" ? or move it directly inside the `PushSubscriptionSetCreatePerformer` class.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [james-project] chibenwa commented on a change in pull request #716: JAMES-3539 PushSubscriptionSetCreateProcessor - pushVerification

Posted by GitBox <gi...@apache.org>.
chibenwa commented on a change in pull request #716:
URL: https://github.com/apache/james-project/pull/716#discussion_r740763972



##########
File path: server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/PushSubscriptionSetMethodContract.scala
##########
@@ -820,4 +836,100 @@ trait PushSubscriptionSetMethodContract {
            |    ]
            |}""".stripMargin)
   }
+
+  @Test
+  def setMethodCreateShouldCallVerificationToPushServer(pushServer: ClientAndServer): Unit = {
+    val request: String =
+      s"""{
+         |    "using": ["urn:ietf:params:jmap:core"],
+         |    "methodCalls": [
+         |      [
+         |        "PushSubscription/set",
+         |        {
+         |            "create": {
+         |                "4f29": {
+         |                  "deviceClientId": "a889-ffea-910",
+         |                  "url": "${getPushServerUrl(pushServer)}",
+         |                  "types": ["Mailbox"]
+         |                }
+         |              }
+         |        },
+         |        "c1"
+         |      ]
+         |    ]
+         |  }""".stripMargin
+
+    `given`
+      .body(request)
+    .when
+      .post
+    .`then`
+      .statusCode(SC_OK)
+
+    pushServer.verify(HttpRequest.request()
+      .withPath("/subscribe"),

Review comment:
       > For validate body request, It already at org.apache.james.jmap.pushsubscription.PushSubscriptionSetCreateProcessorTest#pushVerificationShouldSuccess
   
   I would love to see it in an integration test




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [james-project] chibenwa merged pull request #716: JAMES-3539 PushSubscriptionSetCreateProcessor - pushVerification

Posted by GitBox <gi...@apache.org>.
chibenwa merged pull request #716:
URL: https://github.com/apache/james-project/pull/716


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [james-project] chibenwa commented on a change in pull request #716: JAMES-3539 PushSubscriptionSetCreateProcessor - pushVerification

Posted by GitBox <gi...@apache.org>.
chibenwa commented on a change in pull request #716:
URL: https://github.com/apache/james-project/pull/716#discussion_r740859173



##########
File path: server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/pushsubscription/PushSubscriptionSetCreateProcessorTest.scala
##########
@@ -0,0 +1,73 @@
+/****************************************************************
+ * 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.pushsubscription
+
+import org.apache.james.jmap.api.model.{PushSubscriptionId, PushSubscriptionServerURL, VerificationCode}
+import org.apache.james.jmap.json.PushSerializer
+import org.apache.james.jmap.method.{PushSubscriptionSetCreateProcessor, PushVerification}
+import org.apache.james.jmap.pushsubscription.PushSubscriptionSetCreateProcessorTest.PUSH_VERIFICATION_SAMPLE
+import org.junit.jupiter.api.extension.ExtendWith
+import org.junit.jupiter.api.{BeforeEach, Test}
+import org.mockserver.integration.ClientAndServer
+import org.mockserver.model.HttpRequest.request
+import org.mockserver.model.HttpResponse.response
+import org.mockserver.model.NottableString.string
+import org.mockserver.verify.VerificationTimes
+import play.api.libs.json.Json
+
+import java.net.URL
+import java.util.UUID
+
+object PushSubscriptionSetCreateProcessorTest {
+  val PUSH_VERIFICATION_SAMPLE: PushVerification = PushVerification(
+    PushSubscriptionId(UUID.fromString("44111166-affc-4187-b974-0672e312b72e")),
+    VerificationCode("2b295d19-b37a-4865-b93e-bbb59f76ffc0"))
+}
+
+@ExtendWith(Array(classOf[PushServerExtension]))
+class PushSubscriptionSetCreateProcessorTest {
+
+  var testee: PushSubscriptionSetCreateProcessor = _
+  var pushServerUrl: PushSubscriptionServerURL = _
+
+  @BeforeEach
+  def setup(pushServer: ClientAndServer): Unit = {
+    val webPushClient: WebPushClient = new DefaultWebPushClient(WebPushClientTestFixture.PUSH_CLIENT_CONFIGURATION)
+    testee = new PushSubscriptionSetCreateProcessor(webPushClient)
+    pushServerUrl = PushSubscriptionServerURL(new URL(s"http://127.0.0.1:${pushServer.getLocalPort}/subscribe"))
+
+    pushServer
+      .when(request
+        .withPath("/subscribe")
+        .withMethod("POST")
+        .withHeader(string("Content-type"), string("application/json charset=utf-8")))
+      .respond(response
+        .withStatusCode(201))
+  }
+
+  @Test
+  def pushVerificationShouldSuccess(pushServer: ClientAndServer): Unit = {
+    testee.pushVerificationToPushServer(pushServerUrl, PUSH_VERIFICATION_SAMPLE, None).block()
+    pushServer.verify(request()
+      .withPath("/subscribe")
+      .withBody(Json.stringify(PushSerializer.serializePushVerification(PUSH_VERIFICATION_SAMPLE))),

Review comment:
       ```suggestion
         .withBody("json string"),
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [james-project] chibenwa commented on a change in pull request #716: JAMES-3539 PushSubscriptionSetCreateProcessor - pushVerification

Posted by GitBox <gi...@apache.org>.
chibenwa commented on a change in pull request #716:
URL: https://github.com/apache/james-project/pull/716#discussion_r740752574



##########
File path: server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/PushSubscriptionSetMethodContract.scala
##########
@@ -820,4 +836,100 @@ trait PushSubscriptionSetMethodContract {
            |    ]
            |}""".stripMargin)
   }
+
+  @Test
+  def setMethodCreateShouldCallVerificationToPushServer(pushServer: ClientAndServer): Unit = {
+    val request: String =
+      s"""{
+         |    "using": ["urn:ietf:params:jmap:core"],
+         |    "methodCalls": [
+         |      [
+         |        "PushSubscription/set",
+         |        {
+         |            "create": {
+         |                "4f29": {
+         |                  "deviceClientId": "a889-ffea-910",
+         |                  "url": "${getPushServerUrl(pushServer)}",
+         |                  "types": ["Mailbox"]
+         |                }
+         |              }
+         |        },
+         |        "c1"
+         |      ]
+         |    ]
+         |  }""".stripMargin
+
+    `given`
+      .body(request)
+    .when
+      .post
+    .`then`
+      .statusCode(SC_OK)
+
+    pushServer.verify(HttpRequest.request()
+      .withPath("/subscribe"),

Review comment:
       Can we verify the format of the message sent?
   
   cf: https://jmap.io/spec-core.html#pushsubscription
   
   ```
   The server also immediately makes a POST request to https://example.com/push/?device=X8980fc&client=12c6d086 with the data:
   
   {
     "@type": "PushVerification",
     "pushSubscriptionId": "P43dcfa4-1dd4-41ef-9156-2c89b3b19c60",
     "verificationCode": "da1f097b11ca17f06424e30bf02bfa67"
   }
   ```

##########
File path: server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/PushSubscriptionSetCreatePerformer.scala
##########
@@ -87,3 +95,20 @@ class PushSubscriptionSetCreatePerformer @Inject()(pushSubscriptionRepository: P
       case (path, _) => SetError.invalidArguments(SetErrorDescription(s"Unknown error on property '$path'"))
     }
 }
+
+object PushSubscriptionSetCreateProcessor {
+  val PUSH_VERIFICATION_TO_PUSH_SERVER_TTL_DEFAULT: PushTTL = PushTTL.validate(15).toOption.get

Review comment:
       Why a TTL so low? Can't we keep the default?

##########
File path: server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/PushSubscriptionSetCreatePerformer.scala
##########
@@ -87,3 +95,20 @@ class PushSubscriptionSetCreatePerformer @Inject()(pushSubscriptionRepository: P
       case (path, _) => SetError.invalidArguments(SetErrorDescription(s"Unknown error on property '$path'"))
     }
 }
+
+object PushSubscriptionSetCreateProcessor {
+  val PUSH_VERIFICATION_TO_PUSH_SERVER_TTL_DEFAULT: PushTTL = PushTTL.validate(15).toOption.get
+}
+
+class PushSubscriptionSetCreateProcessor @Inject()(webPushClient: WebPushClient) {
+
+  def pushVerificationToPushServer(pushSubscriptionServerURL: PushSubscriptionServerURL, pushVerification: PushVerification): SMono[Unit] = {
+    SMono.fromPublisher(webPushClient.push(pushSubscriptionServerURL,
+      PushRequest(
+        ttl = PUSH_VERIFICATION_TO_PUSH_SERVER_TTL_DEFAULT,
+        payload = Json.stringify(PushSerializer.serializePushVerification(pushVerification)).getBytes(StandardCharsets.UTF_8))))

Review comment:
       Please encrypt the payload if the subscription have encryption keys.

##########
File path: server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/PushSubscriptionSetMethodContract.scala
##########
@@ -820,4 +836,100 @@ trait PushSubscriptionSetMethodContract {
            |    ]
            |}""".stripMargin)
   }
+
+  @Test
+  def setMethodCreateShouldCallVerificationToPushServer(pushServer: ClientAndServer): Unit = {
+    val request: String =
+      s"""{
+         |    "using": ["urn:ietf:params:jmap:core"],
+         |    "methodCalls": [
+         |      [
+         |        "PushSubscription/set",
+         |        {
+         |            "create": {
+         |                "4f29": {
+         |                  "deviceClientId": "a889-ffea-910",
+         |                  "url": "${getPushServerUrl(pushServer)}",
+         |                  "types": ["Mailbox"]
+         |                }
+         |              }
+         |        },
+         |        "c1"
+         |      ]
+         |    ]
+         |  }""".stripMargin
+
+    `given`
+      .body(request)
+    .when
+      .post
+    .`then`
+      .statusCode(SC_OK)
+
+    pushServer.verify(HttpRequest.request()
+      .withPath("/subscribe"),

Review comment:
       > For validate body request, It already at org.apache.james.jmap.pushsubscription.PushSubscriptionSetCreateProcessorTest#pushVerificationShouldSuccess
   
   I would love to see it in an integration test

##########
File path: server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/pushsubscription/PushSubscriptionSetCreateProcessorTest.scala
##########
@@ -0,0 +1,73 @@
+/****************************************************************
+ * 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.pushsubscription
+
+import org.apache.james.jmap.api.model.{PushSubscriptionId, PushSubscriptionServerURL, VerificationCode}
+import org.apache.james.jmap.json.PushSerializer
+import org.apache.james.jmap.method.{PushSubscriptionSetCreateProcessor, PushVerification}
+import org.apache.james.jmap.pushsubscription.PushSubscriptionSetCreateProcessorTest.PUSH_VERIFICATION_SAMPLE
+import org.junit.jupiter.api.extension.ExtendWith
+import org.junit.jupiter.api.{BeforeEach, Test}
+import org.mockserver.integration.ClientAndServer
+import org.mockserver.model.HttpRequest.request
+import org.mockserver.model.HttpResponse.response
+import org.mockserver.model.NottableString.string
+import org.mockserver.verify.VerificationTimes
+import play.api.libs.json.Json
+
+import java.net.URL
+import java.util.UUID
+
+object PushSubscriptionSetCreateProcessorTest {
+  val PUSH_VERIFICATION_SAMPLE: PushVerification = PushVerification(
+    PushSubscriptionId(UUID.fromString("44111166-affc-4187-b974-0672e312b72e")),
+    VerificationCode("2b295d19-b37a-4865-b93e-bbb59f76ffc0"))
+}
+
+@ExtendWith(Array(classOf[PushServerExtension]))
+class PushSubscriptionSetCreateProcessorTest {
+
+  var testee: PushSubscriptionSetCreateProcessor = _
+  var pushServerUrl: PushSubscriptionServerURL = _
+
+  @BeforeEach
+  def setup(pushServer: ClientAndServer): Unit = {
+    val webPushClient: WebPushClient = new DefaultWebPushClient(WebPushClientTestFixture.PUSH_CLIENT_CONFIGURATION)
+    testee = new PushSubscriptionSetCreateProcessor(webPushClient)
+    pushServerUrl = PushSubscriptionServerURL(new URL(s"http://127.0.0.1:${pushServer.getLocalPort}/subscribe"))
+
+    pushServer
+      .when(request
+        .withPath("/subscribe")
+        .withMethod("POST")
+        .withHeader(string("Content-type"), string("application/json charset=utf-8")))
+      .respond(response
+        .withStatusCode(201))
+  }
+
+  @Test
+  def pushVerificationShouldSuccess(pushServer: ClientAndServer): Unit = {
+    testee.pushVerificationToPushServer(pushServerUrl, PUSH_VERIFICATION_SAMPLE, None).block()
+    pushServer.verify(request()
+      .withPath("/subscribe")
+      .withBody(Json.stringify(PushSerializer.serializePushVerification(PUSH_VERIFICATION_SAMPLE))),

Review comment:
       ```suggestion
         .withBody("json string"),
   ```

##########
File path: server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/pushsubscription/PushSubscriptionSetCreateProcessorTest.scala
##########
@@ -65,9 +71,35 @@ class PushSubscriptionSetCreateProcessorTest {
   @Test
   def pushVerificationShouldSuccess(pushServer: ClientAndServer): Unit = {
     testee.pushVerificationToPushServer(pushServerUrl, PUSH_VERIFICATION_SAMPLE, None).block()
+    print(Json.stringify(PushSerializer.serializePushVerification(PUSH_VERIFICATION_SAMPLE)))
     pushServer.verify(request()
       .withPath("/subscribe")
-      .withBody(Json.stringify(PushSerializer.serializePushVerification(PUSH_VERIFICATION_SAMPLE))),
+      .withBody(json("""{
+                       |    "@type": "PushVerification",
+                       |    "pushSubscriptionId": "44111166-affc-4187-b974-0672e312b72e",
+                       |    "verificationCode": "2b295d19-b37a-4865-b93e-bbb59f76ffc0"
+                       |}""".stripMargin)),
+      VerificationTimes.atLeast(1))
+  }
+
+  @Test
+  def pushVerificationShouldEncryptedPayloadWhenAssignKeys(pushServer: ClientAndServer): Unit = {
+    val uaKeyPair: KeyPair = EllipticCurves.generateKeyPair(CurveType.NIST_P256)
+    val uaPublicKey: ECPublicKey = uaKeyPair.getPublic.asInstanceOf[ECPublicKey]
+    val authSecret: Array[Byte] = "secret123secret1".getBytes
+
+    val p256dh: String = Base64.getEncoder.encodeToString(uaPublicKey.getEncoded)
+    val auth: String = Base64.getEncoder.encodeToString(authSecret)
+
+    testee.pushVerificationToPushServer(pushServerUrl, PUSH_VERIFICATION_SAMPLE, Some(PushSubscriptionKeys(p256dh, auth))).block()
+    print(Json.stringify(PushSerializer.serializePushVerification(PUSH_VERIFICATION_SAMPLE)))

Review comment:
       ```suggestion
   
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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