mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-28 14:52:24 +00:00
Fixed tests which were making assumptions about ordering within sets.
This commit is contained in:
parent
aa0744a705
commit
f121b6ac90
@ -22,6 +22,9 @@ import org.springframework.security.ui.session.HttpSessionDestroyedEvent;
|
|||||||
import org.springframework.mock.web.MockHttpSession;
|
import org.springframework.mock.web.MockHttpSession;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,16 +34,20 @@ import java.util.Date;
|
|||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public class SessionRegistryImplTests extends TestCase {
|
public class SessionRegistryImplTests extends TestCase {
|
||||||
|
private SessionRegistryImpl sessionRegistry;
|
||||||
|
|
||||||
//~ Methods ========================================================================================================
|
//~ Methods ========================================================================================================
|
||||||
|
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
sessionRegistry = new SessionRegistryImpl();
|
||||||
|
}
|
||||||
|
|
||||||
public void testEventPublishing() {
|
public void testEventPublishing() {
|
||||||
MockHttpSession httpSession = new MockHttpSession();
|
MockHttpSession httpSession = new MockHttpSession();
|
||||||
Object principal = "Some principal object";
|
Object principal = "Some principal object";
|
||||||
String sessionId = httpSession.getId();
|
String sessionId = httpSession.getId();
|
||||||
assertNotNull(sessionId);
|
assertNotNull(sessionId);
|
||||||
|
|
||||||
SessionRegistryImpl sessionRegistry = new SessionRegistryImpl();
|
|
||||||
|
|
||||||
// Register new Session
|
// Register new Session
|
||||||
sessionRegistry.registerNewSession(sessionId, principal);
|
sessionRegistry.registerNewSession(sessionId, principal);
|
||||||
|
|
||||||
@ -58,8 +65,6 @@ public class SessionRegistryImplTests extends TestCase {
|
|||||||
String sessionId2 = "9876543210";
|
String sessionId2 = "9876543210";
|
||||||
String sessionId3 = "5432109876";
|
String sessionId3 = "5432109876";
|
||||||
|
|
||||||
SessionRegistryImpl sessionRegistry = new SessionRegistryImpl();
|
|
||||||
|
|
||||||
sessionRegistry.registerNewSession(sessionId1, principal1);
|
sessionRegistry.registerNewSession(sessionId1, principal1);
|
||||||
sessionRegistry.registerNewSession(sessionId2, principal1);
|
sessionRegistry.registerNewSession(sessionId2, principal1);
|
||||||
sessionRegistry.registerNewSession(sessionId3, principal2);
|
sessionRegistry.registerNewSession(sessionId3, principal2);
|
||||||
@ -71,8 +76,6 @@ public class SessionRegistryImplTests extends TestCase {
|
|||||||
public void testSessionInformationLifecycle() throws Exception {
|
public void testSessionInformationLifecycle() throws Exception {
|
||||||
Object principal = "Some principal object";
|
Object principal = "Some principal object";
|
||||||
String sessionId = "1234567890";
|
String sessionId = "1234567890";
|
||||||
SessionRegistryImpl sessionRegistry = new SessionRegistryImpl();
|
|
||||||
|
|
||||||
// Register new Session
|
// Register new Session
|
||||||
sessionRegistry.registerNewSession(sessionId, principal);
|
sessionRegistry.registerNewSession(sessionId, principal);
|
||||||
|
|
||||||
@ -109,17 +112,16 @@ public class SessionRegistryImplTests extends TestCase {
|
|||||||
Object principal = "Some principal object";
|
Object principal = "Some principal object";
|
||||||
String sessionId1 = "1234567890";
|
String sessionId1 = "1234567890";
|
||||||
String sessionId2 = "9876543210";
|
String sessionId2 = "9876543210";
|
||||||
SessionRegistryImpl sessionRegistry = new SessionRegistryImpl();
|
|
||||||
|
|
||||||
// Register new Session
|
|
||||||
sessionRegistry.registerNewSession(sessionId1, principal);
|
sessionRegistry.registerNewSession(sessionId1, principal);
|
||||||
assertEquals(1, sessionRegistry.getAllSessions(principal, false).length);
|
SessionInformation[] sessions = sessionRegistry.getAllSessions(principal, false);
|
||||||
assertEquals(sessionId1, sessionRegistry.getAllSessions(principal, false)[0].getSessionId());
|
assertEquals(1, sessions.length);
|
||||||
|
assertTrue(contains(sessionId1, principal));
|
||||||
|
|
||||||
// Register new Session
|
|
||||||
sessionRegistry.registerNewSession(sessionId2, principal);
|
sessionRegistry.registerNewSession(sessionId2, principal);
|
||||||
assertEquals(2, sessionRegistry.getAllSessions(principal, false).length);
|
sessions = sessionRegistry.getAllSessions(principal, false);
|
||||||
assertEquals(sessionId2, sessionRegistry.getAllSessions(principal, false)[1].getSessionId());
|
assertEquals(2, sessions.length);
|
||||||
|
assertTrue(contains(sessionId2, principal));
|
||||||
|
|
||||||
// Expire one session
|
// Expire one session
|
||||||
SessionInformation session = sessionRegistry.getSessionInformation(sessionId2);
|
SessionInformation session = sessionRegistry.getSessionInformation(sessionId2);
|
||||||
@ -134,26 +136,36 @@ public class SessionRegistryImplTests extends TestCase {
|
|||||||
Object principal = "Some principal object";
|
Object principal = "Some principal object";
|
||||||
String sessionId1 = "1234567890";
|
String sessionId1 = "1234567890";
|
||||||
String sessionId2 = "9876543210";
|
String sessionId2 = "9876543210";
|
||||||
SessionRegistryImpl sessionRegistry = new SessionRegistryImpl();
|
|
||||||
|
|
||||||
// Register new Session
|
|
||||||
sessionRegistry.registerNewSession(sessionId1, principal);
|
sessionRegistry.registerNewSession(sessionId1, principal);
|
||||||
assertEquals(1, sessionRegistry.getAllSessions(principal, false).length);
|
SessionInformation[] sessions = sessionRegistry.getAllSessions(principal, false);
|
||||||
assertEquals(sessionId1, sessionRegistry.getAllSessions(principal, false)[0].getSessionId());
|
assertEquals(1, sessions.length);
|
||||||
|
assertTrue(contains(sessionId1, principal));
|
||||||
|
|
||||||
// Register new Session
|
|
||||||
sessionRegistry.registerNewSession(sessionId2, principal);
|
sessionRegistry.registerNewSession(sessionId2, principal);
|
||||||
assertEquals(2, sessionRegistry.getAllSessions(principal, false).length);
|
sessions = sessionRegistry.getAllSessions(principal, false);
|
||||||
assertEquals(sessionId2, sessionRegistry.getAllSessions(principal, false)[1].getSessionId());
|
assertEquals(2, sessions.length);
|
||||||
|
assertTrue(contains(sessionId2, principal));
|
||||||
|
|
||||||
// Clear session information
|
|
||||||
sessionRegistry.removeSessionInformation(sessionId1);
|
sessionRegistry.removeSessionInformation(sessionId1);
|
||||||
assertEquals(1, sessionRegistry.getAllSessions(principal, false).length);
|
sessions = sessionRegistry.getAllSessions(principal, false);
|
||||||
assertEquals(sessionId2, sessionRegistry.getAllSessions(principal, false)[0].getSessionId());
|
assertEquals(1, sessions.length);
|
||||||
|
assertTrue(contains(sessionId2, principal));
|
||||||
|
|
||||||
// Clear final session
|
|
||||||
sessionRegistry.removeSessionInformation(sessionId2);
|
sessionRegistry.removeSessionInformation(sessionId2);
|
||||||
assertNull(sessionRegistry.getSessionInformation(sessionId2));
|
assertNull(sessionRegistry.getSessionInformation(sessionId2));
|
||||||
assertNull(sessionRegistry.getAllSessions(principal, false));
|
assertNull(sessionRegistry.getAllSessions(principal, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean contains(String sessionId, Object principal) {
|
||||||
|
SessionInformation[] info = sessionRegistry.getAllSessions(principal, false);
|
||||||
|
|
||||||
|
for (int i = 0; i < info.length; i++) {
|
||||||
|
if (sessionId.equals(info[i].getSessionId())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user