Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[UNDERTOW-2316] Add test case #1531

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.io.IOException;

import io.undertow.UndertowMessages;
import io.undertow.server.HttpHandler;
import io.undertow.server.HttpServerExchange;
import io.undertow.server.session.InMemorySessionManager;
Expand Down Expand Up @@ -249,4 +250,37 @@ public void run() {
client.getConnectionManager().shutdown();
}
}

@Test
public void inMemorySessionNoConfigTest() throws IOException {
try (TestHttpClient client = new TestHttpClient()) {
client.setCookieStore(new BasicCookieStore());

final SessionAttachmentHandler handler = new SessionAttachmentHandler(new InMemorySessionManager(""), null);
final Throwable[] thrown = {null};
handler.setNext(new HttpHandler() {
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
final SessionManager manager = exchange.getAttachment(SessionManager.ATTACHMENT_KEY);
try {
manager.getSession(exchange, null);
} catch (Throwable t) {
thrown[0] = t;
}
}
});
DefaultServer.setRootHandler(handler);

HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/notamatchingpath");
client.execute(get);

if (thrown[0] != null) {
Assert.assertTrue(thrown[0] instanceof IllegalStateException);
Assert.assertEquals(UndertowMessages.MESSAGES.couldNotFindSessionCookieConfig().getCause(), thrown[0].getCause());
Assert.assertEquals(UndertowMessages.MESSAGES.couldNotFindSessionCookieConfig().getMessage(), thrown[0].getMessage());
} else {
Assert.fail("No exception was thrown.");
}
}
}
}