Skip to content

Commit

Permalink
#1766 Added tactic field to procedure
Browse files Browse the repository at this point in the history
  • Loading branch information
rriclet committed Feb 15, 2021
1 parent bd1bcd9 commit 683f108
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions dto/src/main/scala/org/thp/thehive/dto/v1/Procedure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import java.util.Date
case class InputProcedure(
description: String,
occurDate: Date,
tactic: String,
caseId: String,
patternId: String
)
Expand All @@ -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
)
Expand All @@ -38,6 +41,7 @@ case class OutputProcedure(
description: String,
occurDate: Date,
patternId: String,
tactic: String,
extraData: JsObject
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
4 changes: 3 additions & 1 deletion thehive/app/org/thp/thehive/models/Procedure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import java.util.Date
@BuildVertexEntity
case class Procedure(
description: String,
occurDate: Date
occurDate: Date,
tactic: String
// metadata
)

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import java.util.Date
case class TestProcedure(
description: String,
occurDate: Date,
tactic: String,
patternId: String
)

Expand All @@ -26,6 +27,7 @@ class ProcedureCtrlTest extends PlaySpecification with TestAppBuilder {
val inputProcedure = InputProcedure(
"testProcedure3",
procedureDate,
"tactic1",
"1",
"T123"
)
Expand All @@ -42,6 +44,7 @@ class ProcedureCtrlTest extends PlaySpecification with TestAppBuilder {
TestProcedure(resultProcedure) must_=== TestProcedure(
"testProcedure3",
procedureDate,
"tactic1",
"T123"
)
}
Expand All @@ -53,6 +56,7 @@ class ProcedureCtrlTest extends PlaySpecification with TestAppBuilder {
InputProcedure(
"an old description",
new Date(),
"tactic1",
"1",
"T123"
)
Expand All @@ -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)}")

Expand All @@ -79,6 +83,7 @@ class ProcedureCtrlTest extends PlaySpecification with TestAppBuilder {
TestProcedure(resultProcedure) must_=== TestProcedure(
"a new description",
updatedDate,
"tactic2",
"T123"
)
}
Expand All @@ -90,6 +95,7 @@ class ProcedureCtrlTest extends PlaySpecification with TestAppBuilder {
InputProcedure(
"testProcedure3",
new Date(),
"tactic1",
"1",
"T123"
)
Expand Down

0 comments on commit 683f108

Please sign in to comment.