This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git


The following commit(s) were added to refs/heads/master by this push:
     new 7eff66d0a1 JAMES-3539 WebPushClient should accept more flexible 20x 
codes from Push server
7eff66d0a1 is described below

commit 7eff66d0a1614d148ee4f3c3cab3c451bf8ade27
Author: Quan Tran <hqt...@linagora.com>
AuthorDate: Thu May 15 14:15:29 2025 +0700

    JAMES-3539 WebPushClient should accept more flexible 20x codes from Push 
server
    
    It seems that some push gateways, like MSGraph, are using return codes 200 
and 202 as well.
---
 .../jmap/pushsubscription/WebPushClient.scala      |  2 +-
 .../pushsubscription/WebPushClientContract.scala   | 33 ++++++++++++++++++++++
 2 files changed, 34 insertions(+), 1 deletion(-)

diff --git 
a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/pushsubscription/WebPushClient.scala
 
b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/pushsubscription/WebPushClient.scala
index 5ad1300ad5..37b306aa4e 100644
--- 
a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/pushsubscription/WebPushClient.scala
+++ 
b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/pushsubscription/WebPushClient.scala
@@ -128,7 +128,7 @@ class DefaultWebPushClient @Inject()(configuration: 
PushClientConfiguration) ext
   private def afterHTTPResponseHandler(httpResponse: HttpClientResponse, 
dataBuf: ByteBufMono): Mono[Void] =
     Mono.just(httpResponse.status())
       .flatMap {
-        case HttpResponseStatus.CREATED => Mono.empty()
+        case HttpResponseStatus.OK | HttpResponseStatus.CREATED | 
HttpResponseStatus.ACCEPTED => Mono.empty()
         case HttpResponseStatus.BAD_REQUEST => preProcessingData(dataBuf)
           .flatMap(string => 
Mono.error(WebPushInvalidRequestException(string)))
         case statusCode: HttpResponseStatus => preProcessingData(dataBuf)
diff --git 
a/server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/pushsubscription/WebPushClientContract.scala
 
b/server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/pushsubscription/WebPushClientContract.scala
index a41b292d5d..a43ef50681 100644
--- 
a/server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/pushsubscription/WebPushClientContract.scala
+++ 
b/server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/pushsubscription/WebPushClientContract.scala
@@ -21,6 +21,8 @@ package org.apache.james.jmap.pushsubscription
 
 import java.net.URL
 import java.nio.charset.StandardCharsets
+import java.time.Clock
+import java.util.UUID
 
 import org.apache.james.jmap.api.model.PushSubscriptionServerURL
 import 
org.apache.james.jmap.pushsubscription.WebPushClientTestFixture.PUSH_REQUEST_SAMPLE
@@ -31,6 +33,7 @@ import org.junit.jupiter.params.provider.ValueSource
 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 reactor.core.scala.publisher.SMono
 
@@ -110,6 +113,36 @@ trait WebPushClientContract {
       VerificationTimes.atLeast(1))
   }
 
+  @ParameterizedTest
+  @ValueSource(ints = Array(200, 201, 202))
+  def pushClientShouldAcceptFlexible20xCodes(httpStatusCode: Int, pushServer: 
ClientAndServer): Unit = {
+    pushServer
+      .when(request
+        .withPath("/pushh")
+        .withMethod("POST")
+        .withHeader(string("Content-type"), string("application/json 
charset=utf-8"))
+        .withHeader(string("Urgency"))
+        .withHeader(string("Topic"))
+        .withHeader(string("TTL")))
+      .respond(response
+        .withStatusCode(httpStatusCode)
+        .withHeader("Location", 
String.format("https://push.example.net/message/%s";, UUID.randomUUID))
+        .withHeader("Date", Clock.systemUTC.toString)
+        .withBody(UUID.randomUUID.toString))
+
+    assertThatCode(() => 
SMono.fromPublisher(testee.push(PushSubscriptionServerURL.from(s"${pushServerBaseUrl.toString}/pushh").get,
 PUSH_REQUEST_SAMPLE))
+      .block())
+      .doesNotThrowAnyException()
+
+    pushServer.verify(request()
+      .withPath("/pushh")
+      .withHeader("TTL", "15")
+      .withHeader("Topic", "topicabc")
+      .withHeader("Urgency", "High")
+      .withBody(new String(PUSH_REQUEST_SAMPLE.payload, 
StandardCharsets.UTF_8)),
+      VerificationTimes.once)
+  }
+
   @Test
   def pushRequestShouldParserErrorResponseFromPushServerWhenFail(pushServer: 
ClientAndServer): Unit = {
     pushServer


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

Reply via email to