Session implements Serializable { public static boolean isValidSessionId(String sessionId) { return (sessionId != null) && !sessionId.isEmpty() && (sessionId.length() == Session.SESSION_ID_LENGTH * 2); } Session(User user); String getSessionId(); User getUser(); String getThemeName(); String getCsrfToken(); void setThemeName(String themeName); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString(); static boolean isValidSessionId(String sessionId); static final int SESSION_ID_LENGTH; }
@Test public void testSessionIdValidation() { Assert.assertEquals(Session.isValidSessionId(null), false); Assert.assertEquals(Session.isValidSessionId(""), false); Assert.assertEquals(Session.isValidSessionId("1234567890123456789012345678901"), false); Assert.assertEquals(Session.isValidSessionId("123456789012345678901234567890123"), false); Assert.assertEquals(Session.isValidSessionId("12345678901234567890123456789012"), true); Assert.assertEquals(Session.isValidSessionId("2B2F3466F1937F70B50A610453509EEB"), true); }