Repository navigation
Replace direct servlet advice tests with instrumentation coverage #12696
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -460,6 +460,24 @@ class JakartaHttpServletRequestInstrumentationTest extends InstrumentationSpecif | |
| suite << testSuite() | ||
| } | ||
|
|
||
| void 'getSession tolerates a null servlet context'() { | ||
| setup: | ||
| final module = Mock(ApplicationModule) | ||
| InstrumentationBridge.registerIastModule(module) | ||
| final session = Mock(HttpSession) | ||
| final delegate = Mock(HttpServletRequest) | ||
| final request = new CustomRequest(request: delegate) | ||
|
|
||
| when: | ||
| final result = request.getSession() | ||
|
|
||
| then: | ||
| result.is(session) | ||
| 1 * delegate.getSession() >> session | ||
| 1 * delegate.getServletContext() >> null | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If the null-context guard regresses, the context-store access throws, but Was this helpful? React 👍 or 👎
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That reasoning overlooks the test harness: suppressed advice exceptions are recorded in InstrumentationErrors, and InstrumentationSpecification checks for those errors during cleanup. Removing the guard therefore fails the replacement tests even if the session is returned and the module remains untouched. |
||
| 0 * module._ | ||
| } | ||
|
|
||
| protected <E> E runUnderIastTrace(Closure<E> cl) { | ||
| final ddctx = new TagContext().withRequestContextDataIast(iastCtx) | ||
| final span = TEST_TRACER.startSpan("test", "test-iast-span", ddctx) | ||
|
|
||
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This instrumented call cannot detect the regression the deleted direct-advice test covered:
GetHttpSessionAdviceuses@Advice.OnMethodExit(suppress = Throwable.class), so if the null guard is removed and the context store again throws onget(null), Byte Buddy suppresses that exception and this test still receives the session, observesgetServletContext(), and sees no module calls. The equivalent javax test atJettyServlet3Test.groovy:583has the same blind spot; retain a direct advice invocation or otherwise assert that the advice body completes past the potentially throwing context-store access.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That reasoning overlooks the test harness: suppressed advice exceptions are recorded in InstrumentationErrors, and InstrumentationSpecification checks for those errors during cleanup. Removing the guard therefore fails the replacement tests even if the session is returned and the module remains untouched.