Skip to content

Commit 02b938c

Browse files
adinauerdependabot[bot]claudesentry-junior[bot]runningcode
authored
test(servlet): Verify Servlet 3.1 and 4.0 compatibility (#6624)
* collection: Servlet API compatibility * chore(deps): bump javax.servlet:javax.servlet-api from 3.1.0 to 4.0.1 (#6475) Bumps [javax.servlet:javax.servlet-api](https://github.com/javaee/servlet-spec) from 3.1.0 to 4.0.1. - [Commits](javaee/servlet-spec@3.1.0...4.0.1) --- updated-dependencies: - dependency-name: javax.servlet:javax.servlet-api dependency-version: 4.0.1 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(servlet): Keep Servlet 3.1 as compatibility floor Compile the javax servlet integrations against the minimum supported API. Exclude the intentionally pinned API from Dependabot while retaining the separate Servlet 4 alias for latest-runtime coverage. Co-Authored-By: Claude <noreply@anthropic.com> * test(servlet): Test Servlet 3.1 and 4.0 runtimes (#6625) * test(servlet): Test Servlet 3.1 on Tomcat 8.5 Run sentry-servlet against the minimum supported servlet container while keeping Servlet 3.1 as the production compile target. Exercise the service-loaded initializer through a real HTTP request and verify that request context reaches Sentry. * test(servlet): Run integration test on Tomcat 9 Reuse the real-container servlet integration test with a Tomcat 9 and Servlet 4 runtime classpath. Keep the Tomcat 8.5 run as the minimum-runtime check and attach both runs to the verification lifecycle. * build(servlet): Use JVM test suites for Tomcat matrix Replace the hand-built Tomcat 9 test task with isolated JVM test suites. Run the shared servlet integration test with independent Tomcat 8.5 and Tomcat 9 dependency graphs and attach both suites to check. Co-Authored-By: Claude <noreply@anthropic.com> * build(servlet): Remove unused Truth dependency The servlet integration suites declare Truth directly, so the regular unit test configuration no longer needs it after moving the integration test. Co-Authored-By: Claude <noreply@anthropic.com> * build(deps): Share the Tomcat 9 version Reference one catalog version from the Tomcat 9 core, Catalina, and Jasper aliases so dependency updates keep the runtime components aligned. Co-Authored-By: Claude <noreply@anthropic.com> * test(servlet): Run Tomcat matrix in dedicated CI job Compile the servlet integration test once and execute it with separate Tomcat 8.5 and Tomcat 9 runtime targets. Move both targets out of the standard check lifecycle and run them in a dedicated CI job. Co-Authored-By: Claude <noreply@anthropic.com> * ci: Move integration tests to dedicated workflow Create a shared workflow for non-Spring Boot integration suites and move the servlet runtime matrix there instead of adding it to the main build workflow. Co-Authored-By: Claude <noreply@anthropic.com> * ci: Restrict integration test workflow permissions Limit the workflow token to read-only repository contents because the test, artifact, and step-summary operations do not require write access. Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com> * build(deps): Share the Tomcat 11 version Restore Tomcat 11.0.27 after the collection branch merge and use one catalog version for Catalina and embedded Jasper so future updates keep them aligned. Co-Authored-By: Claude <noreply@anthropic.com> * Revert "fix(replay): Support Compose 1.13 and mask Compose views that can't be traversed (#6626)" This reverts commit 7eda470. Co-Authored-By: Nelson Osacky <nelson.osacky@sentry.io> * Reapply "fix(replay): Support Compose 1.13 and mask Compose views that can't be traversed (#6626)" This reverts commit ee14ece. Co-Authored-By: Nelson Osacky <nelson.osacky@sentry.io> * build: Lower Gradle daemon heap to 7g and metaspace to 1g Co-Authored-By: Nelson Osacky <nelson.osacky@sentry.io> * build: Restore 8g Gradle heap and cap Kotlin daemon heap at 3g Co-Authored-By: Nelson Osacky <nelson.osacky@sentry.io> --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: Nelson Osacky <nelson.osacky@sentry.io>
1 parent 85a215a commit 02b938c

6 files changed

Lines changed: 227 additions & 5 deletions

File tree

‎.github/dependabot.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ updates:
1717
ignore:
1818
- dependency-name: "org.springframework.boot*"
1919
- dependency-name: "io.opentelemetry*"
20+
# Servlet 3.1 is the minimum supported API and must remain the production compile target.
21+
- dependency-name: "javax.servlet:javax.servlet-api"
2022
# DGS 5+ needs Spring Boot 3; the sample is on Spring Boot 2.
2123
- dependency-name: "com.netflix.graphql.dgs*"
2224
commit-message:
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Integration Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
permissions:
10+
contents: read
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: true
15+
16+
jobs:
17+
integration-tests:
18+
name: Integration Tests
19+
timeout-minutes: 30
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- name: Checkout Repo
24+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
25+
with:
26+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
27+
28+
- name: Setup Java Version
29+
uses: actions/setup-java@77dd5b2ce225ea11469928ac317850245a74ae78 # v6.2.0
30+
with:
31+
distribution: 'temurin'
32+
java-version: '21'
33+
34+
- name: Setup Gradle
35+
uses: gradle/actions/setup-gradle@8da46b539cd8fe6ab27ca75128919a18d757604c # v6.4.1
36+
37+
- name: Run integration tests
38+
# Spring Boot integration suites run in their version-matrix workflows.
39+
run: |
40+
./gradlew \
41+
:sentry-servlet:integrationTest \
42+
:sentry-servlet:integrationTestTomcat9
43+
44+
- name: Upload test results
45+
if: always()
46+
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7
47+
with:
48+
name: test-results-integration-tests
49+
path: |
50+
**/build/reports/*
51+
**/build/test-results/**/*.xml
52+
53+
- name: Test Report
54+
uses: phoenix-actions/test-reporting@7317eea6e13c47348dd0bb318669485157c518d6 # pin@v16
55+
if: always()
56+
with:
57+
name: JUnit Integration Tests
58+
path: |
59+
**/build/test-results/**/*.xml
60+
reporter: java-junit
61+
output-to: step-summary
62+
fail-on-error: false

‎gradle.properties‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Daemons heap size
2-
org.gradle.jvmargs=-Xmx8g -XX:MaxMetaspaceSize=2g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -XX:+UseParallelGC
2+
org.gradle.jvmargs=-Xmx8g -XX:MaxMetaspaceSize=1g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -XX:+UseParallelGC
3+
kotlin.daemon.jvmargs=-Xmx3g
34
org.gradle.caching=true
45
org.gradle.parallel=true
56
org.gradle.configureondemand=true

‎gradle/libs.versions.toml‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ springboot4 = "4.1.0"
5353
springKafka2 = "2.8.11"
5454
springKafka3 = "3.3.5"
5555
sqldelight = "2.4.1"
56+
tomcat9 = "9.0.108"
57+
tomcat11 = "11.0.27"
5658
vanniktechMavenPublish = "0.37.0"
5759

5860
# Android
@@ -266,10 +268,12 @@ gummy-bears-api21 = { module = "com.toasttab.android:gummy-bears-api-21", versio
266268
java8-signature = { module = "org.codehaus.mojo.signature:java18", version.ref = "java8Signature" }
267269

268270
# tomcat libraries
269-
tomcat-catalina = { module = "org.apache.tomcat:tomcat-catalina", version = "9.0.108" }
270-
tomcat-embed-jasper = { module = "org.apache.tomcat.embed:tomcat-embed-jasper", version = "9.0.108" }
271-
tomcat-catalina-jakarta = { module = "org.apache.tomcat:tomcat-catalina", version = "11.0.27" }
272-
tomcat-embed-jasper-jakarta = { module = "org.apache.tomcat.embed:tomcat-embed-jasper", version = "11.0.22" }
271+
tomcat85-embed-core = { module = "org.apache.tomcat.embed:tomcat-embed-core", version = "8.5.100" }
272+
tomcat9-embed-core = { module = "org.apache.tomcat.embed:tomcat-embed-core", version.ref = "tomcat9" }
273+
tomcat-catalina = { module = "org.apache.tomcat:tomcat-catalina", version.ref = "tomcat9" }
274+
tomcat-embed-jasper = { module = "org.apache.tomcat.embed:tomcat-embed-jasper", version.ref = "tomcat9" }
275+
tomcat-catalina-jakarta = { module = "org.apache.tomcat:tomcat-catalina", version.ref = "tomcat11" }
276+
tomcat-embed-jasper-jakarta = { module = "org.apache.tomcat.embed:tomcat-embed-jasper", version.ref = "tomcat11" }
273277
# The version comes from the Spring Boot BOM of whichever Spring line uses it.
274278
tomcat-embed-core = { module = "org.apache.tomcat.embed:tomcat-embed-core" }
275279

‎sentry-servlet/build.gradle.kts‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,52 @@ dependencies {
4141
testImplementation(libs.springboot.starter.web)
4242
}
4343

44+
val integrationTest =
45+
testing.suites.register<JvmTestSuite>("integrationTest") {
46+
useJUnit()
47+
dependencies {
48+
implementation(project())
49+
implementation(projects.sentryTestSupport)
50+
implementation(libs.google.truth)
51+
implementation(libs.kotlin.test.junit)
52+
compileOnly(libs.tomcat85.embed.core)
53+
runtimeOnly(libs.tomcat85.embed.core)
54+
}
55+
targets.named("integrationTest") {
56+
testTask.configure {
57+
description = "Runs the servlet integration test on Tomcat 8.5 and Servlet 3.1"
58+
systemProperty("io.sentry.test.tomcat-version-prefix", "8.5.")
59+
systemProperty("io.sentry.test.servlet-major-version", "3")
60+
systemProperty("io.sentry.test.servlet-minor-version", "1")
61+
}
62+
}
63+
}
64+
65+
val integrationTestSourceSet = sourceSets["integrationTest"]
66+
val integrationTestTomcat9RuntimeClasspath =
67+
configurations.resolvable("integrationTestTomcat9RuntimeClasspath") {
68+
extendsFrom(configurations[integrationTestSourceSet.implementationConfigurationName])
69+
attributes.addAllLater(
70+
configurations[integrationTestSourceSet.runtimeClasspathConfigurationName].attributes,
71+
)
72+
}
73+
74+
dependencies {
75+
add(integrationTestTomcat9RuntimeClasspath.name, libs.tomcat9.embed.core)
76+
}
77+
78+
integrationTest {
79+
targets.register("integrationTestTomcat9") {
80+
testTask.configure {
81+
description = "Runs the servlet integration test on Tomcat 9 and Servlet 4"
82+
classpath = integrationTestSourceSet.output + integrationTestTomcat9RuntimeClasspath.get()
83+
systemProperty("io.sentry.test.tomcat-version-prefix", "9.0.")
84+
systemProperty("io.sentry.test.servlet-major-version", "4")
85+
systemProperty("io.sentry.test.servlet-minor-version", "0")
86+
}
87+
}
88+
}
89+
4490
tasks.withType<JavaCompile>().configureEach {
4591
options.errorprone {
4692
check("NullAway", net.ltgt.gradle.errorprone.CheckSeverity.ERROR)
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
package io.sentry.servlet
2+
3+
import com.google.common.truth.Truth.assertThat
4+
import io.sentry.Sentry
5+
import io.sentry.test.MockSentryServer
6+
import io.sentry.test.event
7+
import java.net.HttpURLConnection
8+
import java.net.URI
9+
import java.nio.file.Files
10+
import java.util.ServiceLoader
11+
import javax.servlet.ServletContainerInitializer
12+
import javax.servlet.ServletContext
13+
import javax.servlet.http.HttpServlet
14+
import javax.servlet.http.HttpServletRequest
15+
import javax.servlet.http.HttpServletResponse
16+
import kotlin.test.AfterTest
17+
import kotlin.test.BeforeTest
18+
import kotlin.test.Test
19+
import org.apache.catalina.startup.Tomcat
20+
import org.apache.catalina.util.ServerInfo
21+
22+
class SentryServletIntegrationTest {
23+
private val servletMajorVersion =
24+
System.getProperty("io.sentry.test.servlet-major-version", "3").toInt()
25+
private val servletMinorVersion =
26+
System.getProperty("io.sentry.test.servlet-minor-version", "1").toInt()
27+
private val tomcatVersionPrefix =
28+
System.getProperty("io.sentry.test.tomcat-version-prefix", "8.5.")
29+
30+
private var server: MockSentryServer? = null
31+
private var servletContext: ServletContext? = null
32+
private var tomcat: Tomcat? = null
33+
34+
@BeforeTest
35+
fun setUp() {
36+
val mockServer = MockSentryServer()
37+
server = mockServer
38+
Sentry.init { it.dsn = mockServer.dsn }
39+
40+
tomcat =
41+
Tomcat().apply {
42+
setBaseDir(Files.createTempDirectory("tomcat").toString())
43+
setPort(0)
44+
connector.setProperty("address", "127.0.0.1")
45+
46+
val context = addContext("", Files.createTempDirectory("servlet-docbase").toString())
47+
context.effectiveMajorVersion = servletMajorVersion
48+
context.effectiveMinorVersion = servletMinorVersion
49+
context.parentClassLoader = javaClass.classLoader
50+
Tomcat.addServlet(context, "capture", CaptureServlet())
51+
context.addServletMappingDecoded("/capture", "capture")
52+
val initializer =
53+
ServiceLoader.load(ServletContainerInitializer::class.java)
54+
.filterIsInstance<SentryServletContainerInitializer>()
55+
.single()
56+
context.addServletContainerInitializer(initializer, emptySet())
57+
58+
start()
59+
servletContext = context.servletContext
60+
}
61+
}
62+
63+
@AfterTest
64+
fun tearDown() {
65+
Sentry.close()
66+
tomcat?.stop()
67+
tomcat?.destroy()
68+
server?.close()
69+
}
70+
71+
@Test
72+
fun `captures request data on supported servlet container`() {
73+
assertThat(ServerInfo.getServerNumber()).startsWith(tomcatVersionPrefix)
74+
assertThat(servletContext!!.effectiveMajorVersion).isEqualTo(servletMajorVersion)
75+
assertThat(servletContext!!.effectiveMinorVersion).isEqualTo(servletMinorVersion)
76+
77+
val port = tomcat!!.connector.localPort
78+
val connection =
79+
URI("http://127.0.0.1:$port/capture?customer=123").toURL().openConnection()
80+
as HttpURLConnection
81+
82+
try {
83+
assertThat(connection.responseCode).isEqualTo(HttpServletResponse.SC_OK)
84+
assertThat(connection.inputStream.bufferedReader().use { it.readText().trim() })
85+
.isEqualTo("captured")
86+
} finally {
87+
connection.disconnect()
88+
}
89+
90+
val event = server!!.awaitEnvelope { it.event()?.message?.formatted == MESSAGE }.event()!!
91+
92+
assertThat(event.request?.method).isEqualTo("GET")
93+
assertThat(event.request?.url).isEqualTo("http://127.0.0.1:$port/capture")
94+
assertThat(event.request?.queryString).isEqualTo("customer=123")
95+
}
96+
97+
private class CaptureServlet : HttpServlet() {
98+
override fun doGet(request: HttpServletRequest, response: HttpServletResponse) {
99+
Sentry.captureMessage(MESSAGE)
100+
response.writer.print("captured")
101+
}
102+
}
103+
104+
private companion object {
105+
const val MESSAGE = "captured from servlet integration test"
106+
}
107+
}

0 commit comments

Comments
 (0)