diff --git a/app/org/thp/thehive/CustomServer.scala b/app/org/thp/thehive/CustomServer.scala index cd6fb93719..0734f2829c 100644 --- a/app/org/thp/thehive/CustomServer.scala +++ b/app/org/thp/thehive/CustomServer.scala @@ -1,9 +1,8 @@ package org.thp.thehive -import play.core.server.{AkkaHttpServer, ServerProvider} - import akka.http.scaladsl.model.HttpMethod import akka.http.scaladsl.settings.ParserSettings +import play.core.server.{AkkaHttpServer, ServerProvider} /** A custom Akka HTTP server with advanced configuration. */ class CustomAkkaHttpServer(context: AkkaHttpServer.Context) extends AkkaHttpServer(context) { diff --git a/client-common/src/main/scala/org/thp/client/BaseClient.scala b/client-common/src/main/scala/org/thp/client/BaseClient.scala index 3d6ad9ab5a..be75b07ee1 100644 --- a/client-common/src/main/scala/org/thp/client/BaseClient.scala +++ b/client-common/src/main/scala/org/thp/client/BaseClient.scala @@ -1,13 +1,13 @@ package org.thp.client -import scala.concurrent.{ExecutionContext, Future} -import scala.util.{Failure, Success, Try} - import play.api.Logger import play.api.http.Status import play.api.libs.json._ import play.api.libs.ws.{WSClient, WSResponse} +import scala.concurrent.{ExecutionContext, Future} +import scala.util.{Failure, Success, Try} + case class ApplicationError(status: Int, body: JsValue) extends Exception(s"ApplicationError($status):\n${Json.prettyPrint(body)}") object ApplicationError { diff --git a/client/src/main/scala/org/thp/thehive/client/TheHiveClient.scala b/client/src/main/scala/org/thp/thehive/client/TheHiveClient.scala index 79c64ff334..799590a33e 100644 --- a/client/src/main/scala/org/thp/thehive/client/TheHiveClient.scala +++ b/client/src/main/scala/org/thp/thehive/client/TheHiveClient.scala @@ -1,15 +1,14 @@ package org.thp.thehive.client -import scala.concurrent.{ExecutionContext, Future} -import scala.util.{Failure, Success} - +import org.thp.client.{ApplicationError, Authentication, BaseClient} +import org.thp.thehive.dto.v1._ import play.api.Logger import play.api.http.Status import play.api.libs.json.{JsObject, JsValue, Json} import play.api.libs.ws.WSClient -import org.thp.client.{ApplicationError, Authentication, BaseClient} -import org.thp.thehive.dto.v1._ +import scala.concurrent.{ExecutionContext, Future} +import scala.util.{Failure, Success} class TheHiveClient(baseUrl: String)(implicit ws: WSClient) { lazy val logger: Logger = Logger(getClass) diff --git a/cortex/client/src/main/scala/org/thp/cortex/client/CortexClient.scala b/cortex/client/src/main/scala/org/thp/cortex/client/CortexClient.scala index 1ad08c5022..a714efb91e 100644 --- a/cortex/client/src/main/scala/org/thp/cortex/client/CortexClient.scala +++ b/cortex/client/src/main/scala/org/thp/cortex/client/CortexClient.scala @@ -1,9 +1,10 @@ package org.thp.cortex.client -import scala.concurrent.duration.Duration -import scala.concurrent.{ExecutionContext, Future} -import scala.util.{Failure, Success, Try} - +import akka.stream.Materializer +import akka.stream.scaladsl.Source +import akka.util.ByteString +import org.thp.client._ +import org.thp.cortex.dto.v0.{Attachment, _} import play.api.Logger import play.api.http.Status import play.api.libs.json.{Format, JsObject, JsString, Json} @@ -11,11 +12,9 @@ import play.api.libs.ws.WSClient import play.api.libs.ws.ahc.AhcWSClientConfig import play.api.mvc.MultipartFormData.{DataPart, FilePart} -import akka.stream.Materializer -import akka.stream.scaladsl.Source -import akka.util.ByteString -import org.thp.client._ -import org.thp.cortex.dto.v0.{Attachment, _} +import scala.concurrent.duration.Duration +import scala.concurrent.{ExecutionContext, Future} +import scala.util.{Failure, Success, Try} case class CortexClientConfig( name: String, diff --git a/cortex/client/src/test/scala/org/thp/cortex/client/TestCortexClientProvider.scala b/cortex/client/src/test/scala/org/thp/cortex/client/TestCortexClientProvider.scala index 52ddbf8a37..5d2b92128c 100644 --- a/cortex/client/src/test/scala/org/thp/cortex/client/TestCortexClientProvider.scala +++ b/cortex/client/src/test/scala/org/thp/cortex/client/TestCortexClientProvider.scala @@ -3,20 +3,19 @@ package org.thp.cortex.client import java.net.URLEncoder import java.nio.file.{Path, Paths} -import scala.concurrent.ExecutionContext -import scala.io.Source -import scala.util.matching.Regex - -import play.api.http.{FileMimeTypes, HttpEntity} -import play.api.libs.json.{JsValue, Json} -import play.api.mvc._ -import play.api.test.Helpers._ - import akka.stream.scaladsl._ import javax.inject.{Inject, Provider} import mockws.MockWS import org.thp.client.NoAuthentication import org.thp.cortex.dto.v0.{OutputJob, OutputWorker} +import play.api.http.{FileMimeTypes, HttpEntity} +import play.api.libs.json.{JsValue, Json} +import play.api.mvc._ +import play.api.test.Helpers._ + +import scala.concurrent.ExecutionContext +import scala.io.Source +import scala.util.matching.Regex class TestCortexClientProvider @Inject() (Action: DefaultActionBuilder, implicit val fileMimeTypes: FileMimeTypes, implicit val ec: ExecutionContext) extends Provider[CortexClient] { diff --git a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/CortexRouter.scala b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/CortexRouter.scala index 4813bfd227..a705015f9a 100644 --- a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/CortexRouter.scala +++ b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/CortexRouter.scala @@ -1,10 +1,9 @@ package org.thp.thehive.connector.cortex -import play.api.Logger -import play.api.routing.Router - import javax.inject.{Inject, Provider, Singleton} import org.thp.thehive.connector.cortex.controllers.v0 +import play.api.Logger +import play.api.routing.Router @Singleton class CortexRouter @Inject() (routerV0: v0.Router) extends Provider[Router] { diff --git a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/controllers/v0/AnalyzerCtrl.scala b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/controllers/v0/AnalyzerCtrl.scala index 264116561e..3f440b3978 100644 --- a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/controllers/v0/AnalyzerCtrl.scala +++ b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/controllers/v0/AnalyzerCtrl.scala @@ -1,15 +1,14 @@ package org.thp.thehive.connector.cortex.controllers.v0 -import scala.concurrent.ExecutionContext - -import play.api.mvc.{Action, AnyContent, Results} - import akka.actor.ActorSystem import javax.inject.{Inject, Singleton} import org.thp.scalligraph.controllers.{Entrypoint, FieldsParser} import org.thp.thehive.connector.cortex.controllers.v0.Conversion._ import org.thp.thehive.connector.cortex.services.AnalyzerSrv import org.thp.thehive.controllers.v0.Conversion._ +import play.api.mvc.{Action, AnyContent, Results} + +import scala.concurrent.ExecutionContext @Singleton class AnalyzerCtrl @Inject() ( diff --git a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/controllers/v0/Conversion.scala b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/controllers/v0/Conversion.scala index 931f74c8ac..e5a3997798 100644 --- a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/controllers/v0/Conversion.scala +++ b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/controllers/v0/Conversion.scala @@ -4,7 +4,7 @@ import io.scalaland.chimney.dsl._ import org.thp.cortex.dto.v0.{OutputWorker => CortexWorker} import org.thp.scalligraph.controllers.Renderer import org.thp.scalligraph.models.Entity -import org.thp.thehive.connector.cortex.dto.v0.{InputAnalyzerTemplate, OutputAction, OutputAnalyzerTemplate, OutputJob, OutputWorker} +import org.thp.thehive.connector.cortex.dto.v0._ import org.thp.thehive.connector.cortex.models._ import play.api.libs.json.{JsArray, JsFalse, Json} diff --git a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/controllers/v0/Router.scala b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/controllers/v0/Router.scala index 59992cd58c..9dac1e8383 100644 --- a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/controllers/v0/Router.scala +++ b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/controllers/v0/Router.scala @@ -1,11 +1,10 @@ package org.thp.thehive.connector.cortex.controllers.v0 +import javax.inject.{Inject, Singleton} import play.api.routing.Router.Routes import play.api.routing.SimpleRouter import play.api.routing.sird._ -import javax.inject.{Inject, Singleton} - @Singleton class Router @Inject() ( jobCtrl: JobCtrl, diff --git a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/models/Action.scala b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/models/Action.scala index 0b21b33dd2..a5e7a78c9f 100644 --- a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/models/Action.scala +++ b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/models/Action.scala @@ -2,11 +2,10 @@ package org.thp.thehive.connector.cortex.models import java.util.Date -import play.api.libs.json.JsObject - import gremlin.scala.{Edge, Graph, Vertex} import org.thp.scalligraph.VertexEntity import org.thp.scalligraph.models._ +import play.api.libs.json.JsObject @VertexEntity case class Action( @@ -67,6 +66,7 @@ object ActionContext extends HasEdgeModel[ActionContext, Action, Product] { override def _createdAt: Date = entity._createdAt override def _updatedAt: Option[Date] = entity._updatedAt } - override def create(e: ActionContext, from: Vertex, to: Vertex)(implicit db: Database, graph: Graph): Edge = from.addEdge(label, to) + override def create(e: ActionContext, from: Vertex, to: Vertex)(implicit db: Database, graph: Graph): Edge = + from.addEdge(label, to) } } diff --git a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/services/ActionOperationSrv.scala b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/services/ActionOperationSrv.scala index ab8c2ad82b..e080801a32 100644 --- a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/services/ActionOperationSrv.scala +++ b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/services/ActionOperationSrv.scala @@ -2,10 +2,6 @@ package org.thp.thehive.connector.cortex.services import java.util.Date -import scala.util.{Failure, Success, Try} - -import play.api.Logger - import gremlin.scala.Graph import javax.inject.Inject import org.thp.scalligraph.InternalError @@ -17,6 +13,9 @@ import org.thp.thehive.controllers.v0.Conversion._ import org.thp.thehive.dto.v0.InputTask import org.thp.thehive.models._ import org.thp.thehive.services._ +import play.api.Logger + +import scala.util.{Failure, Success, Try} class ActionOperationSrv @Inject() ( caseSrv: CaseSrv, diff --git a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/services/AnalyzerSrv.scala b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/services/AnalyzerSrv.scala index 8c93054bdc..a319024ef7 100644 --- a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/services/AnalyzerSrv.scala +++ b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/services/AnalyzerSrv.scala @@ -1,14 +1,13 @@ package org.thp.thehive.connector.cortex.services -import scala.concurrent.{ExecutionContext, Future} -import scala.util.{Failure, Success} - -import play.api.Logger - import javax.inject.{Inject, Singleton} import org.thp.cortex.dto.v0.{OutputWorker => CortexWorker} import org.thp.scalligraph.NotFoundError import org.thp.scalligraph.auth.AuthContext +import play.api.Logger + +import scala.concurrent.{ExecutionContext, Future} +import scala.util.{Failure, Success} @Singleton class AnalyzerSrv @Inject() (connector: Connector, serviceHelper: ServiceHelper, implicit val ec: ExecutionContext) { diff --git a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/services/Connector.scala b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/services/Connector.scala index 60d5e52b73..99435c545d 100644 --- a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/services/Connector.scala +++ b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/services/Connector.scala @@ -1,11 +1,5 @@ package org.thp.thehive.connector.cortex.services -import scala.concurrent.duration.FiniteDuration -import scala.concurrent.{ExecutionContext, Future} -import scala.util.{Failure, Success} - -import play.api.libs.json.{JsObject, Json} - import akka.actor.ActorSystem import akka.stream.Materializer import javax.inject.{Inject, Singleton} @@ -14,6 +8,11 @@ import org.thp.scalligraph.services.config.ApplicationConfig.finiteDurationForma import org.thp.scalligraph.services.config.{ApplicationConfig, ConfigItem} import org.thp.thehive.models.HealthStatus import org.thp.thehive.services.{Connector => TheHiveConnector} +import play.api.libs.json.{JsObject, Json} + +import scala.concurrent.duration.FiniteDuration +import scala.concurrent.{ExecutionContext, Future} +import scala.util.{Failure, Success} @Singleton class Connector @Inject() ( diff --git a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/services/Conversion.scala b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/services/Conversion.scala index b9df8a1d16..1a1608bd07 100644 --- a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/services/Conversion.scala +++ b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/services/Conversion.scala @@ -1,7 +1,7 @@ package org.thp.thehive.connector.cortex.services import io.scalaland.chimney.dsl._ -import org.thp.cortex.dto.v0.{OutputMinireport, OutputArtifact, JobStatus => CortexJobStatus} +import org.thp.cortex.dto.v0.{OutputArtifact, OutputMinireport, JobStatus => CortexJobStatus} import org.thp.thehive.connector.cortex.models.JobStatus import org.thp.thehive.models.{Observable, ReportTag, ReportTagLevel} diff --git a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/services/EntityHelper.scala b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/services/EntityHelper.scala index 842d304590..a0cc00f82b 100644 --- a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/services/EntityHelper.scala +++ b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/services/EntityHelper.scala @@ -1,9 +1,5 @@ package org.thp.thehive.connector.cortex.services -import scala.util.{Failure, Try} - -import play.api.Logger - import gremlin.scala.Graph import javax.inject.{Inject, Singleton} import org.thp.scalligraph.BadRequestError @@ -12,6 +8,9 @@ import org.thp.scalligraph.models.Entity import org.thp.scalligraph.steps.StepsOps._ import org.thp.thehive.models._ import org.thp.thehive.services._ +import play.api.Logger + +import scala.util.{Failure, Try} @Singleton class EntityHelper @Inject() ( diff --git a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/services/package.scala b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/services/package.scala index 589e83bf3a..e397955856 100644 --- a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/services/package.scala +++ b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/services/package.scala @@ -1,11 +1,13 @@ package org.thp.thehive.connector.cortex +import org.thp.scalligraph.models.Database import org.thp.scalligraph.steps.StepsOps._ import org.thp.thehive.connector.cortex.models.ObservableJob import org.thp.thehive.services.ObservableSteps package object services { implicit class RichObservableSteps(observableSteps: ObservableSteps) { - def jobs: JobSteps = new JobSteps(observableSteps.outTo[ObservableJob].raw)(observableSteps.db, observableSteps.graph) + def jobs: JobSteps = + new JobSteps(observableSteps.outTo[ObservableJob].raw)(observableSteps.db.asInstanceOf[Database], observableSteps.graph) } } diff --git a/cortex/connector/src/test/scala/org/thp/thehive/connector/cortex/services/EntityHelperTest.scala b/cortex/connector/src/test/scala/org/thp/thehive/connector/cortex/services/EntityHelperTest.scala index c29ae9cf68..fe1c06a98e 100644 --- a/cortex/connector/src/test/scala/org/thp/thehive/connector/cortex/services/EntityHelperTest.scala +++ b/cortex/connector/src/test/scala/org/thp/thehive/connector/cortex/services/EntityHelperTest.scala @@ -1,13 +1,12 @@ package org.thp.thehive.connector.cortex.services -import play.api.test.PlaySpecification - import org.thp.scalligraph.auth.AuthContext import org.thp.scalligraph.models.{Database, DummyUserSrv} import org.thp.scalligraph.steps.StepsOps._ import org.thp.thehive.TestAppBuilder import org.thp.thehive.models.Permissions import org.thp.thehive.services.{AlertSrv, ObservableSrv, TaskSrv} +import play.api.test.PlaySpecification class EntityHelperTest extends PlaySpecification with TestAppBuilder { implicit val authContext: AuthContext = diff --git a/cortex/connector/src/test/scala/org/thp/thehive/connector/cortex/services/TestConnector.scala b/cortex/connector/src/test/scala/org/thp/thehive/connector/cortex/services/TestConnector.scala index 0943ef1d7f..3cda6c562a 100644 --- a/cortex/connector/src/test/scala/org/thp/thehive/connector/cortex/services/TestConnector.scala +++ b/cortex/connector/src/test/scala/org/thp/thehive/connector/cortex/services/TestConnector.scala @@ -1,15 +1,15 @@ package org.thp.thehive.connector.cortex.services -import scala.concurrent.ExecutionContext - import akka.actor.ActorSystem import akka.stream.Materializer import javax.inject.{Inject, Singleton} import org.thp.cortex.client.CortexClient import org.thp.scalligraph.services.config.ApplicationConfig +import scala.concurrent.ExecutionContext + @Singleton -class TestConnector @Inject()(client: CortexClient, appConfig: ApplicationConfig, mat: Materializer, system: ActorSystem, ec: ExecutionContext) +class TestConnector @Inject() (client: CortexClient, appConfig: ApplicationConfig, mat: Materializer, system: ActorSystem, ec: ExecutionContext) extends Connector(appConfig, mat, system, ec) { override def clients: Seq[CortexClient] = Seq(client) diff --git a/dto/src/main/scala/org/thp/thehive/dto/v0/Alert.scala b/dto/src/main/scala/org/thp/thehive/dto/v0/Alert.scala index 3cd2878708..2991dd86a8 100644 --- a/dto/src/main/scala/org/thp/thehive/dto/v0/Alert.scala +++ b/dto/src/main/scala/org/thp/thehive/dto/v0/Alert.scala @@ -2,9 +2,8 @@ package org.thp.thehive.dto.v0 import java.util.Date -import play.api.libs.json._ - import org.thp.scalligraph.controllers.WithParser +import play.api.libs.json._ case class InputAlert( `type`: String, diff --git a/dto/src/main/scala/org/thp/thehive/dto/v0/Audit.scala b/dto/src/main/scala/org/thp/thehive/dto/v0/Audit.scala index cc7c237b0d..8b35fa228c 100644 --- a/dto/src/main/scala/org/thp/thehive/dto/v0/Audit.scala +++ b/dto/src/main/scala/org/thp/thehive/dto/v0/Audit.scala @@ -2,9 +2,8 @@ package org.thp.thehive.dto.v0 import java.util.Date -import play.api.libs.json._ - import org.thp.scalligraph.models.Entity +import play.api.libs.json._ case class OutputEntity(_type: String, _id: String, _createdAt: Date, _createdBy: String, _updatedAt: Option[Date], _updatedBy: Option[String]) diff --git a/dto/src/main/scala/org/thp/thehive/dto/v0/Case.scala b/dto/src/main/scala/org/thp/thehive/dto/v0/Case.scala index 334aaec047..b1782a1b79 100644 --- a/dto/src/main/scala/org/thp/thehive/dto/v0/Case.scala +++ b/dto/src/main/scala/org/thp/thehive/dto/v0/Case.scala @@ -2,9 +2,8 @@ package org.thp.thehive.dto.v0 import java.util.Date -import play.api.libs.json._ - import org.thp.scalligraph.controllers.WithParser +import play.api.libs.json._ case class InputCase( title: String, diff --git a/dto/src/main/scala/org/thp/thehive/dto/v0/CaseTemplate.scala b/dto/src/main/scala/org/thp/thehive/dto/v0/CaseTemplate.scala index 18fa82a1a3..b1b8c4d7a8 100644 --- a/dto/src/main/scala/org/thp/thehive/dto/v0/CaseTemplate.scala +++ b/dto/src/main/scala/org/thp/thehive/dto/v0/CaseTemplate.scala @@ -2,9 +2,8 @@ package org.thp.thehive.dto.v0 import java.util.Date -import play.api.libs.json.{JsObject, Json, OFormat, OWrites} - import org.thp.scalligraph.controllers.WithParser +import play.api.libs.json.{JsObject, Json, OFormat, OWrites} case class InputCaseTemplate( name: String, diff --git a/dto/src/main/scala/org/thp/thehive/dto/v0/CustomFieldValue.scala b/dto/src/main/scala/org/thp/thehive/dto/v0/CustomFieldValue.scala index e9cf565699..3931d5b4dd 100644 --- a/dto/src/main/scala/org/thp/thehive/dto/v0/CustomFieldValue.scala +++ b/dto/src/main/scala/org/thp/thehive/dto/v0/CustomFieldValue.scala @@ -2,12 +2,11 @@ package org.thp.thehive.dto.v0 import java.util.Date -import play.api.libs.json._ - import org.scalactic.Accumulation._ -import org.scalactic.{Bad, Every, Good, One, Or} -import org.thp.scalligraph.{AttributeError, InvalidFormatAttributeError} +import org.scalactic._ import org.thp.scalligraph.controllers.{FNull, _} +import org.thp.scalligraph.{AttributeError, InvalidFormatAttributeError} +import play.api.libs.json._ case class OutputCustomField( id: String, diff --git a/dto/src/main/scala/org/thp/thehive/dto/v0/Log.scala b/dto/src/main/scala/org/thp/thehive/dto/v0/Log.scala index 7dbaf2b46a..418f98caf9 100644 --- a/dto/src/main/scala/org/thp/thehive/dto/v0/Log.scala +++ b/dto/src/main/scala/org/thp/thehive/dto/v0/Log.scala @@ -2,9 +2,8 @@ package org.thp.thehive.dto.v0 import java.util.Date -import play.api.libs.json.{Json, OFormat} - import org.thp.scalligraph.controllers.FFile +import play.api.libs.json.{Json, OFormat} case class InputLog(message: String, startDate: Option[Date] = None, attachment: Option[FFile] = None) diff --git a/dto/src/main/scala/org/thp/thehive/dto/v0/Share.scala b/dto/src/main/scala/org/thp/thehive/dto/v0/Share.scala index 8ac9d78401..3ff4a758c8 100644 --- a/dto/src/main/scala/org/thp/thehive/dto/v0/Share.scala +++ b/dto/src/main/scala/org/thp/thehive/dto/v0/Share.scala @@ -2,10 +2,9 @@ package org.thp.thehive.dto.v0 import java.util.Date -import play.api.libs.json.{Format, Json, Writes} - import org.thp.thehive.dto.v0.ObservablesFilter.ObservablesFilter import org.thp.thehive.dto.v0.TasksFilter.TasksFilter +import play.api.libs.json.{Format, Json, Writes} case class InputShare(organisationName: String, profile: String, tasks: TasksFilter, observables: ObservablesFilter) diff --git a/dto/src/main/scala/org/thp/thehive/dto/v0/User.scala b/dto/src/main/scala/org/thp/thehive/dto/v0/User.scala index 5d02581f77..b35703628f 100644 --- a/dto/src/main/scala/org/thp/thehive/dto/v0/User.scala +++ b/dto/src/main/scala/org/thp/thehive/dto/v0/User.scala @@ -2,9 +2,8 @@ package org.thp.thehive.dto.v0 import java.util.Date -import play.api.libs.json.{Json, OFormat, Writes} - import org.thp.scalligraph.controllers.FFile +import play.api.libs.json.{Json, OFormat, Writes} case class InputUser( login: String, diff --git a/dto/src/main/scala/org/thp/thehive/dto/v1/Alert.scala b/dto/src/main/scala/org/thp/thehive/dto/v1/Alert.scala index f1fd827080..13f26c4906 100644 --- a/dto/src/main/scala/org/thp/thehive/dto/v1/Alert.scala +++ b/dto/src/main/scala/org/thp/thehive/dto/v1/Alert.scala @@ -2,9 +2,8 @@ package org.thp.thehive.dto.v1 import java.util.Date -import play.api.libs.json.{Json, OFormat, OWrites} - import org.thp.scalligraph.controllers.WithParser +import play.api.libs.json.{Json, OFormat, OWrites} case class InputAlert( `type`: String, diff --git a/dto/src/main/scala/org/thp/thehive/dto/v1/Audit.scala b/dto/src/main/scala/org/thp/thehive/dto/v1/Audit.scala index b079da7ae5..9c08cd20f3 100644 --- a/dto/src/main/scala/org/thp/thehive/dto/v1/Audit.scala +++ b/dto/src/main/scala/org/thp/thehive/dto/v1/Audit.scala @@ -2,9 +2,8 @@ package org.thp.thehive.dto.v1 import java.util.Date -import play.api.libs.json.{Json, OFormat} - import org.thp.scalligraph.models.Entity +import play.api.libs.json.{Json, OFormat} case class OutputEntity(_type: String, _id: String, _createdAt: Date, _createdBy: String, _updatedAt: Option[Date], _updatedBy: Option[String]) diff --git a/dto/src/main/scala/org/thp/thehive/dto/v1/Case.scala b/dto/src/main/scala/org/thp/thehive/dto/v1/Case.scala index 667ffcd3e4..335b1019e2 100644 --- a/dto/src/main/scala/org/thp/thehive/dto/v1/Case.scala +++ b/dto/src/main/scala/org/thp/thehive/dto/v1/Case.scala @@ -2,9 +2,8 @@ package org.thp.thehive.dto.v1 import java.util.Date -import play.api.libs.json.{Json, OFormat, OWrites} - import org.thp.scalligraph.controllers.WithParser +import play.api.libs.json.{Json, OFormat, OWrites} case class InputCase( title: String, diff --git a/dto/src/main/scala/org/thp/thehive/dto/v1/CaseTemplate.scala b/dto/src/main/scala/org/thp/thehive/dto/v1/CaseTemplate.scala index c77efbcbae..f57a63af9e 100644 --- a/dto/src/main/scala/org/thp/thehive/dto/v1/CaseTemplate.scala +++ b/dto/src/main/scala/org/thp/thehive/dto/v1/CaseTemplate.scala @@ -2,9 +2,8 @@ package org.thp.thehive.dto.v1 import java.util.Date -import play.api.libs.json.{Json, OFormat, OWrites} - import org.thp.scalligraph.controllers.WithParser +import play.api.libs.json.{Json, OFormat, OWrites} case class InputCaseTemplate( name: String, diff --git a/dto/src/main/scala/org/thp/thehive/dto/v1/CustomFieldValue.scala b/dto/src/main/scala/org/thp/thehive/dto/v1/CustomFieldValue.scala index 7adebff810..c82b5500b9 100644 --- a/dto/src/main/scala/org/thp/thehive/dto/v1/CustomFieldValue.scala +++ b/dto/src/main/scala/org/thp/thehive/dto/v1/CustomFieldValue.scala @@ -2,12 +2,11 @@ package org.thp.thehive.dto.v1 import java.util.Date -import play.api.libs.json._ - import org.scalactic.Accumulation._ import org.scalactic.{Bad, Good, One} import org.thp.scalligraph.InvalidFormatAttributeError import org.thp.scalligraph.controllers._ +import play.api.libs.json._ case class InputCustomField(name: String, description: String, `type`: String, mandatory: Option[Boolean]) @@ -43,6 +42,7 @@ object InputCustomFieldValue { ) } .map(_.toSeq) + case _ => Good(Nil) } implicit val writes: Writes[Seq[InputCustomFieldValue]] = Writes[Seq[InputCustomFieldValue]] { icfv => val fields = icfv.map { diff --git a/dto/src/main/scala/org/thp/thehive/dto/v1/Log.scala b/dto/src/main/scala/org/thp/thehive/dto/v1/Log.scala index 53bc899048..24eedbb4c2 100644 --- a/dto/src/main/scala/org/thp/thehive/dto/v1/Log.scala +++ b/dto/src/main/scala/org/thp/thehive/dto/v1/Log.scala @@ -2,9 +2,8 @@ package org.thp.thehive.dto.v1 import java.util.Date -import play.api.libs.json.{Json, OFormat} - import org.thp.scalligraph.controllers.FFile +import play.api.libs.json.{Json, OFormat} case class InputLog(message: String, startDate: Option[Date] = None, attachment: Option[FFile] = None) diff --git a/dto/src/main/scala/org/thp/thehive/dto/v1/Observable.scala b/dto/src/main/scala/org/thp/thehive/dto/v1/Observable.scala index 83174f13c8..5ff6e5ec09 100644 --- a/dto/src/main/scala/org/thp/thehive/dto/v1/Observable.scala +++ b/dto/src/main/scala/org/thp/thehive/dto/v1/Observable.scala @@ -2,11 +2,10 @@ package org.thp.thehive.dto.v1 import java.util.Date -import play.api.libs.json.{JsObject, Json, OFormat, Writes} - import org.scalactic.Accumulation._ import org.scalactic.Good import org.thp.scalligraph.controllers._ +import play.api.libs.json.{JsObject, Json, OFormat, Writes} case class InputObservable( dataType: String, diff --git a/dto/src/main/scala/org/thp/thehive/dto/v1/User.scala b/dto/src/main/scala/org/thp/thehive/dto/v1/User.scala index 3cb0736b3d..dba6f4304b 100644 --- a/dto/src/main/scala/org/thp/thehive/dto/v1/User.scala +++ b/dto/src/main/scala/org/thp/thehive/dto/v1/User.scala @@ -2,9 +2,8 @@ package org.thp.thehive.dto.v1 import java.util.Date -import play.api.libs.json.{Json, OFormat, Writes} - import org.thp.scalligraph.controllers.FFile +import play.api.libs.json.{Json, OFormat, Writes} case class InputUser(login: String, name: String, password: Option[String], profile: String, organisation: Option[String], avatar: Option[FFile]) diff --git a/migration/src/main/scala/org/thp/thehive/migration/th3/DBConfiguration.scala b/migration/src/main/scala/org/thp/thehive/migration/th3/DBConfiguration.scala index 742771b89f..315df391b3 100644 --- a/migration/src/main/scala/org/thp/thehive/migration/th3/DBConfiguration.scala +++ b/migration/src/main/scala/org/thp/thehive/migration/th3/DBConfiguration.scala @@ -3,14 +3,6 @@ package org.thp.thehive.migration.th3 import java.nio.file.{Files, Paths} import java.security.KeyStore -import scala.collection.JavaConverters._ -import scala.concurrent.duration.DurationInt -import scala.concurrent.{ExecutionContext, Future, Promise} - -import play.api.inject.ApplicationLifecycle -import play.api.libs.json.JsObject -import play.api.{Configuration, Logger} - import akka.NotUsed import akka.actor.ActorSystem import akka.stream.scaladsl.{Sink, Source} @@ -29,6 +21,13 @@ import org.apache.http.impl.client.BasicCredentialsProvider import org.apache.http.impl.nio.client.HttpAsyncClientBuilder import org.elasticsearch.client.RestClientBuilder.{HttpClientConfigCallback, RequestConfigCallback} import org.thp.scalligraph.{CreateError, InternalError, SearchError} +import play.api.inject.ApplicationLifecycle +import play.api.libs.json.JsObject +import play.api.{Configuration, Logger} + +import scala.collection.JavaConverters._ +import scala.concurrent.duration.DurationInt +import scala.concurrent.{ExecutionContext, Future, Promise} /** * This class is a wrapper of ElasticSearch client from Elastic4s diff --git a/migration/src/main/scala/org/thp/thehive/migration/th3/DBFind.scala b/migration/src/main/scala/org/thp/thehive/migration/th3/DBFind.scala index d1a1429428..336fa585b6 100644 --- a/migration/src/main/scala/org/thp/thehive/migration/th3/DBFind.scala +++ b/migration/src/main/scala/org/thp/thehive/migration/th3/DBFind.scala @@ -1,13 +1,5 @@ package org.thp.thehive.migration.th3 -import scala.collection.mutable -import scala.concurrent.duration.{DurationLong, FiniteDuration} -import scala.concurrent.{ExecutionContext, Future} -import scala.util.{Failure, Success, Try} - -import play.api.libs.json._ -import play.api.{Configuration, Logger} - import akka.NotUsed import akka.stream.scaladsl.Source import akka.stream.stage.{AsyncCallback, GraphStage, GraphStageLogic, OutHandler} @@ -17,6 +9,13 @@ import com.sksamuel.elastic4s.http.search.{SearchHit, SearchResponse} import com.sksamuel.elastic4s.searches.SearchRequest import javax.inject.{Inject, Singleton} import org.thp.scalligraph.{InternalError, SearchError} +import play.api.libs.json._ +import play.api.{Configuration, Logger} + +import scala.collection.mutable +import scala.concurrent.duration.{DurationLong, FiniteDuration} +import scala.concurrent.{ExecutionContext, Future} +import scala.util.{Failure, Success, Try} /** * Service class responsible for entity search diff --git a/migration/src/main/scala/org/thp/thehive/migration/th3/DBGet.scala b/migration/src/main/scala/org/thp/thehive/migration/th3/DBGet.scala index e39738dea5..d6f6983175 100644 --- a/migration/src/main/scala/org/thp/thehive/migration/th3/DBGet.scala +++ b/migration/src/main/scala/org/thp/thehive/migration/th3/DBGet.scala @@ -1,12 +1,11 @@ package org.thp.thehive.migration.th3 +import com.sksamuel.elastic4s.http.ElasticDsl._ import javax.inject.{Inject, Singleton} -import scala.concurrent.{ExecutionContext, Future} - +import org.thp.scalligraph.NotFoundError import play.api.libs.json.JsObject -import com.sksamuel.elastic4s.http.ElasticDsl._ -import org.thp.scalligraph.NotFoundError +import scala.concurrent.{ExecutionContext, Future} @Singleton class DBGet @Inject() (db: DBConfiguration, implicit val ec: ExecutionContext) { diff --git a/migration/src/main/scala/org/thp/thehive/migration/th3/DBUtils.scala b/migration/src/main/scala/org/thp/thehive/migration/th3/DBUtils.scala index 6104e3f72a..7f88364e52 100644 --- a/migration/src/main/scala/org/thp/thehive/migration/th3/DBUtils.scala +++ b/migration/src/main/scala/org/thp/thehive/migration/th3/DBUtils.scala @@ -1,14 +1,13 @@ package org.thp.thehive.migration.th3 -import scala.collection.IterableLike -import scala.collection.generic.CanBuildFrom - -import play.api.libs.json._ - import com.sksamuel.elastic4s.http.ElasticDsl.fieldSort import com.sksamuel.elastic4s.http.search.SearchHit import com.sksamuel.elastic4s.searches.sort.Sort import com.sksamuel.elastic4s.searches.sort.SortOrder.{ASC, DESC} +import play.api.libs.json._ + +import scala.collection.IterableLike +import scala.collection.generic.CanBuildFrom object DBUtils { @@ -36,8 +35,7 @@ object DBUtils { } // then remove duplicates // Same as : val fieldSortDefs = byFieldList.groupBy(_._1).map(_._2.head).values.toSeq - distinctBy(byFieldList)(_._1) - .map(_._2) :+ fieldSort("_id").order(DESC) + distinctBy(byFieldList)(_._1).map(_._2) } /** diff --git a/misp/client/src/main/scala/org/thp/misp/client/MispClient.scala b/misp/client/src/main/scala/org/thp/misp/client/MispClient.scala index 9e7805aedc..3a664de478 100644 --- a/misp/client/src/main/scala/org/thp/misp/client/MispClient.scala +++ b/misp/client/src/main/scala/org/thp/misp/client/MispClient.scala @@ -2,15 +2,6 @@ package org.thp.misp.client import java.util.Date -import scala.concurrent.duration.{Duration, DurationInt} -import scala.concurrent.{Await, ExecutionContext, Future} -import scala.util.{Failure, Success, Try} - -import play.api.Logger -import play.api.http.Status -import play.api.libs.json.{JsObject, JsString, JsValue, Json} -import play.api.libs.ws.{WSClient, WSRequest} - import akka.NotUsed import akka.stream.alpakka.json.scaladsl.JsonReader import akka.stream.scaladsl.{JsonFraming, Source} @@ -18,6 +9,14 @@ import akka.util.ByteString import org.thp.client.{ApplicationError, Authentication, ProxyWS} import org.thp.misp.dto.{Attribute, Event, Organisation, User} import org.thp.scalligraph.InternalError +import play.api.Logger +import play.api.http.Status +import play.api.libs.json.{JsObject, JsString, JsValue, Json} +import play.api.libs.ws.{WSClient, WSRequest} + +import scala.concurrent.duration.{Duration, DurationInt} +import scala.concurrent.{Await, ExecutionContext, Future} +import scala.util.{Failure, Success, Try} object MispPurpose extends Enumeration { val ImportOnly, ExportOnly, ImportAndExport = Value diff --git a/misp/client/src/main/scala/org/thp/misp/dto/Attribute.scala b/misp/client/src/main/scala/org/thp/misp/dto/Attribute.scala index 074d1ac82b..33c65b1927 100644 --- a/misp/client/src/main/scala/org/thp/misp/dto/Attribute.scala +++ b/misp/client/src/main/scala/org/thp/misp/dto/Attribute.scala @@ -4,11 +4,10 @@ import java.time.OffsetDateTime import java.time.format.{DateTimeFormatter, DateTimeFormatterBuilder} import java.util.{Base64, Date} -import play.api.libs.functional.syntax._ -import play.api.libs.json.{JsPath, Json, OWrites, Reads} - import akka.stream.scaladsl.Source import akka.util.ByteString +import play.api.libs.functional.syntax._ +import play.api.libs.json.{JsPath, Json, OWrites, Reads} case class Attribute( id: String, diff --git a/misp/connector/src/main/scala/org/thp/thehive/connector/misp/MispModule.scala b/misp/connector/src/main/scala/org/thp/thehive/connector/misp/MispModule.scala index 43519257c4..caade07f0a 100644 --- a/misp/connector/src/main/scala/org/thp/thehive/connector/misp/MispModule.scala +++ b/misp/connector/src/main/scala/org/thp/thehive/connector/misp/MispModule.scala @@ -1,15 +1,14 @@ package org.thp.thehive.connector.misp -import play.api.libs.concurrent.AkkaGuiceSupport -import play.api.routing.{Router => PlayRouter} -import play.api.{Configuration, Environment, Logger} - import akka.actor.{ActorRef, PoisonPill} import akka.cluster.singleton.{ClusterSingletonManager, ClusterSingletonManagerSettings} import com.google.inject.AbstractModule import net.codingwell.scalaguice.{ScalaModule, ScalaMultibinder} import org.thp.thehive.connector.misp.services.{Connector, MispActor, MispActorProvider} import org.thp.thehive.services.{Connector => TheHiveConnector} +import play.api.libs.concurrent.AkkaGuiceSupport +import play.api.routing.{Router => PlayRouter} +import play.api.{Configuration, Environment, Logger} class MispModule(environment: Environment, configuration: Configuration) extends AbstractModule with ScalaModule with AkkaGuiceSupport { lazy val logger: Logger = Logger(getClass) diff --git a/misp/connector/src/main/scala/org/thp/thehive/connector/misp/MispRouter.scala b/misp/connector/src/main/scala/org/thp/thehive/connector/misp/MispRouter.scala index 5d98fd339f..bce499ed20 100644 --- a/misp/connector/src/main/scala/org/thp/thehive/connector/misp/MispRouter.scala +++ b/misp/connector/src/main/scala/org/thp/thehive/connector/misp/MispRouter.scala @@ -1,10 +1,9 @@ package org.thp.thehive.connector.misp -import play.api.Logger -import play.api.routing.Router - import javax.inject.{Inject, Provider, Singleton} import org.thp.thehive.connector.misp.controllers.v0 +import play.api.Logger +import play.api.routing.Router @Singleton class MispRouter @Inject() (routerV0: v0.Router) extends Provider[Router] { diff --git a/misp/connector/src/main/scala/org/thp/thehive/connector/misp/controllers/v0/Router.scala b/misp/connector/src/main/scala/org/thp/thehive/connector/misp/controllers/v0/Router.scala index 679b7e14e3..cac4abd380 100644 --- a/misp/connector/src/main/scala/org/thp/thehive/connector/misp/controllers/v0/Router.scala +++ b/misp/connector/src/main/scala/org/thp/thehive/connector/misp/controllers/v0/Router.scala @@ -1,12 +1,11 @@ package org.thp.thehive.connector.misp.controllers.v0 +import javax.inject.{Inject, Singleton} +import org.thp.scalligraph.NotFoundError import play.api.routing.Router.Routes import play.api.routing.SimpleRouter import play.api.routing.sird._ -import javax.inject.{Inject, Singleton} -import org.thp.scalligraph.NotFoundError - @Singleton class Router @Inject() (mispCtrl: MispCtrl) extends SimpleRouter { diff --git a/misp/connector/src/main/scala/org/thp/thehive/connector/misp/services/Connector.scala b/misp/connector/src/main/scala/org/thp/thehive/connector/misp/services/Connector.scala index 48e00be657..c94e84b16a 100644 --- a/misp/connector/src/main/scala/org/thp/thehive/connector/misp/services/Connector.scala +++ b/misp/connector/src/main/scala/org/thp/thehive/connector/misp/services/Connector.scala @@ -1,10 +1,5 @@ package org.thp.thehive.connector.misp.services -import scala.concurrent.duration.FiniteDuration -import scala.concurrent.{ExecutionContext, Future} - -import play.api.libs.json.{JsObject, Json} - import akka.actor.ActorSystem import akka.stream.Materializer import javax.inject.{Inject, Singleton} @@ -12,6 +7,10 @@ import org.thp.scalligraph.services.config.ApplicationConfig.finiteDurationForma import org.thp.scalligraph.services.config.{ApplicationConfig, ConfigItem} import org.thp.thehive.models.{HealthStatus, ObservableType} import org.thp.thehive.services.{Connector => TheHiveConnector} +import play.api.libs.json.{JsObject, Json} + +import scala.concurrent.duration.FiniteDuration +import scala.concurrent.{ExecutionContext, Future} @Singleton class Connector @Inject() (appConfig: ApplicationConfig, system: ActorSystem, mat: Materializer, implicit val ec: ExecutionContext) diff --git a/misp/connector/src/main/scala/org/thp/thehive/connector/misp/services/TheHiveMispClient.scala b/misp/connector/src/main/scala/org/thp/thehive/connector/misp/services/TheHiveMispClient.scala index 15c8587799..5e11d651f6 100644 --- a/misp/connector/src/main/scala/org/thp/thehive/connector/misp/services/TheHiveMispClient.scala +++ b/misp/connector/src/main/scala/org/thp/thehive/connector/misp/services/TheHiveMispClient.scala @@ -1,12 +1,5 @@ package org.thp.thehive.connector.misp.services -import scala.concurrent.duration.Duration -import scala.concurrent.{ExecutionContext, Future} - -import play.api.libs.json._ -import play.api.libs.ws.WSClient -import play.api.libs.ws.ahc.AhcWSClientConfig - import akka.stream.Materializer import gremlin.scala.P import javax.inject.Inject @@ -16,6 +9,12 @@ import org.thp.scalligraph.services.config.ApplicationConfig.durationFormat import org.thp.scalligraph.steps.StepsOps._ import org.thp.thehive.models.HealthStatus import org.thp.thehive.services.OrganisationSteps +import play.api.libs.json._ +import play.api.libs.ws.WSClient +import play.api.libs.ws.ahc.AhcWSClientConfig + +import scala.concurrent.duration.Duration +import scala.concurrent.{ExecutionContext, Future} case class TheHiveMispClientConfig( name: String, diff --git a/misp/connector/src/test/scala/org/thp/thehive/connector/misp/services/MispImportSrvTest.scala b/misp/connector/src/test/scala/org/thp/thehive/connector/misp/services/MispImportSrvTest.scala index ea2ae96e31..a1bf904276 100644 --- a/misp/connector/src/test/scala/org/thp/thehive/connector/misp/services/MispImportSrvTest.scala +++ b/misp/connector/src/test/scala/org/thp/thehive/connector/misp/services/MispImportSrvTest.scala @@ -2,11 +2,6 @@ package org.thp.thehive.connector.misp.services import java.util.{Date, UUID} -import scala.concurrent.ExecutionContext -import scala.concurrent.duration.DurationInt - -import play.api.test.PlaySpecification - import akka.stream.Materializer import akka.stream.scaladsl.Sink import org.thp.misp.dto.{Event, Organisation, Tag, User} @@ -17,6 +12,10 @@ import org.thp.scalligraph.steps.StepsOps._ import org.thp.thehive.TestAppBuilder import org.thp.thehive.models.{Alert, Permissions} import org.thp.thehive.services.{AlertSrv, OrganisationSrv} +import play.api.test.PlaySpecification + +import scala.concurrent.ExecutionContext +import scala.concurrent.duration.DurationInt class MispImportSrvTest(implicit ec: ExecutionContext) extends PlaySpecification with TestAppBuilder { implicit val authContext: AuthContext = diff --git a/misp/connector/src/test/scala/org/thp/thehive/connector/misp/services/TestMispClientProvider.scala b/misp/connector/src/test/scala/org/thp/thehive/connector/misp/services/TestMispClientProvider.scala index b21444eadb..9538840aec 100644 --- a/misp/connector/src/test/scala/org/thp/thehive/connector/misp/services/TestMispClientProvider.scala +++ b/misp/connector/src/test/scala/org/thp/thehive/connector/misp/services/TestMispClientProvider.scala @@ -1,17 +1,16 @@ package org.thp.thehive.connector.misp.services -import scala.concurrent.ExecutionContext -import scala.io.Source - +import javax.inject.{Inject, Provider} +import mockws.MockWS +import org.thp.client.NoAuthentication +import org.thp.misp.client.MispPurpose import play.api.http.FileMimeTypes import play.api.libs.json.{JsValue, Json} import play.api.mvc.{DefaultActionBuilder, Results} import play.api.test.Helpers.{GET, POST} -import javax.inject.{Inject, Provider} -import mockws.MockWS -import org.thp.client.NoAuthentication -import org.thp.misp.client.MispPurpose +import scala.concurrent.ExecutionContext +import scala.io.Source class TestMispClientProvider @Inject() (Action: DefaultActionBuilder, implicit val fileMimeTypes: FileMimeTypes, implicit val ec: ExecutionContext) extends Provider[TheHiveMispClient] { diff --git a/project/FileBuilder.scala b/project/FileBuilder.scala index 682e46d7a5..75d0b67ed1 100644 --- a/project/FileBuilder.scala +++ b/project/FileBuilder.scala @@ -1,8 +1,8 @@ -import scala.sys.process.{Process, ProcessLogger} - import sbt.Keys.TaskStreams import sbt._ +import scala.sys.process.{Process, ProcessLogger} + object FileBuilder { def prefixLogs(log: ProcessLogger, prefix: String): ProcessLogger = new ProcessLogger { diff --git a/thehive/app/org/thp/thehive/TheHiveRouter.scala b/thehive/app/org/thp/thehive/TheHiveRouter.scala index 1c2db492b6..a704ee6289 100644 --- a/thehive/app/org/thp/thehive/TheHiveRouter.scala +++ b/thehive/app/org/thp/thehive/TheHiveRouter.scala @@ -1,13 +1,13 @@ package org.thp.thehive -import play.api.mvc._ -import play.api.routing.sird._ -import play.api.routing.{Router, SimpleRouter} -import play.api.{Configuration, Environment, Logger, Mode} import _root_.controllers.{Assets, ExternalAssets} import com.google.inject.ProvidedBy import javax.inject.{Inject, Provider, Singleton} import org.thp.thehive.controllers.{dav, v0, v1} +import play.api.mvc._ +import play.api.routing.sird._ +import play.api.routing.{Router, SimpleRouter} +import play.api.{Configuration, Environment, Logger, Mode} @Singleton class TheHiveRouter @Inject() ( diff --git a/thehive/app/org/thp/thehive/controllers/dav/Resource.scala b/thehive/app/org/thp/thehive/controllers/dav/Resource.scala index 66f90c0530..80344d74a0 100644 --- a/thehive/app/org/thp/thehive/controllers/dav/Resource.scala +++ b/thehive/app/org/thp/thehive/controllers/dav/Resource.scala @@ -3,11 +3,11 @@ package org.thp.thehive.controllers.dav import java.text.SimpleDateFormat import java.util.Date -import scala.xml.{Elem, Node} - import org.thp.scalligraph.models.Entity import org.thp.thehive.models.Attachment +import scala.xml.{Elem, Node} + trait Resource { def url: String def displayName: String diff --git a/thehive/app/org/thp/thehive/controllers/v0/AuditRenderer.scala b/thehive/app/org/thp/thehive/controllers/v0/AuditRenderer.scala index 1b6b8e36a8..c2c0fc7114 100644 --- a/thehive/app/org/thp/thehive/controllers/v0/AuditRenderer.scala +++ b/thehive/app/org/thp/thehive/controllers/v0/AuditRenderer.scala @@ -3,15 +3,14 @@ package org.thp.thehive.controllers.v0 import java.lang.{Long => JLong} import java.util.{Map => JMap} -import scala.collection.JavaConverters._ - -import play.api.libs.json.{JsNumber, JsObject} - import gremlin.scala.{__, By, Graph, Key, Vertex} import org.thp.scalligraph.steps.StepsOps._ import org.thp.scalligraph.steps._ import org.thp.thehive.controllers.v0.Conversion._ import org.thp.thehive.services._ +import play.api.libs.json.{JsNumber, JsObject} + +import scala.collection.JavaConverters._ trait AuditRenderer { diff --git a/thehive/app/org/thp/thehive/controllers/v0/CaseCtrl.scala b/thehive/app/org/thp/thehive/controllers/v0/CaseCtrl.scala index 0310629688..9008619ac8 100644 --- a/thehive/app/org/thp/thehive/controllers/v0/CaseCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v0/CaseCtrl.scala @@ -1,6 +1,6 @@ package org.thp.thehive.controllers.v0 -import javax.inject.{Inject, Singleton} +import javax.inject.{Inject, Named, Singleton} import org.thp.scalligraph.controllers.{Entrypoint, FieldsParser} import org.thp.scalligraph.models.Database import org.thp.scalligraph.query.{ParamQuery, PropertyUpdater, PublicProperty, Query} diff --git a/thehive/app/org/thp/thehive/controllers/v0/ObservableRenderer.scala b/thehive/app/org/thp/thehive/controllers/v0/ObservableRenderer.scala index 2d91905129..d0fe512837 100644 --- a/thehive/app/org/thp/thehive/controllers/v0/ObservableRenderer.scala +++ b/thehive/app/org/thp/thehive/controllers/v0/ObservableRenderer.scala @@ -1,15 +1,14 @@ package org.thp.thehive.controllers.v0 -import scala.collection.JavaConverters._ - -import play.api.libs.json.{JsObject, Json} - import gremlin.scala.{By, Key} import org.thp.scalligraph.auth.AuthContext import org.thp.scalligraph.steps.StepsOps._ import org.thp.scalligraph.steps.Traversal import org.thp.thehive.controllers.v0.Conversion._ import org.thp.thehive.services.ObservableSteps +import play.api.libs.json.{JsObject, Json} + +import scala.collection.JavaConverters._ trait ObservableRenderer { diff --git a/thehive/app/org/thp/thehive/controllers/v0/Properties.scala b/thehive/app/org/thp/thehive/controllers/v0/Properties.scala index b6ccafb411..812de4b19a 100644 --- a/thehive/app/org/thp/thehive/controllers/v0/Properties.scala +++ b/thehive/app/org/thp/thehive/controllers/v0/Properties.scala @@ -2,9 +2,6 @@ package org.thp.thehive.controllers.v0 import java.util.Date -import scala.collection.JavaConverters._ -import scala.util.{Failure, Success, Try} -import play.api.libs.json.{JsNull, JsObject, JsValue, Json} import gremlin.scala.{__, By, Key, P, Vertex} import javax.inject.{Inject, Singleton} import org.scalactic.Accumulation._ @@ -43,6 +40,10 @@ import org.thp.thehive.services.{ UserSrv, UserSteps } +import play.api.libs.json.{JsNull, JsObject, JsValue, Json} + +import scala.collection.JavaConverters._ +import scala.util.{Failure, Success, Try} @Singleton class Properties @Inject() ( diff --git a/thehive/app/org/thp/thehive/controllers/v1/AuditCtrl.scala b/thehive/app/org/thp/thehive/controllers/v1/AuditCtrl.scala index 2bcb9a5616..60d2da0c50 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/AuditCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/AuditCtrl.scala @@ -1,6 +1,6 @@ package org.thp.thehive.controllers.v1 -import javax.inject.{Inject, Singleton} +import javax.inject.{Inject, Named, Singleton} import org.thp.scalligraph.controllers.{Entrypoint, FieldsParser} import org.thp.scalligraph.models.Database import org.thp.scalligraph.query.{ParamQuery, PublicProperty, Query} @@ -14,7 +14,8 @@ import play.api.mvc.{Action, AnyContent, Results} import scala.util.Success @Singleton -class AuditCtrl @Inject() (entrypoint: Entrypoint, db: Database, properties: Properties, auditSrv: AuditSrv) extends QueryableCtrl { +class AuditCtrl @Inject() (entrypoint: Entrypoint, @Named("with-thehive-schema") db: Database, properties: Properties, auditSrv: AuditSrv) + extends QueryableCtrl { val entityName: String = "audit" diff --git a/thehive/app/org/thp/thehive/controllers/v1/Properties.scala b/thehive/app/org/thp/thehive/controllers/v1/Properties.scala index 0271658148..02511c2753 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/Properties.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/Properties.scala @@ -1,10 +1,5 @@ package org.thp.thehive.controllers.v1 -import scala.collection.JavaConverters._ -import scala.util.Failure - -import play.api.libs.json.{JsNull, JsObject, JsValue, Json} - import gremlin.scala.{__, By, Key, Vertex} import javax.inject.{Inject, Singleton} import org.thp.scalligraph.BadRequestError @@ -30,6 +25,10 @@ import org.thp.thehive.services.{ UserSrv, UserSteps } +import play.api.libs.json.{JsNull, JsObject, JsValue, Json} + +import scala.collection.JavaConverters._ +import scala.util.Failure @Singleton class Properties @Inject() ( diff --git a/thehive/app/org/thp/thehive/controllers/v1/QueryCtrl.scala b/thehive/app/org/thp/thehive/controllers/v1/QueryCtrl.scala index fca3cc8ac5..cfaeac2f26 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/QueryCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/QueryCtrl.scala @@ -1,11 +1,11 @@ package org.thp.thehive.controllers.v1 -import scala.reflect.runtime.{universe => ru} - import org.thp.scalligraph.models.UniMapping import org.thp.scalligraph.query.{ParamQuery, PublicProperty, PublicPropertyListBuilder, Query} import org.thp.scalligraph.steps.BaseVertexSteps +import scala.reflect.runtime.{universe => ru} + case class IdOrName(idOrName: String) trait QueryableCtrl { diff --git a/thehive/app/org/thp/thehive/controllers/v1/Router.scala b/thehive/app/org/thp/thehive/controllers/v1/Router.scala index 2cc2959a56..70e4477a87 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/Router.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/Router.scala @@ -1,11 +1,10 @@ package org.thp.thehive.controllers.v1 +import javax.inject.{Inject, Singleton} import play.api.routing.Router.Routes import play.api.routing.SimpleRouter import play.api.routing.sird._ -import javax.inject.{Inject, Singleton} - @Singleton class Router @Inject() ( caseCtrl: CaseCtrl, diff --git a/thehive/app/org/thp/thehive/controllers/v1/StatusCtrl.scala b/thehive/app/org/thp/thehive/controllers/v1/StatusCtrl.scala index 510ba46314..3930124ecd 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/StatusCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/StatusCtrl.scala @@ -1,16 +1,15 @@ package org.thp.thehive.controllers.v1 -import scala.util.Success - -import play.api.libs.json.{JsObject, JsString, Json} -import play.api.mvc.{AbstractController, Action, AnyContent, Results} - import javax.inject.{Inject, Singleton} import org.thp.scalligraph.ScalligraphApplicationLoader import org.thp.scalligraph.auth.{AuthCapability, AuthSrv, MultiAuthSrv} import org.thp.scalligraph.controllers.Entrypoint import org.thp.scalligraph.services.config.{ApplicationConfig, ConfigItem} import org.thp.thehive.TheHiveModule +import play.api.libs.json.{JsObject, JsString, Json} +import play.api.mvc.{AbstractController, Action, AnyContent, Results} + +import scala.util.Success @Singleton class StatusCtrl @Inject() (entrypoint: Entrypoint, appConfig: ApplicationConfig, authSrv: AuthSrv) { diff --git a/thehive/app/org/thp/thehive/models/Config.scala b/thehive/app/org/thp/thehive/models/Config.scala index fb2ad3788f..1711a4268e 100644 --- a/thehive/app/org/thp/thehive/models/Config.scala +++ b/thehive/app/org/thp/thehive/models/Config.scala @@ -1,8 +1,7 @@ package org.thp.thehive.models -import play.api.libs.json.JsValue - import org.thp.scalligraph.{EdgeEntity, VertexEntity} +import play.api.libs.json.JsValue @VertexEntity case class Config(name: String, value: JsValue) diff --git a/thehive/app/org/thp/thehive/models/ReportTag.scala b/thehive/app/org/thp/thehive/models/ReportTag.scala index 55f8aa3080..dfb15d53b8 100644 --- a/thehive/app/org/thp/thehive/models/ReportTag.scala +++ b/thehive/app/org/thp/thehive/models/ReportTag.scala @@ -1,8 +1,7 @@ package org.thp.thehive.models -import play.api.libs.json.JsValue - import org.thp.scalligraph.{EdgeEntity, VertexEntity} +import play.api.libs.json.JsValue object ReportTagLevel extends Enumeration { val info, safe, suspicious, malicious = Value diff --git a/thehive/app/org/thp/thehive/models/Task.scala b/thehive/app/org/thp/thehive/models/Task.scala index 20ffe49698..b16dda48a6 100644 --- a/thehive/app/org/thp/thehive/models/Task.scala +++ b/thehive/app/org/thp/thehive/models/Task.scala @@ -2,10 +2,9 @@ package org.thp.thehive.models import java.util.Date -import play.api.libs.json.{Format, Json} - import org.thp.scalligraph._ import org.thp.scalligraph.models.Entity +import play.api.libs.json.{Format, Json} object TaskStatus extends Enumeration { val Waiting, InProgress, Completed, Cancel = Value diff --git a/thehive/app/org/thp/thehive/services/AuditSrv.scala b/thehive/app/org/thp/thehive/services/AuditSrv.scala index 75891d625e..ec72c93c3e 100644 --- a/thehive/app/org/thp/thehive/services/AuditSrv.scala +++ b/thehive/app/org/thp/thehive/services/AuditSrv.scala @@ -28,7 +28,7 @@ class AuditSrv @Inject() ( userSrvProvider: Provider[UserSrv], @Named("notification-actor") notificationActor: ActorRef, eventSrv: EventSrv -)(implicit db: Database, schema: Schema) +)(implicit @Named("with-thehive-schema") db: Database, schema: Schema) extends VertexSrv[Audit, AuditSteps] { auditSrv => lazy val userSrv: UserSrv = userSrvProvider.get val auditUserSrv = new EdgeSrv[AuditUser, Audit, User] @@ -273,7 +273,8 @@ class AuditSrv @Inject() ( } @EntitySteps[Audit] -class AuditSteps(raw: GremlinScala[Vertex])(implicit db: Database, schema: Schema, graph: Graph) extends VertexSteps[Audit](raw) { +class AuditSteps(raw: GremlinScala[Vertex])(implicit @Named("with-thehive-schema") db: Database, schema: Schema, graph: Graph) + extends VertexSteps[Audit](raw) { def organisation: OrganisationSteps = new OrganisationSteps(getOrganisation(raw)) diff --git a/thehive/app/org/thp/thehive/services/Connector.scala b/thehive/app/org/thp/thehive/services/Connector.scala index a9ed645594..fec3027ce2 100644 --- a/thehive/app/org/thp/thehive/services/Connector.scala +++ b/thehive/app/org/thp/thehive/services/Connector.scala @@ -1,8 +1,7 @@ package org.thp.thehive.services -import play.api.libs.json.{JsObject, Json} - import org.thp.thehive.models.HealthStatus +import play.api.libs.json.{JsObject, Json} trait Connector { val name: String diff --git a/thehive/app/org/thp/thehive/services/notification/NotificationConfig.scala b/thehive/app/org/thp/thehive/services/notification/NotificationConfig.scala index bd000145aa..0a6262f1bf 100644 --- a/thehive/app/org/thp/thehive/services/notification/NotificationConfig.scala +++ b/thehive/app/org/thp/thehive/services/notification/NotificationConfig.scala @@ -1,11 +1,10 @@ package org.thp.thehive.services.notification +import org.thp.scalligraph.services.config.ApplicationConfig.configurationFormat import play.api.Configuration import play.api.libs.functional.syntax._ import play.api.libs.json.{JsPath, Json, Reads, Writes} -import org.thp.scalligraph.services.config.ApplicationConfig.configurationFormat - case class NotificationConfig(delegate: Boolean, triggerConfig: Configuration, notifierConfig: Configuration, roleRestriction: Set[String]) object NotificationConfig { diff --git a/thehive/app/org/thp/thehive/services/notification/NotificationSerializer.scala b/thehive/app/org/thp/thehive/services/notification/NotificationSerializer.scala index 7b1f336d65..5f93113634 100644 --- a/thehive/app/org/thp/thehive/services/notification/NotificationSerializer.scala +++ b/thehive/app/org/thp/thehive/services/notification/NotificationSerializer.scala @@ -2,9 +2,8 @@ package org.thp.thehive.services.notification import java.io.NotSerializableException -import play.api.libs.json.Json - import akka.serialization.Serializer +import play.api.libs.json.Json class NotificationSerializer extends Serializer { override def identifier: Int = 226591536 diff --git a/thehive/app/org/thp/thehive/services/notification/notifiers/AppendToFile.scala b/thehive/app/org/thp/thehive/services/notification/notifiers/AppendToFile.scala index a9c26b6549..bd80d8629e 100644 --- a/thehive/app/org/thp/thehive/services/notification/notifiers/AppendToFile.scala +++ b/thehive/app/org/thp/thehive/services/notification/notifiers/AppendToFile.scala @@ -3,16 +3,15 @@ package org.thp.thehive.services.notification.notifiers import java.nio.charset.Charset import java.nio.file.{Files, Paths, StandardOpenOption} -import scala.concurrent.{ExecutionContext, Future} -import scala.util.Try - -import play.api.Configuration - import gremlin.scala.Graph import javax.inject.{Inject, Singleton} import org.thp.scalligraph.models.Entity import org.thp.scalligraph.services.config.{ApplicationConfig, ConfigItem} import org.thp.thehive.models.{Audit, Organisation, User} +import play.api.Configuration + +import scala.concurrent.{ExecutionContext, Future} +import scala.util.Try @Singleton class AppendToFileProvider @Inject() (appConfig: ApplicationConfig, ec: ExecutionContext) extends NotifierProvider { diff --git a/thehive/app/org/thp/thehive/services/notification/notifiers/Emailer.scala b/thehive/app/org/thp/thehive/services/notification/notifiers/Emailer.scala index 6dc2c780d1..dff9901c77 100644 --- a/thehive/app/org/thp/thehive/services/notification/notifiers/Emailer.scala +++ b/thehive/app/org/thp/thehive/services/notification/notifiers/Emailer.scala @@ -1,14 +1,15 @@ package org.thp.thehive.services.notification.notifiers -import scala.concurrent.{ExecutionContext, Future} -import scala.util.{Success, Try} -import play.api.{Configuration, Logger} -import play.api.libs.mailer.{Email, MailerClient} import gremlin.scala.Graph import javax.inject.{Inject, Singleton} import org.thp.scalligraph.models.Entity import org.thp.scalligraph.services.config.{ApplicationConfig, ConfigItem} import org.thp.thehive.models.{Audit, Organisation, User} +import play.api.libs.mailer.{Email, MailerClient} +import play.api.{Configuration, Logger} + +import scala.concurrent.{ExecutionContext, Future} +import scala.util.{Success, Try} @Singleton class EmailerProvider @Inject() (appConfig: ApplicationConfig, mailerClient: MailerClient, ec: ExecutionContext) extends NotifierProvider { diff --git a/thehive/app/org/thp/thehive/services/notification/notifiers/Mattermost.scala b/thehive/app/org/thp/thehive/services/notification/notifiers/Mattermost.scala index a60ebb77c8..4259e10cea 100644 --- a/thehive/app/org/thp/thehive/services/notification/notifiers/Mattermost.scala +++ b/thehive/app/org/thp/thehive/services/notification/notifiers/Mattermost.scala @@ -1,18 +1,18 @@ package org.thp.thehive.services.notification.notifiers import akka.stream.Materializer - -import scala.concurrent.{ExecutionContext, Future} -import scala.util.{Success, Try} -import play.api.libs.json.{Json, Reads, Writes} -import play.api.libs.ws.WSClient -import play.api.{Configuration, Logger} import gremlin.scala.Graph import javax.inject.{Inject, Singleton} import org.thp.client.{ProxyWS, ProxyWSConfig} import org.thp.scalligraph.models.Entity import org.thp.scalligraph.services.config.{ApplicationConfig, ConfigItem} import org.thp.thehive.models.{Audit, Organisation, User} +import play.api.libs.json.{Json, Reads, Writes} +import play.api.libs.ws.WSClient +import play.api.{Configuration, Logger} + +import scala.concurrent.{ExecutionContext, Future} +import scala.util.{Success, Try} case class MattermostNotification(text: String, url: String, channel: Option[String], username: Option[String]) diff --git a/thehive/app/org/thp/thehive/services/notification/notifiers/Notifier.scala b/thehive/app/org/thp/thehive/services/notification/notifiers/Notifier.scala index 8be8129378..bf955faed9 100644 --- a/thehive/app/org/thp/thehive/services/notification/notifiers/Notifier.scala +++ b/thehive/app/org/thp/thehive/services/notification/notifiers/Notifier.scala @@ -1,14 +1,13 @@ package org.thp.thehive.services.notification.notifiers -import scala.concurrent.Future -import scala.util.{Failure, Success, Try} - -import play.api.{ConfigLoader, Configuration} - import gremlin.scala.Graph import org.thp.scalligraph.BadConfigurationError import org.thp.scalligraph.models.Entity import org.thp.thehive.models.{Audit, Organisation, User} +import play.api.{ConfigLoader, Configuration} + +import scala.concurrent.Future +import scala.util.{Failure, Success, Try} trait Notifier { diff --git a/thehive/app/org/thp/thehive/services/notification/notifiers/Template.scala b/thehive/app/org/thp/thehive/services/notification/notifiers/Template.scala index 621aebb3f4..710665f615 100644 --- a/thehive/app/org/thp/thehive/services/notification/notifiers/Template.scala +++ b/thehive/app/org/thp/thehive/services/notification/notifiers/Template.scala @@ -2,14 +2,14 @@ package org.thp.thehive.services.notification.notifiers import java.util.{HashMap => JHashMap} -import scala.collection.JavaConverters._ -import scala.util.Try - import com.github.jknack.handlebars.Handlebars import com.github.jknack.handlebars.helper.ConditionalHelpers import org.thp.scalligraph.models.Entity import org.thp.thehive.models.{Audit, User} +import scala.collection.JavaConverters._ +import scala.util.Try + trait Template { val handlebars: Handlebars = new Handlebars().registerHelpers(classOf[ConditionalHelpers]) diff --git a/thehive/app/org/thp/thehive/services/notification/triggers/AlertCreated.scala b/thehive/app/org/thp/thehive/services/notification/triggers/AlertCreated.scala index f67d913074..eff157e25b 100644 --- a/thehive/app/org/thp/thehive/services/notification/triggers/AlertCreated.scala +++ b/thehive/app/org/thp/thehive/services/notification/triggers/AlertCreated.scala @@ -1,11 +1,10 @@ package org.thp.thehive.services.notification.triggers -import scala.util.{Success, Try} - -import play.api.Configuration - import javax.inject.{Inject, Singleton} import org.thp.thehive.models.Audit +import play.api.Configuration + +import scala.util.{Success, Try} @Singleton class AlertCreatedProvider @Inject() extends TriggerProvider { diff --git a/thehive/app/org/thp/thehive/services/notification/triggers/CaseCreated.scala b/thehive/app/org/thp/thehive/services/notification/triggers/CaseCreated.scala index 88a9a043d3..7f3ed326fa 100644 --- a/thehive/app/org/thp/thehive/services/notification/triggers/CaseCreated.scala +++ b/thehive/app/org/thp/thehive/services/notification/triggers/CaseCreated.scala @@ -1,13 +1,12 @@ package org.thp.thehive.services.notification.triggers -import scala.util.{Success, Try} - -import play.api.Configuration - import gremlin.scala.Graph import javax.inject.{Inject, Singleton} import org.thp.scalligraph.models.Entity import org.thp.thehive.models.{Audit, Organisation, User} +import play.api.Configuration + +import scala.util.{Success, Try} @Singleton class CaseCreatedProvider @Inject() extends TriggerProvider { diff --git a/thehive/app/org/thp/thehive/services/notification/triggers/JobFinished.scala b/thehive/app/org/thp/thehive/services/notification/triggers/JobFinished.scala index 2f713b4e1a..83719ec413 100644 --- a/thehive/app/org/thp/thehive/services/notification/triggers/JobFinished.scala +++ b/thehive/app/org/thp/thehive/services/notification/triggers/JobFinished.scala @@ -1,11 +1,10 @@ package org.thp.thehive.services.notification.triggers -import scala.util.{Success, Try} - -import play.api.Configuration - import javax.inject.{Inject, Singleton} import org.thp.thehive.models.Audit +import play.api.Configuration + +import scala.util.{Success, Try} @Singleton class JobFinishedProvider @Inject() extends TriggerProvider { diff --git a/thehive/app/org/thp/thehive/services/notification/triggers/TaskAssigned.scala b/thehive/app/org/thp/thehive/services/notification/triggers/TaskAssigned.scala index 3dcab70566..c39378dd7d 100644 --- a/thehive/app/org/thp/thehive/services/notification/triggers/TaskAssigned.scala +++ b/thehive/app/org/thp/thehive/services/notification/triggers/TaskAssigned.scala @@ -1,15 +1,14 @@ package org.thp.thehive.services.notification.triggers -import scala.util.{Success, Try} - -import play.api.Configuration - import gremlin.scala.Graph import javax.inject.{Inject, Singleton} import org.thp.scalligraph.models.Entity import org.thp.scalligraph.steps.StepsOps._ import org.thp.thehive.models.{Audit, Organisation, User} import org.thp.thehive.services.TaskSrv +import play.api.Configuration + +import scala.util.{Success, Try} @Singleton class TaskAssignedProvider @Inject() (taskSrv: TaskSrv) extends TriggerProvider { diff --git a/thehive/app/org/thp/thehive/services/notification/triggers/Trigger.scala b/thehive/app/org/thp/thehive/services/notification/triggers/Trigger.scala index f561ac45c7..9ecbf381fc 100644 --- a/thehive/app/org/thp/thehive/services/notification/triggers/Trigger.scala +++ b/thehive/app/org/thp/thehive/services/notification/triggers/Trigger.scala @@ -1,13 +1,12 @@ package org.thp.thehive.services.notification.triggers -import scala.util.{Failure, Success, Try} - -import play.api.{ConfigLoader, Configuration} - import gremlin.scala.Graph import org.thp.scalligraph.BadConfigurationError import org.thp.scalligraph.models.Entity import org.thp.thehive.models.{Audit, Organisation, User} +import play.api.{ConfigLoader, Configuration} + +import scala.util.{Failure, Success, Try} trait Trigger { val name: String diff --git a/thehive/test/org/thp/thehive/controllers/v0/AlertCtrlTest.scala b/thehive/test/org/thp/thehive/controllers/v0/AlertCtrlTest.scala index 3a1928fce9..4c410afe35 100644 --- a/thehive/test/org/thp/thehive/controllers/v0/AlertCtrlTest.scala +++ b/thehive/test/org/thp/thehive/controllers/v0/AlertCtrlTest.scala @@ -2,16 +2,15 @@ package org.thp.thehive.controllers.v0 import java.util.Date -import play.api.libs.json.{JsNull, JsObject, JsString, Json} -import play.api.test.{FakeRequest, PlaySpecification} - import io.scalaland.chimney.dsl._ import org.thp.scalligraph.models.{Database, DummyUserSrv} import org.thp.scalligraph.steps.StepsOps._ import org.thp.thehive.TestAppBuilder import org.thp.thehive.dto.v0._ import org.thp.thehive.models.RichObservable -import org.thp.thehive.services.{CaseSrv, ObservableSrv} +import org.thp.thehive.services.CaseSrv +import play.api.libs.json.{JsNull, JsObject, JsString, Json} +import play.api.test.{FakeRequest, PlaySpecification} case class TestAlert( `type`: String, diff --git a/thehive/test/org/thp/thehive/controllers/v0/CaseCtrlTest.scala b/thehive/test/org/thp/thehive/controllers/v0/CaseCtrlTest.scala index da063fe58f..e06294e864 100644 --- a/thehive/test/org/thp/thehive/controllers/v0/CaseCtrlTest.scala +++ b/thehive/test/org/thp/thehive/controllers/v0/CaseCtrlTest.scala @@ -9,7 +9,7 @@ import org.thp.scalligraph.steps.StepsOps._ import org.thp.thehive.TestAppBuilder import org.thp.thehive.dto.v0._ import org.thp.thehive.services.{CaseSrv, TaskSrv} -import play.api.libs.json.{JsNull, JsObject, JsString, JsValue, Json} +import play.api.libs.json._ import play.api.test.{FakeRequest, PlaySpecification} case class TestCase( diff --git a/thehive/test/org/thp/thehive/controllers/v0/CaseTemplateCtrlTest.scala b/thehive/test/org/thp/thehive/controllers/v0/CaseTemplateCtrlTest.scala index cc98bf4169..67ef1fb220 100644 --- a/thehive/test/org/thp/thehive/controllers/v0/CaseTemplateCtrlTest.scala +++ b/thehive/test/org/thp/thehive/controllers/v0/CaseTemplateCtrlTest.scala @@ -1,13 +1,12 @@ package org.thp.thehive.controllers.v0 -import play.api.libs.json.Json -import play.api.test.{FakeRequest, PlaySpecification} - import org.thp.scalligraph.models.Database import org.thp.scalligraph.steps.StepsOps._ import org.thp.thehive.TestAppBuilder import org.thp.thehive.dto.v0.OutputCaseTemplate import org.thp.thehive.services.CaseTemplateSrv +import play.api.libs.json.Json +import play.api.test.{FakeRequest, PlaySpecification} class CaseTemplateCtrlTest extends PlaySpecification with TestAppBuilder { // val dummyUserSrv = DummyUserSrv(userId = "admin@thehive.local", permissions = Permissions.all) diff --git a/thehive/test/org/thp/thehive/controllers/v0/DashboardCtrlTest.scala b/thehive/test/org/thp/thehive/controllers/v0/DashboardCtrlTest.scala index 21a8c6bcb3..e0e25257ed 100644 --- a/thehive/test/org/thp/thehive/controllers/v0/DashboardCtrlTest.scala +++ b/thehive/test/org/thp/thehive/controllers/v0/DashboardCtrlTest.scala @@ -1,12 +1,12 @@ package org.thp.thehive.controllers.v0 import org.thp.scalligraph.models.Database +import org.thp.scalligraph.steps.StepsOps._ import org.thp.thehive.TestAppBuilder import org.thp.thehive.dto.v0.OutputDashboard import org.thp.thehive.services.DashboardSrv import play.api.libs.json.Json import play.api.test.{FakeRequest, PlaySpecification} -import org.thp.scalligraph.steps.StepsOps._ class DashboardCtrlTest extends PlaySpecification with TestAppBuilder { "dashboard controller" should { diff --git a/thehive/test/org/thp/thehive/controllers/v0/OrganisationCtrlTest.scala b/thehive/test/org/thp/thehive/controllers/v0/OrganisationCtrlTest.scala index e46fddbd96..3e1f11f21b 100644 --- a/thehive/test/org/thp/thehive/controllers/v0/OrganisationCtrlTest.scala +++ b/thehive/test/org/thp/thehive/controllers/v0/OrganisationCtrlTest.scala @@ -1,13 +1,12 @@ package org.thp.thehive.controllers.v0 -import play.api.libs.json.Json -import play.api.test.{FakeRequest, PlaySpecification} - import org.thp.scalligraph.models.Database import org.thp.scalligraph.steps.StepsOps._ import org.thp.thehive.TestAppBuilder import org.thp.thehive.dto.v0.{InputOrganisation, OutputOrganisation} import org.thp.thehive.services.OrganisationSrv +import play.api.libs.json.Json +import play.api.test.{FakeRequest, PlaySpecification} class OrganisationCtrlTest extends PlaySpecification with TestAppBuilder { "organisation controller" should { diff --git a/thehive/test/org/thp/thehive/controllers/v0/PageCtrlTest.scala b/thehive/test/org/thp/thehive/controllers/v0/PageCtrlTest.scala index 9078c8c624..ce8d638f69 100644 --- a/thehive/test/org/thp/thehive/controllers/v0/PageCtrlTest.scala +++ b/thehive/test/org/thp/thehive/controllers/v0/PageCtrlTest.scala @@ -1,13 +1,12 @@ package org.thp.thehive.controllers.v0 -import play.api.libs.json.Json -import play.api.test.{FakeRequest, PlaySpecification} - import org.thp.scalligraph.models.Database import org.thp.scalligraph.steps.StepsOps._ import org.thp.thehive.TestAppBuilder import org.thp.thehive.dto.v0.OutputPage import org.thp.thehive.services.PageSrv +import play.api.libs.json.Json +import play.api.test.{FakeRequest, PlaySpecification} class PageCtrlTest extends PlaySpecification with TestAppBuilder { // val dummyUserSrv = DummyUserSrv(userId = "admin@thehive.local", permissions = Permissions.all) diff --git a/thehive/test/org/thp/thehive/controllers/v0/StreamCtrlTest.scala b/thehive/test/org/thp/thehive/controllers/v0/StreamCtrlTest.scala index 25e502e995..fa82604aa2 100644 --- a/thehive/test/org/thp/thehive/controllers/v0/StreamCtrlTest.scala +++ b/thehive/test/org/thp/thehive/controllers/v0/StreamCtrlTest.scala @@ -2,13 +2,12 @@ package org.thp.thehive.controllers.v0 import java.util.Date -import play.api.test.{FakeRequest, PlaySpecification} - import org.thp.scalligraph.auth.AuthContext import org.thp.scalligraph.models.{Database, DummyUserSrv} import org.thp.thehive.TestAppBuilder import org.thp.thehive.models._ import org.thp.thehive.services.{CaseSrv, OrganisationSrv} +import play.api.test.{FakeRequest, PlaySpecification} class StreamCtrlTest extends PlaySpecification with TestAppBuilder { "stream controller" should { diff --git a/thehive/test/org/thp/thehive/models/TagTest.scala b/thehive/test/org/thp/thehive/models/TagTest.scala index 42dce1500f..f1e093e4ae 100644 --- a/thehive/test/org/thp/thehive/models/TagTest.scala +++ b/thehive/test/org/thp/thehive/models/TagTest.scala @@ -11,7 +11,7 @@ class TagTest extends PlaySpecification { "be parsed from key:value" in { val tag = parseTag("Module:atest_blah_blah") tag must beEqualTo(Tag(defaultNamespace, "Module", Some("atest_blah_blah"), None, defaultColor)) - tag.toString must beEqualTo("Module\"atest_blah_blah\"") + tag.toString must beEqualTo("Module=\"atest_blah_blah\"") } "be parsed from key:value=" in { diff --git a/thehive/test/org/thp/thehive/services/AlertSrvTest.scala b/thehive/test/org/thp/thehive/services/AlertSrvTest.scala index 8f74d444a0..151c98117f 100644 --- a/thehive/test/org/thp/thehive/services/AlertSrvTest.scala +++ b/thehive/test/org/thp/thehive/services/AlertSrvTest.scala @@ -2,15 +2,14 @@ package org.thp.thehive.services import java.util.Date -import play.api.libs.json.JsString -import play.api.test.PlaySpecification - import org.thp.scalligraph.CreateError import org.thp.scalligraph.auth.AuthContext import org.thp.scalligraph.models._ import org.thp.scalligraph.steps.StepsOps._ import org.thp.thehive.TestAppBuilder import org.thp.thehive.models._ +import play.api.libs.json.JsString +import play.api.test.PlaySpecification class AlertSrvTest extends PlaySpecification with TestAppBuilder { implicit val authContext: AuthContext = DummyUserSrv(userId = "certuser@thehive.local", organisation = "cert").authContext diff --git a/thehive/test/org/thp/thehive/services/AttachmentSrvTest.scala b/thehive/test/org/thp/thehive/services/AttachmentSrvTest.scala index edaa459c56..bff38c1376 100644 --- a/thehive/test/org/thp/thehive/services/AttachmentSrvTest.scala +++ b/thehive/test/org/thp/thehive/services/AttachmentSrvTest.scala @@ -4,17 +4,16 @@ import java.io.{File, InputStream} import java.nio.file.{Path, Files => JFiles} import java.util.UUID -import scala.annotation.tailrec - -import play.api.libs.Files -import play.api.libs.Files.TemporaryFileCreator -import play.api.test.{NoTemporaryFileCreator, PlaySpecification} - import org.thp.scalligraph.auth.AuthContext import org.thp.scalligraph.controllers.FFile import org.thp.scalligraph.models._ import org.thp.scalligraph.steps.StepsOps._ import org.thp.thehive.TestAppBuilder +import play.api.libs.Files +import play.api.libs.Files.TemporaryFileCreator +import play.api.test.{NoTemporaryFileCreator, PlaySpecification} + +import scala.annotation.tailrec class AttachmentSrvTest extends PlaySpecification with TestAppBuilder { implicit val authContext: AuthContext = DummyUserSrv(userId = "certuser@thehive.local", organisation = "cert").getSystemAuthContext @@ -30,7 +29,8 @@ class AttachmentSrvTest extends PlaySpecification with TestAppBuilder { "attachment service" should { "create an attachment from a file" in testApp { app => WithFakeScalligraphFile { tempFile => - val r = app[Database].tryTransaction(implicit graph => app[AttachmentSrv].create(FFile("test.txt", tempFile.path, "text/plain"))) + val r = + app[Database].tryTransaction(implicit graph => app[AttachmentSrv].create(FFile("test.txt", tempFile.path, "text/plain"))) r must beSuccessfulTry.which { a => a.name shouldEqual "test.txt" diff --git a/thehive/test/org/thp/thehive/services/AuditSrvTest.scala b/thehive/test/org/thp/thehive/services/AuditSrvTest.scala index de98350723..8a1a4ac9d7 100644 --- a/thehive/test/org/thp/thehive/services/AuditSrvTest.scala +++ b/thehive/test/org/thp/thehive/services/AuditSrvTest.scala @@ -2,57 +2,55 @@ package org.thp.thehive.services import java.util.Date -import play.api.test.PlaySpecification - import org.apache.tinkerpop.gremlin.process.traversal.Order import org.thp.scalligraph.auth.AuthContext import org.thp.scalligraph.models._ import org.thp.scalligraph.steps.StepsOps._ import org.thp.thehive.TestAppBuilder import org.thp.thehive.models._ +import play.api.test.PlaySpecification class AuditSrvTest extends PlaySpecification with TestAppBuilder { implicit val authContext: AuthContext = DummyUserSrv(userId = "certuser@thehive.local", organisation = "cert").getSystemAuthContext "audit service" should { "get main audits by ids and sorted" in testApp { app => - app[Database].roTransaction(implicit graph => { + app[Database].roTransaction { implicit graph => // Create 3 case events first val orgAdmin = app[OrganisationSrv].getOrFail("admin").get val c1 = app[Database] - .tryTransaction( - implicit graph => - app[CaseSrv].create( - Case(0, "case audit", "desc audit", 1, new Date(), None, flag = false, 1, 1, CaseStatus.Open, None), - None, - orgAdmin, - Set.empty, - Map.empty, - None, - Nil - ) + .tryTransaction(implicit graph => + app[CaseSrv].create( + Case(0, "case audit", "desc audit", 1, new Date(), None, flag = false, 1, 1, CaseStatus.Open, None), + None, + orgAdmin, + Set.empty, + Map.empty, + None, + Nil + ) ) .get app[CaseSrv].updateTagNames(c1.`case`, Set("lol")) - app[Database].tryTransaction(implicit graph => { + app[Database].tryTransaction { implicit graph => val t = app[TaskSrv].create(Task("test audit", "", None, TaskStatus.Waiting, flag = false, None, None, 0, None), None) app[ShareSrv].shareTask(t.get, c1.`case`, orgAdmin) - }) + } val audits = app[AuditSrv].initSteps.toList val r = app[AuditSrv].getMainByIds(Order.asc, audits.map(_._id): _*).toList // Only the main ones r.head shouldEqual audits.filter(_.mainAction).minBy(_._createdAt) - }) + } } "merge audits" in testApp { app => val auditedTask = app[Database] - .tryTransaction( - implicit graph => app[TaskSrv].create(Task("test audit 1", "", None, TaskStatus.Waiting, flag = false, None, None, 0, None), None) + .tryTransaction(implicit graph => + app[TaskSrv].create(Task("test audit 1", "", None, TaskStatus.Waiting, flag = false, None, None, 0, None), None) ) .get - app[Database].tryTransaction(implicit graph => { + app[Database].tryTransaction { implicit graph => app[AuditSrv].mergeAudits(app[TaskSrv].update(app[TaskSrv].get(auditedTask._id), Nil)) { case (taskSteps, updatedFields) => taskSteps @@ -60,7 +58,7 @@ class AuditSrvTest extends PlaySpecification with TestAppBuilder { .getOrFail() .flatMap(app[AuditSrv].task.update(_, updatedFields)) } - }) must beSuccessfulTry + } must beSuccessfulTry } } } diff --git a/thehive/test/org/thp/thehive/services/CaseSrvTest.scala b/thehive/test/org/thp/thehive/services/CaseSrvTest.scala index c39a1da27a..9dcab465d1 100644 --- a/thehive/test/org/thp/thehive/services/CaseSrvTest.scala +++ b/thehive/test/org/thp/thehive/services/CaseSrvTest.scala @@ -2,11 +2,6 @@ package org.thp.thehive.services import java.util.Date -import scala.util.Success - -import play.api.libs.json.Json -import play.api.test.PlaySpecification - import org.specs2.matcher.Matcher import org.thp.scalligraph.CreateError import org.thp.scalligraph.auth.AuthContext @@ -16,6 +11,10 @@ import org.thp.scalligraph.query.PropertyUpdater import org.thp.scalligraph.steps.StepsOps._ import org.thp.thehive.TestAppBuilder import org.thp.thehive.models._ +import play.api.libs.json.Json +import play.api.test.PlaySpecification + +import scala.util.Success class CaseSrvTest extends PlaySpecification with TestAppBuilder { implicit val authContext: AuthContext = DummyUserSrv(userId = "certuser@thehive.local", organisation = "cert").authContext @@ -376,7 +375,8 @@ class CaseSrvTest extends PlaySpecification with TestAppBuilder { .get .`case` - def checkAssignee(status: Matcher[Boolean]) = app[Database].roTransaction(implicit graph => app[CaseSrv].get(c8).assignee.exists() must status) + def checkAssignee(status: Matcher[Boolean]) = + app[Database].roTransaction(implicit graph => app[CaseSrv].get(c8).assignee.exists() must status) checkAssignee(beTrue) app[Database].tryTransaction(implicit graph => app[CaseSrv].unassign(c8)) must beSuccessfulTry diff --git a/thehive/test/org/thp/thehive/services/CaseTemplateSrvTest.scala b/thehive/test/org/thp/thehive/services/CaseTemplateSrvTest.scala index 2ef1fac1b2..f80f73d150 100644 --- a/thehive/test/org/thp/thehive/services/CaseTemplateSrvTest.scala +++ b/thehive/test/org/thp/thehive/services/CaseTemplateSrvTest.scala @@ -1,13 +1,12 @@ package org.thp.thehive.services -import play.api.libs.json.{JsNumber, JsString, JsTrue, JsValue} -import play.api.test.PlaySpecification - import org.thp.scalligraph.auth.AuthContext import org.thp.scalligraph.models._ import org.thp.scalligraph.steps.StepsOps._ import org.thp.thehive.TestAppBuilder import org.thp.thehive.models._ +import play.api.libs.json.{JsNumber, JsString, JsTrue, JsValue} +import play.api.test.PlaySpecification class CaseTemplateSrvTest extends PlaySpecification with TestAppBuilder { implicit val authcontext: AuthContext = DummyUserSrv(userId = "certuser@thehive.local", organisation = "cert").authContext diff --git a/thehive/test/org/thp/thehive/services/ConfigSrvTest.scala b/thehive/test/org/thp/thehive/services/ConfigSrvTest.scala index 5d62b8b043..61b2cbc794 100644 --- a/thehive/test/org/thp/thehive/services/ConfigSrvTest.scala +++ b/thehive/test/org/thp/thehive/services/ConfigSrvTest.scala @@ -1,11 +1,10 @@ package org.thp.thehive.services -import play.api.libs.json.{JsBoolean, JsString} -import play.api.test.PlaySpecification - import org.thp.scalligraph.auth.AuthContext import org.thp.scalligraph.models._ import org.thp.thehive.TestAppBuilder +import play.api.libs.json.{JsBoolean, JsString} +import play.api.test.PlaySpecification class ConfigSrvTest extends PlaySpecification with TestAppBuilder { implicit val authContext: AuthContext = DummyUserSrv(userId = "certuser@thehive.local", organisation = "cert").authContext diff --git a/thehive/test/org/thp/thehive/services/CustomFieldSrvTest.scala b/thehive/test/org/thp/thehive/services/CustomFieldSrvTest.scala index a6824b0b85..ea44ab8f82 100644 --- a/thehive/test/org/thp/thehive/services/CustomFieldSrvTest.scala +++ b/thehive/test/org/thp/thehive/services/CustomFieldSrvTest.scala @@ -1,12 +1,11 @@ package org.thp.thehive.services -import play.api.libs.json._ -import play.api.test.PlaySpecification - import org.thp.scalligraph.auth.AuthContext import org.thp.scalligraph.models._ import org.thp.thehive.TestAppBuilder import org.thp.thehive.models._ +import play.api.libs.json._ +import play.api.test.PlaySpecification class CustomFieldSrvTest extends PlaySpecification with TestAppBuilder { implicit val authContext: AuthContext = DummyUserSrv(userId = "certuser@thehive.local", organisation = "cert").authContext diff --git a/thehive/test/org/thp/thehive/services/DashboardSrvTest.scala b/thehive/test/org/thp/thehive/services/DashboardSrvTest.scala index 673fcd1c7f..64cdc41834 100644 --- a/thehive/test/org/thp/thehive/services/DashboardSrvTest.scala +++ b/thehive/test/org/thp/thehive/services/DashboardSrvTest.scala @@ -1,12 +1,12 @@ package org.thp.thehive.services -import play.api.test.PlaySpecification import org.thp.scalligraph.auth.AuthContext import org.thp.scalligraph.models._ import org.thp.scalligraph.steps.StepsOps._ import org.thp.thehive.TestAppBuilder import org.thp.thehive.models._ import play.api.libs.json.{JsObject, Json} +import play.api.test.PlaySpecification class DashboardSrvTest extends PlaySpecification with TestAppBuilder { implicit val authContext: AuthContext = DummyUserSrv(userId = "certuser@thehive.local", organisation = "cert").authContext diff --git a/thehive/test/org/thp/thehive/services/DataSrvTest.scala b/thehive/test/org/thp/thehive/services/DataSrvTest.scala index b73b1f7b57..c4195a8ee7 100644 --- a/thehive/test/org/thp/thehive/services/DataSrvTest.scala +++ b/thehive/test/org/thp/thehive/services/DataSrvTest.scala @@ -1,12 +1,11 @@ package org.thp.thehive.services -import play.api.test.PlaySpecification - import org.thp.scalligraph.auth.AuthContext import org.thp.scalligraph.models._ import org.thp.scalligraph.steps.StepsOps._ import org.thp.thehive.TestAppBuilder import org.thp.thehive.models._ +import play.api.test.PlaySpecification class DataSrvTest extends PlaySpecification with TestAppBuilder { implicit val authContext: AuthContext = DummyUserSrv(userId = "certuser@thehive.local", organisation = "cert").authContext diff --git a/thehive/test/org/thp/thehive/services/ImpactStatusSrvTest.scala b/thehive/test/org/thp/thehive/services/ImpactStatusSrvTest.scala index 5b4548efdf..6476fb72aa 100644 --- a/thehive/test/org/thp/thehive/services/ImpactStatusSrvTest.scala +++ b/thehive/test/org/thp/thehive/services/ImpactStatusSrvTest.scala @@ -1,11 +1,10 @@ package org.thp.thehive.services -import play.api.test.PlaySpecification - import org.thp.scalligraph.models._ import org.thp.scalligraph.steps.StepsOps._ import org.thp.thehive.TestAppBuilder import org.thp.thehive.models._ +import play.api.test.PlaySpecification class ImpactStatusSrvTest extends PlaySpecification with TestAppBuilder { "impact status service" should { diff --git a/thehive/test/org/thp/thehive/services/LocalPasswordAuthSrvTest.scala b/thehive/test/org/thp/thehive/services/LocalPasswordAuthSrvTest.scala index 75cc0afc1c..6244b871da 100644 --- a/thehive/test/org/thp/thehive/services/LocalPasswordAuthSrvTest.scala +++ b/thehive/test/org/thp/thehive/services/LocalPasswordAuthSrvTest.scala @@ -1,12 +1,11 @@ package org.thp.thehive.services +import org.thp.scalligraph.models.Database +import org.thp.thehive.TestAppBuilder import play.api.Configuration import play.api.libs.json.Json import play.api.test.{FakeRequest, PlaySpecification} -import org.thp.scalligraph.models.Database -import org.thp.thehive.TestAppBuilder - class LocalPasswordAuthSrvTest extends PlaySpecification with TestAppBuilder { "localPasswordAuth service" should { "be able to verify passwords" in testApp { app => diff --git a/thehive/test/org/thp/thehive/services/ObservableSrvTest.scala b/thehive/test/org/thp/thehive/services/ObservableSrvTest.scala index 28da3dc459..16a2a84341 100644 --- a/thehive/test/org/thp/thehive/services/ObservableSrvTest.scala +++ b/thehive/test/org/thp/thehive/services/ObservableSrvTest.scala @@ -1,58 +1,57 @@ -package org.thp.thehive.services - -import play.api.test.PlaySpecification - -import org.thp.scalligraph.RichSeq -import org.thp.scalligraph.auth.AuthContext -import org.thp.scalligraph.models.{Database, DummyUserSrv} -import org.thp.thehive.TestAppBuilder -import org.thp.thehive.models._ - -class ObservableSrvTest extends PlaySpecification with TestAppBuilder { - implicit val authContext: AuthContext = DummyUserSrv(userId = "admin@thehive.local").authContext - - def printTiming[A](message: String)(body: => A): A = { - val start = System.currentTimeMillis() - val ret = body - val time = System.currentTimeMillis() - start - println(s"$message: $time ms") - ret - } - - "observable service" should { - "create observable" in testApp { app => - val observable = Observable(Some("test observable message"), 2, ioc = false, sighted = false) - val observableSrv = app[ObservableSrv] - val observableTypeSrv = app[ObservableTypeSrv] - val dataSrv = app[DataSrv] - val tagNames = Set("t1", "t2", "t3") - - (1 to 100).map(i => s"data$i").toTry { dataValue => - println("====================================") - printTiming("transaction") { - app[Database].tryTransaction { implicit graph => - printTiming("createObservable") { - for { - createdObservable <- printTiming("createEntity")(observableSrv.createEntity(observable)) - tpe <- printTiming("getType")(observableTypeSrv.getOrFail("domain")) - _ <- printTiming("linkType")(observableSrv.observableObservableType.create(ObservableObservableType(), createdObservable, tpe)) - data <- printTiming("createData")(dataSrv.create(Data(dataValue))) - _ <- printTiming("linkData")(observableSrv.observableDataSrv.create(ObservableData(), createdObservable, data)) - tags <- printTiming("createTags")(observableSrv.addTags(createdObservable, tagNames)) - // ext <- observableSrv.addExtensions(createdObservable, extensions) - } yield RichObservable(createdObservable, tpe, Some(data), None, tags, None, Nil, Nil) - } - } - } - } must beSuccessfulTry - } - } -} -/* -observableType <- observableTypeSrv.getOrFail(inputObservable.`type`) -case Left(data) => observableSrv.create(inputObservable.observable, observableType, data, inputObservable.tags, Nil) - } - case0 <- caseSrv.getOrFail(caseId) - orgs <- inputObservable.organisations.toTry(organisationSrv.getOrFail) - _ <- orgs.toTry(o => shareSrv.shareObservable(richObservable, case0, o)) - */ +//package org.thp.thehive.services +// +//import org.thp.scalligraph.RichSeq +//import org.thp.scalligraph.auth.AuthContext +//import org.thp.scalligraph.models.{Database, DummyUserSrv} +//import org.thp.thehive.TestAppBuilder +//import org.thp.thehive.models._ +//import play.api.test.PlaySpecification +// +//class ObservableSrvTest extends PlaySpecification with TestAppBuilder { +// implicit val authContext: AuthContext = DummyUserSrv(userId = "admin@thehive.local").authContext +// +// def printTiming[A](message: String)(body: => A): A = { +// val start = System.currentTimeMillis() +// val ret = body +// val time = System.currentTimeMillis() - start +// println(s"$message: $time ms") +// ret +// } +// +// "observable service" should { +// "create observable" in testApp { app => +// val observable = Observable(Some("test observable message"), 2, ioc = false, sighted = false) +// val observableSrv = app[ObservableSrv] +// val observableTypeSrv = app[ObservableTypeSrv] +// val dataSrv = app[DataSrv] +// val tagNames = Set("t1", "t2", "t3") +// +// (1 to 100).map(i => s"data$i").toTry { dataValue => +// println("====================================") +// printTiming("transaction") { +// app[Database].tryTransaction { implicit graph => +// printTiming("createObservable") { +// for { +// createdObservable <- printTiming("createEntity")(observableSrv.createEntity(observable)) +// tpe <- printTiming("getType")(observableTypeSrv.getOrFail("domain")) +// _ <- printTiming("linkType")(observableSrv.observableObservableType.create(ObservableObservableType(), createdObservable, tpe)) +// data <- printTiming("createData")(dataSrv.create(Data(dataValue))) +// _ <- printTiming("linkData")(observableSrv.observableDataSrv.create(ObservableData(), createdObservable, data)) +// tags <- printTiming("createTags")(observableSrv.addTags(createdObservable, tagNames)) +// // ext <- observableSrv.addExtensions(createdObservable, extensions) +// } yield RichObservable(createdObservable, tpe, Some(data), None, tags, None, Nil, Nil) +// } +// } +// } +// } must beSuccessfulTry +// } +// } +//} +///* +//observableType <- observableTypeSrv.getOrFail(inputObservable.`type`) +//case Left(data) => observableSrv.create(inputObservable.observable, observableType, data, inputObservable.tags, Nil) +// } +// case0 <- caseSrv.getOrFail(caseId) +// orgs <- inputObservable.organisations.toTry(organisationSrv.getOrFail) +// _ <- orgs.toTry(o => shareSrv.shareObservable(richObservable, case0, o)) +// */ diff --git a/thehive/test/org/thp/thehive/services/OrganisationSrvTest.scala b/thehive/test/org/thp/thehive/services/OrganisationSrvTest.scala index d524f53ec2..c8c3056afb 100644 --- a/thehive/test/org/thp/thehive/services/OrganisationSrvTest.scala +++ b/thehive/test/org/thp/thehive/services/OrganisationSrvTest.scala @@ -1,11 +1,10 @@ package org.thp.thehive.services -import play.api.test.PlaySpecification - import org.thp.scalligraph.auth.AuthContext import org.thp.scalligraph.models.{Database, DummyUserSrv} import org.thp.thehive.TestAppBuilder import org.thp.thehive.models._ +import play.api.test.PlaySpecification class OrganisationSrvTest extends PlaySpecification with TestAppBuilder { implicit val authContext: AuthContext = DummyUserSrv(userId = "admin@thehive.local").authContext diff --git a/thehive/test/org/thp/thehive/services/notification/notifiers/NotificationTemplateTest.scala b/thehive/test/org/thp/thehive/services/notification/notifiers/NotificationTemplateTest.scala index fa5655a89a..777e86c595 100644 --- a/thehive/test/org/thp/thehive/services/notification/notifiers/NotificationTemplateTest.scala +++ b/thehive/test/org/thp/thehive/services/notification/notifiers/NotificationTemplateTest.scala @@ -2,15 +2,14 @@ package org.thp.thehive.services.notification.notifiers import java.util.{HashMap => JHashMap} -import scala.collection.JavaConverters._ - -import play.api.test.PlaySpecification - import org.thp.scalligraph.auth.AuthContext import org.thp.scalligraph.models.{Database, DummyUserSrv} import org.thp.scalligraph.steps.StepsOps._ import org.thp.thehive.TestAppBuilder import org.thp.thehive.services.{AuditSrv, CaseSrv, UserSrv} +import play.api.test.PlaySpecification + +import scala.collection.JavaConverters._ class NotificationTemplateTest extends PlaySpecification with TestAppBuilder { implicit val authContext: AuthContext = DummyUserSrv(userId = "certuser@thehive.local").authContext @@ -25,11 +24,11 @@ class NotificationTemplateTest extends PlaySpecification with TestAppBuilder { |The {{audit.objectType}} {{audit.objectId}} has been {{audit.action}}d by {{audit._createdBy}} | |{{#with object~}} - | {{#if (eq _type "Case")}} - | {{~title}} - | {{else}} - | {{~_type}} is not a case - | {{/if}} + |{{#if (eq _type "Case")}} + |{{~title}} + |{{else}} + |{{~_type}} is not a case + |{{/if}} |{{~/with}} | |Audit ({{audit.requestId}}): {{audit.action}} {{audit.objectType}} {{audit.objectId}} by {{audit._createdBy}} @@ -50,7 +49,7 @@ class NotificationTemplateTest extends PlaySpecification with TestAppBuilder { |The Case 2231 has been created by admin@thehive.local | |case title - | + | | |Audit (testRequest): create Case 2231 by admin@thehive.local |Context 2231""".stripMargin) @@ -64,11 +63,11 @@ class NotificationTemplateTest extends PlaySpecification with TestAppBuilder { |The {{audit.objectType}} {{audit.objectId}} has been {{audit.action}}d by {{audit._createdBy}} | |{{#with object~}} - | {{#if (eq _type "Case")}} - | {{~title}} - | {{else}} - | {{~_type}} is not a case - | {{/if}} + |{{#if (eq _type "Case")}} + |{{~title}} + |{{else}} + |{{~_type}} is not a case + |{{/if}} |{{~/with}} | |Audit ({{audit.requestId}}): {{audit.action}} {{audit.objectType}} {{audit.objectId}} by {{audit._createdBy}} @@ -91,7 +90,7 @@ class NotificationTemplateTest extends PlaySpecification with TestAppBuilder { |The Case \d+ has been updated by certuser@thehive.local | |case#1 - | + | | |Audit \(testRequest\): update Case \d+ by certuser@thehive.local |Context \d+""".stripMargin) diff --git a/thehive/test/org/thp/thehive/services/notification/triggers/AlertCreatedTest.scala b/thehive/test/org/thp/thehive/services/notification/triggers/AlertCreatedTest.scala index 30d6d8326a..4695e5f20b 100644 --- a/thehive/test/org/thp/thehive/services/notification/triggers/AlertCreatedTest.scala +++ b/thehive/test/org/thp/thehive/services/notification/triggers/AlertCreatedTest.scala @@ -2,15 +2,14 @@ package org.thp.thehive.services.notification.triggers import java.util.Date -import play.api.libs.json.{JsObject, Json} -import play.api.test.{FakeRequest, PlaySpecification} - import org.thp.scalligraph.models.Database import org.thp.scalligraph.steps.StepsOps._ import org.thp.thehive.TestAppBuilder import org.thp.thehive.controllers.v0.AlertCtrl import org.thp.thehive.dto.v0.{InputAlert, OutputAlert} import org.thp.thehive.services.{AlertSrv, AuditSrv, OrganisationSrv, UserSrv} +import play.api.libs.json.{JsObject, Json} +import play.api.test.{FakeRequest, PlaySpecification} class AlertCreatedTest extends PlaySpecification with TestAppBuilder { diff --git a/thehive/test/org/thp/thehive/services/notification/triggers/TaskAssignedTest.scala b/thehive/test/org/thp/thehive/services/notification/triggers/TaskAssignedTest.scala index bc8423ff0d..6e90e12944 100644 --- a/thehive/test/org/thp/thehive/services/notification/triggers/TaskAssignedTest.scala +++ b/thehive/test/org/thp/thehive/services/notification/triggers/TaskAssignedTest.scala @@ -1,12 +1,11 @@ package org.thp.thehive.services.notification.triggers -import play.api.test.PlaySpecification - import org.thp.scalligraph.auth.AuthContext import org.thp.scalligraph.models.{Database, DummyUserSrv} import org.thp.scalligraph.steps.StepsOps._ import org.thp.thehive.TestAppBuilder import org.thp.thehive.services._ +import play.api.test.PlaySpecification class TaskAssignedTest extends PlaySpecification with TestAppBuilder { implicit val authContext: AuthContext = DummyUserSrv(userId = "certadmin@thehive.local").authContext