use of io.undertow.server.session.SessionConfig in project wildfly by wildfly.
the class DistributableSessionManagerTestCase method getSessionNoSessionId.
@Test
public void getSessionNoSessionId() {
HttpServerExchange exchange = new HttpServerExchange(null);
SessionConfig config = mock(SessionConfig.class);
when(config.findSessionId(exchange)).thenReturn(null);
io.undertow.server.session.Session sessionAdapter = this.adapter.getSession(exchange, config);
assertNull(sessionAdapter);
}
use of io.undertow.server.session.SessionConfig in project wildfly by wildfly.
the class DistributableSessionManagerTestCase method getSessionInvalidCharacters.
@Test
public void getSessionInvalidCharacters() {
HttpServerExchange exchange = new HttpServerExchange(null);
SessionConfig config = mock(SessionConfig.class);
String sessionId = "session+";
when(config.findSessionId(exchange)).thenReturn(sessionId);
io.undertow.server.session.Session sessionAdapter = this.adapter.getSession(exchange, config);
assertNull(sessionAdapter);
verify(this.manager, never()).findSession(sessionId);
}
use of io.undertow.server.session.SessionConfig in project wildfly by wildfly.
the class DistributableSessionManagerTestCase method createSessionNoSessionId.
@Test
public void createSessionNoSessionId() {
HttpServerExchange exchange = new HttpServerExchange(null);
Batcher<Batch> batcher = mock(Batcher.class);
Batch batch = mock(Batch.class);
SessionConfig config = mock(SessionConfig.class);
Session<LocalSessionContext> session = mock(Session.class);
String sessionId = "session";
when(this.manager.createIdentifier()).thenReturn(sessionId);
when(this.manager.createSession(sessionId)).thenReturn(session);
when(this.manager.getBatcher()).thenReturn(batcher);
when(batcher.createBatch()).thenReturn(batch);
when(session.getId()).thenReturn(sessionId);
io.undertow.server.session.Session sessionAdapter = this.adapter.createSession(exchange, config);
assertNotNull(sessionAdapter);
verify(this.listener).sessionCreated(sessionAdapter, exchange);
verify(config).setSessionId(exchange, sessionId);
verify(batcher).suspendBatch();
verify(this.statistics).record(sessionAdapter);
String expected = "expected";
when(session.getId()).thenReturn(expected);
String result = sessionAdapter.getId();
assertSame(expected, result);
}
use of io.undertow.server.session.SessionConfig in project wildfly by wildfly.
the class DistributableSessionManagerTestCase method getSession.
@Test
public void getSession() {
HttpServerExchange exchange = new HttpServerExchange(null);
Batcher<Batch> batcher = mock(Batcher.class);
Batch batch = mock(Batch.class);
SessionConfig config = mock(SessionConfig.class);
Session<LocalSessionContext> session = mock(Session.class);
String sessionId = "session";
when(config.findSessionId(exchange)).thenReturn(sessionId);
when(this.manager.findSession(sessionId)).thenReturn(session);
when(this.manager.getBatcher()).thenReturn(batcher);
when(batcher.createBatch()).thenReturn(batch);
when(session.getId()).thenReturn(sessionId);
io.undertow.server.session.Session sessionAdapter = this.adapter.getSession(exchange, config);
assertNotNull(sessionAdapter);
verifyZeroInteractions(this.statistics);
verify(batcher).suspendBatch();
String expected = "expected";
when(session.getId()).thenReturn(expected);
String result = sessionAdapter.getId();
assertSame(expected, result);
}
use of io.undertow.server.session.SessionConfig in project wildfly by wildfly.
the class DistributableSessionTestCase method changeSessionId.
@Test
public void changeSessionId() {
HttpServerExchange exchange = new HttpServerExchange(null);
SessionConfig config = mock(SessionConfig.class);
this.validate(session -> session.changeSessionId(exchange, config));
SessionManager<LocalSessionContext, Batch> manager = mock(SessionManager.class);
Batcher<Batch> batcher = mock(Batcher.class);
BatchContext context = mock(BatchContext.class);
Session<LocalSessionContext> session = mock(Session.class);
SessionAttributes oldAttributes = mock(SessionAttributes.class);
SessionAttributes newAttributes = mock(SessionAttributes.class);
SessionMetaData oldMetaData = mock(SessionMetaData.class);
SessionMetaData newMetaData = mock(SessionMetaData.class);
LocalSessionContext oldContext = mock(LocalSessionContext.class);
LocalSessionContext newContext = mock(LocalSessionContext.class);
SessionListener listener = mock(SessionListener.class);
SessionListeners listeners = new SessionListeners();
listeners.addSessionListener(listener);
String oldSessionId = "old";
String newSessionId = "new";
String name = "name";
Object value = new Object();
Instant now = Instant.now();
Duration interval = Duration.ofSeconds(10L);
AuthenticatedSession authenticatedSession = new AuthenticatedSession(null, null);
when(this.manager.getSessionManager()).thenReturn(manager);
when(manager.getBatcher()).thenReturn(batcher);
when(batcher.resumeBatch(this.batch)).thenReturn(context);
when(manager.createIdentifier()).thenReturn(newSessionId);
when(manager.createSession(newSessionId)).thenReturn(session);
when(this.session.getAttributes()).thenReturn(oldAttributes);
when(this.session.getMetaData()).thenReturn(oldMetaData);
when(session.getAttributes()).thenReturn(newAttributes);
when(session.getMetaData()).thenReturn(newMetaData);
when(oldAttributes.getAttributeNames()).thenReturn(Collections.singleton(name));
when(oldAttributes.getAttribute(name)).thenReturn(value);
when(newAttributes.setAttribute(name, value)).thenReturn(null);
when(oldMetaData.getLastAccessedTime()).thenReturn(now);
when(oldMetaData.getMaxInactiveInterval()).thenReturn(interval);
when(this.session.getId()).thenReturn(oldSessionId);
when(session.getId()).thenReturn(newSessionId);
when(this.session.getLocalContext()).thenReturn(oldContext);
when(session.getLocalContext()).thenReturn(newContext);
when(oldContext.getAuthenticatedSession()).thenReturn(authenticatedSession);
when(this.manager.getSessionListeners()).thenReturn(listeners);
String result = this.adapter.changeSessionId(exchange, config);
assertSame(newSessionId, result);
verify(newMetaData).setLastAccessedTime(now);
verify(newMetaData).setMaxInactiveInterval(interval);
verify(config).setSessionId(exchange, newSessionId);
verify(newContext).setAuthenticatedSession(same(authenticatedSession));
verify(listener).sessionIdChanged(this.adapter, oldSessionId);
verify(context).close();
}
Aggregations