Skip to content

Commit fcef18b

Browse files
committed
Add test case for UNDERTOW-2316
1 parent 88553c2 commit fcef18b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

core/src/test/java/io/undertow/server/handlers/session/InMemorySessionTestCase.java

+27
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import java.io.IOException;
2222

23+
import io.undertow.UndertowMessages;
2324
import io.undertow.server.HttpHandler;
2425
import io.undertow.server.HttpServerExchange;
2526
import io.undertow.server.session.InMemorySessionManager;
@@ -249,4 +250,30 @@ public void run() {
249250
client.getConnectionManager().shutdown();
250251
}
251252
}
253+
254+
@Test
255+
public void inMemorySessionNoConfigTest() throws IOException {
256+
try (TestHttpClient client = new TestHttpClient()) {
257+
client.setCookieStore(new BasicCookieStore());
258+
259+
final SessionAttachmentHandler handler = new SessionAttachmentHandler(new InMemorySessionManager(""), null);
260+
handler.setNext(new HttpHandler() {
261+
@Override
262+
public void handleRequest(final HttpServerExchange exchange) throws Exception {
263+
final SessionManager manager = exchange.getAttachment(SessionManager.ATTACHMENT_KEY);
264+
265+
IllegalStateException thrown = Assert.assertThrows(IllegalStateException.class, () -> {
266+
manager.getSession(exchange, null);
267+
});
268+
269+
Assert.assertEquals(UndertowMessages.MESSAGES.couldNotFindSessionCookieConfig().getCause(), thrown.getCause());
270+
Assert.assertEquals(UndertowMessages.MESSAGES.couldNotFindSessionCookieConfig().getMessage(), thrown.getMessage());
271+
}
272+
});
273+
DefaultServer.setRootHandler(handler);
274+
275+
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/notamatchingpath");
276+
client.execute(get);
277+
}
278+
}
252279
}

0 commit comments

Comments
 (0)