Skip to content

Commit

Permalink
#1731 Fix most tests
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Mar 3, 2021
1 parent 9c28d5c commit 6dfcb2a
Show file tree
Hide file tree
Showing 36 changed files with 180 additions and 356 deletions.
2 changes: 1 addition & 1 deletion ScalliGraph
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class MispImportSrvTest(implicit ec: ExecutionContext) extends PlaySpecification
pap = 2,
read = false,
follow = true,
tags = Nil,
tags = Seq("TH-test", "TH-test-2"),
organisationId = alert.organisationId,
caseId = None
)
Expand Down
6 changes: 3 additions & 3 deletions thehive/app/org/thp/thehive/services/AlertSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ class AlertSrv @Inject() (
authContext: AuthContext
): Try[(Seq[Tag with Entity], Seq[Tag with Entity])] =
for {
tagsToAdd <- (tags -- alert.tags).toTry(tagSrv.getOrCreate)
tagsToRemove <- (alert.tags.toSet -- tags).toTry(tagSrv.getOrCreate)
_ <- tagsToAdd.toTry(alertTagSrv.create(AlertTag(), alert, _))
tagsToAdd <- (tags -- alert.tags).toTry(tagSrv.getOrCreate)
tagsToRemove = get(alert).tags.toSeq.filterNot(t => tags.contains(t.toString))
_ <- tagsToAdd.toTry(alertTagSrv.create(AlertTag(), alert, _))
_ = if (tags.nonEmpty) get(alert).outE[AlertTag].filter(_.otherV.hasId(tagsToRemove.map(_._id): _*)).remove()
_ <- get(alert).update(_.tags, tags.toSeq).getOrFail("Alert")
_ <- auditSrv.alert.update(alert, Json.obj("tags" -> tags))
Expand Down
6 changes: 3 additions & 3 deletions thehive/app/org/thp/thehive/services/CaseSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ class CaseSrv @Inject() (
authContext: AuthContext
): Try[(Seq[Tag with Entity], Seq[Tag with Entity])] =
for {
tagsToAdd <- (tags -- `case`.tags).toTry(tagSrv.getOrCreate)
tagsToRemove <- (`case`.tags.toSet -- tags).toTry(tagSrv.getOrCreate)
_ <- tagsToAdd.toTry(caseTagSrv.create(CaseTag(), `case`, _))
tagsToAdd <- (tags -- `case`.tags).toTry(tagSrv.getOrCreate)
tagsToRemove = get(`case`).tags.toSeq.filterNot(t => tags.contains(t.toString))
_ <- tagsToAdd.toTry(caseTagSrv.create(CaseTag(), `case`, _))
_ = if (tags.nonEmpty) get(`case`).outE[CaseTag].filter(_.otherV.hasId(tagsToRemove.map(_._id): _*)).remove()
_ <- get(`case`).update(_.tags, tags.toSeq).getOrFail("Case")
_ <- auditSrv.`case`.update(`case`, Json.obj("tags" -> tags))
Expand Down
6 changes: 3 additions & 3 deletions thehive/app/org/thp/thehive/services/CaseTemplateSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ class CaseTemplateSrv @Inject() (
authContext: AuthContext
): Try[(Seq[Tag with Entity], Seq[Tag with Entity])] =
for {
tagsToAdd <- (tags -- caseTemplate.tags).toTry(tagSrv.getOrCreate)
tagsToRemove <- (caseTemplate.tags.toSet -- tags).toTry(tagSrv.getOrCreate)
_ <- tagsToAdd.toTry(caseTemplateTagSrv.create(CaseTemplateTag(), caseTemplate, _))
tagsToAdd <- (tags -- caseTemplate.tags).toTry(tagSrv.getOrCreate)
tagsToRemove = get(caseTemplate).tags.toSeq.filterNot(t => tags.contains(t.toString))
_ <- tagsToAdd.toTry(caseTemplateTagSrv.create(CaseTemplateTag(), caseTemplate, _))
_ = if (tags.nonEmpty) get(caseTemplate).outE[CaseTemplateTag].filter(_.otherV.hasId(tagsToRemove.map(_._id): _*)).remove()
_ <- get(caseTemplate).update(_.tags, tags.toSeq).getOrFail("CaseTemplate")
_ <- auditSrv.caseTemplate.update(caseTemplate, Json.obj("tags" -> tags))
Expand Down
5 changes: 4 additions & 1 deletion thehive/app/org/thp/thehive/services/DataSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.thp.thehive.services

import akka.actor.ActorRef
import org.apache.tinkerpop.gremlin.process.traversal.P
import org.apache.tinkerpop.gremlin.structure.T
import org.apache.tinkerpop.gremlin.structure.{T, Vertex}
import org.thp.scalligraph.auth.AuthContext
import org.thp.scalligraph.models.{Database, Entity}
import org.thp.scalligraph.services.{VertexSrv, _}
Expand Down Expand Up @@ -30,6 +30,9 @@ class DataSrv @Inject() (@Named("integrity-check-actor") integrityCheckActor: Ac
.fold(createEntity(e))(Success(_))

override def exists(e: Data)(implicit graph: Graph): Boolean = startTraversal.getByData(e.data).exists

override def getByName(name: String)(implicit graph: Graph): Traversal.V[Data] =
startTraversal.getByData(name)
}

object DataOps {
Expand Down
3 changes: 3 additions & 0 deletions thehive/app/org/thp/thehive/services/LogSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ object LogOps {
def get(idOrName: EntityIdOrName): Traversal.V[Log] =
idOrName.fold(traversal.getByIds(_), _ => traversal.empty)

def organisations: Traversal.V[Organisation] =
task.organisations

def visible(organisationSrv: OrganisationSrv)(implicit authContext: AuthContext): Traversal.V[Log] =
traversal.has(_.organisationIds, organisationSrv.currentId(traversal.graph, authContext))

Expand Down
6 changes: 3 additions & 3 deletions thehive/app/org/thp/thehive/services/ObservableSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ class ObservableSrv @Inject() (
authContext: AuthContext
): Try[(Seq[Tag with Entity], Seq[Tag with Entity])] =
for {
tagsToAdd <- (tags -- observable.tags).toTry(tagSrv.getOrCreate)
tagsToRemove <- (observable.tags.toSet -- tags).toTry(tagSrv.getOrCreate)
_ <- tagsToAdd.toTry(observableTagSrv.create(ObservableTag(), observable, _))
tagsToAdd <- (tags -- observable.tags).toTry(tagSrv.getOrCreate)
tagsToRemove = get(observable).tags.toSeq.filterNot(t => tags.contains(t.toString))
_ <- tagsToAdd.toTry(observableTagSrv.create(ObservableTag(), observable, _))
_ = if (tags.nonEmpty) get(observable).outE[ObservableTag].filter(_.otherV.hasId(tagsToRemove.map(_._id): _*)).remove()
_ <- get(observable).update(_.tags, tags.toSeq).getOrFail("Observable")
_ <- auditSrv.observable.update(observable, Json.obj("tags" -> tags))
Expand Down
Loading

0 comments on commit 6dfcb2a

Please sign in to comment.