Skip to content

Commit

Permalink
#1264 alertCase are now merged
Browse files Browse the repository at this point in the history
  • Loading branch information
rriclet committed Mar 2, 2021
1 parent 127e0d0 commit 5ef6cdc
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 5 deletions.
9 changes: 8 additions & 1 deletion thehive/app/org/thp/thehive/services/CaseSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import play.api.libs.json.{JsNull, JsObject, Json}

import java.lang.{Long => JLong}
import java.util.{Map => JMap}
import javax.inject.{Inject, Named, Singleton}
import javax.inject.{Inject, Named, Provider, Singleton}
import scala.util.{Failure, Success, Try}

@Singleton
Expand All @@ -40,9 +40,11 @@ class CaseSrv @Inject() (
auditSrv: AuditSrv,
resolutionStatusSrv: ResolutionStatusSrv,
impactStatusSrv: ImpactStatusSrv,
alertSrvProvider: Provider[AlertSrv],
@Named("integrity-check-actor") integrityCheckActor: ActorRef
)(implicit @Named("with-thehive-schema") db: Database)
extends VertexSrv[Case] {
lazy val alertSrv: AlertSrv = alertSrvProvider.get

val caseTagSrv = new EdgeSrv[CaseTag, Case, Tag]
val caseImpactStatusSrv = new EdgeSrv[CaseImpactStatus, Case, ImpactStatus]
Expand Down Expand Up @@ -330,6 +332,11 @@ class CaseSrv @Inject() (
.richObservable
.toList
.toTry(shareSrv.shareObservable(_, richCase.`case`, orga))
_ <-
get(c)
.alert
.toList
.toTry(alertSrv.alertCaseSrv.create(AlertCase(), _, richCase.`case`))
_ <-
get(c)
.procedure
Expand Down
5 changes: 5 additions & 0 deletions thehive/test/org/thp/thehive/services/CaseSrvTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,10 @@ class CaseSrvTest extends PlaySpecification with TestAppBuilder {
case21.observables.toSeq.size mustEqual 1
case22.observables.toSeq.size mustEqual 0
case23.observables.toSeq.size mustEqual 2
// Alerts
case21.alert.toSeq.size mustEqual 1
case22.alert.toSeq.size mustEqual 0
case23.alert.toSeq.size mustEqual 0

for {
c21 <- case21.clone().getOrFail("Case")
Expand All @@ -427,6 +431,7 @@ class CaseSrvTest extends PlaySpecification with TestAppBuilder {
mergedCase.customFields.toSeq.size mustEqual 2
mergedCase.tasks.toSeq.size mustEqual 3
mergedCase.observables.toSeq.size mustEqual 3
mergedCase.alert.toSeq.size mustEqual 1

app[CaseSrv].get(EntityName("21")).getOrFail("Case") must beAFailedTry
app[CaseSrv].get(EntityName("22")).getOrFail("Case") must beAFailedTry
Expand Down
16 changes: 16 additions & 0 deletions thehive/test/resources/data/Alert.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,21 @@
"pap": 2,
"read": false,
"follow": true
},
{
"id": "alertMerge1",
"type": "testType",
"source": "testSource",
"sourceRef": "ref6",
"title": "alert#6",
"description": "description of alert #6",
"severity": 2,
"date": 1555359572000,
"lastSyncDate": 1555359600000,
"flag": false,
"tlp": 2,
"pap": 2,
"read": false,
"follow": true
}
]
3 changes: 3 additions & 0 deletions thehive/test/resources/data/AlertCase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
{"from": "alertMerge1", "to": "caseMerge21"}
]
4 changes: 4 additions & 0 deletions thehive/test/resources/data/Data.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@
{
"id": "data-perdu.com",
"data": "perdu.com"
},
{
"id": "data-merge.fr",
"data": "merge.fr"
}
]
2 changes: 1 addition & 1 deletion thehive/test/resources/data/Observable.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
},
{
"id": "mergeObs232",
"message": "merge Obs 211",
"message": "merge Obs 232",
"tlp": 4,
"ioc": true,
"sighted": true
Expand Down
6 changes: 3 additions & 3 deletions thehive/test/resources/data/ObservableData.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{"from": "c.fr", "to": "data-c.fr"},
{"from": "perdu.com", "to": "data-perdu.com"},
{"from": "alert-h.fr", "to": "data-h.fr"},
{"from": "mergeObs211","to": "data-h.fr"},
{"from": "mergeObs231", "to": "data-c.fr"},
{"from": "mergeObs232", "to": "data-perdu.com"}
{"from": "mergeObs211","to": "data-merge.fr"},
{"from": "mergeObs231", "to": "data-merge.fr"},
{"from": "mergeObs232", "to": "data-merge.fr"}
]

0 comments on commit 5ef6cdc

Please sign in to comment.