Skip to content

Commit

Permalink
#1473 fixed case creation assignee & tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rriclet committed Mar 16, 2021
1 parent 2ea4414 commit c2cf25f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 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 @@ -54,7 +54,7 @@ class CaseCtrl @Inject() (
.organisations(Permissions.manageCase)
.get(request.organisation)
.orFail(AuthorizationError("Operation not permitted"))
user <- userSrv.current.getOrFail("User")
user <- inputCase.user.fold(userSrv.current.getOrFail("User"))(userSrv.getByName(_).getOrFail("User"))
caseTemplate <- caseTemplateName.map(ct => caseTemplateSrv.get(EntityIdOrName(ct)).visible.richCaseTemplate.getOrFail("CaseTemplate")).flip
richCase <- caseSrv.create(
caseTemplate.fold(inputCase)(inputCase.withCaseTemplate).toCase,
Expand Down
2 changes: 1 addition & 1 deletion thehive/app/org/thp/thehive/controllers/v1/CaseCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class CaseCtrl @Inject() (
for {
caseTemplate <- caseTemplateName.map(ct => caseTemplateSrv.get(EntityIdOrName(ct)).visible.richCaseTemplate.getOrFail("CaseTemplate")).flip
organisation <- userSrv.current.organisations(Permissions.manageCase).get(request.organisation).getOrFail("Organisation")
user <- userSrv.current.getOrFail("User")
user <- inputCase.user.fold(userSrv.current.getOrFail("User"))(userSrv.getByName(_).getOrFail("User"))
richCase <- caseSrv.create(
caseTemplate.fold(inputCase)(inputCase.withCaseTemplate).toCase,
Some(user),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ class CaseCtrlTest extends PlaySpecification with TestAppBuilder {
"flag":false,
"status":"Waiting"
}
]
],
"user":"certro@thehive.local"
}"""
)
.as[JsObject]
Expand All @@ -140,7 +141,7 @@ class CaseCtrlTest extends PlaySpecification with TestAppBuilder {
pap = 2,
status = "Open",
tags = Set.empty,
owner = Some("certuser@thehive.local"),
owner = Some("certro@thehive.local"),
stats = JsObject.empty
)
)
Expand All @@ -155,7 +156,7 @@ class CaseCtrlTest extends PlaySpecification with TestAppBuilder {
val assignee = app[Database].roTransaction(implicit graph => app[CaseSrv].get(EntityIdOrName(outputCase._id)).assignee.getOrFail("Case"))

assignee must beSuccessfulTry
assignee.get.login shouldEqual "certuser@thehive.local"
assignee.get.login shouldEqual "certro@thehive.local"
}

"try to get a case" in testApp { app =>
Expand Down Expand Up @@ -380,7 +381,7 @@ class CaseCtrlTest extends PlaySpecification with TestAppBuilder {
// Merge result
TestCase(outputCase) must equalTo(
TestCase(
caseId = 26,
caseId = 27,
title = "case#21 / case#22",
description = "description of case #21\n\ndescription of case #22",
severity = 3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class CaseCtrlTest extends PlaySpecification with TestAppBuilder {
tags = Set("tag1", "tag2"),
flag = Some(false),
tlp = Some(1),
pap = Some(3)
pap = Some(3),
user = Some("certro@thehive.local")
)
)
)
Expand All @@ -77,7 +78,7 @@ class CaseCtrlTest extends PlaySpecification with TestAppBuilder {
pap = 3,
status = "Open",
summary = None,
user = Some("certuser@thehive.local"),
user = Some("certro@thehive.local"),
customFields = Seq.empty
)

Expand Down

0 comments on commit c2cf25f

Please sign in to comment.