Skip to content

Commit

Permalink
#2334 Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Feb 4, 2022
1 parent 431760c commit 364902c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class AttachmentCtrl @Inject() (
header = ResponseHeader(
200,
Map(
"Content-Disposition" -> s"""attachment; ${HttpHeaderParameterEncoding.encode("filename", filename)}.zip""",
"Content-Disposition" -> s"""attachment; ${HttpHeaderParameterEncoding.encode("filename", s"$filename.zip")}""",
"Content-Type" -> "application/zip",
"Content-Transfer-Encoding" -> "binary",
"Content-Length" -> Files.size(f).toString
Expand Down
10 changes: 10 additions & 0 deletions thehive/test/org/thp/thehive/TestAppBuilder.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.thp.thehive

import akka.actor.ActorSystem
import akka.actor.typed.scaladsl.Behaviors
import akka.actor.typed.{ActorRef => TypedActorRef}
import akka.actor.typed.scaladsl.adapter.ClassicActorSystemOps
import org.apache.commons.io.FileUtils
Expand All @@ -18,6 +19,7 @@ import org.thp.thehive.services.{UserSrv => _, _}

import java.io.File
import java.nio.file.{Files, Paths}
import java.util.UUID
import javax.inject.{Inject, Provider, Singleton}
import scala.util.Try

Expand Down Expand Up @@ -60,6 +62,7 @@ trait TestAppBuilder {
)
.bindActor[DummyActor]("config-actor")
.bindActor[DummyActor]("notification-actor")
.bindToProvider[TypedActorRef[IntegrityCheck.Request], DummyTypedActorProvider[IntegrityCheck.Request]]
.bindActor[DummyActor]("integrity-check-actor")
.bindActor[DummyActor]("flow-actor")
.addConfiguration("auth.providers = [{name:local},{name:key},{name:header, userHeader:user}]")
Expand Down Expand Up @@ -135,3 +138,10 @@ class TestNumberActorProvider @Inject() (actorSystem: ActorSystem) extends Provi
.toTyped
.systemActorOf(CaseNumberActor.caseNumberProvider(getNextNumber = () => 36, reloadTimer = () => (), nextNumber = 36), "case-number")
}

class DummyTypedActorProvider[T] @Inject() (actorSystem: ActorSystem) extends Provider[TypedActorRef[T]] {
override def get(): TypedActorRef[T] =
actorSystem
.toTyped
.systemActorOf(Behaviors.empty, UUID.randomUUID().toString)
}
3 changes: 2 additions & 1 deletion thehive/test/org/thp/thehive/services/UserSrvTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.thp.thehive.services.OrganisationOps._
import org.thp.thehive.services.UserOps._
import play.api.test.PlaySpecification

import scala.concurrent.duration.DurationInt
import scala.util.{Failure, Success}

class UserSrvTest extends PlaySpecification with TestAppBuilder {
Expand Down Expand Up @@ -73,7 +74,7 @@ class UserSrvTest extends PlaySpecification with TestAppBuilder {
if (userCount == 2) Success(())
else Failure(new Exception(s"User certadmin is not in cert organisation twice ($userCount)"))
}
new UserIntegrityCheck(db, userSrv, profileSrv, organisationSrv, roleSrv).dedup(KillSwitch.alwaysOn)
new UserIntegrityCheck(db, userSrv, profileSrv, organisationSrv, roleSrv).runGlobalCheck(5.minutes, KillSwitch.alwaysOn)
db.roTransaction { implicit graph =>
val userCount = userSrv.get(EntityName("[email protected]")).organisations.get(EntityName("cert")).getCount
userCount must beEqualTo(1)
Expand Down

0 comments on commit 364902c

Please sign in to comment.