From 7475bc2b5db4f4d58772e0931930635d61c5ec20 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Sat, 27 Jan 2024 20:43:29 +0100 Subject: [PATCH] upgrade jwt-scala (#257) * upgrade jwt-scala Update Dependencies.scala * compile problem * Update Dependencies.scala * Update Dependencies.scala * compile issues * Update SqsAckSpec.scala --- .../connectors/google/auth/GoogleOAuth2.scala | 2 +- .../connectors/google/jwt/JwtSprayJson.scala | 18 ++++++++---------- project/Dependencies.scala | 14 +++++++------- .../test/scala/docs/scaladsl/SqsAckSpec.scala | 12 +++++++++--- .../scala/docs/scaladsl/SqsSourceSpec.scala | 2 +- 5 files changed, 26 insertions(+), 22 deletions(-) diff --git a/google-common/src/main/scala/org/apache/pekko/stream/connectors/google/auth/GoogleOAuth2.scala b/google-common/src/main/scala/org/apache/pekko/stream/connectors/google/auth/GoogleOAuth2.scala index 4455748c4..0e41b30c2 100644 --- a/google-common/src/main/scala/org/apache/pekko/stream/connectors/google/auth/GoogleOAuth2.scala +++ b/google-common/src/main/scala/org/apache/pekko/stream/connectors/google/auth/GoogleOAuth2.scala @@ -69,7 +69,7 @@ private[auth] object GoogleOAuth2 { .expiresIn(3600) .issuedNow - JwtSprayJson.encode(claim, privateKey, RS256) + JwtSprayJson(clock).encode(claim, privateKey, RS256) } final case class JwtClaimContent(scope: String) diff --git a/google-common/src/main/scala/org/apache/pekko/stream/connectors/google/jwt/JwtSprayJson.scala b/google-common/src/main/scala/org/apache/pekko/stream/connectors/google/jwt/JwtSprayJson.scala index d10fff1ca..dc2ede264 100644 --- a/google-common/src/main/scala/org/apache/pekko/stream/connectors/google/jwt/JwtSprayJson.scala +++ b/google-common/src/main/scala/org/apache/pekko/stream/connectors/google/jwt/JwtSprayJson.scala @@ -39,10 +39,15 @@ private[google] trait JwtSprayJsonParser[H, C] extends JwtJsonCommon[JsObject, H } @InternalApi -private[google] object JwtSprayJson extends JwtSprayJsonParser[JwtHeader, JwtClaim] { - import DefaultJsonProtocol._ - +private[google] object JwtSprayJson { def apply(clock: Clock): JwtSprayJson = new JwtSprayJson(clock) +} + +@InternalApi +private[google] class JwtSprayJson private (defaultClock: Clock) + extends JwtSprayJsonParser[JwtHeader, JwtClaim] { + import DefaultJsonProtocol._ + implicit val clock: Clock = defaultClock override def parseHeader(header: String): JwtHeader = { val jsObj = parse(header) @@ -75,10 +80,3 @@ private[google] object JwtSprayJson extends JwtSprayJsonParser[JwtHeader, JwtCla private[this] def safeGetField[A: JsonReader](js: JsObject, name: String) = js.fields.get(name).flatMap(safeRead[A]) } - -@InternalApi -private[google] class JwtSprayJson private (override val clock: Clock) - extends JwtSprayJsonParser[JwtHeader, JwtClaim] { - override def parseHeader(header: String): JwtHeader = JwtSprayJson.parseHeader(header) - override def parseClaim(header: String): JwtClaim = JwtSprayJson.parseClaim(header) -} diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 5a1dba58d..2ed27a5c2 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -33,12 +33,12 @@ object Dependencies { val PekkoGrpcBinaryVersion = "1.0" val PekkoHttpVersion = PekkoHttpDependency.version val PekkoHttpBinaryVersion = "1.0" - val ScalaTestVersion = "3.2.14" + val ScalaTestVersion = "3.2.17" val TestContainersScalaTestVersion = "0.41.0" - val mockitoVersion = "4.2.0" // check even https://github.com/scalatest/scalatestplus-mockito/releases + val mockitoVersion = "4.11.0" // check even https://github.com/scalatest/scalatestplus-mockito/releases val protobufJavaVersion = "3.21.12" val hoverflyVersion = "0.14.1" - val scalaCheckVersion = "1.16.0" + val scalaCheckVersion = "1.17.0" val LogbackForSlf4j1Version = "1.2.13" val LogbackForSlf4j2Version = "1.3.14" @@ -60,7 +60,7 @@ object Dependencies { val CouchbaseVersionForDocs = "2.7" val GoogleAuthVersion = "1.20.0" - val JwtCoreVersion = "3.0.1" + val JwtScalaVersion = "9.4.4" val log4jOverSlf4jVersion = "1.7.36" val jclOverSlf4jVersion = "1.7.36" @@ -85,7 +85,7 @@ object Dependencies { val Mockito = Seq( "org.mockito" % "mockito-core" % mockitoVersion % Test, // https://github.com/scalatest/scalatestplus-mockito/releases - "org.scalatestplus" %% "mockito-4-6" % (ScalaTestVersion + ".0") % Test) + "org.scalatestplus" %% "mockito-4-11" % (ScalaTestVersion + ".0") % Test) // Releases https://github.com/FasterXML/jackson-databind/releases // CVE issues https://github.com/FasterXML/jackson-databind/issues?utf8=%E2%9C%93&q=+label%3ACVE @@ -204,7 +204,7 @@ object Dependencies { libraryDependencies ++= Seq( "org.apache.pekko" %% "pekko-http" % PekkoHttpVersion, "org.apache.pekko" %% "pekko-http-spray-json" % PekkoHttpVersion, - "com.github.jwt-scala" %% "jwt-json-common" % "7.1.5", + "com.github.jwt-scala" %% "jwt-json-common" % JwtScalaVersion, "com.google.auth" % "google-auth-library-credentials" % GoogleAuthVersion, "io.specto" % "hoverfly-java" % hoverflyVersion % Test) ++ Mockito) @@ -295,7 +295,7 @@ object Dependencies { libraryDependencies ++= Seq( "org.apache.pekko" %% "pekko-http" % PekkoHttpVersion, "org.apache.pekko" %% "pekko-http-spray-json" % PekkoHttpVersion, - "com.github.jwt-scala" %% "jwt-json-common" % "7.1.5") ++ Mockito) + "com.github.jwt-scala" %% "jwt-json-common" % JwtScalaVersion) ++ Mockito) val InfluxDB = Seq( libraryDependencies ++= Seq( diff --git a/sqs/src/test/scala/docs/scaladsl/SqsAckSpec.scala b/sqs/src/test/scala/docs/scaladsl/SqsAckSpec.scala index 2751a01e2..46a83d757 100644 --- a/sqs/src/test/scala/docs/scaladsl/SqsAckSpec.scala +++ b/sqs/src/test/scala/docs/scaladsl/SqsAckSpec.scala @@ -15,7 +15,6 @@ package docs.scaladsl import java.util.concurrent.{ CompletableFuture, TimeUnit } import java.util.function.Supplier - import org.apache.pekko import pekko.Done import pekko.stream.connectors.sqs.scaladsl._ @@ -25,8 +24,9 @@ import pekko.stream.connectors.sqs.SqsAckResultEntry._ import pekko.stream.connectors.testkit.scaladsl.LogCapturing import pekko.stream.scaladsl.{ Sink, Source } import pekko.util.ccompat.JavaConverters._ +import org.mockito.{ Answers, Mockito } import org.mockito.ArgumentMatchers.any -import org.mockito.Mockito.{ spy, times, verify, when } +import org.mockito.Mockito.{ times, verify, when, withSettings } import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers import org.scalatestplus.mockito.MockitoSugar.mock @@ -39,7 +39,13 @@ class SqsAckSpec extends AnyFlatSpec with Matchers with DefaultTestContext with trait IntegrationFixture { val queueUrl: String = randomQueueUrl() - implicit val awsSqsClient: SqsAsyncClient = spy(sqsClient) + implicit val awsSqsClient: SqsAsyncClient = spyInternal(sqsClient) + + // spyInternal was created due to compile problems using Mockito 4.11 in Scala 2.12 + private def spyInternal[T](t: T): T = + Mockito.mock(t.getClass.asInstanceOf[Class[T]], + withSettings.spiedInstance(t) + .defaultAnswer(Answers.CALLS_REAL_METHODS)) def sendMessage(message: String): Unit = { def request = diff --git a/sqs/src/test/scala/docs/scaladsl/SqsSourceSpec.scala b/sqs/src/test/scala/docs/scaladsl/SqsSourceSpec.scala index 8677c6d25..6b2963dfe 100644 --- a/sqs/src/test/scala/docs/scaladsl/SqsSourceSpec.scala +++ b/sqs/src/test/scala/docs/scaladsl/SqsSourceSpec.scala @@ -48,7 +48,7 @@ class SqsSourceSpec extends AnyFlatSpec with ScalaFutures with Matchers with Def import SqsSourceSpec._ - implicit override val patienceConfig = PatienceConfig(timeout = 10.seconds, interval = 100.millis) + implicit override val patienceConfig: PatienceConfig = PatienceConfig(timeout = 10.seconds, interval = 100.millis) trait IntegrationFixture { val queueUrl: String = randomQueueUrl()