Skip to content

Commit

Permalink
Merge pull request #12627 from playframework/mergify/bp/2.9.x/pr-12626
Browse files Browse the repository at this point in the history
[2.9.x] Add scripted test to check jjwt compatibility (backport #12626) by @mkurz
  • Loading branch information
mergify[bot] committed May 8, 2024
2 parents dd0463d + abc630a commit 8f849e1
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 0 deletions.
@@ -0,0 +1,16 @@
/*
* Copyright (C) from 2022 The Play Framework Contributors <https://github.com/playframework>, 2011-2021 Lightbend Inc. <https://www.lightbend.com>
*/

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
}

}
@@ -0,0 +1,31 @@
// Copyright (C) from 2022 The Play Framework Contributors <https://github.com/playframework>, 2011-2021 Lightbend Inc. <https://www.lightbend.com>

// 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("<path> <status> <cookie> <words> ...").parsed
val path :: status :: cookie :: assertions = args
ScriptedTools.verifyResourceContains(path, status.toInt, assertions, "Cookie" -> s"PLAY_SESSION=$cookie")
},
)

@@ -0,0 +1,4 @@
# This is the main configuration file for the application.
# https://www.playframework.com/documentation/latest/ConfigFile

play.http.secret.key="<Lt>v_F:bfRC=/YN8riEbEUAM1C:wT^1a92ywJ8>PI6Vb5c8Brq?b@y1HgzU2qgA"
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8" ?>

<!-- https://www.playframework.com/documentation/latest/SettingsLogger -->

<!DOCTYPE configuration>

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

<appender name="FILE" class="FileAppender">
<file>${application.home:-.}/logs/application.log</file>
<encoder class="PatternLayoutEncoder">
<charset>UTF-8</charset>
<pattern>%d{yyyy-MM-dd HH:mm:ss} %highlight(%-5level) %cyan(%logger{36}) %magenta(%X{pekkoSource}) %msg%n</pattern>
</encoder>
</appender>

<appender name="STDOUT" class="ConsoleAppender">
<!--
On Windows, enabling Jansi is recommended to benefit from color code interpretation on DOS command prompts,
which otherwise risk being sent ANSI escape sequences that they cannot interpret.
See https://logback.qos.ch/manual/layouts.html#coloring
-->
<!-- <withJansi>true</withJansi> -->
<encoder class="PatternLayoutEncoder">
<charset>UTF-8</charset>
<pattern>%d{yyyy-MM-dd HH:mm:ss} %highlight(%-5level) %cyan(%logger{36}) %magenta(%X{pekkoSource}) %msg%n</pattern>
</encoder>
</appender>

<appender name="ASYNCFILE" class="AsyncAppender">
<appender-ref ref="FILE"/>
</appender>

<appender name="ASYNCSTDOUT" class="AsyncAppender">
<appender-ref ref="STDOUT"/>
</appender>

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

<root level="WARN">
<appender-ref ref="ASYNCFILE"/>
<appender-ref ref="ASYNCSTDOUT"/>
</root>

</configuration>
@@ -0,0 +1,3 @@
# Copyright (C) from 2022 The Play Framework Contributors <https://github.com/playframework>, 2011-2021 Lightbend Inc. <https://www.lightbend.com>

GET / controllers.HomeController.index(request: Request)
@@ -0,0 +1,5 @@
// Copyright (C) from 2022 The Play Framework Contributors <https://github.com/playframework>, 2011-2021 Lightbend Inc. <https://www.lightbend.com>

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"))
@@ -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

0 comments on commit 8f849e1

Please sign in to comment.