session#getLastAccessedTime should throw IllegalStateException if session has been invalidated (#4023)
* per servlet api javadoc getLastAccessedTime should throw IllegalStateException if session has been invalidated Signed-off-by: olivier lamy <oliver.lamy@gmail.com> * isInvalid test should be done within lock Signed-off-by: olivier lamy <oliver.lamy@gmail.com>
This commit is contained in:
parent
7bc04d3d4f
commit
5403a30b32
|
@ -476,6 +476,10 @@ public class Session implements SessionHandler.SessionIf
|
|||
{
|
||||
try (Lock lock = _lock.lock())
|
||||
{
|
||||
if (isInvalid())
|
||||
{
|
||||
throw new IllegalStateException("Session not valid");
|
||||
}
|
||||
return _sessionData.getLastAccessed();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,9 +23,10 @@ import java.util.Collections;
|
|||
import java.util.HashSet;
|
||||
import javax.servlet.SessionTrackingMode;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
public class SessionHandlerTest
|
||||
{
|
||||
@Test
|
||||
|
@ -34,7 +35,18 @@ public class SessionHandlerTest
|
|||
SessionHandler sessionHandler = new SessionHandler();
|
||||
sessionHandler.setSessionTrackingModes(new HashSet<>(Arrays.asList(SessionTrackingMode.COOKIE, SessionTrackingMode.URL)));
|
||||
sessionHandler.setSessionTrackingModes(Collections.singleton(SessionTrackingMode.SSL));
|
||||
Assertions.assertThrows(IllegalArgumentException.class,() ->
|
||||
assertThrows(IllegalArgumentException.class,() ->
|
||||
sessionHandler.setSessionTrackingModes(new HashSet<>(Arrays.asList(SessionTrackingMode.SSL, SessionTrackingMode.URL))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidSessiongetLastAccessedTime()
|
||||
{
|
||||
Session session = new Session(new SessionHandler(),
|
||||
new SessionData("sd" ,"", "", 0, 0, 0, 0));
|
||||
session.getLastAccessedTime();
|
||||
session.invalidate();
|
||||
assertThrows(IllegalStateException.class, () -> session.getLastAccessedTime());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue