Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to Play 3 #83

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '11'
java-version: '21'
cache: 'sbt'
- name: Compile, test
run: sbt clean coverage test coverageReport
Expand Down
6 changes: 3 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import ReleaseTransformations._

val commonSettings = Seq(
organization := "io.toolsplus",
scalaVersion := "2.13.5",
scalaVersion := "2.13.14",
versionScheme := Some("early-semver"),
resolvers ++= Seq(
"Typesafe repository releases" at "https://repo.typesafe.com/typesafe/releases/",
"Bintary JCenter" at "https://jcenter.bintray.com"
Resolver.typesafeRepo("releases"),
Resolver.jcenterRepo
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.nimbusds.jose.jwk.source.{JWKSource, JWKSourceBuilder}
import com.nimbusds.jose.util.DefaultResourceRetriever
import io.toolsplus.atlassian.connect.play.models.AtlassianForgeProperties

import java.net.URL
import java.net.{URI, URL}
import javax.inject.Inject
import ForgeRemoteJWKSourceProvider._

Expand All @@ -28,10 +28,11 @@ class ForgeRemoteJWKSourceProvider @Inject()(

JWKSourceBuilder
.create[ForgeInvocationContext](
new URL(jwkSetUrl),
new URI(jwkSetUrl).toURL,
new DefaultResourceRetriever(remoteJWKSetHttpConnectTimeoutMs,
remoteJWKSetHttpReadTimeoutMs,
remoteJWKSetHttpEntitySizeLimitByte))
remoteJWKSetHttpEntitySizeLimitByte)
)
.retrying(true)
.build()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.toolsplus.atlassian.connect.play.events

import akka.event.{ActorEventBus, SubchannelClassification}
import akka.util.Subclassification
import org.apache.pekko.event.{ActorEventBus, SubchannelClassification}
import org.apache.pekko.util.Subclassification
import io.toolsplus.atlassian.connect.play.api.events.AppEvent

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
package io.toolsplus.atlassian.connect.play.events

import akka.actor.{Actor, ActorSystem, Props}
import akka.testkit.TestProbe
import org.apache.pekko.actor.{Actor, ActorSystem, Props}
import org.apache.pekko.testkit.TestProbe
import io.toolsplus.atlassian.connect.play.TestSpec
import io.toolsplus.atlassian.connect.play.api.events.{AppEvent, AppInstalledEvent, AppUninstalledEvent}
import io.toolsplus.atlassian.connect.play.api.events.{
AppEvent,
AppInstalledEvent,
AppUninstalledEvent
}
import io.toolsplus.atlassian.connect.play.generators.AtlassianHostGen
import org.scalatestplus.play.guice.GuiceOneAppPerSuite

import scala.concurrent.duration._
import scala.language.postfixOps

class EventBusSpec extends TestSpec with GuiceOneAppPerSuite with AtlassianHostGen {
class EventBusSpec
extends TestSpec
with GuiceOneAppPerSuite
with AtlassianHostGen {

"Given an EventBus" when {

Expand Down Expand Up @@ -58,7 +65,7 @@ class EventBusSpec extends TestSpec with GuiceOneAppPerSuite with AtlassianHostG
"handle multiple event" in new Context {
val listener = system.actorOf(Props(new Actor {
def receive = {
case e @ AppInstalledEvent(_) => testProbe.ref ! e
case e @ AppInstalledEvent(_) => testProbe.ref ! e
case e @ AppUninstalledEvent(_) => testProbe.ref ! e
}
}))
Expand Down Expand Up @@ -106,7 +113,7 @@ class EventBusSpec extends TestSpec with GuiceOneAppPerSuite with AtlassianHostG
/**
* Play actor system.
*/
lazy implicit val system = app.injector.instanceOf[ActorSystem]
lazy implicit val system: ActorSystem = app.injector.instanceOf[ActorSystem]

/**
* Test probe.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package io.toolsplus.atlassian.connect.play.request.ws

import java.net.URI
import akka.util.ByteString
import io.toolsplus.atlassian.connect.play.TestSpec
import io.toolsplus.atlassian.connect.play.api.models.AtlassianHost
import io.toolsplus.atlassian.connect.play.auth.jwt.symmetric.JwtGenerator
import io.toolsplus.atlassian.connect.play.request.ws.PlayWsAtlassianConnectHttpClient
import io.toolsplus.atlassian.connect.play.request.ws.jwt.JwtSignatureCalculator
import org.apache.pekko.util.ByteString
import org.scalacheck.Shrink
import org.scalatestplus.play.guice.GuiceOneAppPerSuite
import play.api.http.HeaderNames.{AUTHORIZATION, USER_AGENT}
Expand All @@ -15,11 +13,15 @@ import play.api.libs.ws.WSClient
import play.api.mvc._
import play.api.test.{Helpers, TestServer, WsTestClient}

import java.net.URI
import scala.concurrent.{Future, Promise}

class PlayWsAtlassianConnectHttpClientSpec extends TestSpec with GuiceOneAppPerSuite {
class PlayWsAtlassianConnectHttpClientSpec
extends TestSpec
with GuiceOneAppPerSuite {

val action: DefaultActionBuilder = app.injector.instanceOf[DefaultActionBuilder]
val action: DefaultActionBuilder =
app.injector.instanceOf[DefaultActionBuilder]
val parser: PlayBodyParsers = app.injector.instanceOf[PlayBodyParsers]

val testServerPort = 44444
Expand All @@ -31,7 +33,8 @@ class PlayWsAtlassianConnectHttpClientSpec extends TestSpec with GuiceOneAppPerS

"successfully return a WSRequest with resolved host URL" in WsTestClient
.withClient { client =>
val httpClient = new PlayWsAtlassianConnectHttpClient(client, jwtGenerator)
val httpClient =
new PlayWsAtlassianConnectHttpClient(client, jwtGenerator)
forAll(rootRelativePathGen, atlassianHostGen) { (path, host) =>
val absoluteRequestUri = URI.create(s"${host.baseUrl}$path")
val request = httpClient.authenticatedAsAddon(path)(host)
Expand All @@ -43,25 +46,27 @@ class PlayWsAtlassianConnectHttpClientSpec extends TestSpec with GuiceOneAppPerS
implicit val doNotShrinkStrings: Shrink[String] = Shrink.shrinkAny
forAll(atlassianHostGen) { host =>
val path = "foo"
forAll(symmetricJwtCredentialsGen(host, subject = "bar")) { credentials =>
val absoluteRequestUri =
URI.create(s"http://localhost:$testServerPort/$path")
forAll(symmetricJwtCredentialsGen(host, subject = "bar")) {
credentials =>
val absoluteRequestUri =
URI.create(s"http://localhost:$testServerPort/$path")

(jwtGenerator
.createJwtToken(_: String, _: URI, _: AtlassianHost))
.expects("GET", absoluteRequestUri, host)
.returning(Right(credentials.rawJwt))
(jwtGenerator
.createJwtToken(_: String, _: URI, _: AtlassianHost))
.expects("GET", absoluteRequestUri, host)
.returning(Right(credentials.rawJwt))

val (request, _, _) = receiveRequest { hostUrl => wsClient =>
val httpClient = new PlayWsAtlassianConnectHttpClient(wsClient, jwtGenerator)
val (request, _, _) = receiveRequest { hostUrl => wsClient =>
val httpClient =
new PlayWsAtlassianConnectHttpClient(wsClient, jwtGenerator)

httpClient.authenticatedAsAddon(s"$hostUrl/$path")(host).get()
}
request.headers(AUTHORIZATION).startsWith("JWT ") mustBe true
request
.headers(AUTHORIZATION)
.drop("JWT ".length) mustBe credentials.rawJwt
request.headers(USER_AGENT) mustBe JwtSignatureCalculator.userAgent
httpClient.authenticatedAsAddon(s"$hostUrl/$path")(host).get()
}
request.headers(AUTHORIZATION).startsWith("JWT ") mustBe true
request
.headers(AUTHORIZATION)
.drop("JWT ".length) mustBe credentials.rawJwt
request.headers(USER_AGENT) mustBe JwtSignatureCalculator.userAgent
}
}
}
Expand Down
33 changes: 15 additions & 18 deletions modules/core/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration>

<configuration>
<import class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"/>
<import class="ch.qos.logback.core.ConsoleAppender"/>

<conversionRule conversionWord="coloredLevel" converterClass="play.api.libs.logback.ColoredLevel" />

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<appender name="STDOUT" class="ConsoleAppender">
<encoder class="PatternLayoutEncoder">
<pattern>%coloredLevel %logger{15} - %message%n%xException{10}</pattern>
</encoder>
</appender>

<logger name="play" level="INFO" />
<logger name="application" level="INFO" />

<logger name="io.toolsplus.atlassian.connect" level="OFF" />
<logger name="play" level="INFO"/>
<logger name="application" level="INFO"/>
<logger name="io.toolsplus.atlassian.connect" level="OFF"/>

<root level="WARN">
<appender-ref ref="STDOUT" />
<appender-ref ref="STDOUT"/>
</root>

<!-- Off these ones as they are annoying, and anyway we manage configuration ourself -->
<logger name="com.avaje.ebean.config.PropertyMapLoader" level="OFF" />
<logger name="com.avaje.ebeaninternal.server.core.XmlConfigLoader" level="OFF" />
<logger name="com.avaje.ebeaninternal.server.lib.BackgroundThread" level="OFF" />
<logger name="com.gargoylesoftware.htmlunit.javascript" level="OFF" />
<logger name="slick" level="OFF" />


<logger name="com.avaje.ebean.config.PropertyMapLoader" level="OFF"/>
<logger name="com.avaje.ebeaninternal.server.core.XmlConfigLoader" level="OFF"/>
<logger name="com.avaje.ebeaninternal.server.lib.BackgroundThread" level="OFF"/>
<logger name="com.gargoylesoftware.htmlunit.javascript" level="OFF"/>
<logger name="slick" level="OFF"/>
</configuration>
22 changes: 11 additions & 11 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@ object Dependencies {
Library.scalaMock % "test",
Library.scalaCheck % "test",
Library.atlassianJwtGenerators % "test",
Library.akkaTestKit % "test"
Library.pekkoTestKit % "test"
)
}

object Version {
val atlassianJwt = "0.2.1"
val cats = "2.10.0"
val atlassianJwt = "0.3.0"
val cats = "2.12.0"
val circe = "0.14.7"
val playCirce = "2814.4"
val playCirce = "3014.1"
val scalaUri = "4.0.3"
val sttp = "3.9.6"
val nimbusJoseJwt = "9.39"
val nimbusJoseJwt = "9.39.3"
val scalaTest = "3.2.18"
val scalaTestPlusPlay = "5.1.0"
val scalaTestPlusScalaCheck = "3.2.11.0"
val scalaMock = "5.1.0"
val scalaTestPlusPlay = "7.0.1"
val scalaTestPlusScalaCheck = "3.2.18.0"
val scalaMock = "6.0.0"
val scalaCheck = "1.18.0"
val akkaTestKit = "2.6.21"
val pekkoTestKit = "1.0.2"
}

object Library {
Expand All @@ -49,9 +49,9 @@ object Library {
val sttp = "com.softwaremill.sttp.client3" %% "core" % Version.sttp
val nimbusJoseJwt = "com.nimbusds" % "nimbus-jose-jwt" % Version.nimbusJoseJwt
val scalaTest = "org.scalatest" %% "scalatest" % Version.scalaTest
val scalaTestPlusScalaCheck = "org.scalatestplus" %% "scalacheck-1-15" % Version.scalaTestPlusScalaCheck
val scalaTestPlusScalaCheck = "org.scalatestplus" %% "scalacheck-1-17" % Version.scalaTestPlusScalaCheck
val scalaTestPlusPlay = "org.scalatestplus.play" %% "scalatestplus-play" % Version.scalaTestPlusPlay
val scalaMock = "org.scalamock" %% "scalamock" % Version.scalaMock
val scalaCheck = "org.scalacheck" %% "scalacheck" % Version.scalaCheck
val akkaTestKit = "com.typesafe.akka" %% "akka-testkit" % Version.akkaTestKit
val pekkoTestKit = "org.apache.pekko" %% "pekko-testkit" % Version.pekkoTestKit
}
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.5.2
sbt.version=1.10.0
4 changes: 2 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.20")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.1")
addSbtPlugin("org.playframework" % "sbt-plugin" % "3.0.3")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.12")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.0")
addSbtPlugin("com.github.sbt" % "sbt-release" % "1.1.0")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.2")
Expand Down
Loading