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

commit d124e2b21f76860a13686834ba5ce6864554c65d
Author: RĂ©mi Kowalski <[email protected]>
AuthorDate: Thu Sep 24 15:14:14 2020 +0200

    JAMES-3387 validate accountId for vacationResponse/set
---
 .../VacationResponseSetMethodContract.scala        | 50 ++++++++++++++++++++++
 .../jmap/method/VacationResponseSetMethod.scala    | 23 ++++------
 .../james/jmap/vacation/VacationResponseSet.scala  |  3 +-
 3 files changed, 61 insertions(+), 15 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/VacationResponseSetMethodContract.scala
 
b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/VacationResponseSetMethodContract.scala
index d2fc11e..a2a8c21 100644
--- 
a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/VacationResponseSetMethodContract.scala
+++ 
b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/VacationResponseSetMethodContract.scala
@@ -45,6 +45,56 @@ trait VacationResponseSetMethodContract {
   }
 
   @Test
+  def vacationResponseSetShouldFailWhenWrongAccountId(server: 
GuiceJamesServer): Unit = {
+    val request =
+      s"""
+         |{
+         |  "using": [ "urn:ietf:params:jmap:core",
+         |    "urn:ietf:params:jmap:mail",
+         |    "urn:ietf:params:jmap:vacationresponse" ],
+         |  "methodCalls": [
+         |    ["VacationResponse/set", {
+         |      "accountId": "unknownAccountId",
+         |      "update": {
+         |        "singleton": {
+         |          "isEnabled": true,
+         |          "fromDate": "2014-10-30T14:12:00Z",
+         |          "toDate": "2014-11-30T14:12:00Z",
+         |          "subject": "I am in vacation",
+         |          "textBody": "I'm currently enjoying life. Please disturb 
me later",
+         |          "htmlBody": "I'm currently enjoying <b>life</b>. 
<br/>Please disturb me later"
+         |        }
+         |      }
+         |    }, "c1"]
+         |  ]
+         |}
+         |""".stripMargin
+
+    val response =  `given`
+      .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+      .body(request)
+    .when
+      .post
+    .`then`
+      .log().ifValidationFails()
+      .statusCode(SC_OK)
+      .contentType(JSON)
+      .extract
+      .body
+      .asString
+
+    assertThatJson(response).isEqualTo(
+      """{
+        |  "sessionState": "75128aab4b1b",
+        |  "methodResponses": [
+        |    ["error", {
+        |      "type": "accountNotFound"
+        |    }, "c1"]
+        |  ]
+        |}""".stripMargin)
+  }
+
+  @Test
   @Tag(CategoryTags.BASIC_FEATURE)
   def updateShouldSucceed(): Unit = {
     val request =
diff --git 
a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/VacationResponseSetMethod.scala
 
b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/VacationResponseSetMethod.scala
index c3febb9..66e52e0 100644
--- 
a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/VacationResponseSetMethod.scala
+++ 
b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/VacationResponseSetMethod.scala
@@ -30,12 +30,9 @@ import 
org.apache.james.jmap.model.DefaultCapabilities.{CORE_CAPABILITY, MAIL_CA
 import org.apache.james.jmap.model.Invocation.{Arguments, MethodName}
 import org.apache.james.jmap.model.SetError.SetErrorDescription
 import org.apache.james.jmap.model.{Capabilities, Invocation, State}
-import org.apache.james.jmap.routes.ProcessingContext
 import org.apache.james.jmap.vacation.{VacationResponseSetError, 
VacationResponseSetRequest, VacationResponseSetResponse, 
VacationResponseUpdateResponse}
 import org.apache.james.mailbox.MailboxSession
 import org.apache.james.metrics.api.MetricFactory
-import org.apache.james.util.date.ZonedDateTimeProvider
-import org.reactivestreams.Publisher
 import play.api.libs.json.{JsError, JsObject, JsSuccess}
 import reactor.core.scala.publisher.{SFlux, SMono}
 
@@ -73,22 +70,20 @@ object VacationResponseSetMethod {
   val VACATION_RESPONSE_PATCH_OBJECT_KEY = "singleton"
 }
 
-class VacationResponseSetMethod @Inject() (vacationRepository: 
VacationRepository,
-                                           zonedDateTimeProvider: 
ZonedDateTimeProvider,
-                                           metricFactory: MetricFactory) 
extends Method {
+class VacationResponseSetMethod @Inject()(vacationRepository: 
VacationRepository,
+                                          val metricFactory: MetricFactory,
+                                          val sessionSupplier: 
SessionSupplier) extends MethodRequiringAccountId[VacationResponseSetRequest] {
   override val methodName: MethodName = MethodName("VacationResponse/set")
   override val requiredCapabilities: Capabilities = 
Capabilities(CORE_CAPABILITY, MAIL_CAPABILITY, VACATION_RESPONSE_CAPABILITY)
 
-  override def process(capabilities: Set[CapabilityIdentifier],
-                       invocation: InvocationWithContext,
-                       mailboxSession: MailboxSession): 
Publisher[InvocationWithContext] = {
-      metricFactory.decoratePublisherWithTimerMetricLogP99(JMAP_RFC8621_PREFIX 
+ methodName.value,
-        asVacationResponseSetRequest(invocation.invocation.arguments)
-          .flatMap(vacationResponseSetRequest => update(mailboxSession, 
vacationResponseSetRequest)
-            .map(updateResult => createResponse(invocation.invocation, 
vacationResponseSetRequest, updateResult)))
-          .map(InvocationWithContext(_, invocation.processingContext)))
+  override def doProcess(capabilities: Set[CapabilityIdentifier], invocation: 
InvocationWithContext, mailboxSession: MailboxSession, request: 
VacationResponseSetRequest): SMono[InvocationWithContext] = {
+    update(mailboxSession, request)
+      .map(updateResult => createResponse(invocation.invocation, request, 
updateResult))
+      .map(InvocationWithContext(_, invocation.processingContext))
   }
 
+  override def getRequest(mailboxSession: MailboxSession, invocation: 
Invocation): SMono[VacationResponseSetRequest] = 
asVacationResponseSetRequest(invocation.arguments)
+
   private def update(mailboxSession: MailboxSession, 
vacationResponseSetRequest: VacationResponseSetRequest): 
SMono[VacationResponseUpdateResults] = {
     SFlux.fromIterable(vacationResponseSetRequest.parsePatch()
       .map[SMono[VacationResponseUpdateResult]]({
diff --git 
a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/vacation/VacationResponseSet.scala
 
b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/vacation/VacationResponseSet.scala
index b7b00ca..6a68a53 100644
--- 
a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/vacation/VacationResponseSet.scala
+++ 
b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/vacation/VacationResponseSet.scala
@@ -24,6 +24,7 @@ import java.time.format.DateTimeFormatter
 
 import org.apache.james.jmap.api.vacation.Vacation.ID
 import org.apache.james.jmap.api.vacation.VacationPatch
+import org.apache.james.jmap.method.WithAccountId
 import org.apache.james.jmap.model.AccountId
 import org.apache.james.jmap.model.SetError.{SetErrorDescription, 
SetErrorType, invalidArgumentValue, serverFailValue}
 import org.apache.james.jmap.model.State.State
@@ -35,7 +36,7 @@ import scala.util.{Failure, Success, Try}
 case class VacationResponseSetRequest(accountId: AccountId,
                                       update: Option[Map[String, 
VacationResponsePatchObject]],
                                       create: Option[Map[String, JsObject]],
-                                      destroy: Option[Seq[String]]) {
+                                      destroy: Option[Seq[String]]) extends 
WithAccountId{
   def parsePatch(): Map[String, Either[IllegalArgumentException, 
VacationResponsePatchObject]] =
     update.getOrElse(Map())
     .map({


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

Reply via email to