Repository navigation
test(servlet): Verify Servlet 3.1 and 4.0 compatibility #6624
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
Merged
+227
−5
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0d55daf
collection: Servlet API compatibility
adinauer 98875ae
chore(deps): bump javax.servlet:javax.servlet-api from 3.1.0 to 4.0.1…
dependabot[bot] 48a9334
build(servlet): Keep Servlet 3.1 as compatibility floor
adinauer 31f58ed
test(servlet): Test Servlet 3.1 and 4.0 runtimes (#6625)
adinauer 3e48695
Merge branch 'main' into chore/servlet-api-compatibility-stack
adinauer 97f84a7
build(deps): Share the Tomcat 11 version
adinauer ee14ece
Revert "fix(replay): Support Compose 1.13 and mask Compose views that…
sentry-junior[bot] 8d47ad1
Reapply "fix(replay): Support Compose 1.13 and mask Compose views tha…
sentry-junior[bot] 1009bdd
build: Lower Gradle daemon heap to 7g and metaspace to 1g
sentry-junior[bot] d1f04b4
build: Restore 8g Gradle heap and cap Kotlin daemon heap at 3g
sentry-junior[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| name: Integration Tests | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| pull_request: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| integration-tests: | ||
| name: Integration Tests | ||
| timeout-minutes: 30 | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout Repo | ||
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| with: | ||
| ref: ${{ github.event.pull_request.head.sha || github.sha }} | ||
|
|
||
| - name: Setup Java Version | ||
| uses: actions/setup-java@77dd5b2ce225ea11469928ac317850245a74ae78 # v6.2.0 | ||
| with: | ||
| distribution: 'temurin' | ||
| java-version: '21' | ||
|
|
||
| - name: Setup Gradle | ||
| uses: gradle/actions/setup-gradle@8da46b539cd8fe6ab27ca75128919a18d757604c # v6.4.1 | ||
|
|
||
| - name: Run integration tests | ||
| # Spring Boot integration suites run in their version-matrix workflows. | ||
| run: | | ||
| ./gradlew \ | ||
| :sentry-servlet:integrationTest \ | ||
| :sentry-servlet:integrationTestTomcat9 | ||
|
|
||
| - name: Upload test results | ||
| if: always() | ||
| uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7 | ||
| with: | ||
| name: test-results-integration-tests | ||
| path: | | ||
| **/build/reports/* | ||
| **/build/test-results/**/*.xml | ||
|
|
||
| - name: Test Report | ||
| uses: phoenix-actions/test-reporting@7317eea6e13c47348dd0bb318669485157c518d6 # pin@v16 | ||
| if: always() | ||
| with: | ||
| name: JUnit Integration Tests | ||
| path: | | ||
| **/build/test-results/**/*.xml | ||
| reporter: java-junit | ||
| output-to: step-summary | ||
| fail-on-error: false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
sentry-servlet/src/integrationTest/kotlin/io/sentry/servlet/SentryServletIntegrationTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| package io.sentry.servlet | ||
|
|
||
| import com.google.common.truth.Truth.assertThat | ||
| import io.sentry.Sentry | ||
| import io.sentry.test.MockSentryServer | ||
| import io.sentry.test.event | ||
| import java.net.HttpURLConnection | ||
| import java.net.URI | ||
| import java.nio.file.Files | ||
| import java.util.ServiceLoader | ||
| import javax.servlet.ServletContainerInitializer | ||
| import javax.servlet.ServletContext | ||
| import javax.servlet.http.HttpServlet | ||
| import javax.servlet.http.HttpServletRequest | ||
| import javax.servlet.http.HttpServletResponse | ||
| import kotlin.test.AfterTest | ||
| import kotlin.test.BeforeTest | ||
| import kotlin.test.Test | ||
| import org.apache.catalina.startup.Tomcat | ||
| import org.apache.catalina.util.ServerInfo | ||
|
|
||
| class SentryServletIntegrationTest { | ||
| private val servletMajorVersion = | ||
| System.getProperty("io.sentry.test.servlet-major-version", "3").toInt() | ||
| private val servletMinorVersion = | ||
| System.getProperty("io.sentry.test.servlet-minor-version", "1").toInt() | ||
| private val tomcatVersionPrefix = | ||
| System.getProperty("io.sentry.test.tomcat-version-prefix", "8.5.") | ||
|
|
||
| private var server: MockSentryServer? = null | ||
| private var servletContext: ServletContext? = null | ||
| private var tomcat: Tomcat? = null | ||
|
|
||
| @BeforeTest | ||
| fun setUp() { | ||
| val mockServer = MockSentryServer() | ||
| server = mockServer | ||
| Sentry.init { it.dsn = mockServer.dsn } | ||
|
|
||
| tomcat = | ||
| Tomcat().apply { | ||
| setBaseDir(Files.createTempDirectory("tomcat").toString()) | ||
| setPort(0) | ||
| connector.setProperty("address", "127.0.0.1") | ||
|
|
||
| val context = addContext("", Files.createTempDirectory("servlet-docbase").toString()) | ||
| context.effectiveMajorVersion = servletMajorVersion | ||
| context.effectiveMinorVersion = servletMinorVersion | ||
| context.parentClassLoader = javaClass.classLoader | ||
| Tomcat.addServlet(context, "capture", CaptureServlet()) | ||
| context.addServletMappingDecoded("/capture", "capture") | ||
| val initializer = | ||
| ServiceLoader.load(ServletContainerInitializer::class.java) | ||
| .filterIsInstance<SentryServletContainerInitializer>() | ||
| .single() | ||
| context.addServletContainerInitializer(initializer, emptySet()) | ||
|
|
||
| start() | ||
| servletContext = context.servletContext | ||
| } | ||
| } | ||
|
|
||
| @AfterTest | ||
| fun tearDown() { | ||
| Sentry.close() | ||
| tomcat?.stop() | ||
| tomcat?.destroy() | ||
| server?.close() | ||
| } | ||
|
|
||
| @Test | ||
| fun `captures request data on supported servlet container`() { | ||
| assertThat(ServerInfo.getServerNumber()).startsWith(tomcatVersionPrefix) | ||
| assertThat(servletContext!!.effectiveMajorVersion).isEqualTo(servletMajorVersion) | ||
| assertThat(servletContext!!.effectiveMinorVersion).isEqualTo(servletMinorVersion) | ||
|
|
||
| val port = tomcat!!.connector.localPort | ||
| val connection = | ||
| URI("http://127.0.0.1:$port/capture?customer=123").toURL().openConnection() | ||
| as HttpURLConnection | ||
|
|
||
| try { | ||
| assertThat(connection.responseCode).isEqualTo(HttpServletResponse.SC_OK) | ||
| assertThat(connection.inputStream.bufferedReader().use { it.readText().trim() }) | ||
| .isEqualTo("captured") | ||
| } finally { | ||
| connection.disconnect() | ||
| } | ||
|
|
||
| val event = server!!.awaitEnvelope { it.event()?.message?.formatted == MESSAGE }.event()!! | ||
|
|
||
| assertThat(event.request?.method).isEqualTo("GET") | ||
| assertThat(event.request?.url).isEqualTo("http://127.0.0.1:$port/capture") | ||
| assertThat(event.request?.queryString).isEqualTo("customer=123") | ||
| } | ||
|
|
||
| private class CaptureServlet : HttpServlet() { | ||
| override fun doGet(request: HttpServletRequest, response: HttpServletResponse) { | ||
| Sentry.captureMessage(MESSAGE) | ||
| response.writer.print("captured") | ||
| } | ||
| } | ||
|
|
||
| private companion object { | ||
| const val MESSAGE = "captured from servlet integration test" | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.