Skip to content

Commit

Permalink
Upgrade to cats effect 3 (#853)
Browse files Browse the repository at this point in the history
* Upgrade to cats effect 3

* Minor adjustments

* Fix cross compilation

* Fix it tests

* Fix it test assertion

* Bump http4s version
  • Loading branch information
joedarby authored Dec 27, 2023
1 parent 50e3749 commit 7cd634f
Show file tree
Hide file tree
Showing 16 changed files with 304 additions and 381 deletions.
16 changes: 9 additions & 7 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ import sbtrelease.ExtraReleaseCommands
import sbtrelease.ReleaseStateTransformations._
import sbtrelease.tagsonly.TagsOnly._

lazy val fs2Version = "2.5.11"
lazy val catsEffectVersion = "2.5.1"
lazy val fs2Version = "3.9.3"
lazy val catsEffectVersion = "3.5.2"
lazy val scalatestVersion = "3.2.0"
lazy val awsSdkVersion = "2.21.43"
lazy val scalacheckVersion = "1.17.0"
lazy val scalatestScalacheckVersion = "3.1.1.1"
lazy val slf4jVersion = "1.7.32"
lazy val log4jVersion = "2.22.0"
lazy val http4sVersion = "0.21.34"
lazy val scalaXmlVersion = "1.3.0"
lazy val http4sVersion = "0.23.24"
lazy val http4sBlazeClientVersion = "0.23.15"
lazy val scalaXmlVersion = "2.1.0"
lazy val circeVersion = "0.12.2"
lazy val scodecBitsVersion = "1.1.12"
lazy val commonCodecVersion = "1.14"
Expand Down Expand Up @@ -105,11 +106,12 @@ lazy val root = (project in file("."))
),
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % scalatestVersion,
"org.typelevel" %% "cats-effect-testing-scalatest" % "1.5.0",
"org.scalacheck" %% "scalacheck" % scalacheckVersion,
"org.scalatestplus" %% "scalacheck-1-14" % scalatestScalacheckVersion,
"org.apache.logging.log4j" % "log4j-api" % log4jVersion,
"org.apache.logging.log4j" % "log4j-slf4j-impl" % log4jVersion,
"org.http4s" %% "http4s-blaze-client" % http4sVersion
"org.http4s" %% "http4s-blaze-client" % http4sBlazeClientVersion
).map(_ % s"$Test,$IntegrationTest"),
scalafmtOnCompile := true
)
Expand Down Expand Up @@ -164,9 +166,9 @@ lazy val s3 = (project in file("modules/s3"))
.settings(automateHeaderSettings(IntegrationTest))
.settings(
libraryDependencies ++= Seq(
"org.http4s" %% "http4s-scala-xml" % http4sVersion,
"org.http4s" %% "http4s-scala-xml" % "0.23.13",
"org.scala-lang.modules" %% "scala-xml" % scalaXmlVersion,
"org.http4s" %% "http4s-blaze-client" % http4sVersion % Optional,
"org.http4s" %% "http4s-blaze-client" % http4sBlazeClientVersion % Optional,
"software.amazon.awssdk" % "s3" % awsSdkVersion % s"$Test,$IntegrationTest"
)
)
89 changes: 37 additions & 52 deletions modules/auth/src/it/scala/auth/AwsSignerItSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,20 @@ package auth

import common._
import common.model._
import cats.effect.{ContextShift, IO}

import cats.effect.IO
import cats.effect.testing.scalatest.AsyncIOSpec
import org.http4s.client.Client
import org.http4s.client.blaze.BlazeClientBuilder
import org.http4s.blaze.client.BlazeClientBuilder
import org.http4s.client.dsl.Http4sClientDsl
import org.http4s.Method._
import org.http4s.headers._
import org.http4s.{MediaType, Status, Uri}
import org.http4s.{MediaType, Request, Status, Uri}
import org.http4s.client.middleware.{RequestLogger, ResponseLogger}
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.global

import software.amazon.awssdk.auth.credentials.AwsCredentialsProviderChain

class AwsSignerItSpec extends IntegrationSpec with Http4sClientDsl[IO] {
class AwsSignerItSpec extends IntegrationSpec with Http4sClientDsl[IO] with AsyncIOSpec {

implicit val ctx: ContextShift[IO] = IO.contextShift(scala.concurrent.ExecutionContext.global)

// This is our UAT environment
private val esEndpoint = ""
Expand All @@ -40,15 +37,12 @@ class AwsSignerItSpec extends IntegrationSpec with Http4sClientDsl[IO] {

val signedClient: Client[IO] = awsSigner(requestLogger(responseLogger(client)))

for {
req <- GET(
Uri.unsafeFromString("https://s3-eu-west-1.amazonaws.com/ovo-comms-test/more.pdf")
)
status <- signedClient.status(req)
} yield {
status.isSuccess shouldBe true
}
}.futureValue(timeout(scaled(5.seconds)), interval(500.milliseconds))
val req = Request[IO](
uri = Uri.unsafeFromString("https://s3-eu-west-1.amazonaws.com/ovo-comms-test/more.pdf")
)

signedClient.status(req).map(_.isSuccess)
}.asserting(_ shouldBe true)
}

"sign request valid for S3 with nested paths" in {
Expand All @@ -66,13 +60,11 @@ class AwsSignerItSpec extends IntegrationSpec with Http4sClientDsl[IO] {

val signedClient: Client[IO] = awsSigner(requestLogger(responseLogger(client)))

for {
req <- GET(
Uri.unsafeFromString("https://s3-eu-west-1.amazonaws.com/ovo-comms-test/test/more.pdf")
)
status <- signedClient.status(req)
} yield status
}.futureValue(timeout(scaled(5.seconds)), interval(500.milliseconds)) should (not be Status.Unauthorized and not be Status.Forbidden)
val req = Request[IO]( uri = Uri.unsafeFromString("https://s3-eu-west-1.amazonaws.com/ovo-comms-test/test/more.pdf")
)

signedClient.status(req)
}.asserting(_ should (not be Status.Unauthorized and not be Status.Forbidden))
}

"sign request valid for ES GET" ignore {
Expand All @@ -91,10 +83,9 @@ class AwsSignerItSpec extends IntegrationSpec with Http4sClientDsl[IO] {
val signedClient: Client[IO] = awsSigner(requestLogger(responseLogger(client)))

for {
req <- GET(Uri.unsafeFromString(s"$esEndpoint/audit-2018-09/_doc/foo"))
status <- signedClient.status(req)
status <- signedClient.status(GET(Uri.unsafeFromString(s"$esEndpoint/audit-2018-09/_doc/foo")))
} yield status
}.futureValue(timeout(scaled(5.seconds)), interval(500.milliseconds)) should (not be Status.Unauthorized and not be Status.Forbidden)
}.asserting(_ should (not be Status.Unauthorized and not be Status.Forbidden))
}

"sign request valid for ES POST" ignore {
Expand Down Expand Up @@ -123,14 +114,13 @@ class AwsSignerItSpec extends IntegrationSpec with Http4sClientDsl[IO] {
"""

for {
req <- POST(
status <- signedClient.status(POST(
body,
Uri.unsafeFromString(s"$esEndpoint/audit-2018-09/_doc/_search"),
`Content-Type`(MediaType.application.json)
)
status <- signedClient.status(req)
))
} yield status
}.futureValue(timeout(scaled(5.seconds)), interval(500.milliseconds)) should (not be Status.Unauthorized and not be Status.Forbidden)
}.asserting(_ should (not be Status.Unauthorized and not be Status.Forbidden))
}

"sign request valid for ES POST with multiple indexes" ignore {
Expand Down Expand Up @@ -159,16 +149,15 @@ class AwsSignerItSpec extends IntegrationSpec with Http4sClientDsl[IO] {
"""

for {
req <- POST(
status <- signedClient.status(POST(
body,
Uri.unsafeFromString(
s"$esEndpoint/audit-2018-09,audit-2018-10,audit-2018-11/_doc/_search?ignore_unavailable=true"
),
`Content-Type`(MediaType.application.json)
)
status <- signedClient.status(req)
))
} yield status
}.futureValue(timeout(scaled(5.seconds)), interval(500.milliseconds)) should (not be Status.Unauthorized and not be Status.Forbidden)
}.asserting(_ should (not be Status.Unauthorized and not be Status.Forbidden))
}

