mirror of
https://github.com/jetty/jetty.project.git
synced 2025-03-04 04:49:12 +00:00
Fixing WebSocketUpgradeFilter Tests
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
parent
c5755f6686
commit
7db1abafbf
@ -50,7 +50,7 @@ public class LocalServer extends ContainerLifeCycle implements LocalFuzzer.Provi
|
||||
private Server server;
|
||||
private ServerConnector connector;
|
||||
private LocalConnector localConnector;
|
||||
private ServletContextHandler servletContextHandler;
|
||||
protected ServletContextHandler servletContextHandler;
|
||||
private URI serverUri;
|
||||
private boolean ssl = false;
|
||||
private SslContextFactory sslContextFactory;
|
||||
|
@ -161,6 +161,11 @@ public class WSServer extends LocalServer implements LocalFuzzer.Provider
|
||||
}
|
||||
}
|
||||
|
||||
public ContextHandlerCollection getContexts()
|
||||
{
|
||||
return contexts;
|
||||
}
|
||||
|
||||
public Path getWebAppDir()
|
||||
{
|
||||
return this.contextDir;
|
||||
|
@ -166,6 +166,7 @@ public class WebSocketUpgradeFilterEmbeddedTest
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@SuppressWarnings("Duplicates")
|
||||
@ParameterizedTest(name = "[{index}] {0}")
|
||||
@MethodSource("scenarios")
|
||||
public void testNormalConfiguration(String testId, ContextProvider serverProvider) throws Exception
|
||||
@ -190,6 +191,7 @@ public class WebSocketUpgradeFilterEmbeddedTest
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("Duplicates")
|
||||
@ParameterizedTest(name = "[{index}] {0}")
|
||||
@MethodSource("scenarios")
|
||||
public void testStopStartOfHandler(String testId, ContextProvider serverProvider) throws Exception
|
||||
@ -243,13 +245,15 @@ public class WebSocketUpgradeFilterEmbeddedTest
|
||||
@Override
|
||||
protected Handler createRootHandler(Server server) throws Exception
|
||||
{
|
||||
return contextProvider.configureRootHandler(server);
|
||||
servletContextHandler = contextProvider.newServletContextHandler(server);
|
||||
return servletContextHandler;
|
||||
}
|
||||
};
|
||||
this.server.start();
|
||||
}
|
||||
|
||||
interface ContextProvider
|
||||
{
|
||||
Handler configureRootHandler(Server server) throws Exception;
|
||||
ServletContextHandler newServletContextHandler(Server server) throws Exception;
|
||||
}
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ public class WebSocketUpgradeFilterWebappTest
|
||||
|
||||
private static File getNewTestDir()
|
||||
{
|
||||
File testDir = MavenTestingUtils.getTargetTestingDir("WSUF-webxml-" + uniqTestDirId.getAndIncrement());
|
||||
File testDir = MavenTestingUtils.getTargetTestingDir("tests/WSUF-webxml-" + uniqTestDirId.getAndIncrement());
|
||||
FS.ensureDirExists(testDir);
|
||||
return testDir;
|
||||
}
|
||||
@ -66,39 +66,11 @@ public class WebSocketUpgradeFilterWebappTest
|
||||
{
|
||||
List<Arguments> cases = new ArrayList<>();
|
||||
|
||||
// WSUF from web.xml, SCI active, apply app-ws configuration via ServletContextListener
|
||||
|
||||
cases.add(Arguments.of("wsuf/WebAppContext/web.xml/ServletContextListener", (ServerConfiguration) (server) ->
|
||||
{
|
||||
server.copyWebInf("wsuf-config-via-listener.xml");
|
||||
server.copyClass(InfoSocket.class);
|
||||
server.copyClass(InfoContextAttributeListener.class);
|
||||
server.start();
|
||||
|
||||
WebAppContext webapp = server.createWebAppContext();
|
||||
server.deployWebapp(webapp);
|
||||
}));
|
||||
|
||||
// WSUF from web.xml, SCI active, apply app-ws configuration via ServletContextListener with WEB-INF/lib/jetty-http.jar
|
||||
|
||||
cases.add(Arguments.of("wsuf/WebAppContext/web.xml/ServletContextListener/jetty-http.jar", (ServerConfiguration) (server) ->
|
||||
{
|
||||
server.copyWebInf("wsuf-config-via-listener.xml");
|
||||
server.copyClass(InfoSocket.class);
|
||||
server.copyClass(InfoContextAttributeListener.class);
|
||||
// Add a jetty-http.jar to ensure that the classloader constraints
|
||||
// and the WebAppClassloader setup is sane and correct
|
||||
// The odd version string is present to capture bad regex behavior in Jetty
|
||||
server.copyLib(PathSpec.class, "jetty-http-9.99.999.jar");
|
||||
server.start();
|
||||
|
||||
WebAppContext webapp = server.createWebAppContext();
|
||||
server.deployWebapp(webapp);
|
||||
}));
|
||||
|
||||
// WSUF from web.xml, SCI active, apply app-ws configuration via Servlet.init
|
||||
|
||||
cases.add(Arguments.of("wsuf/WebAppContext/web.xml/Servlet.init", (ServerConfiguration) (server) ->
|
||||
cases.add(Arguments.of(
|
||||
"wsuf/WebAppContext/web.xml/Servlet.init",
|
||||
(ServerConfiguration) (server) ->
|
||||
{
|
||||
server.copyWebInf("wsuf-config-via-servlet-init.xml");
|
||||
server.copyClass(InfoSocket.class);
|
||||
@ -107,11 +79,14 @@ public class WebSocketUpgradeFilterWebappTest
|
||||
|
||||
WebAppContext webapp = server.createWebAppContext();
|
||||
server.deployWebapp(webapp);
|
||||
}));
|
||||
}
|
||||
));
|
||||
|
||||
// xml based, wsuf, on alternate url-pattern and config attribute location
|
||||
|
||||
cases.add(Arguments.of("wsuf/WebAppContext/web.xml/ServletContextListener/alt-config", (ServerConfiguration) (server) ->
|
||||
cases.add(Arguments.of(
|
||||
"wsuf/WebAppContext/web.xml/ServletContextListener/alt-config",
|
||||
(ServerConfiguration) (server) ->
|
||||
{
|
||||
server.copyWebInf("wsuf-alt-config-via-listener.xml");
|
||||
server.copyClass(InfoSocket.class);
|
||||
@ -120,7 +95,8 @@ public class WebSocketUpgradeFilterWebappTest
|
||||
|
||||
WebAppContext webapp = server.createWebAppContext();
|
||||
server.deployWebapp(webapp);
|
||||
}));
|
||||
}
|
||||
));
|
||||
|
||||
// WSUF from web.xml, SCI active, apply app-ws configuration via ServletContextListener
|
||||
|
||||
@ -132,6 +108,9 @@ public class WebSocketUpgradeFilterWebappTest
|
||||
server.copyClass(InfoSocket.class);
|
||||
server.copyClass(InfoContextAttributeListener.class);
|
||||
server.start();
|
||||
|
||||
WebAppContext webapp = server.createWebAppContext();
|
||||
server.deployWebapp(webapp);
|
||||
}
|
||||
));
|
||||
|
||||
@ -149,6 +128,9 @@ public class WebSocketUpgradeFilterWebappTest
|
||||
// The odd version string is present to capture bad regex behavior in Jetty
|
||||
server.copyLib(PathSpec.class, "jetty-http-9.99.999.jar");
|
||||
server.start();
|
||||
|
||||
WebAppContext webapp = server.createWebAppContext();
|
||||
server.deployWebapp(webapp);
|
||||
}
|
||||
));
|
||||
|
||||
@ -157,7 +139,7 @@ public class WebSocketUpgradeFilterWebappTest
|
||||
|
||||
private void startServer(ServerConfiguration serverConfiguration) throws Exception
|
||||
{
|
||||
WSServer server = new WSServer(getNewTestDir(), "/");
|
||||
server = new WSServer(getNewTestDir(), "app");
|
||||
serverConfiguration.configure(server);
|
||||
}
|
||||
|
||||
@ -169,13 +151,14 @@ public class WebSocketUpgradeFilterWebappTest
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@SuppressWarnings("Duplicates")
|
||||
@ParameterizedTest(name = "[{index}] {0}")
|
||||
@MethodSource("scenarios")
|
||||
public void testNormalConfiguration(String testId, ServerConfiguration serverConfiguration) throws Exception
|
||||
{
|
||||
startServer(serverConfiguration);
|
||||
|
||||
try (LocalFuzzer session = server.newLocalFuzzer("/info/"))
|
||||
try (LocalFuzzer session = server.newLocalFuzzer("/app/info/"))
|
||||
{
|
||||
session.sendFrames(
|
||||
new TextFrame().setPayload("hello"),
|
||||
@ -193,13 +176,14 @@ public class WebSocketUpgradeFilterWebappTest
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("Duplicates")
|
||||
@ParameterizedTest(name = "[{index}] {0}")
|
||||
@MethodSource("scenarios")
|
||||
public void testStopStartOfHandler(String testId, ServerConfiguration serverConfiguration) throws Exception
|
||||
{
|
||||
startServer(serverConfiguration);
|
||||
|
||||
try (LocalFuzzer session = server.newLocalFuzzer("/info/"))
|
||||
try (LocalFuzzer session = server.newLocalFuzzer("/app/info/"))
|
||||
{
|
||||
session.sendFrames(
|
||||
new TextFrame().setPayload("hello 1"),
|
||||
@ -216,12 +200,12 @@ public class WebSocketUpgradeFilterWebappTest
|
||||
assertThat("Frame.text-payload", frame.getPayloadAsUTF8(), containsString("session.maxTextMessageSize=" + (10 * 1024 * 1024)));
|
||||
}
|
||||
|
||||
server.getServletContextHandler().stop();
|
||||
server.getServletContextHandler().start();
|
||||
server.getContexts().stop();
|
||||
server.getContexts().start();
|
||||
|
||||
// Make request again (server should have retained websocket configuration)
|
||||
|
||||
try (LocalFuzzer session = server.newLocalFuzzer("/info/"))
|
||||
try (LocalFuzzer session = server.newLocalFuzzer("/app/info/"))
|
||||
{
|
||||
session.sendFrames(
|
||||
new TextFrame().setPayload("hello 2"),
|
||||
|
Loading…
x
Reference in New Issue
Block a user