Skip to content

fix: getSession(false) returns null after session invalidation (#115)#116

Open
Artur- wants to merge 2 commits into
mainfrom
logout-tests
Open

fix: getSession(false) returns null after session invalidation (#115)#116
Artur- wants to merge 2 commits into
mainfrom
logout-tests

Conversation

@Artur-

@Artur- Artur- commented Jun 25, 2026

Copy link
Copy Markdown
Member

MockRequest.getSession(false) returned the stale, invalidated session instead of null once the session had been invalidated, violating the servlet container contract. This broke logout: Spring Security's SecurityContextLogoutHandler invalidates the HttpSession and then calls HttpSessionSecurityContextRepository.saveContext, which looks up request.getSession(false). In a real container that returns null and the empty-context save is a no-op, but the mock handed back the invalidated MockHttpSession, so removing the security-context attribute threw IllegalStateException("invalidated").

Honour the servlet contract: once invalidated, getSession(false) returns null and getSession(true) creates a fresh session. Add LogoutTest covering the issue #115 sequence plus the logout->redirect-to-login and logout->new-login flows, and update MockRequestTest to assert the corrected behaviour.

Fixes #115

MockRequest.getSession(false) returned the stale, invalidated session
instead of null once the session had been invalidated, violating the
servlet container contract. This broke logout: Spring Security's
SecurityContextLogoutHandler invalidates the HttpSession and then calls
HttpSessionSecurityContextRepository.saveContext, which looks up
request.getSession(false). In a real container that returns null and the
empty-context save is a no-op, but the mock handed back the invalidated
MockHttpSession, so removing the security-context attribute threw
IllegalStateException("invalidated").

Honour the servlet contract: once invalidated, getSession(false) returns
null and getSession(true) creates a fresh session. Add LogoutTest
covering the issue #115 sequence plus the logout->redirect-to-login and
logout->new-login flows, and update MockRequestTest to assert the
corrected behaviour.
@Artur- Artur- requested a review from mcollovati June 25, 2026 17:53
@Artur-

Artur- commented Jun 25, 2026

Copy link
Copy Markdown
Member Author

/format

@github-actions

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Invalid session" exception when clicking the logout button of the app during Browserless testing

2 participants