mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-17 08:24:13 +00:00
Fix mock servlet request behavior with session ids
Prior to this commit, `MockHttpServletRequest.isRequestedSessionIdValid()` would return `true` by default and could only be changed manually with a setter. This does not align with the Servlet spec because of 1) its default value and 2) it does not react to `changeSessionId()` calls. This commit fixes that behavior while still allowing "manual" booleans being set here. Fixes gh-36631
This commit is contained in:
+10
-2
@@ -251,7 +251,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
||||
|
||||
private @Nullable HttpSession session;
|
||||
|
||||
private boolean requestedSessionIdValid = true;
|
||||
private @Nullable Boolean requestedSessionIdValid;
|
||||
|
||||
private boolean requestedSessionIdFromCookie = true;
|
||||
|
||||
@@ -1352,7 +1352,15 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
||||
|
||||
@Override
|
||||
public boolean isRequestedSessionIdValid() {
|
||||
return this.requestedSessionIdValid;
|
||||
if (this.requestedSessionIdValid != null) {
|
||||
return this.requestedSessionIdValid;
|
||||
}
|
||||
String requestedId = getRequestedSessionId();
|
||||
if (requestedId == null) {
|
||||
return false;
|
||||
}
|
||||
HttpSession currentSession = getSession(false);
|
||||
return (currentSession != null && requestedId.equals(currentSession.getId()));
|
||||
}
|
||||
|
||||
public void setRequestedSessionIdFromCookie(boolean requestedSessionIdFromCookie) {
|
||||
|
||||
Reference in New Issue
Block a user