fix: correct issuedAtTime in JWT cool-off period test#171
Merged
Conversation
… test Agent-Logs-Url: https://github.com/OpenIdentityPlatform/commons/sessions/2d2ea944-f99c-416e-af74-e08948a16c72 Co-authored-by: vharseko <6818498+vharseko@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix failing test for JWT session cookie validation
fix: correct issuedAtTime in JWT cool-off period test
Apr 3, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The test
shouldValidateRequestWhenJwtSessionCookiePresentAndValidCoolOffPeriodNotExpiredwas failing becauseissuedAtTimewas set 1 minute in the past, causing the module's cool-off logic to trigger a cookie refresh — violating theverifyZeroInteractions(response)assertion.Change
ServletJwtSessionModuleTest.java: ChangeissuedAtTimeoffset from-1 minuteto-5 secondsso the JWT is considered fresh and no cookie refresh occurs.This makes the test properly complementary to
shouldValidateRequestWhenJwtSessionCookiePresentAndValidCoolOffPeriodExpired, which uses-1 minute - 5 secondsand expects a cookie refresh.Original prompt
Failing Test
The CI build is failing on the test
shouldValidateRequestWhenJwtSessionCookiePresentAndValidCoolOffPeriodNotExpiredinServletJwtSessionModuleTest.java.Build run: https://github.com/OpenIdentityPlatform/commons/actions/runs/23912306875/job/69737183389
Error:
Root Cause
In the test at line 525,
verifyZeroInteractions(response)asserts that theHttpServletResponsemock should have no interactions. However, the production code inCookie.addCookie()(Cookie.java line 332) callsresp.addCookie(cookie.cookie)on the response — meaning the JWT is being rebuilt and the cookie is being reset even though the cool-off period has supposedly not expired.The issue is that the test sets
issuedAtTimeto 1 minute ago (lines 492-495):This causes the module's cool-off period logic to consider the JWT old enough to warrant refreshing the cookie — which triggers a
Cookie.addCookie()call on the response, violating theverifyZeroInteractions(response)assertion.Fix
In the file
commons/auth-filters/authn-filter/jaspi-modules/jwt-session-module/src/test/java/org/forgerock/jaspi/modules/session/jwt/ServletJwtSessionModuleTest.java, change lines 492-495 from:to:
This sets the issued-at time to only 5 seconds ago (instead of 1 minute), so the cool-off period is truly not expired, and no cookie refresh/response interaction occurs.
Note that the companion test
shouldValidateRequestWhenJwtSessionCookiePresentAndValidCoolOffPeriodExpiredcorrectly sets the issued-at time further in the past (calendar.add(Calendar.MINUTE, -1)pluscalendar.add(Calendar.SECOND, -5)) and expects the response to be interacted with. The fix makes the two tests properly complementary.The following is the prior conversation context from the user's chat exploration (may be truncated):
User: Please find a solution for this failing job. Use the logs, job definition, and any referenced files where the failure occurred. Keep your response focused on the solution and include code suggestions when appropriate.
Assistant:
I'll start by fetching the job logs and the workflow definition to understand the failure.
Assistant: The build fails due to a single test failure:
ServletJwtSessionModuleTest.shouldValidateRequestWhenJwtSessionCookiePresentAndValidCoolOffPeriodNotExpired(line 525)The error is:
This means the test expects no interactions with the
HttpServletResponsemock, but the code is callingaddCookie()on it when it shouldn't be (during the "cool-off period not expired" scenario). Let me look at the test and theCookie.addCookiemethod.Assistant: ## Failing Test Analysis
The build fails on the test
shouldValidateRequestWhenJwtSessionCookiePresentAndValidCoolOffPeriodNotExpiredat line 525 inServletJwtSessionModuleTest.java:Root Cause
The test at line 525 asserts
verifyZeroInteractions(response), expecting no interactions with theHttpServletResponsemock. However, the production code inCookie.addCookie()callsresp.addCookie(cookie.cookie)on the response — meaning the JWT is being rebuilt and the cookie is ...This pull request was created from Copilot chat.