Skip to content

Commit

Permalink
#1264 WIP v0.CaseCtrlTest ok
Browse files Browse the repository at this point in the history
  • Loading branch information
rriclet committed Feb 23, 2021
1 parent 2142286 commit 79980fb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion thehive/app/org/thp/thehive/controllers/v0/CaseCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class CaseCtrl @Inject() (
_ <- sameOrga(Seq(caze, toMerge))
_ <- sameProfile(Seq(caze, toMerge))
merged <- caseSrv.merge(Seq(caze, toMerge))
} yield Results.Ok(merged.toJson)
} yield Results.Created(merged.toJson)
}

private def sameOrga(cases: Seq[Case with Entity])(implicit graph: Graph): Try[Seq[Case with Entity]] =
Expand Down
16 changes: 8 additions & 8 deletions thehive/test/org/thp/thehive/controllers/v0/CaseCtrlTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,8 @@ class CaseCtrlTest extends PlaySpecification with TestAppBuilder {
status(case21) must equalTo(200).updateMessage(s => s"$s\n${contentAsString(case21)}")
val output21 = contentAsJson(case21).as[OutputCase]

val request = FakeRequest("GET", "/api/v0/case/21/_merge/22")
.withHeaders("user" -> "admin@thehive.local")
val request = FakeRequest("POST", "/api/v0/case/21/_merge/22")
.withHeaders("user" -> "certuser@thehive.local")

val result = app[CaseCtrl].merge("21", "22")(request)
status(result) must beEqualTo(201).updateMessage(s => s"$s\n${contentAsString(result)}")
Expand All @@ -389,8 +389,8 @@ class CaseCtrlTest extends PlaySpecification with TestAppBuilder {
tlp = 4,
pap = 3,
status = "Open",
tags = Set.empty,
owner = None,
tags = Set("toMerge:pred1=\"value1\"", "toMerge:pred2=\"value2\""),
owner = Some("[email protected]"),
stats = JsObject.empty
)
)
Expand All @@ -403,17 +403,17 @@ class CaseCtrlTest extends PlaySpecification with TestAppBuilder {
}

"merge two cases error, not same organisation" in testApp { app =>
val request = FakeRequest("GET", "/api/v0/case/21/_merge/24")
.withHeaders("user" -> "admin@thehive.local")
val request = FakeRequest("POST", "/api/v0/case/21/_merge/24")
.withHeaders("user" -> "certuser@thehive.local")

val result = app[CaseCtrl].merge("21", "24")(request)
// User shouldn't be able to see others cases, resulting in 404
status(result) must beEqualTo(404).updateMessage(s => s"$s\n${contentAsString(result)}")
}

"merge two cases error, not same profile" in testApp { app =>
val request = FakeRequest("GET", "/api/v0/case/21/_merge/25")
.withHeaders("user" -> "admin@thehive.local")
val request = FakeRequest("POST", "/api/v0/case/21/_merge/25")
.withHeaders("user" -> "certuser@thehive.local")

val result = app[CaseCtrl].merge("21", "25")(request)
status(result) must beEqualTo(400).updateMessage(s => s"$s\n${contentAsString(result)}")
Expand Down
7 changes: 4 additions & 3 deletions thehive/test/org/thp/thehive/services/CaseSrvTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,10 @@ class CaseSrvTest extends PlaySpecification with TestAppBuilder {
} yield newCase
} must beASuccessfulTry.which { richCase =>
app[Database].roTransaction { implicit graph =>
app[CaseSrv].get(EntityName(richCase.number.toString)).tasks.toSeq.size mustEqual 3
app[CaseSrv].get(EntityName(richCase.number.toString)).observables.toSeq.size mustEqual 3
app[CaseSrv].get(EntityName(richCase.number.toString)).procedure.toSeq.size mustEqual 3
val mergedCase = app[CaseSrv].get(EntityName(richCase.number.toString))
mergedCase.clone().tasks.toSeq.size mustEqual 3
mergedCase.clone().observables.toSeq.size mustEqual 3
mergedCase.clone().procedure.toSeq.size mustEqual 3
}
}
}
Expand Down

0 comments on commit 79980fb

Please sign in to comment.