diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f402938..8a8f977 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,9 +20,9 @@ jobs: with: java-version: adopt@1.11 - name: StaticAnalysis - run: sbt clean scalafmtCheck test:scalafmtCheck scalafmtSbtCheck scapegoat + run: sbt -Dsbt.color=always -Dsbt.supershell=false clean scalafmtCheck test:scalafmtCheck scalafmtSbtCheck scapegoat - name: Tests - run: sbt clean coverage test coverageReport coverageAggregate + run: sbt -Dsbt.color=always -Dsbt.supershell=false clean coverage test coverageReport coverageAggregate publish: if: github.event_name == 'push' runs-on: ubuntu-latest @@ -40,10 +40,10 @@ jobs: with: java-version: adopt@1.11 - name: PublishToBintray - run: sbt releaseEarly + run: sbt -Dsbt.color=always -Dsbt.supershell=false releaseEarly - name: PublishToDockerHub run: | - sbt docker:publishLocal + sbt -Dsbt.color=always -Dsbt.supershell=false docker:publishLocal echo ${{ secrets.DOCKER_PASS }} | docker login --username ${{ secrets.DOCKER_USER }} --password-stdin docker push bluebrain/nexus-iam:latest - name: TriggerIntegrationTests @@ -63,7 +63,7 @@ jobs: -o /dev/null \ ${{ secrets.JOB_ADDRESS }} - name: RecordCoverage - run: sbt clean coverage test coverageReport coverageAggregate + run: sbt -Dsbt.color=always -Dsbt.supershell=false clean coverage test coverageReport coverageAggregate - name: PublishCoverage uses: codecov/codecov-action@v1 with: @@ -87,14 +87,14 @@ jobs: - name: SetVersion run: echo ::set-env name=VERSION::$(echo ${GITHUB_REF:11}) - name: PublishToBintray - run: sbt releaseEarly + run: sbt -Dsbt.color=always -Dsbt.supershell=false releaseEarly - name: PublishToDockerHub run: | - sbt ";set Docker/version := \"${{ env.VERSION }}\"; docker:publishLocal" + sbt -Dsbt.color=always -Dsbt.supershell=false ";set Docker/version := \"${{ env.VERSION }}\"; docker:publishLocal" echo ${{ secrets.DOCKER_PASS }} | docker login --username ${{ secrets.DOCKER_USER }} --password-stdin docker push bluebrain/nexus-iam:${{ env.VERSION }} - name: RecordCoverage - run: sbt clean coverage test coverageReport coverageAggregate + run: sbt -Dsbt.color=always -Dsbt.supershell=false clean coverage test coverageReport coverageAggregate - name: PublishCoverage uses: codecov/codecov-action@v1 with: diff --git a/build.sbt b/build.sbt index f0344a0..5ae2630 100644 --- a/build.sbt +++ b/build.sbt @@ -26,8 +26,8 @@ scalafmt: { // Dependency versions val alpakkaVersion = "1.1.2" -val commonsVersion = "0.19.1" -val sourcingVersion = "0.18.0" +val commonsVersion = "0.20.0" +val sourcingVersion = "0.19.0" val akkaVersion = "2.6.0" val akkaCorsVersion = "0.4.2" val akkaHttpVersion = "10.1.10" @@ -35,46 +35,46 @@ val akkaPersistenceCassVersion = "0.100" val akkaPersistenceMemVersion = "2.5.15.2" val catsVersion = "2.0.0" val circeVersion = "0.12.3" -val journalVersion = "3.0.19" val logbackVersion = "1.2.3" val mockitoVersion = "1.7.1" val monixVersion = "3.1.0" val nimbusJoseJwtVersion = "8.2.1" val pureconfigVersion = "0.12.1" -val scalaTestVersion = "3.0.8" +val scalaLoggingVersion = "3.9.2" +val scalaTestVersion = "3.1.0" val kryoVersion = "1.1.0" // Dependencies modules -lazy val sourcingCore = "ch.epfl.bluebrain.nexus" %% "sourcing-core" % sourcingVersion -lazy val sourcingProjections = "ch.epfl.bluebrain.nexus" %% "sourcing-projections" % sourcingVersion -lazy val commonsCore = "ch.epfl.bluebrain.nexus" %% "commons-core" % commonsVersion -lazy val commonsKamon = "ch.epfl.bluebrain.nexus" %% "commons-kamon" % commonsVersion -lazy val commonsTest = "ch.epfl.bluebrain.nexus" %% "commons-test" % commonsVersion -lazy val akkaDowning = "ch.epfl.bluebrain.nexus" %% "akka-downing" % commonsVersion -lazy val akkaCluster = "com.typesafe.akka" %% "akka-cluster" % akkaVersion -lazy val akkaClusterSharding = "com.typesafe.akka" %% "akka-cluster-sharding" % akkaVersion -lazy val akkaHttp = "com.typesafe.akka" %% "akka-http" % akkaHttpVersion -lazy val akkaHttpCors = "ch.megard" %% "akka-http-cors" % akkaCorsVersion -lazy val akkaHttpTestKit = "com.typesafe.akka" %% "akka-http-testkit" % akkaHttpVersion -lazy val akkaPersistence = "com.typesafe.akka" %% "akka-persistence" % akkaVersion -lazy val akkaPersistenceCass = "com.typesafe.akka" %% "akka-persistence-cassandra" % akkaPersistenceCassVersion -lazy val akkaPersistenceMem = "com.github.dnvriend" %% "akka-persistence-inmemory" % akkaPersistenceMemVersion -lazy val akkaPersistenceQuery = "com.typesafe.akka" %% "akka-persistence-query" % akkaVersion -lazy val akkaTestKit = "com.typesafe.akka" %% "akka-testkit" % akkaVersion -lazy val akkaSlf4j = "com.typesafe.akka" %% "akka-slf4j" % akkaVersion -lazy val akkaStream = "com.typesafe.akka" %% "akka-stream" % akkaVersion -lazy val akkaStreamTestKit = "com.typesafe.akka" %% "akka-stream-testkit" % akkaVersion -lazy val alpakkaSSE = "com.lightbend.akka" %% "akka-stream-alpakka-sse" % alpakkaVersion -lazy val catsCore = "org.typelevel" %% "cats-core" % catsVersion -lazy val circeCore = "io.circe" %% "circe-core" % circeVersion -lazy val journalCore = "io.verizon.journal" %% "core" % journalVersion -lazy val mockitoScala = "org.mockito" %% "mockito-scala" % mockitoVersion -lazy val monixEval = "io.monix" %% "monix-eval" % monixVersion -lazy val nimbusJoseJwt = "com.nimbusds" % "nimbus-jose-jwt" % nimbusJoseJwtVersion -lazy val logbackClassic = "ch.qos.logback" % "logback-classic" % logbackVersion -lazy val pureconfig = "com.github.pureconfig" %% "pureconfig" % pureconfigVersion -lazy val scalaTest = "org.scalatest" %% "scalatest" % scalaTestVersion -lazy val kryo = "io.altoo" %% "akka-kryo-serialization" % kryoVersion +lazy val sourcingCore = "ch.epfl.bluebrain.nexus" %% "sourcing-core" % sourcingVersion +lazy val sourcingProjections = "ch.epfl.bluebrain.nexus" %% "sourcing-projections" % sourcingVersion +lazy val commonsCore = "ch.epfl.bluebrain.nexus" %% "commons-core" % commonsVersion +lazy val commonsKamon = "ch.epfl.bluebrain.nexus" %% "commons-kamon" % commonsVersion +lazy val commonsTest = "ch.epfl.bluebrain.nexus" %% "commons-test" % commonsVersion +lazy val akkaDowning = "ch.epfl.bluebrain.nexus" %% "akka-downing" % commonsVersion +lazy val akkaCluster = "com.typesafe.akka" %% "akka-cluster" % akkaVersion +lazy val akkaClusterSharding = "com.typesafe.akka" %% "akka-cluster-sharding" % akkaVersion +lazy val akkaHttp = "com.typesafe.akka" %% "akka-http" % akkaHttpVersion +lazy val akkaHttpCors = "ch.megard" %% "akka-http-cors" % akkaCorsVersion +lazy val akkaHttpTestKit = "com.typesafe.akka" %% "akka-http-testkit" % akkaHttpVersion +lazy val akkaPersistence = "com.typesafe.akka" %% "akka-persistence" % akkaVersion +lazy val akkaPersistenceCass = "com.typesafe.akka" %% "akka-persistence-cassandra" % akkaPersistenceCassVersion +lazy val akkaPersistenceMem = "com.github.dnvriend" %% "akka-persistence-inmemory" % akkaPersistenceMemVersion +lazy val akkaPersistenceQuery = "com.typesafe.akka" %% "akka-persistence-query" % akkaVersion +lazy val akkaTestKit = "com.typesafe.akka" %% "akka-testkit" % akkaVersion +lazy val akkaSlf4j = "com.typesafe.akka" %% "akka-slf4j" % akkaVersion +lazy val akkaStream = "com.typesafe.akka" %% "akka-stream" % akkaVersion +lazy val akkaStreamTestKit = "com.typesafe.akka" %% "akka-stream-testkit" % akkaVersion +lazy val alpakkaSSE = "com.lightbend.akka" %% "akka-stream-alpakka-sse" % alpakkaVersion +lazy val catsCore = "org.typelevel" %% "cats-core" % catsVersion +lazy val circeCore = "io.circe" %% "circe-core" % circeVersion +lazy val logbackClassic = "ch.qos.logback" % "logback-classic" % logbackVersion +lazy val mockitoScala = "org.mockito" %% "mockito-scala" % mockitoVersion +lazy val monixEval = "io.monix" %% "monix-eval" % monixVersion +lazy val nimbusJoseJwt = "com.nimbusds" % "nimbus-jose-jwt" % nimbusJoseJwtVersion +lazy val pureconfig = "com.github.pureconfig" %% "pureconfig" % pureconfigVersion +lazy val scalaLogging = "com.typesafe.scala-logging" %% "scala-logging" % scalaLoggingVersion +lazy val scalaTest = "org.scalatest" %% "scalatest" % scalaTestVersion +lazy val kryo = "io.altoo" %% "akka-kryo-serialization" % kryoVersion lazy val iam = project .in(file(".")) @@ -103,12 +103,12 @@ lazy val iam = project akkaClusterSharding, catsCore, circeCore, - journalCore, kryo, + logbackClassic, monixEval, nimbusJoseJwt, - logbackClassic, pureconfig, + scalaLogging, akkaTestKit % Test, akkaHttpTestKit % Test, akkaStreamTestKit % Test, diff --git a/client/src/main/scala/ch/epfl/bluebrain/nexus/iam/client/EventSource.scala b/client/src/main/scala/ch/epfl/bluebrain/nexus/iam/client/EventSource.scala index b6ee4df..b933be3 100644 --- a/client/src/main/scala/ch/epfl/bluebrain/nexus/iam/client/EventSource.scala +++ b/client/src/main/scala/ch/epfl/bluebrain/nexus/iam/client/EventSource.scala @@ -12,9 +12,9 @@ import ch.epfl.bluebrain.nexus.iam.client.config.IamClientConfig import ch.epfl.bluebrain.nexus.iam.client.types.AuthToken import ch.epfl.bluebrain.nexus.rdf.Iri.AbsoluteIri import ch.epfl.bluebrain.nexus.commons.rdf.syntax._ +import com.typesafe.scalalogging.Logger import io.circe.Decoder import io.circe.parser.decode -import journal.Logger import scala.concurrent.{ExecutionContext, Future} diff --git a/client/src/main/scala/ch/epfl/bluebrain/nexus/iam/client/IamClient.scala b/client/src/main/scala/ch/epfl/bluebrain/nexus/iam/client/IamClient.scala index b29a1bd..d317b8b 100644 --- a/client/src/main/scala/ch/epfl/bluebrain/nexus/iam/client/IamClient.scala +++ b/client/src/main/scala/ch/epfl/bluebrain/nexus/iam/client/IamClient.scala @@ -22,10 +22,10 @@ import ch.epfl.bluebrain.nexus.iam.client.types._ import ch.epfl.bluebrain.nexus.iam.client.types.events.Event import ch.epfl.bluebrain.nexus.iam.client.types.events.Event.{AclEvent, PermissionsEvent, RealmEvent} import ch.epfl.bluebrain.nexus.rdf.Iri.{AbsoluteIri, Path} +import com.typesafe.scalalogging.Logger import io.circe.generic.auto._ import io.circe.syntax._ import io.circe.{DecodingFailure, Json, ParsingFailure} -import journal.Logger import scala.concurrent.{ExecutionContext, ExecutionContextExecutor, Future} import scala.reflect.ClassTag @@ -93,11 +93,12 @@ class IamClient[F[_]] private[client] ( def putAcls(path: Path, acl: AccessControlList, rev: Option[Long] = None)( implicit credentials: Option[AuthToken] ): F[Unit] = { - implicit val _ = config - val endpoint = config.aclsIri + path - val entity = HttpEntity(ContentTypes.`application/json`, acl.asJson.noSpaces) - val query = rev.map(r => Query("rev" -> r.toString)).getOrElse(Query.Empty) - val request = Put(endpoint.toAkkaUri.withQuery(query), entity) + implicit val iamClientConfig: IamClientConfig = config + + val endpoint = config.aclsIri + path + val entity = HttpEntity(ContentTypes.`application/json`, acl.asJson.noSpaces) + val query = rev.map(r => Query("rev" -> r.toString)).getOrElse(Query.Empty) + val request = Put(endpoint.toAkkaUri.withQuery(query), entity) val requestWithCredentials = credentials.map(token => request.addCredentials(OAuth2BearerToken(token.value))).getOrElse(request) jsonClient(requestWithCredentials) *> F.unit diff --git a/client/src/main/scala/ch/epfl/bluebrain/nexus/iam/client/config/Vocabulary.scala b/client/src/main/scala/ch/epfl/bluebrain/nexus/iam/client/config/Vocabulary.scala index 3578602..b7e8de5 100644 --- a/client/src/main/scala/ch/epfl/bluebrain/nexus/iam/client/config/Vocabulary.scala +++ b/client/src/main/scala/ch/epfl/bluebrain/nexus/iam/client/config/Vocabulary.scala @@ -16,8 +16,8 @@ object Vocabulary { * Nexus vocabulary. */ object nxv { - val base: Iri.AbsoluteIri = url"https://bluebrain.github.io/nexus/vocabulary/".value - private[Vocabulary] implicit val _ = IriNode(base) + val base: Iri.AbsoluteIri = url"https://bluebrain.github.io/nexus/vocabulary/".value + private[Vocabulary] implicit val iriNode: IriNode = IriNode(base) /** * @param suffix the segment to suffix to the base diff --git a/client/src/main/scala/ch/epfl/bluebrain/nexus/iam/client/types/AccessControlList.scala b/client/src/main/scala/ch/epfl/bluebrain/nexus/iam/client/types/AccessControlList.scala index 3dd554b..7e24f46 100644 --- a/client/src/main/scala/ch/epfl/bluebrain/nexus/iam/client/types/AccessControlList.scala +++ b/client/src/main/scala/ch/epfl/bluebrain/nexus/iam/client/types/AccessControlList.scala @@ -20,8 +20,8 @@ final case class AccessControlList(value: Map[Identity, Set[Permission]]) { def ++(acl: AccessControlList): AccessControlList = { val toAddKeys = acl.value.keySet -- value.keySet val toMergeKeys = acl.value.keySet -- toAddKeys - val added = value ++ acl.value.filterKeys(toAddKeys.contains) - val merged = value.filterKeys(toMergeKeys.contains).map { + val added = value ++ acl.value.view.filterKeys(toAddKeys.contains) + val merged = value.view.filterKeys(toMergeKeys.contains).map { case (ident, perms) => ident -> (perms ++ acl.value.getOrElse(ident, Set.empty)) } AccessControlList(added ++ merged) @@ -43,7 +43,7 @@ final case class AccessControlList(value: Map[Identity, Set[Permission]]) { * @param identities the identities to be filtered */ def filter(identities: Set[Identity]): AccessControlList = - AccessControlList(value.filterKeys(identities.contains)) + AccessControlList(value.view.filterKeys(identities.contains).toMap) } object AccessControlList { diff --git a/client/src/main/scala/ch/epfl/bluebrain/nexus/iam/client/types/ResourceAccessControlList.scala b/client/src/main/scala/ch/epfl/bluebrain/nexus/iam/client/types/ResourceAccessControlList.scala index 18b579d..56512f1 100644 --- a/client/src/main/scala/ch/epfl/bluebrain/nexus/iam/client/types/ResourceAccessControlList.scala +++ b/client/src/main/scala/ch/epfl/bluebrain/nexus/iam/client/types/ResourceAccessControlList.scala @@ -2,7 +2,6 @@ package ch.epfl.bluebrain.nexus.iam.client.types import java.time.Instant -import cats.syntax.either._ import ch.epfl.bluebrain.nexus.iam.client.config.Contexts._ import ch.epfl.bluebrain.nexus.iam.client.config.IamClientConfig import ch.epfl.bluebrain.nexus.iam.client.config.Vocabulary._ @@ -84,7 +83,7 @@ object ResourceAccessControlList { } yield ResourceAccessControlList(id, rev, types, createdAt, createdBy, updatedAt, updatedBy, acl) } - private implicit class AbsoluteIriSyntax(private val iri: AbsoluteIri) extends AnyVal { + private[ResourceAccessControlList] implicit class AbsoluteIriSyntax(private val iri: AbsoluteIri) extends AnyVal { def lastSegment: Option[String] = iri.path.head match { case segment: String => Some(segment) diff --git a/client/src/main/scala/ch/epfl/bluebrain/nexus/iam/client/types/events/Event.scala b/client/src/main/scala/ch/epfl/bluebrain/nexus/iam/client/types/events/Event.scala index e571d3b..ccd575c 100644 --- a/client/src/main/scala/ch/epfl/bluebrain/nexus/iam/client/types/events/Event.scala +++ b/client/src/main/scala/ch/epfl/bluebrain/nexus/iam/client/types/events/Event.scala @@ -268,7 +268,7 @@ object Event { subject: Subject ) extends RealmEvent - private implicit val config: Configuration = Configuration.default + private[events] implicit val config: Configuration = Configuration.default .withDiscriminator("@type") .copy(transformMemberNames = { case "label" => "_label" @@ -287,7 +287,7 @@ object Event { case other => other }) - private implicit val subjectDecoder: Decoder[Subject] = + private[events] implicit val subjectDecoder: Decoder[Subject] = Decoder.decodeString.flatMap { id => Iri.absolute(id) match { case Left(_) => Decoder.failedWithMessage(s"Couldn't convert id '$id' to Absolute Iri") @@ -305,7 +305,7 @@ object Event { implicit val eventDecoder: Decoder[Event] = deriveConfiguredDecoder[Event] - private implicit val aclDecoder: Decoder[AccessControlList] = + private[events] implicit val aclDecoder: Decoder[AccessControlList] = Decoder.instance { hc => for { arr <- hc.focus.flatMap(_.asArray).toRight(DecodingFailure("acl field not found", hc.history)) diff --git a/client/src/test/scala/ch/epfl/bluebrain/nexus/iam/client/IamClientSpec.scala b/client/src/test/scala/ch/epfl/bluebrain/nexus/iam/client/IamClientSpec.scala index 6c274c9..32a0539 100644 --- a/client/src/test/scala/ch/epfl/bluebrain/nexus/iam/client/IamClientSpec.scala +++ b/client/src/test/scala/ch/epfl/bluebrain/nexus/iam/client/IamClientSpec.scala @@ -13,7 +13,7 @@ import cats.effect.IO import cats.implicits._ import ch.epfl.bluebrain.nexus.commons.http.HttpClient import ch.epfl.bluebrain.nexus.commons.test.Resources -import ch.epfl.bluebrain.nexus.commons.test.io.IOValues +import ch.epfl.bluebrain.nexus.commons.test.io.IOEitherValues import ch.epfl.bluebrain.nexus.iam.client.IamClientError.{Forbidden, Unauthorized} import ch.epfl.bluebrain.nexus.iam.client.config.IamClientConfig import ch.epfl.bluebrain.nexus.iam.client.types.Identity.{Anonymous, User} @@ -26,7 +26,9 @@ import ch.epfl.bluebrain.nexus.rdf.syntax.node.unsafe._ import io.circe.Json import org.mockito.{ArgumentMatchersSugar, IdiomaticMockito, Mockito} import org.scalatest.concurrent.Eventually -import org.scalatest.{BeforeAndAfter, EitherValues, Matchers, WordSpecLike} +import org.scalatest.wordspec.AnyWordSpecLike +import org.scalatest.BeforeAndAfter +import org.scalatest.matchers.should.Matchers import scala.concurrent.duration._ import scala.util.Random @@ -34,17 +36,16 @@ import scala.util.Random //noinspection ScalaUnnecessaryParentheses,TypeAnnotation,RedundantDefaultArgument class IamClientSpec extends TestKit(ActorSystem("IamClientSpec")) - with WordSpecLike + with AnyWordSpecLike with Matchers with BeforeAndAfter with IdiomaticMockito with ArgumentMatchersSugar - with IOValues - with EitherValues + with IOEitherValues with Resources with Eventually { - override implicit val patienceConfig: PatienceConfig = PatienceConfig(5 seconds, 15 milliseconds) + override implicit val patienceConfig: PatienceConfig = PatienceConfig(5.seconds, 15.milliseconds) private val clock = Clock.fixed(Instant.ofEpochSecond(3600), ZoneId.systemDefault()) private val config = @@ -300,7 +301,7 @@ class IamClientSpec "/events/realm-deprecated.json" ) - val eventsSource = Source(Random.shuffle(resources).map(jsonContentOf(_).as[Event].right.value)) + val eventsSource = Source(Random.shuffle(resources).map(jsonContentOf(_).as[Event].rightValue)) } "apply function when new acl event is received" in new Ctx { @@ -310,7 +311,7 @@ class IamClientSpec case _: AclSubtracted => IO(count.addAndGet(3)) *> IO.unit case _: AclDeleted => IO(count.addAndGet(4)) *> IO.unit } - val eventsIri = Iri.url("http://internal.example.com/some/v1/acls/events").right.value + val eventsIri = Iri.url("http://internal.example.com/some/v1/acls/events").rightValue source(eventsIri, None) shouldReturn eventsSource client.aclEvents(f) eventually(count.get() shouldEqual 10) @@ -323,7 +324,7 @@ class IamClientSpec case _: PermissionsSubtracted => IO(count.addAndGet(3)) *> IO.unit case _: PermissionsDeleted => IO(count.addAndGet(4)) *> IO.unit } - val eventsIri = Iri.url("http://internal.example.com/some/v1/permissions/events").right.value + val eventsIri = Iri.url("http://internal.example.com/some/v1/permissions/events").rightValue source(eventsIri, None) shouldReturn eventsSource client.permissionEvents(f) eventually(count.get() shouldEqual 10) @@ -335,7 +336,7 @@ class IamClientSpec case _: RealmUpdated => IO(count.addAndGet(2)) *> IO.unit case _: RealmDeprecated => IO(count.addAndGet(3)) *> IO.unit } - val eventsIri = Iri.url("http://internal.example.com/some/v1/realms/events").right.value + val eventsIri = Iri.url("http://internal.example.com/some/v1/realms/events").rightValue source(eventsIri, None) shouldReturn eventsSource client.realmEvents(f) eventually(count.get() shouldEqual 6) diff --git a/client/src/test/scala/ch/epfl/bluebrain/nexus/iam/client/types/CallerDecoderSpec.scala b/client/src/test/scala/ch/epfl/bluebrain/nexus/iam/client/types/CallerDecoderSpec.scala index 59b4432..b8c3d7d 100644 --- a/client/src/test/scala/ch/epfl/bluebrain/nexus/iam/client/types/CallerDecoderSpec.scala +++ b/client/src/test/scala/ch/epfl/bluebrain/nexus/iam/client/types/CallerDecoderSpec.scala @@ -1,15 +1,17 @@ package ch.epfl.bluebrain.nexus.iam.client.types -import ch.epfl.bluebrain.nexus.commons.test.Resources + +import ch.epfl.bluebrain.nexus.commons.test.{EitherValues, Resources} import ch.epfl.bluebrain.nexus.iam.client.types.Identity.{Anonymous, Authenticated, Group, User} -import org.scalatest.{EitherValues, Matchers, WordSpecLike} +import org.scalatest.matchers.should.Matchers +import org.scalatest.wordspec.AnyWordSpecLike -class CallerDecoderSpec extends WordSpecLike with Matchers with Resources with EitherValues { +class CallerDecoderSpec extends AnyWordSpecLike with Matchers with Resources with EitherValues { "Caller decoder" should { "decode subject correctly" in { - jsonContentOf("/identities/caller.json").as[Caller].right.value shouldEqual Caller( + jsonContentOf("/identities/caller.json").as[Caller].rightValue shouldEqual Caller( User("nexus-test-user", "nexusdev"), Set( Anonymous, diff --git a/client/src/test/scala/ch/epfl/bluebrain/nexus/iam/client/types/IdentitySpec.scala b/client/src/test/scala/ch/epfl/bluebrain/nexus/iam/client/types/IdentitySpec.scala index 5928977..449b5b5 100644 --- a/client/src/test/scala/ch/epfl/bluebrain/nexus/iam/client/types/IdentitySpec.scala +++ b/client/src/test/scala/ch/epfl/bluebrain/nexus/iam/client/types/IdentitySpec.scala @@ -1,15 +1,17 @@ package ch.epfl.bluebrain.nexus.iam.client.types -import ch.epfl.bluebrain.nexus.commons.test.Resources +import ch.epfl.bluebrain.nexus.commons.test.{EitherValues, Resources} import ch.epfl.bluebrain.nexus.iam.client.config.IamClientConfig import ch.epfl.bluebrain.nexus.iam.client.types.Identity._ import ch.epfl.bluebrain.nexus.rdf.Iri.AbsoluteIri import ch.epfl.bluebrain.nexus.rdf.syntax.node.unsafe._ import io.circe.syntax._ -import org.scalatest._ +import org.scalatest.{Inspectors, OptionValues} +import org.scalatest.matchers.should.Matchers +import org.scalatest.wordspec.AnyWordSpecLike class IdentitySpec - extends WordSpecLike + extends AnyWordSpecLike with Matchers with Inspectors with OptionValues @@ -17,7 +19,7 @@ class IdentitySpec with EitherValues { "An identity" should { - implicit val config = + implicit val config: IamClientConfig = IamClientConfig(url"http://nexus.example.com".value, url"http://internal.nexus.example.com".value, "v1") val user = User("mysubject", "myrealm") val group = Group("mygroup", "myrealm") @@ -64,9 +66,9 @@ class IdentitySpec List(user -> userJson, group -> groupJson, Anonymous -> anonymousJson, authenticated -> authenticatedJson) forAll(cases) { case (model: Subject, json) => - json.as[Subject].right.value shouldEqual model - json.as[Identity].right.value shouldEqual (model: Identity) - case (model: Identity, json) => json.as[Identity].right.value shouldEqual model + json.as[Subject].rightValue shouldEqual model + json.as[Identity].rightValue shouldEqual (model: Identity) + case (model: Identity, json) => json.as[Identity].rightValue shouldEqual model } } } diff --git a/client/src/test/scala/ch/epfl/bluebrain/nexus/iam/client/types/events/EventDecodersSpec.scala b/client/src/test/scala/ch/epfl/bluebrain/nexus/iam/client/types/events/EventDecodersSpec.scala index d7f81b1..b3ed3e4 100644 --- a/client/src/test/scala/ch/epfl/bluebrain/nexus/iam/client/types/events/EventDecodersSpec.scala +++ b/client/src/test/scala/ch/epfl/bluebrain/nexus/iam/client/types/events/EventDecodersSpec.scala @@ -2,7 +2,7 @@ package ch.epfl.bluebrain.nexus.iam.client.types.events import java.time.Instant -import ch.epfl.bluebrain.nexus.commons.test.Resources +import ch.epfl.bluebrain.nexus.commons.test.{EitherValues, Resources} import ch.epfl.bluebrain.nexus.iam.client.types.GrantType._ import ch.epfl.bluebrain.nexus.iam.client.types.Identity.{Anonymous, User} import ch.epfl.bluebrain.nexus.iam.client.types.events.Event._ @@ -10,10 +10,11 @@ import ch.epfl.bluebrain.nexus.iam.client.types.{AccessControlList, Permission} import ch.epfl.bluebrain.nexus.rdf.Iri import ch.epfl.bluebrain.nexus.rdf.Iri.Path._ import io.circe.Json -import org.scalatest.{EitherValues, Matchers, WordSpecLike} +import org.scalatest.matchers.should.Matchers +import org.scalatest.wordspec.AnyWordSpecLike //noinspection TypeAnnotation -class EventDecodersSpec extends WordSpecLike with Matchers with Resources with EitherValues { +class EventDecodersSpec extends AnyWordSpecLike with Matchers with Resources with EitherValues { "Encoders and decoders" when { val read: Permission = Permission.unsafe("read") @@ -29,26 +30,26 @@ class EventDecodersSpec extends WordSpecLike with Matchers with Resources with E "decode acl replaced event" in { val expected: AclEvent = AclReplaced("one" / "two", acl, 1L, instant, subject) val json = jsonContentOf("/events/acl-replaced.json") - json.as[Event].right.value shouldEqual expected + json.as[Event].rightValue shouldEqual expected } "decode acl appended event" in { val appendAcls = AccessControlList(User("some", "myrealm") -> Set(create, read)) val expected: AclEvent = AclAppended("one" / "two", appendAcls, 2L, instant, subject) val json = jsonContentOf("/events/acl-appended.json") - json.as[Event].right.value shouldEqual expected + json.as[Event].rightValue shouldEqual expected } "decode acl subtracted event" in { val expected: AclEvent = AclSubtracted(/, AccessControlList(Anonymous -> Set(read)), 2L, instant, subject) val json = jsonContentOf("/events/acl-subtracted.json") - json.as[Event].right.value shouldEqual expected + json.as[Event].rightValue shouldEqual expected } "decode acl deleted event" in { val expected: AclEvent = AclDeleted("one" / "two", 3L, instant, subject) val json = jsonContentOf("/events/acl-deleted.json") - json.as[Event].right.value shouldEqual expected + json.as[Event].rightValue shouldEqual expected } } @@ -57,25 +58,25 @@ class EventDecodersSpec extends WordSpecLike with Matchers with Resources with E "decode permissions replaced event" in { val expected: PermissionsEvent = PermissionsReplaced(Set(read, write), 1L, instant, subject) val json = jsonContentOf("/events/permissions-replaced.json") - json.as[Event].right.value shouldEqual expected + json.as[Event].rightValue shouldEqual expected } "decode permissions appended event" in { val expected: PermissionsEvent = PermissionsAppended(Set(read), 2L, instant, subject) val json = jsonContentOf("/events/permissions-appended.json") - json.as[Event].right.value shouldEqual expected + json.as[Event].rightValue shouldEqual expected } "decode permissions subtracted event" in { val expected: PermissionsEvent = PermissionsSubtracted(Set(read, create), 3L, instant, subject) val json = jsonContentOf("/events/permissions-subtracted.json") - json.as[Event].right.value shouldEqual expected + json.as[Event].rightValue shouldEqual expected } "decode permissions deleted event" in { val expected: PermissionsEvent = PermissionsDeleted(4L, instant, subject) val json = jsonContentOf("/events/permissions-deleted.json") - json.as[Event].right.value shouldEqual expected + json.as[Event].rightValue shouldEqual expected } } @@ -89,14 +90,14 @@ class EventDecodersSpec extends WordSpecLike with Matchers with Resources with E "n" -> Json.fromString("nvalue"), "use" -> Json.fromString("sig") ) - val openIdConfig = Iri.url("http://nexus.example.com/auth/realms/myrealm/openid-configuration").right.value + val openIdConfig = Iri.url("http://nexus.example.com/auth/realms/myrealm/openid-configuration").rightValue val authorization = - Iri.url("http://nexus.example.com/auth/realms/myrealm/protocol/openid-connect/auth").right.value - val token = Iri.url("http://nexus.example.com/auth/realms/myrealm/protocol/openid-connect/token").right.value + Iri.url("http://nexus.example.com/auth/realms/myrealm/protocol/openid-connect/auth").rightValue + val token = Iri.url("http://nexus.example.com/auth/realms/myrealm/protocol/openid-connect/token").rightValue val userInfo = - Iri.url("http://nexus.example.com/auth/realms/myrealm/protocol/openid-connect/userinfo").right.value + Iri.url("http://nexus.example.com/auth/realms/myrealm/protocol/openid-connect/userinfo").rightValue val endSession = - Iri.url("http://nexus.example.com/auth/realms/myrealm/protocol/openid-connect/logout").right.value + Iri.url("http://nexus.example.com/auth/realms/myrealm/protocol/openid-connect/logout").rightValue val issuer = "http://nexus.example.com/auth/realms/myrealm" "decode realm created event" in { @@ -118,7 +119,7 @@ class EventDecodersSpec extends WordSpecLike with Matchers with Resources with E subject ) val json = jsonContentOf("/events/realm-created.json") - json.as[Event].right.value shouldEqual expected + json.as[Event].rightValue shouldEqual expected } "decode realm updated event" in { @@ -140,13 +141,13 @@ class EventDecodersSpec extends WordSpecLike with Matchers with Resources with E subject ) val json = jsonContentOf("/events/realm-updated.json") - json.as[Event].right.value shouldEqual expected + json.as[Event].rightValue shouldEqual expected } "decode realm deprecated event" in { val expected: RealmEvent = RealmDeprecated("nexusdev", 3L, instant, subject) val json = jsonContentOf("/events/realm-deprecated.json") - json.as[Event].right.value shouldEqual expected + json.as[Event].rightValue shouldEqual expected } } } diff --git a/project/plugins.sbt b/project/plugins.sbt index a585294..8c2cf32 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,5 +1,5 @@ resolvers += Resolver.bintrayRepo("bbp", "nexus-releases") -addSbtPlugin("ch.epfl.bluebrain.nexus" % "sbt-nexus" % "0.13.3") +addSbtPlugin("ch.epfl.bluebrain.nexus" % "sbt-nexus" % "0.14.0") addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.7.0") addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.3.7") diff --git a/src/main/scala/ch/epfl/bluebrain/nexus/iam/Main.scala b/src/main/scala/ch/epfl/bluebrain/nexus/iam/Main.scala index db1810c..1174056 100644 --- a/src/main/scala/ch/epfl/bluebrain/nexus/iam/Main.scala +++ b/src/main/scala/ch/epfl/bluebrain/nexus/iam/Main.scala @@ -48,7 +48,7 @@ object Main { def shutdownMonitoring(): Unit = { if (sys.env.getOrElse("KAMON_ENABLED", "false").toBoolean) { - Await.result(Kamon.stopModules(), 10 seconds) + Await.result(Kamon.stopModules(), 10.seconds) } } @@ -127,7 +127,7 @@ object Main { logger.info(s"Bound to ${binding.localAddress.getHostString}: ${binding.localAddress.getPort}") case Failure(th) => logger.error(th, "Failed to perform an http binding on {}:{}", appConfig.http.interface, appConfig.http.port) - Await.result(as.terminate(), 10 seconds) + Await.result(as.terminate(), 10.seconds) } } @@ -139,7 +139,7 @@ object Main { } // attempt to leave the cluster before shutting down val _ = sys.addShutdownHook { - Await.result(as.terminate().map(_ => ())(as.dispatcher), 10 seconds) + Await.result(as.terminate().map(_ => ())(as.dispatcher), 10.seconds) } } } diff --git a/src/main/scala/ch/epfl/bluebrain/nexus/iam/RepairFromMessages.scala b/src/main/scala/ch/epfl/bluebrain/nexus/iam/RepairFromMessages.scala index 89e56cd..1316706 100644 --- a/src/main/scala/ch/epfl/bluebrain/nexus/iam/RepairFromMessages.scala +++ b/src/main/scala/ch/epfl/bluebrain/nexus/iam/RepairFromMessages.scala @@ -10,7 +10,7 @@ import ch.epfl.bluebrain.nexus.iam.permissions.Permissions import ch.epfl.bluebrain.nexus.iam.realms.Realms import ch.epfl.bluebrain.nexus.iam.types.Label import ch.epfl.bluebrain.nexus.rdf.Iri.Path -import journal.Logger +import com.typesafe.scalalogging.Logger import monix.eval.Task import monix.execution.Scheduler import monix.execution.schedulers.CanBlock diff --git a/src/main/scala/ch/epfl/bluebrain/nexus/iam/acls/AccessControlList.scala b/src/main/scala/ch/epfl/bluebrain/nexus/iam/acls/AccessControlList.scala index 112c392..ea77443 100644 --- a/src/main/scala/ch/epfl/bluebrain/nexus/iam/acls/AccessControlList.scala +++ b/src/main/scala/ch/epfl/bluebrain/nexus/iam/acls/AccessControlList.scala @@ -22,8 +22,8 @@ final case class AccessControlList(value: Map[Identity, Set[Permission]]) { def ++(acl: AccessControlList): AccessControlList = { val toAddKeys = acl.value.keySet -- value.keySet val toMergeKeys = acl.value.keySet -- toAddKeys - val added = value ++ acl.value.filterKeys(toAddKeys.contains) - val merged = value.filterKeys(toMergeKeys.contains).map { + val added = value ++ acl.value.view.filterKeys(toAddKeys.contains) + val merged = value.view.filterKeys(toMergeKeys.contains).map { case (ident, perms) => ident -> (perms ++ acl.value.getOrElse(ident, Set.empty)) } AccessControlList(added ++ merged) @@ -60,7 +60,7 @@ final case class AccessControlList(value: Map[Identity, Set[Permission]]) { * @param identities the identities to be filtered */ def filter(identities: Set[Identity]): AccessControlList = - AccessControlList(value.filterKeys(identities.contains)) + AccessControlList(value.view.filterKeys(identities.contains).toMap) /** * Determines if this contains the argument ''permission'' for at least one of the provided ''identities''. @@ -116,4 +116,9 @@ object AccessControlList { } yield AccessControlList(acl) } } + + object JsonLd { + implicit def aclAsArrayEncoder(implicit http: HttpConfig): Encoder[AccessControlList] = + aclArrayEncoder(http) + } } diff --git a/src/main/scala/ch/epfl/bluebrain/nexus/iam/acls/AccessControlLists.scala b/src/main/scala/ch/epfl/bluebrain/nexus/iam/acls/AccessControlLists.scala index 7383b7c..186eefb 100644 --- a/src/main/scala/ch/epfl/bluebrain/nexus/iam/acls/AccessControlLists.scala +++ b/src/main/scala/ch/epfl/bluebrain/nexus/iam/acls/AccessControlLists.scala @@ -27,8 +27,8 @@ final case class AccessControlLists(value: Map[Path, Resource]) { def ++(acls: AccessControlLists): AccessControlLists = { val toAddKeys = acls.value.keySet -- value.keySet val toMergeKeys = acls.value.keySet -- toAddKeys - val added = value ++ acls.value.filterKeys(toAddKeys.contains) - val merged = value.filterKeys(toMergeKeys.contains).map { + val added = value ++ acls.value.view.filterKeys(toAddKeys.contains) + val merged = value.view.filterKeys(toMergeKeys.contains).map { case (p, currResourceAcl) => p -> currResourceAcl.map(_ ++ acls.value(p).value) } AccessControlLists(added ++ merged) diff --git a/src/main/scala/ch/epfl/bluebrain/nexus/iam/acls/AclEvent.scala b/src/main/scala/ch/epfl/bluebrain/nexus/iam/acls/AclEvent.scala index ff5d057..f1da7ae 100644 --- a/src/main/scala/ch/epfl/bluebrain/nexus/iam/acls/AclEvent.scala +++ b/src/main/scala/ch/epfl/bluebrain/nexus/iam/acls/AclEvent.scala @@ -9,6 +9,7 @@ import ch.epfl.bluebrain.nexus.iam.types.Identity.Subject import ch.epfl.bluebrain.nexus.rdf.Iri.Path import ch.epfl.bluebrain.nexus.rdf.instances._ import ch.epfl.bluebrain.nexus.rdf.syntax._ +import com.github.ghik.silencer.silent import io.circe.Encoder import io.circe.generic.extras.Configuration @@ -110,17 +111,17 @@ object AclEvent { object JsonLd { import io.circe.generic.extras.semiauto._ - private implicit val config: Configuration = Configuration.default - .withDiscriminator("@type") - .copy(transformMemberNames = { - case "rev" => "_rev" - case "instant" => "_instant" - case "subject" => "_subject" - case "path" => "_path" - case other => other - }) - + @silent // defined implicits are not recognized as being used implicit def aclEventEncoder(implicit httpConfig: HttpConfig): Encoder[AclEvent] = { + implicit val config: Configuration = Configuration.default + .withDiscriminator("@type") + .copy(transformMemberNames = { + case "rev" => "_rev" + case "instant" => "_instant" + case "subject" => "_subject" + case "path" => "_path" + case other => other + }) implicit val arrayEncoder: Encoder[AccessControlList] = AccessControlList.aclArrayEncoder implicit val subjectEncoder: Encoder[Subject] = Identity.subjectIdEncoder deriveConfiguredEncoder[AclEvent] diff --git a/src/main/scala/ch/epfl/bluebrain/nexus/iam/acls/AclRejection.scala b/src/main/scala/ch/epfl/bluebrain/nexus/iam/acls/AclRejection.scala index 1d407fe..e91e3b4 100644 --- a/src/main/scala/ch/epfl/bluebrain/nexus/iam/acls/AclRejection.scala +++ b/src/main/scala/ch/epfl/bluebrain/nexus/iam/acls/AclRejection.scala @@ -7,6 +7,7 @@ import ch.epfl.bluebrain.nexus.iam.types.{Permission, ResourceRejection} import ch.epfl.bluebrain.nexus.rdf.Iri.Path import ch.epfl.bluebrain.nexus.rdf.syntax._ import ch.epfl.bluebrain.nexus.rdf.instances._ +import com.github.ghik.silencer.silent import io.circe.generic.extras.Configuration import io.circe.generic.extras.semiauto.deriveConfiguredEncoder import io.circe.{Encoder, Json} @@ -67,6 +68,7 @@ object AclRejection { s"Some of the permissions specified are not known: '${permissions.mkString("\"", ", ", "\"")}'" ) + @silent // rejectionConfig is not recognized as being used implicit val aclRejectionEncoder: Encoder[AclRejection] = { implicit val rejectionConfig: Configuration = Configuration.default.withDiscriminator("@type") val enc = deriveConfiguredEncoder[AclRejection].mapJson(_ addContext errorCtxUri) diff --git a/src/main/scala/ch/epfl/bluebrain/nexus/iam/auth/TokenRejection.scala b/src/main/scala/ch/epfl/bluebrain/nexus/iam/auth/TokenRejection.scala index 4aba95e..a95b8df 100644 --- a/src/main/scala/ch/epfl/bluebrain/nexus/iam/auth/TokenRejection.scala +++ b/src/main/scala/ch/epfl/bluebrain/nexus/iam/auth/TokenRejection.scala @@ -1,5 +1,6 @@ package ch.epfl.bluebrain.nexus.iam.auth +import com.github.ghik.silencer.silent import io.circe.generic.extras.Configuration import io.circe.generic.extras.semiauto.deriveConfiguredEncoder import io.circe.{Encoder, Json} @@ -46,6 +47,7 @@ object TokenRejection { "The token is invalid; possible causes are: incorrect signature, the token is expired or the 'nbf' value was not met." ) + @silent // rejectionConfig is not recognized as being used implicit val tokenRejectionEncoder: Encoder[TokenRejection] = { implicit val rejectionConfig: Configuration = Configuration.default.withDiscriminator("@type") val enc = deriveConfiguredEncoder[TokenRejection] diff --git a/src/main/scala/ch/epfl/bluebrain/nexus/iam/config/Settings.scala b/src/main/scala/ch/epfl/bluebrain/nexus/iam/config/Settings.scala index ee3b809..4c61b92 100644 --- a/src/main/scala/ch/epfl/bluebrain/nexus/iam/config/Settings.scala +++ b/src/main/scala/ch/epfl/bluebrain/nexus/iam/config/Settings.scala @@ -3,6 +3,7 @@ package ch.epfl.bluebrain.nexus.iam.config import akka.actor.{ExtendedActorSystem, Extension, ExtensionId, ExtensionIdProvider} import akka.http.scaladsl.model.Uri import ch.epfl.bluebrain.nexus.iam.types.Permission +import com.github.ghik.silencer.silent import com.typesafe.config.Config import pureconfig.generic.auto._ import pureconfig.ConvertHelpers._ @@ -17,9 +18,11 @@ import pureconfig._ @SuppressWarnings(Array("LooksLikeInterpolatedString")) class Settings(config: Config) extends Extension { + @silent // not recognized as used... but it is below private implicit val uriConverter: ConfigConvert[Uri] = ConfigConvert.viaString[Uri](catchReadError(Uri(_)), _.toString) + @silent // not recognized as used... but it is below private implicit val permissionConverter: ConfigConvert[Permission] = ConfigConvert.viaString[Permission](optF(Permission(_)), _.toString) diff --git a/src/main/scala/ch/epfl/bluebrain/nexus/iam/config/Vocabulary.scala b/src/main/scala/ch/epfl/bluebrain/nexus/iam/config/Vocabulary.scala index ca5c639..f17a158 100644 --- a/src/main/scala/ch/epfl/bluebrain/nexus/iam/config/Vocabulary.scala +++ b/src/main/scala/ch/epfl/bluebrain/nexus/iam/config/Vocabulary.scala @@ -16,8 +16,8 @@ object Vocabulary { * Nexus vocabulary. */ object nxv { - val base: Iri.AbsoluteIri = url"https://bluebrain.github.io/nexus/vocabulary/".value - private[Vocabulary] implicit val _ = IriNode(base) + val base: Iri.AbsoluteIri = url"https://bluebrain.github.io/nexus/vocabulary/".value + private[Vocabulary] implicit val iriNode: IriNode = IriNode(base) /** * @param suffix the segment to suffix to the base diff --git a/src/main/scala/ch/epfl/bluebrain/nexus/iam/directives/RealmDirectives.scala b/src/main/scala/ch/epfl/bluebrain/nexus/iam/directives/RealmDirectives.scala index ed5ff3a..c89303a 100644 --- a/src/main/scala/ch/epfl/bluebrain/nexus/iam/directives/RealmDirectives.scala +++ b/src/main/scala/ch/epfl/bluebrain/nexus/iam/directives/RealmDirectives.scala @@ -27,11 +27,11 @@ trait RealmDirectives { * @return the extracted search parameters from the request query parameters. */ def searchParams: Directive1[SearchParams] = - (parameter('deprecated.as[Boolean].?) & - parameter('rev.as[Long].?) & - parameter('createdBy.as[AbsoluteIri].?) & - parameter('updatedBy.as[AbsoluteIri].?) & - parameter('type.as[AbsoluteIri].*)).tmap { + (parameter("deprecated".as[Boolean].?) & + parameter("rev".as[Long].?) & + parameter("createdBy".as[AbsoluteIri].?) & + parameter("updatedBy".as[AbsoluteIri].?) & + parameter("type".as[AbsoluteIri].*)).tmap { case (deprecated, rev, createdBy, updatedBy, types) => SearchParams(deprecated, rev, createdBy, updatedBy, types.toSet) } diff --git a/src/main/scala/ch/epfl/bluebrain/nexus/iam/index/InMemoryAclsTree.scala b/src/main/scala/ch/epfl/bluebrain/nexus/iam/index/InMemoryAclsTree.scala index 8c26268..4f0d05e 100644 --- a/src/main/scala/ch/epfl/bluebrain/nexus/iam/index/InMemoryAclsTree.scala +++ b/src/main/scala/ch/epfl/bluebrain/nexus/iam/index/InMemoryAclsTree.scala @@ -77,7 +77,7 @@ class InMemoryAclsTree[F[_]] private (tree: ConcurrentHashMap[Path, Set[Path]], if (ancestors) result.removeEmpty else - AccessControlLists(result.value.filterKeys(_.size == path.size)).removeEmpty + AccessControlLists(result.value.view.filterKeys(_.size == path.size).toMap).removeEmpty } } } diff --git a/src/main/scala/ch/epfl/bluebrain/nexus/iam/instances.scala b/src/main/scala/ch/epfl/bluebrain/nexus/iam/instances.scala index f185213..7f405d4 100644 --- a/src/main/scala/ch/epfl/bluebrain/nexus/iam/instances.scala +++ b/src/main/scala/ch/epfl/bluebrain/nexus/iam/instances.scala @@ -1,7 +1,7 @@ package ch.epfl.bluebrain.nexus.iam import cats.effect.Effect -import journal.Logger +import com.typesafe.scalalogging.Logger import retry.RetryDetails object instances { diff --git a/src/main/scala/ch/epfl/bluebrain/nexus/iam/io/EventSerializer.scala b/src/main/scala/ch/epfl/bluebrain/nexus/iam/io/EventSerializer.scala index 48fdea3..01a25d1 100644 --- a/src/main/scala/ch/epfl/bluebrain/nexus/iam/io/EventSerializer.scala +++ b/src/main/scala/ch/epfl/bluebrain/nexus/iam/io/EventSerializer.scala @@ -28,21 +28,21 @@ class EventSerializer(system: ExtendedActorSystem) extends SerializerWithStringM private val printer = Printer.noSpaces.copy(dropNullValues = true) - private implicit val http: HttpConfig = Settings(system).appConfig.http + private[io] implicit val http: HttpConfig = Settings(system).appConfig.http - private implicit val config: Configuration = Configuration.default.withDiscriminator("@type") + private[io] implicit val config: Configuration = Configuration.default.withDiscriminator("@type") - private implicit val urlEncoder: Encoder[Url] = + private[io] implicit val urlEncoder: Encoder[Url] = Encoder.encodeString.contramap(_.asUri) - private implicit val urlDecoder: Decoder[Url] = + private[io] implicit val urlDecoder: Decoder[Url] = Decoder.decodeString.emap(Url.apply) - private implicit val permissionEventEncoder: Encoder[PermissionsEvent] = deriveConfiguredEncoder[PermissionsEvent] - private implicit val permissionEventDecoder: Decoder[PermissionsEvent] = deriveConfiguredDecoder[PermissionsEvent] - private implicit val aclEventEncoder: Encoder[AclEvent] = deriveConfiguredEncoder[AclEvent] - private implicit val aclEventDecoder: Decoder[AclEvent] = deriveConfiguredDecoder[AclEvent] - private implicit val realmEventEncoder: Encoder[RealmEvent] = deriveConfiguredEncoder[RealmEvent] - private implicit val realmEventDecoder: Decoder[RealmEvent] = deriveConfiguredDecoder[RealmEvent] + private[io] implicit val permissionEventEncoder: Encoder[PermissionsEvent] = deriveConfiguredEncoder[PermissionsEvent] + private[io] implicit val permissionEventDecoder: Decoder[PermissionsEvent] = deriveConfiguredDecoder[PermissionsEvent] + private[io] implicit val aclEventEncoder: Encoder[AclEvent] = deriveConfiguredEncoder[AclEvent] + private[io] implicit val aclEventDecoder: Decoder[AclEvent] = deriveConfiguredDecoder[AclEvent] + private[io] implicit val realmEventEncoder: Encoder[RealmEvent] = deriveConfiguredEncoder[RealmEvent] + private[io] implicit val realmEventDecoder: Decoder[RealmEvent] = deriveConfiguredDecoder[RealmEvent] override val identifier: Int = 1225 diff --git a/src/main/scala/ch/epfl/bluebrain/nexus/iam/permissions/Permissions.scala b/src/main/scala/ch/epfl/bluebrain/nexus/iam/permissions/Permissions.scala index 2fde0fc..c0d587a 100644 --- a/src/main/scala/ch/epfl/bluebrain/nexus/iam/permissions/Permissions.scala +++ b/src/main/scala/ch/epfl/bluebrain/nexus/iam/permissions/Permissions.scala @@ -238,7 +238,7 @@ object Permissions { def replace(c: ReplacePermissions): F[EventOrRejection] = if (c.rev != state.rev) reject(IncorrectRev(c.rev, state.rev)) else if (c.permissions.isEmpty) reject(CannotReplaceWithEmptyCollection) - else if (c.permissions -- pc.minimum isEmpty) reject(CannotReplaceWithEmptyCollection) + else if ((c.permissions -- pc.minimum).isEmpty) reject(CannotReplaceWithEmptyCollection) else accept(PermissionsReplaced(c.rev + 1, c.permissions, _, c.subject)) def append(c: AppendPermissions): F[EventOrRejection] = state match { case _ if state.rev != c.rev => reject(IncorrectRev(c.rev, state.rev)) diff --git a/src/main/scala/ch/epfl/bluebrain/nexus/iam/permissions/PermissionsEvent.scala b/src/main/scala/ch/epfl/bluebrain/nexus/iam/permissions/PermissionsEvent.scala index eef06ec..7c1cd58 100644 --- a/src/main/scala/ch/epfl/bluebrain/nexus/iam/permissions/PermissionsEvent.scala +++ b/src/main/scala/ch/epfl/bluebrain/nexus/iam/permissions/PermissionsEvent.scala @@ -7,6 +7,7 @@ import ch.epfl.bluebrain.nexus.iam.config.Contexts._ import ch.epfl.bluebrain.nexus.iam.types.Identity.Subject import ch.epfl.bluebrain.nexus.iam.types.{Identity, Permission} import ch.epfl.bluebrain.nexus.rdf.syntax._ +import com.github.ghik.silencer.silent import io.circe.Encoder import io.circe.generic.extras.Configuration @@ -94,16 +95,16 @@ object PermissionsEvent { object JsonLd { import io.circe.generic.extras.semiauto._ - private implicit val config: Configuration = Configuration.default - .withDiscriminator("@type") - .copy(transformMemberNames = { - case "rev" => "_rev" - case "instant" => "_instant" - case "subject" => "_subject" - case other => other - }) - + @silent // defined implicits are not recognized as being used implicit def permissionsEventEncoder(implicit http: HttpConfig): Encoder[Event] = { + implicit val config: Configuration = Configuration.default + .withDiscriminator("@type") + .copy(transformMemberNames = { + case "rev" => "_rev" + case "instant" => "_instant" + case "subject" => "_subject" + case other => other + }) implicit val subjectEncoder: Encoder[Subject] = Identity.subjectIdEncoder deriveConfiguredEncoder[Event] .mapJson { json => diff --git a/src/main/scala/ch/epfl/bluebrain/nexus/iam/permissions/PermissionsRejection.scala b/src/main/scala/ch/epfl/bluebrain/nexus/iam/permissions/PermissionsRejection.scala index 479ec25..7e7da0e 100644 --- a/src/main/scala/ch/epfl/bluebrain/nexus/iam/permissions/PermissionsRejection.scala +++ b/src/main/scala/ch/epfl/bluebrain/nexus/iam/permissions/PermissionsRejection.scala @@ -77,9 +77,11 @@ object PermissionsRejection { s"Incorrect revision '$provided' provided, expected '$expected', permissions may have been updated since last seen." ) + private[PermissionsRejection] implicit val rejectionConfig: Configuration = + Configuration.default.withDiscriminator("@type") + implicit val permissionRejectionEncoder: Encoder[PermissionsRejection] = { - implicit val rejectionConfig: Configuration = Configuration.default.withDiscriminator("@type") - val enc = deriveConfiguredEncoder[PermissionsRejection].mapJson(_ addContext errorCtxUri) + val enc = deriveConfiguredEncoder[PermissionsRejection].mapJson(_ addContext errorCtxUri) Encoder.instance(r => enc(r) deepMerge Json.obj("reason" -> Json.fromString(r.msg))) } diff --git a/src/main/scala/ch/epfl/bluebrain/nexus/iam/realms/ActiveRealm.scala b/src/main/scala/ch/epfl/bluebrain/nexus/iam/realms/ActiveRealm.scala index 8819d62..48c9560 100644 --- a/src/main/scala/ch/epfl/bluebrain/nexus/iam/realms/ActiveRealm.scala +++ b/src/main/scala/ch/epfl/bluebrain/nexus/iam/realms/ActiveRealm.scala @@ -48,23 +48,23 @@ final case class ActiveRealm( val jwks = keys.foldLeft(Set.empty[JWK]) { case (acc, e) => Try(JWK.parse(e.noSpaces)).map(acc + _).getOrElse(acc) } - import scala.collection.JavaConverters._ + import scala.jdk.CollectionConverters._ new JWKSet(jwks.toList.asJava) } } object ActiveRealm { + private[ActiveRealm] implicit val config: Configuration = Configuration.default.copy(transformMemberNames = { + case "issuer" => nxv.issuer.prefix + case "grantTypes" => nxv.grantTypes.prefix + case "authorizationEndpoint" => nxv.authorizationEndpoint.prefix + case "tokenEndpoint" => nxv.tokenEndpoint.prefix + case "userInfoEndpoint" => nxv.userInfoEndpoint.prefix + case "revocationEndpoint" => nxv.revocationEndpoint.prefix + case "endSessionEndpoint" => nxv.endSessionEndpoint.prefix + case other => other + }) implicit val activeEncoder: Encoder[ActiveRealm] = { - implicit val config: Configuration = Configuration.default.copy(transformMemberNames = { - case "issuer" => nxv.issuer.prefix - case "grantTypes" => nxv.grantTypes.prefix - case "authorizationEndpoint" => nxv.authorizationEndpoint.prefix - case "tokenEndpoint" => nxv.tokenEndpoint.prefix - case "userInfoEndpoint" => nxv.userInfoEndpoint.prefix - case "revocationEndpoint" => nxv.revocationEndpoint.prefix - case "endSessionEndpoint" => nxv.endSessionEndpoint.prefix - case other => other - }) val default = deriveConfiguredEncoder[ActiveRealm] Encoder .instance[ActiveRealm] { realm => diff --git a/src/main/scala/ch/epfl/bluebrain/nexus/iam/realms/Groups.scala b/src/main/scala/ch/epfl/bluebrain/nexus/iam/realms/Groups.scala index 353061f..a7fc373 100644 --- a/src/main/scala/ch/epfl/bluebrain/nexus/iam/realms/Groups.scala +++ b/src/main/scala/ch/epfl/bluebrain/nexus/iam/realms/Groups.scala @@ -22,9 +22,9 @@ import ch.epfl.bluebrain.nexus.iam.types.Identity.Group import ch.epfl.bluebrain.nexus.iam.types.{IamError, Label} import com.nimbusds.jwt.JWTClaimsSet import io.circe.{Decoder, HCursor, Json} -import journal.Logger import retry.RetryPolicy import ch.epfl.bluebrain.nexus.iam.instances._ +import com.typesafe.scalalogging.Logger import retry.CatsEffect._ import retry._ import retry.syntax.all._ @@ -66,7 +66,7 @@ class Groups[F[_]: Timer](ref: ActorRef)( } private def fromClaimSet(claimsSet: JWTClaimsSet, realmId: Label): Set[Group] = { - import scala.collection.JavaConverters._ + import scala.jdk.CollectionConverters._ val strings = Try(claimsSet.getStringListClaim("groups").asScala.toList) .filter(_ != null) .map(_.map(_.trim)) @@ -152,7 +152,7 @@ object Groups { )(implicit as: ActorSystem, cfg: GroupsConfig, hc: HttpClient[F, Json]): F[Groups[F]] = { val settings = shardingSettings.getOrElse(ClusterShardingSettings(as)) val shardExtractor: ExtractShardId = { - case msg: Msg => math.abs(msg.token.value.hashCode) % cfg.shards toString + case msg: Msg => (math.abs(msg.token.value.hashCode) % cfg.shards).toString } val entityExtractor: ExtractEntityId = { case msg: Msg => (msg.token.value, msg) diff --git a/src/main/scala/ch/epfl/bluebrain/nexus/iam/realms/RealmEvent.scala b/src/main/scala/ch/epfl/bluebrain/nexus/iam/realms/RealmEvent.scala index 9d0e9f4..bfee860 100644 --- a/src/main/scala/ch/epfl/bluebrain/nexus/iam/realms/RealmEvent.scala +++ b/src/main/scala/ch/epfl/bluebrain/nexus/iam/realms/RealmEvent.scala @@ -134,7 +134,7 @@ object RealmEvent { import ch.epfl.bluebrain.nexus.iam.types.GrantType.Camel._ import io.circe.generic.extras.semiauto._ - private implicit val config: Configuration = Configuration.default + private[JsonLd] implicit val config: Configuration = Configuration.default .withDiscriminator("@type") .copy(transformMemberNames = { case "id" => nxv.label.prefix @@ -152,9 +152,11 @@ object RealmEvent { case other => other }) + private[JsonLd] implicit def subjectEncoder(implicit http: HttpConfig): Encoder[Subject] = + Identity.subjectIdEncoder + implicit def realmEventEncoder(implicit http: HttpConfig): Encoder[Event] = { Encoder.encodeJson.contramap[Event] { ev => - implicit val subjectEncoder: Encoder[Subject] = Identity.subjectIdEncoder deriveConfiguredEncoder[Event] .mapJson { json => val id = Json.obj("@id" -> Json.fromString((http.realmsIri + ev.id.value).asUri)) diff --git a/src/main/scala/ch/epfl/bluebrain/nexus/iam/realms/RealmRejection.scala b/src/main/scala/ch/epfl/bluebrain/nexus/iam/realms/RealmRejection.scala index ccb7c4f..5b79c8d 100644 --- a/src/main/scala/ch/epfl/bluebrain/nexus/iam/realms/RealmRejection.scala +++ b/src/main/scala/ch/epfl/bluebrain/nexus/iam/realms/RealmRejection.scala @@ -137,9 +137,10 @@ object RealmRejection { final case class NoValidKeysFound(document: Url) extends RealmRejection(s"Failed to find a valid RSA JWK key at '${document.asUri}'.") + private[RealmRejection] implicit val rejectionConfig: Configuration = Configuration.default.withDiscriminator("@type") + implicit val realmRejectionEncoder: Encoder[RealmRejection] = { - implicit val rejectionConfig: Configuration = Configuration.default.withDiscriminator("@type") - val enc = deriveConfiguredEncoder[RealmRejection].mapJson(_ addContext errorCtxUri) + val enc = deriveConfiguredEncoder[RealmRejection].mapJson(_ addContext errorCtxUri) Encoder.instance(r => enc(r) deepMerge Json.obj("reason" -> Json.fromString(r.msg))) } diff --git a/src/main/scala/ch/epfl/bluebrain/nexus/iam/realms/Realms.scala b/src/main/scala/ch/epfl/bluebrain/nexus/iam/realms/Realms.scala index dbe87c3..bae7ecd 100644 --- a/src/main/scala/ch/epfl/bluebrain/nexus/iam/realms/Realms.scala +++ b/src/main/scala/ch/epfl/bluebrain/nexus/iam/realms/Realms.scala @@ -9,7 +9,7 @@ import akka.persistence.query.{NoOffset, PersistenceQuery} import akka.stream.scaladsl.Source import cats.Monad import cats.data.EitherT -import cats.effect._ +import cats.effect.{Clock, Effect, Timer} import cats.implicits._ import ch.epfl.bluebrain.nexus.commons.cache.{KeyValueStore, KeyValueStoreConfig} import ch.epfl.bluebrain.nexus.commons.http.HttpClient diff --git a/src/main/scala/ch/epfl/bluebrain/nexus/iam/routes/AclsRoutes.scala b/src/main/scala/ch/epfl/bluebrain/nexus/iam/routes/AclsRoutes.scala index b5fe011..74025fa 100644 --- a/src/main/scala/ch/epfl/bluebrain/nexus/iam/routes/AclsRoutes.scala +++ b/src/main/scala/ch/epfl/bluebrain/nexus/iam/routes/AclsRoutes.scala @@ -51,7 +51,7 @@ class AclsRoutes(acls: Acls[Task], realms: Realms[Task])(implicit hc: HttpConfig } ) }, - (get & parameter("rev".as[Long] ?) & parameter("ancestors" ? false) & parameter("self" ? true)) { + (get & parameter("rev".as[Long].?) & parameter("ancestors" ? false) & parameter("self" ? true)) { case (Some(_), true, _) => reject(simultaneousRevAndAncestorsRejection) case (Some(_), _, _) if path.segments.contains(any) => diff --git a/src/main/scala/ch/epfl/bluebrain/nexus/iam/routes/EventRoutes.scala b/src/main/scala/ch/epfl/bluebrain/nexus/iam/routes/EventRoutes.scala index b78c350..9abb517 100644 --- a/src/main/scala/ch/epfl/bluebrain/nexus/iam/routes/EventRoutes.scala +++ b/src/main/scala/ch/epfl/bluebrain/nexus/iam/routes/EventRoutes.scala @@ -91,7 +91,7 @@ class EventRoutes(acls: Acls[Task], realms: Realms[Task])( ): Source[ServerSentEvent, NotUsed] = { pq.eventsByTag(tag, offset) .flatMapConcat(ee => Source(toSse(ee).toList)) - .keepAlive(10 seconds, () => ServerSentEvent.heartbeat) + .keepAlive(10.seconds, () => ServerSentEvent.heartbeat) } private def lastEventId: Directive1[Offset] = diff --git a/src/main/scala/ch/epfl/bluebrain/nexus/iam/routes/Routes.scala b/src/main/scala/ch/epfl/bluebrain/nexus/iam/routes/Routes.scala index 694e98c..5caceda 100644 --- a/src/main/scala/ch/epfl/bluebrain/nexus/iam/routes/Routes.scala +++ b/src/main/scala/ch/epfl/bluebrain/nexus/iam/routes/Routes.scala @@ -20,7 +20,7 @@ import ch.epfl.bluebrain.nexus.iam.types.IamError.{InternalError, InvalidAccessT import ch.epfl.bluebrain.nexus.iam.types.{IamError, ResourceRejection} import ch.megard.akka.http.cors.scaladsl.CorsDirectives.{cors, corsRejectionHandler} import ch.megard.akka.http.cors.scaladsl.settings.CorsSettings -import journal.Logger +import com.typesafe.scalalogging.Logger import monix.eval.Task object Routes { diff --git a/src/main/scala/ch/epfl/bluebrain/nexus/iam/types/IamError.scala b/src/main/scala/ch/epfl/bluebrain/nexus/iam/types/IamError.scala index e66723f..7ad2054 100644 --- a/src/main/scala/ch/epfl/bluebrain/nexus/iam/types/IamError.scala +++ b/src/main/scala/ch/epfl/bluebrain/nexus/iam/types/IamError.scala @@ -67,9 +67,10 @@ object IamError { */ final case object NotFound extends IamError("The requested resource could not be found.") + private[IamError] implicit val rejectionConfig: Configuration = Configuration.default.withDiscriminator("@type") + implicit val iamErrorEncoder: Encoder[IamError] = { - implicit val rejectionConfig: Configuration = Configuration.default.withDiscriminator("@type") - val enc = deriveConfiguredEncoder[IamError].mapJson(_ addContext errorCtxUri) + val enc = deriveConfiguredEncoder[IamError].mapJson(_ addContext errorCtxUri) Encoder.instance(r => enc(r) deepMerge Json.obj("reason" -> Json.fromString(r.msg))) } } diff --git a/src/main/scala/ch/epfl/bluebrain/nexus/iam/types/Identity.scala b/src/main/scala/ch/epfl/bluebrain/nexus/iam/types/Identity.scala index b0038e1..13348bb 100644 --- a/src/main/scala/ch/epfl/bluebrain/nexus/iam/types/Identity.scala +++ b/src/main/scala/ch/epfl/bluebrain/nexus/iam/types/Identity.scala @@ -68,7 +68,7 @@ object Identity { http.publicIri + (http.prefix / "realms" / realm / "authenticated") } - private implicit val config: Configuration = Configuration.default.withDiscriminator("@type") + private[Identity] implicit val config: Configuration = Configuration.default.withDiscriminator("@type") implicit def identityEncoder(implicit http: HttpConfig): Encoder[Identity] = { val enc = deriveConfiguredEncoder[Identity] @@ -122,4 +122,9 @@ object Identity { case (_, f) => f(hc) } } + + object JsonLd { + implicit def subjectAsIriEncoder(implicit httpConfig: HttpConfig): Encoder[Subject] = + subjectIdEncoder(httpConfig) + } } diff --git a/src/test/scala/ch/epfl/bluebrain/nexus/iam/acls/AccessControlListSpec.scala b/src/test/scala/ch/epfl/bluebrain/nexus/iam/acls/AccessControlListSpec.scala index e364ea1..a853aa4 100644 --- a/src/test/scala/ch/epfl/bluebrain/nexus/iam/acls/AccessControlListSpec.scala +++ b/src/test/scala/ch/epfl/bluebrain/nexus/iam/acls/AccessControlListSpec.scala @@ -1,14 +1,16 @@ package ch.epfl.bluebrain.nexus.iam.acls -import ch.epfl.bluebrain.nexus.commons.test.Resources +import ch.epfl.bluebrain.nexus.commons.test.{EitherValues, Resources} import ch.epfl.bluebrain.nexus.iam.config.AppConfig.HttpConfig import ch.epfl.bluebrain.nexus.iam.types.Identity._ import ch.epfl.bluebrain.nexus.iam.types.{Identity, Permission} import io.circe.syntax._ -import org.scalatest._ +import org.scalatest.matchers.should.Matchers +import org.scalatest.wordspec.AnyWordSpecLike +import org.scalatest.{Inspectors, OptionValues} class AccessControlListSpec - extends WordSpecLike + extends AnyWordSpecLike with Matchers with Inspectors with EitherValues @@ -20,7 +22,8 @@ class AccessControlListSpec val group: Identity = Group("mygroup", "myrealm") val readWrite = Set(Permission("acls/read").value, Permission("acls/write").value) val manage = Set(Permission("acls/manage").value) - implicit val http = HttpConfig("some", 8080, "v1", "http://nexus.example.com") + + implicit val http: HttpConfig = HttpConfig("some", 8080, "v1", "http://nexus.example.com") "converted to Json" in { val acls = AccessControlList(user -> readWrite, group -> manage) @@ -30,7 +33,7 @@ class AccessControlListSpec "convert from Json" in { val acls = AccessControlList(user -> readWrite, group -> manage) val json = jsonContentOf("/acls/acl.json") - json.as[AccessControlList].right.value shouldEqual acls + json.as[AccessControlList].rightValue shouldEqual acls } "remove ACL" in { diff --git a/src/test/scala/ch/epfl/bluebrain/nexus/iam/acls/AccessControlListsSpec.scala b/src/test/scala/ch/epfl/bluebrain/nexus/iam/acls/AccessControlListsSpec.scala index a35a07e..16a2f0b 100644 --- a/src/test/scala/ch/epfl/bluebrain/nexus/iam/acls/AccessControlListsSpec.scala +++ b/src/test/scala/ch/epfl/bluebrain/nexus/iam/acls/AccessControlListsSpec.scala @@ -2,19 +2,20 @@ package ch.epfl.bluebrain.nexus.iam.acls import java.time.{Clock, Instant, ZoneId} -import ch.epfl.bluebrain.nexus.commons.test.Resources +import ch.epfl.bluebrain.nexus.commons.test.{EitherValues, Resources} import ch.epfl.bluebrain.nexus.iam.config.AppConfig.HttpConfig import ch.epfl.bluebrain.nexus.iam.config.Vocabulary._ import ch.epfl.bluebrain.nexus.iam.types.Identity._ import ch.epfl.bluebrain.nexus.iam.types.{Permission, ResourceF} -import ch.epfl.bluebrain.nexus.rdf.Iri.{AbsoluteIri, Path} import ch.epfl.bluebrain.nexus.rdf.Iri.Path._ +import ch.epfl.bluebrain.nexus.rdf.Iri.{AbsoluteIri, Path} import ch.epfl.bluebrain.nexus.rdf.Vocabulary._ import io.circe.syntax._ -import org.scalatest.{EitherValues, Matchers, WordSpecLike} +import org.scalatest.matchers.should.Matchers +import org.scalatest.wordspec.AnyWordSpecLike //noinspection TypeAnnotation,NameBooleanParameters -class AccessControlListsSpec extends WordSpecLike with Matchers with Resources with EitherValues { +class AccessControlListsSpec extends AnyWordSpecLike with Matchers with Resources with EitherValues { private val clock: Clock = Clock.fixed(Instant.ofEpochSecond(3600), ZoneId.systemDefault()) private implicit val http = HttpConfig("some", 8080, "v1", "http://nexus.example.com") @@ -69,16 +70,16 @@ class AccessControlListsSpec extends WordSpecLike with Matchers with Resources w } "sort ACLs" in { AccessControlLists( - "aa" / "bb" -> acl, - / -> acl3, - "a" / "b" -> acl.map(_ => AccessControlList.empty), - Path("/a").right.value -> acl2 + "aa" / "bb" -> acl, + / -> acl3, + "a" / "b" -> acl.map(_ => AccessControlList.empty), + Path("/a").rightValue -> acl2 ).sorted shouldEqual AccessControlLists( - / -> acl3, - Path("/a").right.value -> acl2, - "a" / "b" -> acl.map(_ => AccessControlList.empty), - "aa" / "bb" -> acl + / -> acl3, + Path("/a").rightValue -> acl2, + "a" / "b" -> acl.map(_ => AccessControlList.empty), + "aa" / "bb" -> acl ) } @@ -111,8 +112,8 @@ class AccessControlListsSpec extends WordSpecLike with Matchers with Resources w "converts ACL to Json" in { val acls = AccessControlLists( - Path("/one/two").right.value -> acl.map(_ => AccessControlList(user -> readWrite, group -> manage)), - Path("/one").right.value -> acl2.map(_ => AccessControlList(user -> readWrite)) + Path("/one/two").rightValue -> acl.map(_ => AccessControlList(user -> readWrite, group -> manage)), + Path("/one").rightValue -> acl2.map(_ => AccessControlList(user -> readWrite)) ) val json = jsonContentOf("/acls/acls.json") acls.asJson shouldEqual json diff --git a/src/test/scala/ch/epfl/bluebrain/nexus/iam/acls/AclsSpec.scala b/src/test/scala/ch/epfl/bluebrain/nexus/iam/acls/AclsSpec.scala index d67d4ee..015b20c 100644 --- a/src/test/scala/ch/epfl/bluebrain/nexus/iam/acls/AclsSpec.scala +++ b/src/test/scala/ch/epfl/bluebrain/nexus/iam/acls/AclsSpec.scala @@ -19,7 +19,8 @@ import ch.epfl.bluebrain.nexus.rdf.Iri.Path._ import ch.epfl.bluebrain.nexus.rdf.Iri.{AbsoluteIri, Path} import ch.epfl.bluebrain.nexus.rdf.Vocabulary._ import org.mockito.IdiomaticMockito -import org.scalatest._ +import org.scalatest.Inspectors +import org.scalatest.matchers.should.Matchers import scala.concurrent.ExecutionContext import scala.concurrent.duration._ @@ -35,7 +36,7 @@ class AclsSpec with Inspectors with IdiomaticMockito { - override implicit val patienceConfig: PatienceConfig = PatienceConfig(3 seconds, 50 milliseconds) + override implicit val patienceConfig: PatienceConfig = PatienceConfig(3.seconds, 50.milliseconds) implicit val appConfig: AppConfig = Settings(system).appConfig val http = appConfig.http @@ -70,7 +71,7 @@ class AclsSpec val createdBy: Subject = User("sub", "realm") implicit val caller = Caller(createdBy, Set[Identity](Group("admin", "realm"), Anonymous)) val path: Path = genString(length = 4) / genString(length = 4) - val id: AbsoluteIri = Iri.absolute("http://127.0.0.1:8080/v1/acls/").right.value + path.asString + val id: AbsoluteIri = Iri.absolute("http://127.0.0.1:8080/v1/acls/").rightValue + path.asString val user1 = identities(genInt(max = 1)) val user2 = identities.filterNot(_ == user1).head val permsUser1 = Random.shuffle(permissions).take(1 + genInt(max = 299)) diff --git a/src/test/scala/ch/epfl/bluebrain/nexus/iam/directives/RealmDirectivesSpec.scala b/src/test/scala/ch/epfl/bluebrain/nexus/iam/directives/RealmDirectivesSpec.scala index 4208383..8bc5336 100644 --- a/src/test/scala/ch/epfl/bluebrain/nexus/iam/directives/RealmDirectivesSpec.scala +++ b/src/test/scala/ch/epfl/bluebrain/nexus/iam/directives/RealmDirectivesSpec.scala @@ -6,6 +6,7 @@ import akka.http.scaladsl.server.Directives._ import akka.http.scaladsl.server.Route import akka.http.scaladsl.testkit.ScalatestRouteTest import ch.epfl.bluebrain.nexus.commons.http.JsonLdCirceSupport._ +import ch.epfl.bluebrain.nexus.commons.test.EitherValues import ch.epfl.bluebrain.nexus.iam.directives.RealmDirectives._ import ch.epfl.bluebrain.nexus.iam.routes.SearchParams import ch.epfl.bluebrain.nexus.rdf.Iri.AbsoluteIri @@ -14,10 +15,11 @@ import ch.epfl.bluebrain.nexus.rdf.syntax._ import io.circe.generic.auto._ import org.mockito.IdiomaticMockito import org.scalatest.concurrent.ScalaFutures -import org.scalatest.{EitherValues, Matchers, WordSpecLike} +import org.scalatest.matchers.should.Matchers +import org.scalatest.wordspec.AnyWordSpecLike class RealmDirectivesSpec - extends WordSpecLike + extends AnyWordSpecLike with ScalatestRouteTest with Matchers with ScalaFutures diff --git a/src/test/scala/ch/epfl/bluebrain/nexus/iam/index/InMemoryAclsTreeBenchmark.scala b/src/test/scala/ch/epfl/bluebrain/nexus/iam/index/InMemoryAclsTreeBenchmark.scala index 7c92e00..149c5f6 100644 --- a/src/test/scala/ch/epfl/bluebrain/nexus/iam/index/InMemoryAclsTreeBenchmark.scala +++ b/src/test/scala/ch/epfl/bluebrain/nexus/iam/index/InMemoryAclsTreeBenchmark.scala @@ -5,7 +5,7 @@ import java.time.{Clock, Instant, ZoneId} import akka.actor.ActorSystem import akka.testkit.TestKit import cats.Id -import ch.epfl.bluebrain.nexus.commons.test.Randomness +import ch.epfl.bluebrain.nexus.commons.test.{EitherValues, Randomness} import ch.epfl.bluebrain.nexus.iam.acls.{State => _, _} import ch.epfl.bluebrain.nexus.iam.config.AppConfig._ import ch.epfl.bluebrain.nexus.iam.config.{AppConfig, Settings} @@ -14,7 +14,6 @@ import ch.epfl.bluebrain.nexus.iam.types.{Identity, Permission, ResourceF} import ch.epfl.bluebrain.nexus.rdf.Iri.Path import ch.epfl.bluebrain.nexus.rdf.Iri.Path._ import org.openjdk.jmh.annotations._ -import org.scalatest.EitherValues import scala.util.Random @@ -84,7 +83,7 @@ class InMemoryAclsTreeBenchmark ) genInt(max = 2) match { case 0 => index.replace(/, acl.copy(rev = v.toLong)) - case 1 => index.replace(Path(org).right.value, acl.copy(rev = v.toLong)) + case 1 => index.replace(Path(org).rightValue, acl.copy(rev = v.toLong)) case 2 => index.replace(org / project, acl.copy(rev = v.toLong)) } } @@ -93,7 +92,7 @@ class InMemoryAclsTreeBenchmark def listSmallAclOrgs(): Unit = { implicit val identities: Set[Identity] = Random.shuffle(users1).take(10).toSet - val _ = index1.get(Path("*").right.value, ancestors = false, self = false) + val _ = index1.get(Path("*").rightValue, ancestors = false, self = false) } @Benchmark @@ -127,7 +126,7 @@ class InMemoryAclsTreeBenchmark def listBigAclOrgs(): Unit = { implicit val identities: Set[Identity] = Random.shuffle(users2).take(10).toSet - val _ = index2.get(Path("*").right.value, ancestors = false, self = false) + val _ = index2.get(Path("*").rightValue, ancestors = false, self = false) } @Benchmark diff --git a/src/test/scala/ch/epfl/bluebrain/nexus/iam/index/InMemoryAclsTreeSpec.scala b/src/test/scala/ch/epfl/bluebrain/nexus/iam/index/InMemoryAclsTreeSpec.scala index c62cc8f..e101500 100644 --- a/src/test/scala/ch/epfl/bluebrain/nexus/iam/index/InMemoryAclsTreeSpec.scala +++ b/src/test/scala/ch/epfl/bluebrain/nexus/iam/index/InMemoryAclsTreeSpec.scala @@ -3,7 +3,7 @@ package ch.epfl.bluebrain.nexus.iam.index import java.time.{Clock, Instant, ZoneId} import cats.Id -import ch.epfl.bluebrain.nexus.commons.test.ActorSystemFixture +import ch.epfl.bluebrain.nexus.commons.test.{ActorSystemFixture, EitherValues} import ch.epfl.bluebrain.nexus.iam.acls.{read => readAcls, _} import ch.epfl.bluebrain.nexus.iam.config.AppConfig._ import ch.epfl.bluebrain.nexus.iam.config.{AppConfig, Settings} @@ -11,12 +11,14 @@ import ch.epfl.bluebrain.nexus.iam.types.Identity._ import ch.epfl.bluebrain.nexus.iam.types._ import ch.epfl.bluebrain.nexus.rdf.Iri.Path import ch.epfl.bluebrain.nexus.rdf.Iri.Path._ -import org.scalatest._ +import org.scalatest.matchers.should.Matchers +import org.scalatest.wordspec.AnyWordSpecLike +import org.scalatest.{Inspectors, OptionValues} //noinspection NameBooleanParameters,TypeAnnotation class InMemoryAclsTreeSpec extends ActorSystemFixture("InMemoryAclsTreeSpec", false) - with WordSpecLike + with AnyWordSpecLike with Matchers with OptionValues with Inspectors @@ -141,7 +143,7 @@ class InMemoryAclsTreeSpec } "add ACLs on /org1" in { - index.replace(Path("/org1").right.value, aclOrg) shouldEqual true + index.replace(Path("/org1").rightValue, aclOrg) shouldEqual true } "failed to add ACLs on /org1 with same revision" in { @@ -156,23 +158,23 @@ class InMemoryAclsTreeSpec user2, AccessControlList(user2 -> Set(Permission("new").value)) ) - index.replace(Path("/org1").right.value, acl) shouldEqual false + index.replace(Path("/org1").rightValue, acl) shouldEqual false } "fetch ACLs on /org1" in { forAll(options) { case (ancestors, self) => - index.get(Path("/org1").right.value, ancestors, self)(Set(user2, group)) shouldEqual - AccessControlLists(Path("/org1").right.value -> aclOrg) + index.get(Path("/org1").rightValue, ancestors, self)(Set(user2, group)) shouldEqual + AccessControlLists(Path("/org1").rightValue -> aclOrg) - index.get(Path("/org1").right.value, ancestors, self)(Set(user)) shouldEqual AccessControlLists.empty + index.get(Path("/org1").rightValue, ancestors, self)(Set(user)) shouldEqual AccessControlLists.empty } - index.get(Path("/org1").right.value, ancestors = false, self = true)(Set(user2)) shouldEqual - AccessControlLists(Path("/org1").right.value -> aclOrg.map(_ => AccessControlList(user2 -> Set(read, other)))) + index.get(Path("/org1").rightValue, ancestors = false, self = true)(Set(user2)) shouldEqual + AccessControlLists(Path("/org1").rightValue -> aclOrg.map(_ => AccessControlList(user2 -> Set(read, other)))) - index.get(Path("/org1").right.value, ancestors = true, self = true)(Set(group)) shouldEqual + index.get(Path("/org1").rightValue, ancestors = true, self = true)(Set(group)) shouldEqual AccessControlLists( - Path("/org1").right.value -> aclOrg.map(_ => AccessControlList(group -> Set(write, readAcls))) + Path("/org1").rightValue -> aclOrg.map(_ => AccessControlList(group -> Set(write, readAcls))) ) } @@ -195,8 +197,8 @@ class InMemoryAclsTreeSpec index.get("org1" / "proj1", ancestors = true, self = true)(Set(group)) shouldEqual AccessControlLists( - Path("/org1").right.value -> aclOrg.map(_ => AccessControlList(group -> Set(write, readAcls))), - "org1" / "proj1" -> aclProject1_org1.map(_ => AccessControlList(group -> Set(read))) + Path("/org1").rightValue -> aclOrg.map(_ => AccessControlList(group -> Set(write, readAcls))), + "org1" / "proj1" -> aclProject1_org1.map(_ => AccessControlList(group -> Set(read))) ) } @@ -217,51 +219,51 @@ class InMemoryAclsTreeSpec } "add acls on /org2" in { - index.replace(Path("/org2").right.value, aclOrg2) shouldEqual true + index.replace(Path("/org2").rightValue, aclOrg2) shouldEqual true } "fetch ACLs on /org2" in { - index.get(Path("/org2").right.value, ancestors = true, self = true)(Set(user, group)) shouldEqual + index.get(Path("/org2").rightValue, ancestors = true, self = true)(Set(user, group)) shouldEqual AccessControlLists( - / -> aclRoot.map(_ => AccessControlList(group -> Set(read))), - Path("/org2").right.value -> aclOrg2 + / -> aclRoot.map(_ => AccessControlList(group -> Set(read))), + Path("/org2").rightValue -> aclOrg2 ) - index.get(Path("/org2").right.value, ancestors = true, self = false)(Set(group)) shouldEqual + index.get(Path("/org2").rightValue, ancestors = true, self = false)(Set(group)) shouldEqual AccessControlLists(/ -> aclRoot.map(_ => AccessControlList(group -> Set(read)))) - index.get(Path("/org2").right.value, ancestors = true, self = false)(Set(user2)) shouldEqual - AccessControlLists(/ -> aclRoot, Path("/org2").right.value -> aclOrg2) + index.get(Path("/org2").rightValue, ancestors = true, self = false)(Set(user2)) shouldEqual + AccessControlLists(/ -> aclRoot, Path("/org2").rightValue -> aclOrg2) forAll(options) { case (ancestors, self) => - index.get(Path("/org2").right.value, ancestors = false, self = false)(Set(user)) shouldEqual - AccessControlLists(Path("/org2").right.value -> aclOrg2) + index.get(Path("/org2").rightValue, ancestors = false, self = false)(Set(user)) shouldEqual + AccessControlLists(Path("/org2").rightValue -> aclOrg2) - index.get(Path("/org2").right.value, ancestors, self)(Set(Anonymous)) shouldEqual AccessControlLists.empty + index.get(Path("/org2").rightValue, ancestors, self)(Set(Anonymous)) shouldEqual AccessControlLists.empty } } "fetch ACLs on /*" in { - index.get(Path("/*").right.value, ancestors = true, self = true)(Set(user2)) shouldEqual + index.get(Path("/*").rightValue, ancestors = true, self = true)(Set(user2)) shouldEqual AccessControlLists( - / -> aclRoot.map(_ => AccessControlList(user2 -> Set(other, readAcls))), - Path("/org1").right.value -> aclOrg.map(_ => AccessControlList(user2 -> Set(read, other))) + / -> aclRoot.map(_ => AccessControlList(user2 -> Set(other, readAcls))), + Path("/org1").rightValue -> aclOrg.map(_ => AccessControlList(user2 -> Set(read, other))) ) - index.get(Path("/*").right.value, ancestors = true, self = false)(Set(user2)) shouldEqual - AccessControlLists(/ -> aclRoot, Path("/org1").right.value -> aclOrg, Path("/org2").right.value -> aclOrg2) + index.get(Path("/*").rightValue, ancestors = true, self = false)(Set(user2)) shouldEqual + AccessControlLists(/ -> aclRoot, Path("/org1").rightValue -> aclOrg, Path("/org2").rightValue -> aclOrg2) - index.get(Path("/*").right.value, ancestors = false, self = true)(Set(user2)) shouldEqual - AccessControlLists(Path("/org1").right.value -> aclOrg.map(_ => AccessControlList(user2 -> Set(read, other)))) + index.get(Path("/*").rightValue, ancestors = false, self = true)(Set(user2)) shouldEqual + AccessControlLists(Path("/org1").rightValue -> aclOrg.map(_ => AccessControlList(user2 -> Set(read, other)))) - index.get(Path("/*").right.value, ancestors = false, self = false)(Set(user2)) shouldEqual - AccessControlLists(Path("/org1").right.value -> aclOrg, Path("/org2").right.value -> aclOrg2) + index.get(Path("/*").rightValue, ancestors = false, self = false)(Set(user2)) shouldEqual + AccessControlLists(Path("/org1").rightValue -> aclOrg, Path("/org2").rightValue -> aclOrg2) - index.get(Path("/*").right.value, ancestors = true, self = false)(Set(group)) shouldEqual + index.get(Path("/*").rightValue, ancestors = true, self = false)(Set(group)) shouldEqual AccessControlLists( - / -> aclRoot.map(_ => AccessControlList(group -> Set(read))), - Path("/org1").right.value -> aclOrg + / -> aclRoot.map(_ => AccessControlList(group -> Set(read))), + Path("/org1").rightValue -> aclOrg ) } @@ -272,20 +274,20 @@ class InMemoryAclsTreeSpec "fetch ACLs on /org2/proj1" in { index.get("org2" / "proj1", ancestors = true, self = true)(Set(user, group)) shouldEqual AccessControlLists( - / -> aclRoot.map(_ => AccessControlList(group -> Set(read))), - Path("/org2").right.value -> aclOrg2, - "org2" / "proj1" -> aclProject1_org2 + / -> aclRoot.map(_ => AccessControlList(group -> Set(read))), + Path("/org2").rightValue -> aclOrg2, + "org2" / "proj1" -> aclProject1_org2 ) index.get("org2" / "proj1", ancestors = true, self = false)(Set(user, group)) shouldEqual AccessControlLists( - / -> aclRoot.map(_ => AccessControlList(group -> Set(read))), - Path("/org2").right.value -> aclOrg2, - "org2" / "proj1" -> aclProject1_org2 + / -> aclRoot.map(_ => AccessControlList(group -> Set(read))), + Path("/org2").rightValue -> aclOrg2, + "org2" / "proj1" -> aclProject1_org2 ) index.get("org2" / "proj1", ancestors = true, self = false)(Set(user)) shouldEqual - AccessControlLists(Path("/org2").right.value -> aclOrg2, "org2" / "proj1" -> aclProject1_org2) + AccessControlLists(Path("/org2").rightValue -> aclOrg2, "org2" / "proj1" -> aclProject1_org2) index.get("org2" / "proj1", ancestors = true, self = false)(Set(group)) shouldEqual AccessControlLists( @@ -306,7 +308,7 @@ class InMemoryAclsTreeSpec AccessControlLists.empty index.get("org2" / "proj1", ancestors = true, self = false)(Set(user2)) shouldEqual - AccessControlLists(/ -> aclRoot, Path("/org2").right.value -> aclOrg2, "org2" / "proj1" -> aclProject1_org2) + AccessControlLists(/ -> aclRoot, Path("/org2").rightValue -> aclOrg2, "org2" / "proj1" -> aclProject1_org2) } "add acls on /org1/proj2" in { @@ -316,16 +318,16 @@ class InMemoryAclsTreeSpec "fetch ACLs on /org1/proj2" in { index.get("org1" / "proj2", ancestors = true, self = true)(Set(user, group)) shouldEqual AccessControlLists( - / -> aclRoot.map(_ => AccessControlList(group -> Set(read))), - Path("/org1").right.value -> aclOrg.map(_ => AccessControlList(group -> Set(write, readAcls))), - "org1" / "proj2" -> aclProject2_org1 + / -> aclRoot.map(_ => AccessControlList(group -> Set(read))), + Path("/org1").rightValue -> aclOrg.map(_ => AccessControlList(group -> Set(write, readAcls))), + "org1" / "proj2" -> aclProject2_org1 ) index.get("org1" / "proj2", ancestors = true, self = false)(Set(group)) shouldEqual AccessControlLists( - / -> aclRoot.map(_ => AccessControlList(group -> Set(read))), - Path("/org1").right.value -> aclOrg, - "org1" / "proj2" -> aclProject2_org1 + / -> aclRoot.map(_ => AccessControlList(group -> Set(read))), + Path("/org1").rightValue -> aclOrg, + "org1" / "proj2" -> aclProject2_org1 ) index.get("org1" / "proj2", ancestors = true, self = false)(Set(user)) shouldEqual @@ -357,26 +359,26 @@ class InMemoryAclsTreeSpec index.get("*" / "proj1", ancestors = true, self = true)(Set(group)) shouldEqual AccessControlLists( - "org1" / "proj1" -> aclProject1_org1.map(_ => AccessControlList(group -> Set(read))), - "org2" / "proj1" -> aclProject1_org2, - Path("/org1").right.value -> aclOrg.map(_ => AccessControlList(group -> Set(write, readAcls))), - / -> aclRoot.map(_ => AccessControlList(group -> Set(read))) + "org1" / "proj1" -> aclProject1_org1.map(_ => AccessControlList(group -> Set(read))), + "org2" / "proj1" -> aclProject1_org2, + Path("/org1").rightValue -> aclOrg.map(_ => AccessControlList(group -> Set(write, readAcls))), + / -> aclRoot.map(_ => AccessControlList(group -> Set(read))) ) index.get("*" / "proj1", ancestors = true, self = false)(Set(group)) shouldEqual AccessControlLists( - "org2" / "proj1" -> aclProject1_org2, - "org1" / "proj1" -> aclProject1_org1, - Path("/org1").right.value -> aclOrg, - / -> aclRoot.map(_ => AccessControlList(group -> Set(read))) + "org2" / "proj1" -> aclProject1_org2, + "org1" / "proj1" -> aclProject1_org1, + Path("/org1").rightValue -> aclOrg, + / -> aclRoot.map(_ => AccessControlList(group -> Set(read))) ) index.get("*" / "proj1", ancestors = true, self = false)(Set(user2)) shouldEqual AccessControlLists( - "org2" / "proj1" -> aclProject1_org2, - "org1" / "proj1" -> aclProject1_org1, - Path("/org1").right.value -> aclOrg, - Path("/org2").right.value -> aclOrg2, - / -> aclRoot + "org2" / "proj1" -> aclProject1_org2, + "org1" / "proj1" -> aclProject1_org1, + Path("/org1").rightValue -> aclOrg, + Path("/org2").rightValue -> aclOrg2, + / -> aclRoot ) index.get("*" / "proj1", ancestors = false, self = true)(Set(user2)) shouldEqual @@ -399,24 +401,24 @@ class InMemoryAclsTreeSpec index.get("org1" / "*", ancestors = true, self = false)(Set(group)) shouldEqual AccessControlLists( - "org1" / "proj1" -> aclProject1_org1, - "org1" / "proj2" -> aclProject2_org1, - Path("/org1").right.value -> aclOrg, - / -> aclRoot.map(_ => AccessControlList(group -> Set(read))) + "org1" / "proj1" -> aclProject1_org1, + "org1" / "proj2" -> aclProject2_org1, + Path("/org1").rightValue -> aclOrg, + / -> aclRoot.map(_ => AccessControlList(group -> Set(read))) ) index.get("org1" / "*", ancestors = true, self = false)(Set(user2)) shouldEqual AccessControlLists( - "org1" / "proj1" -> aclProject1_org1, - "org1" / "proj2" -> aclProject2_org1, - Path("/org1").right.value -> aclOrg, - / -> aclRoot + "org1" / "proj1" -> aclProject1_org1, + "org1" / "proj2" -> aclProject2_org1, + Path("/org1").rightValue -> aclOrg, + / -> aclRoot ) index.get("org1" / "*", ancestors = true, self = true)(Set(user2)) shouldEqual AccessControlLists( - / -> aclRoot.map(_ => AccessControlList(user2 -> Set(other, readAcls))), - Path("/org1").right.value -> aclOrg.map(_ => AccessControlList(user2 -> Set(read, other))) + / -> aclRoot.map(_ => AccessControlList(user2 -> Set(other, readAcls))), + Path("/org1").rightValue -> aclOrg.map(_ => AccessControlList(user2 -> Set(read, other))) ) } @@ -424,9 +426,9 @@ class InMemoryAclsTreeSpec "fetch ACLs on /*/*" in { index.get("*" / "*", ancestors = true, self = true)(Set(user)) shouldEqual AccessControlLists( - "org1" / "proj1" -> aclProject1_org1.map(_ => AccessControlList(user -> Set(read))), - "org1" / "proj2" -> aclProject2_org1.map(_ => AccessControlList(user -> Set(write))), - Path("/org2").right.value -> aclOrg2.map(_ => AccessControlList(user -> Set(other, readAcls))) + "org1" / "proj1" -> aclProject1_org1.map(_ => AccessControlList(user -> Set(read))), + "org1" / "proj2" -> aclProject2_org1.map(_ => AccessControlList(user -> Set(write))), + Path("/org2").rightValue -> aclOrg2.map(_ => AccessControlList(user -> Set(other, readAcls))) ) index.get("*" / "*", ancestors = false, self = true)(Set(user)) shouldEqual @@ -437,10 +439,10 @@ class InMemoryAclsTreeSpec index.get("*" / "*", ancestors = true, self = false)(Set(user)) shouldEqual AccessControlLists( - "org1" / "proj1" -> aclProject1_org1.map(_ => AccessControlList(user -> Set(read))), - "org1" / "proj2" -> aclProject2_org1.map(_ => AccessControlList(user -> Set(write))), - "org2" / "proj1" -> aclProject1_org2, - Path("/org2").right.value -> aclOrg2.map(_ => AccessControlList(user -> Set(other, readAcls))) + "org1" / "proj1" -> aclProject1_org1.map(_ => AccessControlList(user -> Set(read))), + "org1" / "proj2" -> aclProject2_org1.map(_ => AccessControlList(user -> Set(write))), + "org2" / "proj1" -> aclProject1_org2, + Path("/org2").rightValue -> aclOrg2.map(_ => AccessControlList(user -> Set(other, readAcls))) ) index.get("*" / "*", ancestors = false, self = false)(Set(user)) shouldEqual @@ -452,21 +454,21 @@ class InMemoryAclsTreeSpec index.get("*" / "*", ancestors = true, self = false)(Set(group)) shouldEqual AccessControlLists( - / -> aclRoot.map(_ => AccessControlList(group -> Set(read))), - Path("/org1").right.value -> aclOrg, - "org1" / "proj1" -> aclProject1_org1, - "org1" / "proj2" -> aclProject2_org1, - "org2" / "proj1" -> aclProject1_org2 + / -> aclRoot.map(_ => AccessControlList(group -> Set(read))), + Path("/org1").rightValue -> aclOrg, + "org1" / "proj1" -> aclProject1_org1, + "org1" / "proj2" -> aclProject2_org1, + "org2" / "proj1" -> aclProject1_org2 ) index.get("*" / "*", ancestors = true, self = false)(Set(user2)) shouldEqual AccessControlLists( - / -> aclRoot, - Path("/org1").right.value -> aclOrg, - Path("/org2").right.value -> aclOrg2, - "org1" / "proj1" -> aclProject1_org1, - "org1" / "proj2" -> aclProject2_org1, - "org2" / "proj1" -> aclProject1_org2 + / -> aclRoot, + Path("/org1").rightValue -> aclOrg, + Path("/org2").rightValue -> aclOrg2, + "org1" / "proj1" -> aclProject1_org1, + "org1" / "proj2" -> aclProject2_org1, + "org2" / "proj1" -> aclProject1_org2 ) index.get("*" / "*", ancestors = false, self = false)(Set(user2)) shouldEqual diff --git a/src/test/scala/ch/epfl/bluebrain/nexus/iam/io/EventSerializerSpec.scala b/src/test/scala/ch/epfl/bluebrain/nexus/iam/io/EventSerializerSpec.scala index 8b197d5..81e0cac 100644 --- a/src/test/scala/ch/epfl/bluebrain/nexus/iam/io/EventSerializerSpec.scala +++ b/src/test/scala/ch/epfl/bluebrain/nexus/iam/io/EventSerializerSpec.scala @@ -3,7 +3,7 @@ package ch.epfl.bluebrain.nexus.iam.io import java.time.Instant import akka.actor.ExtendedActorSystem -import ch.epfl.bluebrain.nexus.commons.test.ActorSystemFixture +import ch.epfl.bluebrain.nexus.commons.test.{ActorSystemFixture, EitherValues} import ch.epfl.bluebrain.nexus.iam.acls.AclEvent.AclDeleted import ch.epfl.bluebrain.nexus.iam.permissions.PermissionsEvent.PermissionsDeleted import ch.epfl.bluebrain.nexus.iam.realms.RealmEvent.RealmDeprecated @@ -11,7 +11,8 @@ import ch.epfl.bluebrain.nexus.iam.types.Identity.Anonymous import ch.epfl.bluebrain.nexus.iam.types.Label import ch.epfl.bluebrain.nexus.rdf.Iri.Path import io.circe.parser._ -import org.scalatest.{EitherValues, Inspectors, Matchers} +import org.scalatest.Inspectors +import org.scalatest.matchers.should.Matchers class EventSerializerSpec extends ActorSystemFixture("SerializerSpec") with Matchers with Inspectors with EitherValues { @@ -27,7 +28,7 @@ class EventSerializerSpec extends ActorSystemFixture("SerializerSpec") with Matc | "@type": "PermissionsDeleted" |}""".stripMargin - private val ad = AclDeleted(Path("/a/b/c").right.value, 2L, Instant.EPOCH, Anonymous) + private val ad = AclDeleted(Path("/a/b/c").rightValue, 2L, Instant.EPOCH, Anonymous) private val adString = """|{ | "path": "/a/b/c", @@ -72,7 +73,7 @@ class EventSerializerSpec extends ActorSystemFixture("SerializerSpec") with Matc "correctly serialize known events" in { forAll(data.toList) { case (event, (_, repr)) => - parse(new String(serializer.toBinary(event))).right.value shouldEqual parse(repr).right.value + parse(new String(serializer.toBinary(event))).rightValue shouldEqual parse(repr).rightValue } } diff --git a/src/test/scala/ch/epfl/bluebrain/nexus/iam/io/JWKSetSerializerSpec.scala b/src/test/scala/ch/epfl/bluebrain/nexus/iam/io/JWKSetSerializerSpec.scala index c9862fc..dfee5b5 100644 --- a/src/test/scala/ch/epfl/bluebrain/nexus/iam/io/JWKSetSerializerSpec.scala +++ b/src/test/scala/ch/epfl/bluebrain/nexus/iam/io/JWKSetSerializerSpec.scala @@ -5,11 +5,13 @@ import akka.serialization.Serialization import akka.testkit.TestKit import com.nimbusds.jose.jwk.JWKSet import com.typesafe.config.ConfigFactory -import org.scalatest.{Matchers, TryValues, WordSpecLike} +import org.scalatest.TryValues +import org.scalatest.matchers.should.Matchers +import org.scalatest.wordspec.AnyWordSpecLike class JWKSetSerializerSpec extends TestKit(ActorSystem("JWKSetSerializerSpec", ConfigFactory.load("akka-test.conf"))) - with WordSpecLike + with AnyWordSpecLike with Matchers with TryValues { diff --git a/src/test/scala/ch/epfl/bluebrain/nexus/iam/io/TaggingAdapterSpec.scala b/src/test/scala/ch/epfl/bluebrain/nexus/iam/io/TaggingAdapterSpec.scala index 5a54678..bc8d73b 100644 --- a/src/test/scala/ch/epfl/bluebrain/nexus/iam/io/TaggingAdapterSpec.scala +++ b/src/test/scala/ch/epfl/bluebrain/nexus/iam/io/TaggingAdapterSpec.scala @@ -3,18 +3,21 @@ package ch.epfl.bluebrain.nexus.iam.io import java.time.Instant import akka.persistence.journal.Tagged +import ch.epfl.bluebrain.nexus.commons.test.EitherValues import ch.epfl.bluebrain.nexus.iam.acls.AclEvent.AclDeleted import ch.epfl.bluebrain.nexus.iam.permissions.PermissionsEvent.PermissionsDeleted import ch.epfl.bluebrain.nexus.iam.realms.RealmEvent.RealmDeprecated import ch.epfl.bluebrain.nexus.iam.types.Identity.Anonymous import ch.epfl.bluebrain.nexus.iam.types.Label import ch.epfl.bluebrain.nexus.rdf.Iri.Path -import org.scalatest.{EitherValues, Inspectors, Matchers, WordSpecLike} +import org.scalatest.Inspectors +import org.scalatest.matchers.should.Matchers +import org.scalatest.wordspec.AnyWordSpecLike -class TaggingAdapterSpec extends WordSpecLike with Matchers with Inspectors with EitherValues { +class TaggingAdapterSpec extends AnyWordSpecLike with Matchers with Inspectors with EitherValues { private val pd = PermissionsDeleted(2L, Instant.EPOCH, Anonymous) - private val ad = AclDeleted(Path("/a/b/c").right.value, 2L, Instant.EPOCH, Anonymous) + private val ad = AclDeleted(Path("/a/b/c").rightValue, 2L, Instant.EPOCH, Anonymous) private val rd = RealmDeprecated(Label.unsafe("blah"), 2L, Instant.EPOCH, Anonymous) private val data = Map[AnyRef, (String, AnyRef)]( diff --git a/src/test/scala/ch/epfl/bluebrain/nexus/iam/permissions/PermissionsSpec.scala b/src/test/scala/ch/epfl/bluebrain/nexus/iam/permissions/PermissionsSpec.scala index 7994488..3a404e2 100644 --- a/src/test/scala/ch/epfl/bluebrain/nexus/iam/permissions/PermissionsSpec.scala +++ b/src/test/scala/ch/epfl/bluebrain/nexus/iam/permissions/PermissionsSpec.scala @@ -3,8 +3,7 @@ package ch.epfl.bluebrain.nexus.iam.permissions import java.time.Instant import cats.effect.{Clock, ContextShift, IO, Timer} -import ch.epfl.bluebrain.nexus.commons.test.ActorSystemFixture -import ch.epfl.bluebrain.nexus.commons.test.Randomness +import ch.epfl.bluebrain.nexus.commons.test.{ActorSystemFixture, Randomness} import ch.epfl.bluebrain.nexus.commons.test.io.{IOEitherValues, IOOptionValues} import ch.epfl.bluebrain.nexus.iam.acls.Acls import ch.epfl.bluebrain.nexus.iam.config.AppConfig.{HttpConfig, PermissionsConfig} @@ -15,7 +14,7 @@ import ch.epfl.bluebrain.nexus.iam.types.Identity.Anonymous import ch.epfl.bluebrain.nexus.iam.types.{Caller, Permission, ResourceF} import ch.epfl.bluebrain.nexus.rdf.Iri.Path import org.mockito.IdiomaticMockito -import org.scalatest.Matchers +import org.scalatest.matchers.should.Matchers import scala.concurrent.ExecutionContext import scala.concurrent.duration._ @@ -29,7 +28,7 @@ class PermissionsSpec with Randomness with IdiomaticMockito { - override implicit val patienceConfig: PatienceConfig = PatienceConfig(3 seconds, 50 milliseconds) + override implicit val patienceConfig: PatienceConfig = PatienceConfig(3.seconds, 50.milliseconds) val appConfig: AppConfig = Settings(system).appConfig implicit val http: HttpConfig = appConfig.http diff --git a/src/test/scala/ch/epfl/bluebrain/nexus/iam/realms/GroupsSpec.scala b/src/test/scala/ch/epfl/bluebrain/nexus/iam/realms/GroupsSpec.scala index 31fe2aa..7c745e6 100644 --- a/src/test/scala/ch/epfl/bluebrain/nexus/iam/realms/GroupsSpec.scala +++ b/src/test/scala/ch/epfl/bluebrain/nexus/iam/realms/GroupsSpec.scala @@ -21,7 +21,7 @@ import io.circe.Json import io.circe.parser._ import org.mockito.ArgumentMatchersSugar.isA import org.mockito.IdiomaticMockito -import org.scalatest.Matchers +import org.scalatest.matchers.should.Matchers import scala.concurrent.ExecutionContext @@ -49,7 +49,7 @@ class GroupsSpec RealmsSpec.token(genString()) val ar: ActiveRealm = ActiveRealm( - Label("realm").right.value, + Label("realm").rightValue, "The Realm", openIdUrl, issuer, @@ -123,9 +123,9 @@ class GroupsSpec //noinspection TypeAnnotation object GroupsSpec { - import org.scalatest.EitherValues._ + import ch.epfl.bluebrain.nexus.commons.test.EitherValues._ - val userInfoUrl = Url("https://localhost/auth/userinfo").right.value + val userInfoUrl = Url("https://localhost/auth/userinfo").rightValue val userinfoArrayGroupsString = """{ @@ -144,7 +144,7 @@ object GroupsSpec { | "email": "noreply@epfl.ch" |} """.stripMargin - val userinfoArrayGroups = parse(userinfoArrayGroupsString).right.value + val userinfoArrayGroups = parse(userinfoArrayGroupsString).rightValue val userinfoCsvGroupsString = """{ @@ -158,7 +158,7 @@ object GroupsSpec { | "email": "noreply@epfl.ch" |} """.stripMargin - val userinfoCsvGroups = parse(userinfoCsvGroupsString).right.value + val userinfoCsvGroups = parse(userinfoCsvGroupsString).rightValue val userinfoNoGroupsString = """{ @@ -171,7 +171,7 @@ object GroupsSpec { | "email": "noreply@epfl.ch" |} """.stripMargin - val userinfoNoGroups = parse(userinfoNoGroupsString).right.value + val userinfoNoGroups = parse(userinfoNoGroupsString).rightValue val userinfoWrongGroupsString = """{ @@ -185,5 +185,5 @@ object GroupsSpec { | "email": "noreply@epfl.ch" |} """.stripMargin - val userinfoWrongGroups = parse(userinfoWrongGroupsString).right.value + val userinfoWrongGroups = parse(userinfoWrongGroupsString).rightValue } diff --git a/src/test/scala/ch/epfl/bluebrain/nexus/iam/realms/RealmsSpec.scala b/src/test/scala/ch/epfl/bluebrain/nexus/iam/realms/RealmsSpec.scala index 858a094..081eac7 100644 --- a/src/test/scala/ch/epfl/bluebrain/nexus/iam/realms/RealmsSpec.scala +++ b/src/test/scala/ch/epfl/bluebrain/nexus/iam/realms/RealmsSpec.scala @@ -5,8 +5,7 @@ import java.util.Date import akka.http.scaladsl.client.RequestBuilding._ import cats.effect.{Clock, ContextShift, IO, Timer} -import ch.epfl.bluebrain.nexus.commons.test.ActorSystemFixture -import ch.epfl.bluebrain.nexus.commons.test.Randomness +import ch.epfl.bluebrain.nexus.commons.test.{ActorSystemFixture, Randomness} import ch.epfl.bluebrain.nexus.commons.test.io.{IOEitherValues, IOOptionValues} import ch.epfl.bluebrain.nexus.iam.acls.Acls import ch.epfl.bluebrain.nexus.iam.auth.AccessToken @@ -26,7 +25,7 @@ import com.nimbusds.jose.{JWSAlgorithm, JWSHeader} import com.nimbusds.jwt.{JWTClaimsSet, SignedJWT} import org.mockito.ArgumentMatchersSugar._ import org.mockito.IdiomaticMockito -import org.scalatest.Matchers +import org.scalatest.matchers.should.Matchers import scala.concurrent.ExecutionContext import scala.concurrent.duration._ @@ -40,7 +39,7 @@ class RealmsSpec with Randomness with IdiomaticMockito { - override implicit val patienceConfig: PatienceConfig = PatienceConfig(3 seconds, 50 milliseconds) + override implicit val patienceConfig: PatienceConfig = PatienceConfig(3.seconds, 50.milliseconds) val appConfig: AppConfig = Settings(system).appConfig implicit val http: HttpConfig = appConfig.http @@ -84,7 +83,7 @@ class RealmsSpec val first = Label.unsafe("first") val firstName = "The First" - val logoUrl = Url("http://localhost/some/logo").right.value + val logoUrl = Url("http://localhost/some/logo").rightValue val second = Label.unsafe("second") val secondName = "The Second" val depr = Label.unsafe("deprecated") diff --git a/src/test/scala/ch/epfl/bluebrain/nexus/iam/realms/WellKnownSpec.scala b/src/test/scala/ch/epfl/bluebrain/nexus/iam/realms/WellKnownSpec.scala index 8eea500..b881031 100644 --- a/src/test/scala/ch/epfl/bluebrain/nexus/iam/realms/WellKnownSpec.scala +++ b/src/test/scala/ch/epfl/bluebrain/nexus/iam/realms/WellKnownSpec.scala @@ -6,6 +6,7 @@ import akka.http.scaladsl.client.RequestBuilding._ import akka.http.scaladsl.model.HttpResponse import cats.effect.IO import ch.epfl.bluebrain.nexus.commons.http.{HttpClient, UnexpectedUnsuccessfulHttpResponse} +import ch.epfl.bluebrain.nexus.commons.test.EitherValues import ch.epfl.bluebrain.nexus.commons.test.io.IOEitherValues import ch.epfl.bluebrain.nexus.iam.realms.RealmRejection._ import ch.epfl.bluebrain.nexus.iam.realms.WellKnownSpec._ @@ -16,11 +17,13 @@ import com.nimbusds.jose.jwk.gen.RSAKeyGenerator import io.circe.Json import io.circe.parser._ import org.mockito.IdiomaticMockito -import org.scalatest._ +import org.scalatest.matchers.should.Matchers +import org.scalatest.wordspec.AnyWordSpecLike +import org.scalatest.{Inspectors, OptionValues} //noinspection TypeAnnotation class WellKnownSpec - extends WordSpecLike + extends AnyWordSpecLike with Matchers with OptionValues with EitherValues @@ -181,22 +184,22 @@ class WellKnownSpec //noinspection TypeAnnotation object WellKnownSpec { import EitherValues._ - def genUrl = Url(s"https://localhost/auth/realms/master/.well-known/${UUID.randomUUID()}").right.value + def genUrl = Url(s"https://localhost/auth/realms/master/.well-known/${UUID.randomUUID()}").rightValue val openIdUrlString = "https://localhost/auth/realms/master/.well-known/openid-configuration" - val openIdUrl = Url(openIdUrlString).right.value + val openIdUrl = Url(openIdUrlString).rightValue val openIdUrl2 = genUrl val openIdUrl3 = genUrl val jwksUrlString = "https://localhost/auth/realms/master/protocol/openid-connect/certs" - val jwksUrl = Url(jwksUrlString).right.value + val jwksUrl = Url(jwksUrlString).rightValue val issuer = "https://localhost/auth/realms/master" val deprUrlString = "https://localhost/auth/realms/deprecated/.well-known/openid-configuration" - val authorizationUrl = Url("https://localhost/auth").right.value - val tokenUrl = Url("https://localhost/auth/token").right.value - val userInfoUrl = Url("https://localhost/auth/userinfo").right.value - val revocationUrl = Url("https://localhost/auth/revoke").right.value - val endSessionUrl = Url("https://localhost/auth/logout").right.value + val authorizationUrl = Url("https://localhost/auth").rightValue + val tokenUrl = Url("https://localhost/auth/token").rightValue + val userInfoUrl = Url("https://localhost/auth/userinfo").rightValue + val revocationUrl = Url("https://localhost/auth/revoke").rightValue + val endSessionUrl = Url("https://localhost/auth/logout").rightValue val validOpenIdConfigString = s""" @@ -215,7 +218,7 @@ object WellKnownSpec { | "userinfo_endpoint": "${userInfoUrl.asUri}" | } """.stripMargin - val validOpenIdConfig = parse(validOpenIdConfigString).right.value + val validOpenIdConfig = parse(validOpenIdConfigString).rightValue val fullOpenIdConfigString = s""" @@ -236,7 +239,7 @@ object WellKnownSpec { | "end_session_endpoint": "${endSessionUrl.asUri}" | } """.stripMargin - val fullOpenIdConfig = parse(fullOpenIdConfigString).right.value + val fullOpenIdConfig = parse(fullOpenIdConfigString).rightValue val deprecatedOpenIdConfigString = s""" @@ -255,7 +258,7 @@ object WellKnownSpec { | "userinfo_endpoint": "${userInfoUrl.asUri}" | } """.stripMargin - val deprecatedOpenIdConfig = parse(deprecatedOpenIdConfigString).right.value + val deprecatedOpenIdConfig = parse(deprecatedOpenIdConfigString).rightValue val (kid, privateKey, publicKey) = { val rsaJWK = new RSAKeyGenerator(2048) @@ -264,7 +267,7 @@ object WellKnownSpec { (rsaJWK.getKeyID, rsaJWK.toRSAPrivateKey, rsaJWK.toPublicJWK.toJSONString) } - val publicKeyJson = parse(publicKey).right.value + val publicKeyJson = parse(publicKey).rightValue val validJwksString = s""" @@ -275,7 +278,7 @@ object WellKnownSpec { | } """.stripMargin - val validJwks = parse(validJwksString).right.value + val validJwks = parse(validJwksString).rightValue val grantTypes = Set(AuthorizationCode, Implicit, RefreshToken, Password, ClientCredentials) diff --git a/src/test/scala/ch/epfl/bluebrain/nexus/iam/routes/AclsRoutesSpec.scala b/src/test/scala/ch/epfl/bluebrain/nexus/iam/routes/AclsRoutesSpec.scala index 7f73822..1d36ece 100644 --- a/src/test/scala/ch/epfl/bluebrain/nexus/iam/routes/AclsRoutesSpec.scala +++ b/src/test/scala/ch/epfl/bluebrain/nexus/iam/routes/AclsRoutesSpec.scala @@ -7,7 +7,7 @@ import akka.http.scaladsl.model.StatusCodes import akka.http.scaladsl.model.headers.OAuth2BearerToken import akka.http.scaladsl.testkit.ScalatestRouteTest import ch.epfl.bluebrain.nexus.commons.test -import ch.epfl.bluebrain.nexus.commons.test.Randomness +import ch.epfl.bluebrain.nexus.commons.test.{EitherValues, Randomness} import ch.epfl.bluebrain.nexus.iam.ExpectedException import ch.epfl.bluebrain.nexus.iam.acls._ import ch.epfl.bluebrain.nexus.iam.auth.AccessToken @@ -26,14 +26,16 @@ import com.typesafe.config.ConfigFactory import io.circe.Json import monix.eval.Task import org.mockito.{ArgumentMatchersSugar, IdiomaticMockito, Mockito} -import org.scalatest._ import org.scalatest.concurrent.ScalaFutures +import org.scalatest.matchers.should.Matchers +import org.scalatest.wordspec.AnyWordSpecLike +import org.scalatest.{BeforeAndAfter, OptionValues} import scala.concurrent.duration._ //noinspection NameBooleanParameters class AclsRoutesSpec - extends WordSpecLike + extends AnyWordSpecLike with Matchers with EitherValues with OptionValues @@ -45,7 +47,7 @@ class AclsRoutesSpec with Randomness with ScalaFutures { - override implicit def patienceConfig: PatienceConfig = PatienceConfig(3 second, 100 milliseconds) + override implicit def patienceConfig: PatienceConfig = PatienceConfig(3.seconds, 100.milliseconds) private val http = HttpConfig("some", 8080, "v1", "http://nexus.example.com") private implicit val appConfig: AppConfig = new Settings(ConfigFactory.parseResources("app.conf").resolve()).appConfig @@ -98,7 +100,7 @@ class AclsRoutesSpec ) val aclsFetch = - AccessControlLists(Path("/one/two").right.value -> resourceAcl1, Path("/one").right.value -> resourceAcl2) + AccessControlLists(Path("/one/two").rightValue -> resourceAcl1, Path("/one").rightValue -> resourceAcl2) def response(rev: Long, createdBy: Identity, updatedBty: Identity, path: Path): Json = jsonContentOf( @@ -167,7 +169,7 @@ class AclsRoutesSpec } "get ACL self = true with path containing *" in { - acls.list(Path("/myorg/*").right.value, ancestors = false, self = true) shouldReturn Task.pure(aclsFetch) + acls.list(Path("/myorg/*").rightValue, ancestors = false, self = true) shouldReturn Task.pure(aclsFetch) Get(s"/acls/myorg/*") ~> addCredentials(token) ~> routes ~> check { responseAs[Json] shouldEqual jsonContentOf("/acls/acls.json") status shouldEqual StatusCodes.OK diff --git a/src/test/scala/ch/epfl/bluebrain/nexus/iam/routes/EventRoutesSpec.scala b/src/test/scala/ch/epfl/bluebrain/nexus/iam/routes/EventRoutesSpec.scala index 4a75920..eee1ba7 100644 --- a/src/test/scala/ch/epfl/bluebrain/nexus/iam/routes/EventRoutesSpec.scala +++ b/src/test/scala/ch/epfl/bluebrain/nexus/iam/routes/EventRoutesSpec.scala @@ -10,7 +10,7 @@ import akka.http.scaladsl.model.sse.ServerSentEvent import akka.http.scaladsl.testkit.ScalatestRouteTest import akka.persistence.query.{EventEnvelope, NoOffset, Offset, Sequence} import akka.stream.scaladsl.Source -import ch.epfl.bluebrain.nexus.commons.test.Resources +import ch.epfl.bluebrain.nexus.commons.test.{EitherValues, Resources} import ch.epfl.bluebrain.nexus.iam.acls.AclEvent.{AclAppended, AclDeleted, AclReplaced, AclSubtracted} import ch.epfl.bluebrain.nexus.iam.acls.{AccessControlList, Acls} import ch.epfl.bluebrain.nexus.iam.auth.AccessToken @@ -30,14 +30,16 @@ import io.circe.Json import monix.eval.Task import org.mockito.matchers.MacroBasedMatchers import org.mockito.{IdiomaticMockito, Mockito} -import org.scalatest._ +import org.scalatest.{BeforeAndAfter, Inspectors, OptionValues} import org.scalatest.concurrent.ScalaFutures +import org.scalatest.matchers.should.Matchers +import org.scalatest.wordspec.AnyWordSpecLike import scala.concurrent.duration._ //noinspection TypeAnnotation class EventRoutesSpec - extends WordSpecLike + extends AnyWordSpecLike with Matchers with ScalatestRouteTest with BeforeAndAfter @@ -49,7 +51,7 @@ class EventRoutesSpec with Inspectors with IdiomaticMockito { - override implicit def patienceConfig: PatienceConfig = PatienceConfig(3 second, 100 milliseconds) + override implicit def patienceConfig: PatienceConfig = PatienceConfig(3.second, 100.milliseconds) override def testConfig: Config = ConfigFactory.load("test.conf") @@ -76,16 +78,16 @@ class EventRoutesSpec val instant = Instant.EPOCH val name = "The Realm" val issuer = "issuer" - val openIdConfig = Url("http://localhost:8080/myrealm").right.value + val openIdConfig = Url("http://localhost:8080/myrealm").rightValue val grantTypes = Set[GrantType](GrantType.Implicit) val keys = Set[Json](jsonContentOf("/events/realm-key.json")) - val logo = Some(Url("http://localhost:8080/myrealm/logo").right.value) + val logo = Some(Url("http://localhost:8080/myrealm/logo").rightValue) - val authorizationEndpoint = Url("https://localhost/auth").right.value - val tokenEndpoint = Url("https://localhost/auth/token").right.value - val userInfoEndpoint = Url("https://localhost/auth/userinfo").right.value - val revocationEndpoint = Some(Url("https://localhost/auth/revoke").right.value) - val endSessionEndpoint = Some(Url("https://localhost/auth/logout").right.value) + val authorizationEndpoint = Url("https://localhost/auth").rightValue + val tokenEndpoint = Url("https://localhost/auth/token").rightValue + val userInfoEndpoint = Url("https://localhost/auth/userinfo").rightValue + val revocationEndpoint = Some(Url("https://localhost/auth/revoke").rightValue) + val endSessionEndpoint = Some(Url("https://localhost/auth/logout").rightValue) val aclEvents = List( AclReplaced(path, acl, rev, instant, subject), @@ -145,7 +147,7 @@ class EventRoutesSpec .map { case (json, idx) => val data = json.sort.noSpaces - val event = json.hcursor.get[String]("@type").right.value + val event = json.hcursor.get[String]("@type").rightValue val id = idx s"""data:$data |event:$event diff --git a/src/test/scala/ch/epfl/bluebrain/nexus/iam/routes/IdentitiesRoutesSpec.scala b/src/test/scala/ch/epfl/bluebrain/nexus/iam/routes/IdentitiesRoutesSpec.scala index 92816bc..29942da 100644 --- a/src/test/scala/ch/epfl/bluebrain/nexus/iam/routes/IdentitiesRoutesSpec.scala +++ b/src/test/scala/ch/epfl/bluebrain/nexus/iam/routes/IdentitiesRoutesSpec.scala @@ -17,14 +17,16 @@ import io.circe.Json import monix.eval.Task import org.mockito.matchers.MacroBasedMatchers import org.mockito.{IdiomaticMockito, Mockito} +import org.scalatest.BeforeAndAfter import org.scalatest.concurrent.ScalaFutures -import org.scalatest.{BeforeAndAfter, Matchers, WordSpecLike} +import org.scalatest.matchers.should.Matchers +import org.scalatest.wordspec.AnyWordSpecLike import scala.concurrent.duration._ //noinspection TypeAnnotation class IdentitiesRoutesSpec - extends WordSpecLike + extends AnyWordSpecLike with Matchers with ScalatestRouteTest with BeforeAndAfter @@ -33,7 +35,7 @@ class IdentitiesRoutesSpec with ScalaFutures with IdiomaticMockito { - override implicit def patienceConfig: PatienceConfig = PatienceConfig(3 second, 100 milliseconds) + override implicit def patienceConfig: PatienceConfig = PatienceConfig(3.seconds, 100.milliseconds) override def testConfig: Config = ConfigFactory.load("test.conf") diff --git a/src/test/scala/ch/epfl/bluebrain/nexus/iam/routes/PermissionsRoutesSpec.scala b/src/test/scala/ch/epfl/bluebrain/nexus/iam/routes/PermissionsRoutesSpec.scala index 54b8983..e6e0130 100644 --- a/src/test/scala/ch/epfl/bluebrain/nexus/iam/routes/PermissionsRoutesSpec.scala +++ b/src/test/scala/ch/epfl/bluebrain/nexus/iam/routes/PermissionsRoutesSpec.scala @@ -19,14 +19,16 @@ import io.circe.Json import monix.eval.Task import org.mockito.matchers.MacroBasedMatchers import org.mockito.{IdiomaticMockito, Mockito} +import org.scalatest.BeforeAndAfter import org.scalatest.concurrent.ScalaFutures -import org.scalatest.{BeforeAndAfter, Matchers, WordSpecLike} +import org.scalatest.matchers.should.Matchers +import org.scalatest.wordspec.AnyWordSpecLike import scala.concurrent.duration._ //noinspection TypeAnnotation,RedundantDefaultArgument class PermissionsRoutesSpec - extends WordSpecLike + extends AnyWordSpecLike with Matchers with ScalatestRouteTest with BeforeAndAfter @@ -36,7 +38,7 @@ class PermissionsRoutesSpec with IdiomaticMockito with Randomness { - override implicit def patienceConfig: PatienceConfig = PatienceConfig(3 second, 100 milliseconds) + override implicit def patienceConfig: PatienceConfig = PatienceConfig(3.seconds, 100.milliseconds) override def testConfig: Config = ConfigFactory.load("test.conf") diff --git a/src/test/scala/ch/epfl/bluebrain/nexus/iam/routes/RealmsRoutesSpec.scala b/src/test/scala/ch/epfl/bluebrain/nexus/iam/routes/RealmsRoutesSpec.scala index b2cc749..396a7a5 100644 --- a/src/test/scala/ch/epfl/bluebrain/nexus/iam/routes/RealmsRoutesSpec.scala +++ b/src/test/scala/ch/epfl/bluebrain/nexus/iam/routes/RealmsRoutesSpec.scala @@ -5,7 +5,7 @@ import java.util.regex.Pattern.quote import akka.http.scaladsl.model.StatusCodes import akka.http.scaladsl.testkit.ScalatestRouteTest -import ch.epfl.bluebrain.nexus.commons.test.Resources +import ch.epfl.bluebrain.nexus.commons.test.{EitherValues, Resources} import ch.epfl.bluebrain.nexus.iam.auth.AccessToken import ch.epfl.bluebrain.nexus.iam.config.{AppConfig, Settings} import ch.epfl.bluebrain.nexus.iam.marshallers.instances._ @@ -20,13 +20,15 @@ import monix.eval.Task import org.mockito.matchers.MacroBasedMatchers import org.mockito.{IdiomaticMockito, Mockito} import org.scalatest.concurrent.ScalaFutures -import org.scalatest.{BeforeAndAfter, EitherValues, Matchers, WordSpecLike} +import org.scalatest.matchers.should.Matchers +import org.scalatest.wordspec.AnyWordSpecLike +import org.scalatest.BeforeAndAfter import scala.concurrent.duration._ //noinspection TypeAnnotation,NameBooleanParameters class RealmsRoutesSpec - extends WordSpecLike + extends AnyWordSpecLike with Matchers with ScalatestRouteTest with BeforeAndAfter @@ -36,7 +38,7 @@ class RealmsRoutesSpec with EitherValues with IdiomaticMockito { - override implicit def patienceConfig: PatienceConfig = PatienceConfig(3 second, 100 milliseconds) + override implicit def patienceConfig: PatienceConfig = PatienceConfig(3.second, 100.milliseconds) override def testConfig: Config = ConfigFactory.load("test.conf") @@ -50,11 +52,11 @@ class RealmsRoutesSpec realms.caller(any[AccessToken]) shouldReturn Task.pure(Caller.anonymous) } - val authorizationEndpoint = Url("https://localhost/auth").right.value - val tokenEndpoint = Url("https://localhost/auth/token").right.value - val userInfoEndpoint = Url("https://localhost/auth/userinfo").right.value - val revocationEndpoint = Some(Url("https://localhost/auth/revoke").right.value) - val endSessionEndpoint = Some(Url("https://localhost/auth/logout").right.value) + val authorizationEndpoint = Url("https://localhost/auth").rightValue + val tokenEndpoint = Url("https://localhost/auth/token").rightValue + val userInfoEndpoint = Url("https://localhost/auth/userinfo").rightValue + val revocationEndpoint = Some(Url("https://localhost/auth/revoke").rightValue) + val endSessionEndpoint = Some(Url("https://localhost/auth/logout").rightValue) def response(label: Label, rev: Long, deprecated: Boolean): Json = jsonContentOf( @@ -108,8 +110,8 @@ class RealmsRoutesSpec val routes = Routes.wrap(new RealmsRoutes(realms).routes) val label = Label.unsafe("therealm") val name = "The Realm" - val openIdConfig = Url("http://localhost:8080/realm").right.get - val logo = Url("http://localhost:8080/realm/logo").right.get + val openIdConfig = Url("http://localhost:8080/realm").rightValue + val logo = Url("http://localhost:8080/realm/logo").rightValue "create a new realm" in { realms.create(any[Label], any[String], any[Url], any[Option[Url]])(any[Caller]) shouldReturn Task.pure( Right(meta(label, 1L, false)) diff --git a/src/test/scala/ch/epfl/bluebrain/nexus/iam/types/GrantTypeSpec.scala b/src/test/scala/ch/epfl/bluebrain/nexus/iam/types/GrantTypeSpec.scala index 7867a37..a6cc49b 100644 --- a/src/test/scala/ch/epfl/bluebrain/nexus/iam/types/GrantTypeSpec.scala +++ b/src/test/scala/ch/epfl/bluebrain/nexus/iam/types/GrantTypeSpec.scala @@ -1,10 +1,13 @@ package ch.epfl.bluebrain.nexus.iam.types +import ch.epfl.bluebrain.nexus.commons.test.EitherValues import ch.epfl.bluebrain.nexus.iam.types.GrantType._ import io.circe.{Decoder, Encoder, Json} -import org.scalatest.{EitherValues, Inspectors, Matchers, WordSpecLike} +import org.scalatest.matchers.should.Matchers +import org.scalatest.wordspec.AnyWordSpecLike +import org.scalatest.Inspectors -class GrantTypeSpec extends WordSpecLike with Matchers with Inspectors with EitherValues { +class GrantTypeSpec extends AnyWordSpecLike with Matchers with Inspectors with EitherValues { "A GrantType" when { "using Camel encoders" should { @@ -28,12 +31,12 @@ class GrantTypeSpec extends WordSpecLike with Matchers with Inspectors with Eith val decoder = implicitly[Decoder[GrantType]] forAll(map.toList) { case (expected, gt) => - decoder.decodeJson(Json.fromString(gt)).right.value shouldEqual expected + decoder.decodeJson(Json.fromString(gt)).rightValue shouldEqual expected } } "fail to decode for unknown string" in { val decoder = implicitly[Decoder[GrantType]] - decoder.decodeJson(Json.fromString("incorrect")).left.value + decoder.decodeJson(Json.fromString("incorrect")).leftValue } } "using Snake encoders" should { @@ -57,12 +60,12 @@ class GrantTypeSpec extends WordSpecLike with Matchers with Inspectors with Eith val decoder = implicitly[Decoder[GrantType]] forAll(map.toList) { case (expected, gtString) => - decoder.decodeJson(Json.fromString(gtString)).right.value shouldEqual expected + decoder.decodeJson(Json.fromString(gtString)).rightValue shouldEqual expected } } "fail to decode for unknown string" in { val decoder = implicitly[Decoder[GrantType]] - decoder.decodeJson(Json.fromString("incorrect")).left.value + decoder.decodeJson(Json.fromString("incorrect")).leftValue } } } diff --git a/src/test/scala/ch/epfl/bluebrain/nexus/iam/types/IdentitySpec.scala b/src/test/scala/ch/epfl/bluebrain/nexus/iam/types/IdentitySpec.scala index 76e6601..0050e01 100644 --- a/src/test/scala/ch/epfl/bluebrain/nexus/iam/types/IdentitySpec.scala +++ b/src/test/scala/ch/epfl/bluebrain/nexus/iam/types/IdentitySpec.scala @@ -1,18 +1,21 @@ package ch.epfl.bluebrain.nexus.iam.types -import ch.epfl.bluebrain.nexus.commons.test.Resources +import ch.epfl.bluebrain.nexus.commons.test.{EitherValues, Resources} import ch.epfl.bluebrain.nexus.iam.config.AppConfig.HttpConfig import ch.epfl.bluebrain.nexus.iam.types.Identity.{Anonymous, Authenticated, Group, Subject, User} import io.circe.syntax._ -import org.scalatest._ +import org.scalatest.Inspectors +import org.scalatest.matchers.should.Matchers +import org.scalatest.wordspec.AnyWordSpecLike -class IdentitySpec extends WordSpecLike with Matchers with Inspectors with EitherValues with Resources { +class IdentitySpec extends AnyWordSpecLike with Matchers with Inspectors with EitherValues with Resources { "An Identity" should { val user = User("mysubject", "myrealm") val group = Group("mygroup", "myrealm") val authenticated = Authenticated("myrealm") - implicit val http = HttpConfig("some", 8080, "v1", "http://nexus.example.com") + + implicit val http: HttpConfig = HttpConfig("some", 8080, "v1", "http://nexus.example.com") "converted to Json" in { val userJson = jsonContentOf("/identities/produce/user.json") @@ -39,9 +42,9 @@ class IdentitySpec extends WordSpecLike with Matchers with Inspectors with Eithe List(user -> userJson, group -> groupJson, Anonymous -> anonymousJson, authenticated -> authenticatedJson) forAll(cases) { case (model: Subject, json) => - json.as[Subject].right.value shouldEqual model - json.as[Identity].right.value shouldEqual (model: Identity) - case (model: Identity, json) => json.as[Identity].right.value shouldEqual model + json.as[Subject].rightValue shouldEqual model + json.as[Identity].rightValue shouldEqual (model: Identity) + case (model: Identity, json) => json.as[Identity].rightValue shouldEqual model } } diff --git a/src/test/scala/ch/epfl/bluebrain/nexus/iam/types/LabelSpec.scala b/src/test/scala/ch/epfl/bluebrain/nexus/iam/types/LabelSpec.scala index 35aa3bc..8f285d9 100644 --- a/src/test/scala/ch/epfl/bluebrain/nexus/iam/types/LabelSpec.scala +++ b/src/test/scala/ch/epfl/bluebrain/nexus/iam/types/LabelSpec.scala @@ -1,34 +1,36 @@ package ch.epfl.bluebrain.nexus.iam.types -import ch.epfl.bluebrain.nexus.commons.test.Randomness +import ch.epfl.bluebrain.nexus.commons.test.{EitherValues, Randomness} import ch.epfl.bluebrain.nexus.rdf.Iri.{Path, Url} -import org.scalatest.{EitherValues, Inspectors, Matchers, WordSpecLike} +import org.scalatest.Inspectors +import org.scalatest.matchers.should.Matchers +import org.scalatest.wordspec.AnyWordSpecLike -class LabelSpec extends WordSpecLike with Matchers with Randomness with Inspectors with EitherValues { +class LabelSpec extends AnyWordSpecLike with Matchers with Randomness with Inspectors with EitherValues { "A Label" should { "be constructed correctly from alphanumeric chars" in { forAll(1 to 32) { length => val string = genString(length, Vector.range('a', 'z') ++ Vector.range('0', '9')) Label.unsafe(string).value shouldEqual string - Label(string).right.value.value shouldEqual string + Label(string).rightValue.value shouldEqual string } } "fail to construct for illegal formats" in { val cases = List("", " ", "a ", " a", "a-", "_") forAll(cases) { string => intercept[IllegalArgumentException](Label.unsafe(string)) - Label(string).left.value shouldEqual s"Label '$string' does not match pattern '${Label.regex.regex}'" + Label(string).leftValue shouldEqual s"Label '$string' does not match pattern '${Label.regex.regex}'" } } "return its path representation" in { - Label.unsafe("abc").toPath shouldEqual Path("/abc").right.value + Label.unsafe("abc").toPath shouldEqual Path("/abc").rightValue } "return an iri representation" in { forAll(List("http://localhost", "http://localhost/")) { str => - val base = Url(str).right.value + val base = Url(str).rightValue val label = Label.unsafe("abc") - label.toIri(base) shouldEqual Url("http://localhost/abc").right.value + label.toIri(base) shouldEqual Url("http://localhost/abc").rightValue } } } diff --git a/src/test/scala/ch/epfl/bluebrain/nexus/iam/types/PermissionSpec.scala b/src/test/scala/ch/epfl/bluebrain/nexus/iam/types/PermissionSpec.scala index d629e10..9fad8fe 100644 --- a/src/test/scala/ch/epfl/bluebrain/nexus/iam/types/PermissionSpec.scala +++ b/src/test/scala/ch/epfl/bluebrain/nexus/iam/types/PermissionSpec.scala @@ -1,11 +1,12 @@ package ch.epfl.bluebrain.nexus.iam.types import ch.epfl.bluebrain.nexus.commons.test.Randomness -import org.scalatest.{Matchers, WordSpec} +import org.scalatest.matchers.should.Matchers +import org.scalatest.wordspec.AnyWordSpecLike import scala.util.Random -class PermissionSpec extends WordSpec with Matchers with Randomness { +class PermissionSpec extends AnyWordSpecLike with Matchers with Randomness { "A Permission" should { "be constructed correctly for valid strings" in { for (_ <- 1 to 100) { diff --git a/src/test/scala/ch/epfl/bluebrain/nexus/iam/types/ResourceFSpec.scala b/src/test/scala/ch/epfl/bluebrain/nexus/iam/types/ResourceFSpec.scala index 5601065..17d54ad 100644 --- a/src/test/scala/ch/epfl/bluebrain/nexus/iam/types/ResourceFSpec.scala +++ b/src/test/scala/ch/epfl/bluebrain/nexus/iam/types/ResourceFSpec.scala @@ -2,7 +2,7 @@ package ch.epfl.bluebrain.nexus.iam.types import java.time.{Clock, Instant, ZoneId} -import ch.epfl.bluebrain.nexus.commons.test.Resources +import ch.epfl.bluebrain.nexus.commons.test.{EitherValues, Resources} import ch.epfl.bluebrain.nexus.iam.config.AppConfig.HttpConfig import ch.epfl.bluebrain.nexus.iam.config.Vocabulary._ import ch.epfl.bluebrain.nexus.iam.testsyntax._ @@ -11,10 +11,12 @@ import ch.epfl.bluebrain.nexus.rdf.Vocabulary._ import ch.epfl.bluebrain.nexus.rdf.syntax.node.unsafe._ import io.circe.Printer import io.circe.syntax._ -import org.scalatest.{EitherValues, Inspectors, Matchers, WordSpecLike} +import org.scalatest.Inspectors +import org.scalatest.matchers.should.Matchers +import org.scalatest.wordspec.AnyWordSpecLike //noinspection TypeAnnotation -class ResourceFSpec extends WordSpecLike with Matchers with Inspectors with EitherValues with Resources { +class ResourceFSpec extends AnyWordSpecLike with Matchers with Inspectors with EitherValues with Resources { "A ResourceMetadata" should { val user = User("mysubject", "myrealm")