From 683f108b095ed9cf592319830f360b3e17a7c0da Mon Sep 17 00:00:00 2001 From: Robin Riclet Date: Mon, 15 Feb 2021 12:32:16 +0100 Subject: [PATCH] #1766 Added tactic field to procedure --- dto/src/main/scala/org/thp/thehive/dto/v1/Procedure.scala | 4 ++++ .../app/org/thp/thehive/controllers/v1/Properties.scala | 1 + thehive/app/org/thp/thehive/models/Procedure.scala | 4 +++- .../thp/thehive/controllers/v1/ProcedureCtrlTest.scala | 8 +++++++- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/dto/src/main/scala/org/thp/thehive/dto/v1/Procedure.scala b/dto/src/main/scala/org/thp/thehive/dto/v1/Procedure.scala index 8356fe5ca5..80a419bd86 100644 --- a/dto/src/main/scala/org/thp/thehive/dto/v1/Procedure.scala +++ b/dto/src/main/scala/org/thp/thehive/dto/v1/Procedure.scala @@ -7,6 +7,7 @@ import java.util.Date case class InputProcedure( description: String, occurDate: Date, + tactic: String, caseId: String, patternId: String ) @@ -16,11 +17,13 @@ object InputProcedure { for { description <- (json \ "description").validate[String] occurDate <- (json \ "occurDate").validate[Date] + tactic <- (json \ "tactic").validate[String] caseId <- (json \ "caseId").validate[String] patternId <- (json \ "patternId").validate[String] } yield InputProcedure( description, occurDate, + tactic, caseId, patternId ) @@ -38,6 +41,7 @@ case class OutputProcedure( description: String, occurDate: Date, patternId: String, + tactic: String, extraData: JsObject ) diff --git a/thehive/app/org/thp/thehive/controllers/v1/Properties.scala b/thehive/app/org/thp/thehive/controllers/v1/Properties.scala index 11a15263ca..94aacf8427 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/Properties.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/Properties.scala @@ -366,6 +366,7 @@ class Properties @Inject() ( PublicPropertyListBuilder[Procedure] .property("description", UMapping.string)(_.field.updatable) .property("occurDate", UMapping.date)(_.field.updatable) + .property("tactic", UMapping.string)(_.field.updatable) .build lazy val profile: PublicProperties = diff --git a/thehive/app/org/thp/thehive/models/Procedure.scala b/thehive/app/org/thp/thehive/models/Procedure.scala index 3d4684b09a..3a7825c555 100644 --- a/thehive/app/org/thp/thehive/models/Procedure.scala +++ b/thehive/app/org/thp/thehive/models/Procedure.scala @@ -8,7 +8,8 @@ import java.util.Date @BuildVertexEntity case class Procedure( description: String, - occurDate: Date + occurDate: Date, + tactic: String // metadata ) @@ -18,6 +19,7 @@ case class ProcedurePattern() case class RichProcedure(procedure: Procedure with Entity, pattern: Pattern with Entity) { def description: String = procedure.description def occurDate: Date = procedure.occurDate + def tactic: String = procedure.tactic def _id: EntityId = procedure._id def _createdAt: Date = procedure._createdAt def _createdBy: String = procedure._createdBy diff --git a/thehive/test/org/thp/thehive/controllers/v1/ProcedureCtrlTest.scala b/thehive/test/org/thp/thehive/controllers/v1/ProcedureCtrlTest.scala index cfe0f7ebb1..7bdcdb8fd1 100644 --- a/thehive/test/org/thp/thehive/controllers/v1/ProcedureCtrlTest.scala +++ b/thehive/test/org/thp/thehive/controllers/v1/ProcedureCtrlTest.scala @@ -11,6 +11,7 @@ import java.util.Date case class TestProcedure( description: String, occurDate: Date, + tactic: String, patternId: String ) @@ -26,6 +27,7 @@ class ProcedureCtrlTest extends PlaySpecification with TestAppBuilder { val inputProcedure = InputProcedure( "testProcedure3", procedureDate, + "tactic1", "1", "T123" ) @@ -42,6 +44,7 @@ class ProcedureCtrlTest extends PlaySpecification with TestAppBuilder { TestProcedure(resultProcedure) must_=== TestProcedure( "testProcedure3", procedureDate, + "tactic1", "T123" ) } @@ -53,6 +56,7 @@ class ProcedureCtrlTest extends PlaySpecification with TestAppBuilder { InputProcedure( "an old description", new Date(), + "tactic1", "1", "T123" ) @@ -66,7 +70,7 @@ class ProcedureCtrlTest extends PlaySpecification with TestAppBuilder { val updatedDate = new Date() val request2 = FakeRequest("PATCH", "/api/v1/procedure/testProcedure3") .withHeaders("user" -> "certadmin@thehive.local") - .withJsonBody(Json.obj("description" -> "a new description", "occurDate" -> updatedDate)) + .withJsonBody(Json.obj("description" -> "a new description", "occurDate" -> updatedDate, "tactic" -> "tactic2")) val result2 = app[ProcedureCtrl].update(procedureId)(request2) status(result2) must beEqualTo(204).updateMessage(s => s"$s\n${contentAsString(result2)}") @@ -79,6 +83,7 @@ class ProcedureCtrlTest extends PlaySpecification with TestAppBuilder { TestProcedure(resultProcedure) must_=== TestProcedure( "a new description", updatedDate, + "tactic2", "T123" ) } @@ -90,6 +95,7 @@ class ProcedureCtrlTest extends PlaySpecification with TestAppBuilder { InputProcedure( "testProcedure3", new Date(), + "tactic1", "1", "T123" )