Search in sources :

Example 11 with SessionConfig

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);
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) SessionConfig(io.undertow.server.session.SessionConfig) Test(org.junit.Test)

Example 12 with SessionConfig

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);
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) SessionConfig(io.undertow.server.session.SessionConfig) Test(org.junit.Test)

Example 13 with SessionConfig

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);
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) Batch(org.wildfly.clustering.ee.Batch) SessionConfig(io.undertow.server.session.SessionConfig) Test(org.junit.Test)

Example 14 with SessionConfig

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);
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) Batch(org.wildfly.clustering.ee.Batch) SessionConfig(io.undertow.server.session.SessionConfig) Test(org.junit.Test)

Example 15 with SessionConfig

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();
}
Also used : AuthenticatedSession(io.undertow.security.api.AuthenticatedSessionManager.AuthenticatedSession) Instant(java.time.Instant) SessionConfig(io.undertow.server.session.SessionConfig) BatchContext(org.wildfly.clustering.ee.BatchContext) Duration(java.time.Duration) HttpServerExchange(io.undertow.server.HttpServerExchange) Batch(org.wildfly.clustering.ee.Batch) SessionListeners(io.undertow.server.session.SessionListeners) SessionMetaData(org.wildfly.clustering.web.session.SessionMetaData) SessionAttributes(org.wildfly.clustering.web.session.SessionAttributes) SessionListener(io.undertow.server.session.SessionListener) Test(org.junit.Test)

Aggregations

SessionConfig (io.undertow.server.session.SessionConfig)16 HttpServerExchange (io.undertow.server.HttpServerExchange)10 Test (org.junit.Test)8 SessionManager (io.undertow.server.session.SessionManager)6 Batch (org.wildfly.clustering.ee.Batch)6 Session (io.undertow.server.session.Session)5 AuthenticatedSession (io.undertow.security.api.AuthenticatedSessionManager.AuthenticatedSession)3 PathParameterSessionConfig (io.undertow.server.session.PathParameterSessionConfig)2 SslSessionConfig (io.undertow.server.session.SslSessionConfig)2 Map (java.util.Map)2 BatchContext (org.wildfly.clustering.ee.BatchContext)2 Undertow (io.undertow.Undertow)1 AuthenticatedSessionManager (io.undertow.security.api.AuthenticatedSessionManager)1 SecurityContext (io.undertow.security.api.SecurityContext)1 HttpHandler (io.undertow.server.HttpHandler)1 PathHandler (io.undertow.server.handlers.PathHandler)1 InMemorySessionManager (io.undertow.server.session.InMemorySessionManager)1 SessionAttachmentHandler (io.undertow.server.session.SessionAttachmentHandler)1 SessionCookieConfig (io.undertow.server.session.SessionCookieConfig)1 SessionListener (io.undertow.server.session.SessionListener)1