diff --git a/dev-mode/sbt-plugin/src/sbt-test/play-sbt-plugin/jjwt-compatibility/app/controllers/HomeController.java b/dev-mode/sbt-plugin/src/sbt-test/play-sbt-plugin/jjwt-compatibility/app/controllers/HomeController.java new file mode 100644 index 00000000000..aac89ca601f --- /dev/null +++ b/dev-mode/sbt-plugin/src/sbt-test/play-sbt-plugin/jjwt-compatibility/app/controllers/HomeController.java @@ -0,0 +1,16 @@ +/* + * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. + */ + +package controllers; + +import play.mvc.*; + +public class HomeController extends Controller { + + public Result index(Http.Request req) { + return ok("hello_world_" + req.session().get("foo").orElse("empty")) // This line tests session cookie parsing + .addingToSession(req, "one", "two"); // This lines tests session cookie creation + } + +} diff --git a/dev-mode/sbt-plugin/src/sbt-test/play-sbt-plugin/jjwt-compatibility/build.sbt b/dev-mode/sbt-plugin/src/sbt-test/play-sbt-plugin/jjwt-compatibility/build.sbt new file mode 100644 index 00000000000..fafe8c88e56 --- /dev/null +++ b/dev-mode/sbt-plugin/src/sbt-test/play-sbt-plugin/jjwt-compatibility/build.sbt @@ -0,0 +1,31 @@ +// Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. + +// See: +// https://github.com/playframework/playframework/pull/12474 +// https://github.com/playframework/playframework/pull/12624 +val jjwtVersion = "0.12.5" +val jjwts = Seq( + "io.jsonwebtoken" % "jjwt-api", + "io.jsonwebtoken" % "jjwt-impl" +).map(_ % jjwtVersion) ++ Seq( + ("io.jsonwebtoken" % "jjwt-jackson" % jjwtVersion).excludeAll(ExclusionRule("com.fasterxml.jackson.core")) +) + +lazy val root = (project in file(".")) + .enablePlugins(PlayJava) + .settings( + name := "jjwt-compatibility", + version := "1.0-SNAPSHOT", + scalaVersion := ScriptedTools.scalaVersionFromJavaProperties(), + updateOptions := updateOptions.value.withLatestSnapshots(false), + update / evictionWarningOptions ~= (_.withWarnTransitiveEvictions(false).withWarnDirectEvictions(false)), + PlayKeys.playInteractionMode := play.sbt.StaticPlayNonBlockingInteractionMode, + libraryDependencies += guice, + libraryDependencies ++= jjwts, + InputKey[Unit]("makeRequestWithSessionCookie") := { + val args = Def.spaceDelimited(" ...").parsed + val path :: status :: cookie :: assertions = args + ScriptedTools.verifyResourceContains(path, status.toInt, assertions, "Cookie" -> s"PLAY_SESSION=$cookie") + }, + ) + diff --git a/dev-mode/sbt-plugin/src/sbt-test/play-sbt-plugin/jjwt-compatibility/conf/application.conf b/dev-mode/sbt-plugin/src/sbt-test/play-sbt-plugin/jjwt-compatibility/conf/application.conf new file mode 100644 index 00000000000..e4e0c6bb8fe --- /dev/null +++ b/dev-mode/sbt-plugin/src/sbt-test/play-sbt-plugin/jjwt-compatibility/conf/application.conf @@ -0,0 +1,4 @@ +# This is the main configuration file for the application. +# https://www.playframework.com/documentation/latest/ConfigFile + +play.http.secret.key="v_F:bfRC=/YN8riEbEUAM1C:wT^1a92ywJ8>PI6Vb5c8Brq?b@y1HgzU2qgA" diff --git a/dev-mode/sbt-plugin/src/sbt-test/play-sbt-plugin/jjwt-compatibility/conf/logback.xml b/dev-mode/sbt-plugin/src/sbt-test/play-sbt-plugin/jjwt-compatibility/conf/logback.xml new file mode 100644 index 00000000000..ab6c2b1264f --- /dev/null +++ b/dev-mode/sbt-plugin/src/sbt-test/play-sbt-plugin/jjwt-compatibility/conf/logback.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + ${application.home:-.}/logs/application.log + + UTF-8 + %d{yyyy-MM-dd HH:mm:ss} %highlight(%-5level) %cyan(%logger{36}) %magenta(%X{pekkoSource}) %msg%n + + + + + + + + UTF-8 + %d{yyyy-MM-dd HH:mm:ss} %highlight(%-5level) %cyan(%logger{36}) %magenta(%X{pekkoSource}) %msg%n + + + + + + + + + + + + + + + + + + + + diff --git a/dev-mode/sbt-plugin/src/sbt-test/play-sbt-plugin/jjwt-compatibility/conf/routes b/dev-mode/sbt-plugin/src/sbt-test/play-sbt-plugin/jjwt-compatibility/conf/routes new file mode 100644 index 00000000000..19e75649957 --- /dev/null +++ b/dev-mode/sbt-plugin/src/sbt-test/play-sbt-plugin/jjwt-compatibility/conf/routes @@ -0,0 +1,3 @@ +# Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. + +GET / controllers.HomeController.index(request: Request) diff --git a/dev-mode/sbt-plugin/src/sbt-test/play-sbt-plugin/jjwt-compatibility/project/plugins.sbt b/dev-mode/sbt-plugin/src/sbt-test/play-sbt-plugin/jjwt-compatibility/project/plugins.sbt new file mode 100644 index 00000000000..b79417abc48 --- /dev/null +++ b/dev-mode/sbt-plugin/src/sbt-test/play-sbt-plugin/jjwt-compatibility/project/plugins.sbt @@ -0,0 +1,5 @@ +// Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. + +updateOptions := updateOptions.value.withLatestSnapshots(false) +addSbtPlugin("com.typesafe.play" % "sbt-plugin" % sys.props("project.version")) +addSbtPlugin("com.typesafe.play" % "sbt-scripted-tools" % sys.props("project.version")) diff --git a/dev-mode/sbt-plugin/src/sbt-test/play-sbt-plugin/jjwt-compatibility/test b/dev-mode/sbt-plugin/src/sbt-test/play-sbt-plugin/jjwt-compatibility/test new file mode 100644 index 00000000000..8a15adbd37d --- /dev/null +++ b/dev-mode/sbt-plugin/src/sbt-test/play-sbt-plugin/jjwt-compatibility/test @@ -0,0 +1,8 @@ +> run +# First send a request with an invalid session cookie value: +> makeRequestWithSessionCookie / 200 foo hello_world_empty +# Next send a request with a valid session cookie value but it was encoded with a different secret: +> makeRequestWithSessionCookie / 200 eyJhbGciOiJIUzI1MiJ9.eyJkYXRhIjp7ImNzcmZUb2tlbiI7IjVhMTIzMDY4YTE3NGVkMWZlMDkzMWVjZThmMmVkZDE5NWJiYjM2MCAtMTcxNTE1NDc0NDc2My0wMmNlMWQ2MDk2ZDgwYmJkYjBiZDhmOTgiLCJmb28iOiJiYXIifSwibmJmIjoxNzE1MTYwNTU3LCJpYXQiOjE3MTUxNjA1NTd9.N0LWvuPzslvbUsY8v19XXwW1KXKsW-pQY_zctWLgSkU hello_world_empty +# Now send a request with a valid session cookie, encoded with the secret from application.conf, the session contains the key/value foo->bar +> makeRequestWithSessionCookie / 200 eyJhbGciOiJIUzI1NiJ9.eyJkYXRhIjp7ImZvbyI6ImJhciJ9LCJuYmYiOjE3MTUxNzE3NjcsImlhdCI6MTcxNTE3MTc2N30.cA0x9_rsyctV1qiMvAydsJPMyrLah4qu0TaSmiVN0nQ hello_world_bar +> playStop