"sign request valid for ES POST with query" ignore {
Expand Down Expand Up @@ -197,16 +186,15 @@ class AwsSignerItSpec extends IntegrationSpec with Http4sClientDsl[IO] {
"""

for {
req <- POST(
status <- signedClient.status(POST(
body,
Uri.unsafeFromString(
s"$esEndpoint/audit-2018-09/_doc/_search?ignore_unavailable=true"
),
`Content-Type`(MediaType.application.json)
)
status <- signedClient.status(req)
))
} yield status
}.futureValue(timeout(scaled(5.seconds)), interval(500.milliseconds)) should (not be Status.Unauthorized and not be Status.Forbidden)
}.asserting(_ should (not be Status.Unauthorized and not be Status.Forbidden))
}

"sign request valid for ES POST with query and multiple parameters" ignore {
Expand Down Expand Up @@ -235,16 +223,15 @@ class AwsSignerItSpec extends IntegrationSpec with Http4sClientDsl[IO] {
"""

for {
req <- POST(
status <- signedClient.status(POST(
body,
Uri.unsafeFromString(
s"$esEndpoint/audit-2018-09/_doc/_search?ignore_unavailable=true&refresh=true"
),
`Content-Type`(MediaType.application.json)
)
status <- signedClient.status(req)
))
} yield status
}.futureValue(timeout(scaled(5.seconds)), interval(500.milliseconds)) should (not be Status.Unauthorized and not be Status.Forbidden)
}.asserting(_ should (not be Status.Unauthorized and not be Status.Forbidden))
}

"sign request valid for ES POST with query and multiple parameters with comas and stars" ignore {
Expand Down Expand Up @@ -273,16 +260,15 @@ class AwsSignerItSpec extends IntegrationSpec with Http4sClientDsl[IO] {
"""

for {
req <- POST(
status <- signedClient.status(POST(
body,
Uri.unsafeFromString(
"/audit-2018-09/_doc/_search?ignore_unavailable=true&refresh=true&foo*=foo&bar,baz=baz"
),
`Content-Type`(MediaType.application.json)
)
status <- signedClient.status(req)
))
} yield status
}.futureValue(timeout(scaled(5.seconds)), interval(500.milliseconds)) should (not be Status.Unauthorized and not be Status.Forbidden)
}.asserting(_ should (not be Status.Unauthorized and not be Status.Forbidden))
}

"sign request valid for ES POST with star in path" ignore {
Expand Down Expand Up @@ -311,19 +297,18 @@ class AwsSignerItSpec extends IntegrationSpec with Http4sClientDsl[IO] {
"""

for {
req <- POST(
status <- signedClient.status(POST(
body,
Uri.unsafeFromString(s"$esEndpoint/audit-*/_doc/_search"),
`Content-Type`(MediaType.application.json)
)
status <- signedClient.status(req)
))
} yield status
}.futureValue(timeout(scaled(5.seconds)), interval(500.milliseconds)) should (not be Status.Unauthorized and not be Status.Forbidden)
}.asserting(_ should (not be Status.Unauthorized and not be Status.Forbidden))
}
}

def withHttpClient[A](f: Client[IO] => IO[A]): IO[A] = {
BlazeClientBuilder[IO](global).resource
BlazeClientBuilder[IO].resource
.use(f)
}

Expand Down
Loading

0 comments on commit 7cd634f

Please sign in to comment.