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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to