From 7e2e64e8561a3f10c4106fd05eb13478c7b3828a Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Tue, 11 Apr 2017 15:46:47 -0700 Subject: [PATCH] Issue #207 - testcase rework due to new async behaviors --- .../jsr356/DecoderReaderManySmallTest.java | 10 +- .../websocket/jsr356/DecoderReaderTest.java | 10 +- .../jetty/websocket/jsr356/EncoderTest.java | 10 +- .../misbehaving/MisbehavingClassTest.java | 4 +- .../jsr356/server/ConfiguratorTest.java | 24 +- jetty-websocket/pom.xml | 1 + .../websocket/client/WebSocketClient.java | 19 - .../client/io/ConnectionManager.java | 70 --- .../websocket/client/BadNetworkTest.java | 6 +- .../websocket/client/ClientCloseTest.java | 10 +- .../websocket/client/ClientConnectTest.java | 6 +- .../client/ConnectionManagerTest.java | 82 ---- .../jetty/websocket/client/CookieTest.java | 6 +- .../websocket/client/ServerReadThread.java | 2 +- .../jetty/websocket/client/SessionTest.java | 6 +- .../websocket/client/SlowClientTest.java | 8 +- .../websocket/client/SlowServerTest.java | 8 +- .../client/TomcatServerQuirksTest.java | 4 +- .../websocket/client/WebSocketClientTest.java | 6 +- .../jetty/websocket/common/Generator.java | 8 +- .../jetty/websocket/common/Parser.java | 37 +- .../common/WebSocketSessionFactory.java | 8 +- .../io/AbstractWebSocketConnection.java | 7 +- .../test/BlockheadClientConstructionTest.java | 2 +- .../websocket/common/test/EventTracker.java | 2 +- .../websocket/common/test/RegexMatcher.java | 66 --- .../websocket/common/test/UnitParser.java | 2 +- ...kheadClient.java => XBlockheadClient.java} | 8 +- ...kheadServer.java => XBlockheadServer.java} | 6 +- ...n.java => XBlockheadServerConnection.java} | 6 +- .../common/test/{Fuzzer.java => XFuzzer.java} | 10 +- .../server/AnnotatedMaxMessageSizeTest.java | 8 +- .../jetty/websocket/server/ChromeTest.java | 4 +- .../server/DecoratorsLegacyTest.java | 4 +- .../websocket/server/DecoratorsTest.java | 4 +- .../jetty/websocket/server/FirefoxTest.java | 4 +- .../server/FragmentExtensionTest.java | 4 +- .../server/IdentityExtensionTest.java | 4 +- .../websocket/server/IdleTimeoutTest.java | 4 +- .../server/ManyConnectionsCleanupTest.java | 16 +- .../websocket/server/RequestHeadersTest.java | 5 +- .../websocket/server/SubProtocolTest.java | 4 +- .../websocket/server/SuspendResumeTest.java | 4 +- .../websocket/server/TooFastClientTest.java | 6 +- .../websocket/server/WebSocketCloseTest.java | 22 +- .../server/WebSocketInvalidVersionTest.java | 4 +- .../server/WebSocketServerSessionTest.java | 6 +- .../server/WebSocketServletRFCTest.java | 14 +- .../server/WebSocketUpgradeFilterTest.java | 8 +- .../server/ab/TestABCase6_GoodUTF.java | 150 ------- .../misbehaving/MisbehavingClassTest.java | 10 +- .../test/resources/jetty-logging.properties | 2 +- jetty-websocket/websocket-tests/pom.xml | 86 ++++ .../jetty/websocket/tests/CloseState.java | 44 ++ .../eclipse/jetty/websocket/tests/Fuzzed.java | 32 ++ .../eclipse/jetty/websocket/tests/Fuzzer.java | 368 ++++++++++++++++ .../tests/LeakTrackingBufferPoolRule.java | 61 +++ .../websocket/tests/RawFrameBuilder.java | 110 +++++ .../websocket/tests/SimpleServletServer.java | 163 +++++++ .../websocket/tests/UntrustedWSClient.java | 69 +++ .../tests/UntrustedWSConnection.java | 124 ++++++ .../websocket/tests/UntrustedWSEndpoint.java | 157 +++++++ .../websocket/tests/UntrustedWSSession.java | 49 +++ .../tests/UntrustedWSSessionFactory.java | 50 +++ .../tests/UntrustedWSClientTest.java | 126 ++++++ .../websocket/tests/server}/ABServlet.java | 2 +- .../websocket/tests/server}/ABSocket.java | 2 +- .../tests/server}/AbstractABCase.java | 29 +- .../websocket/tests/server}/TestABCase1.java | 317 +++++++------- .../websocket/tests/server}/TestABCase2.java | 137 +++--- .../websocket/tests/server}/TestABCase3.java | 83 ++-- .../websocket/tests/server}/TestABCase4.java | 124 +++--- .../websocket/tests/server}/TestABCase5.java | 414 +++++++++--------- .../websocket/tests/server}/TestABCase6.java | 160 ++++--- .../tests/server}/TestABCase6_BadUTF.java | 17 +- .../tests/server/TestABCase6_GoodUTF.java | 149 +++++++ .../websocket/tests/server}/TestABCase7.java | 146 +++--- .../server}/TestABCase7_BadStatusCodes.java | 92 ++-- .../server}/TestABCase7_GoodStatusCodes.java | 86 ++-- .../websocket/tests/server}/TestABCase9.java | 155 +++---- .../test/resources/jetty-logging.properties | 50 +++ pom.xml | 13 +- 82 files changed, 2687 insertions(+), 1469 deletions(-) delete mode 100644 jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/io/ConnectionManager.java delete mode 100644 jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/ConnectionManagerTest.java delete mode 100644 jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/RegexMatcher.java rename jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/{BlockheadClient.java => XBlockheadClient.java} (98%) rename jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/{BlockheadServer.java => XBlockheadServer.java} (94%) rename jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/{BlockheadServerConnection.java => XBlockheadServerConnection.java} (98%) rename jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/{Fuzzer.java => XFuzzer.java} (97%) delete mode 100644 jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase6_GoodUTF.java create mode 100644 jetty-websocket/websocket-tests/pom.xml create mode 100644 jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/CloseState.java create mode 100644 jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/Fuzzed.java create mode 100644 jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/Fuzzer.java create mode 100644 jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/LeakTrackingBufferPoolRule.java create mode 100644 jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/RawFrameBuilder.java create mode 100644 jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/SimpleServletServer.java create mode 100644 jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/UntrustedWSClient.java create mode 100644 jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/UntrustedWSConnection.java create mode 100644 jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/UntrustedWSEndpoint.java create mode 100644 jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/UntrustedWSSession.java create mode 100644 jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/UntrustedWSSessionFactory.java create mode 100644 jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/UntrustedWSClientTest.java rename jetty-websocket/{websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab => websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server}/ABServlet.java (96%) rename jetty-websocket/{websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab => websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server}/ABSocket.java (98%) rename jetty-websocket/{websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab => websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server}/AbstractABCase.java (89%) rename jetty-websocket/{websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab => websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server}/TestABCase1.java (75%) rename jetty-websocket/{websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab => websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server}/TestABCase2.java (76%) rename jetty-websocket/{websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab => websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server}/TestABCase3.java (75%) rename jetty-websocket/{websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab => websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server}/TestABCase4.java (73%) rename jetty-websocket/{websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab => websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server}/TestABCase5.java (73%) rename jetty-websocket/{websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab => websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server}/TestABCase6.java (77%) rename jetty-websocket/{websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab => websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server}/TestABCase6_BadUTF.java (94%) create mode 100644 jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/TestABCase6_GoodUTF.java rename jetty-websocket/{websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab => websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server}/TestABCase7.java (72%) rename jetty-websocket/{websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab => websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server}/TestABCase7_BadStatusCodes.java (67%) rename jetty-websocket/{websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab => websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server}/TestABCase7_GoodStatusCodes.java (68%) rename jetty-websocket/{websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab => websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server}/TestABCase9.java (86%) create mode 100644 jetty-websocket/websocket-tests/src/test/resources/jetty-logging.properties diff --git a/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/DecoderReaderManySmallTest.java b/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/DecoderReaderManySmallTest.java index c867b9a6e2e..af14fce2e6c 100644 --- a/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/DecoderReaderManySmallTest.java +++ b/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/DecoderReaderManySmallTest.java @@ -41,7 +41,7 @@ import org.eclipse.jetty.toolchain.test.TestTracker; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.websocket.common.frames.TextFrame; -import org.eclipse.jetty.websocket.common.test.BlockheadServer; +import org.eclipse.jetty.websocket.common.test.XBlockheadServer; import org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection; import org.junit.After; import org.junit.Assert; @@ -112,11 +112,11 @@ public class DecoderReaderManySmallTest private static class EventIdServer implements Runnable { - private BlockheadServer server; + private XBlockheadServer server; private IBlockheadServerConnection sconnection; private CountDownLatch connectLatch = new CountDownLatch(1); - public EventIdServer(BlockheadServer server) + public EventIdServer(XBlockheadServer server) { this.server = server; } @@ -166,7 +166,7 @@ public class DecoderReaderManySmallTest @Rule public TestTracker tt = new TestTracker(); - private BlockheadServer server; + private XBlockheadServer server; private WebSocketContainer client; @Before @@ -178,7 +178,7 @@ public class DecoderReaderManySmallTest @Before public void startServer() throws Exception { - server = new BlockheadServer(); + server = new XBlockheadServer(); server.start(); } diff --git a/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/DecoderReaderTest.java b/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/DecoderReaderTest.java index e5f137b2257..d07933f3d1e 100644 --- a/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/DecoderReaderTest.java +++ b/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/DecoderReaderTest.java @@ -49,7 +49,7 @@ import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.frames.ContinuationFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame; -import org.eclipse.jetty.websocket.common.test.BlockheadServer; +import org.eclipse.jetty.websocket.common.test.XBlockheadServer; import org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection; import org.junit.After; import org.junit.Assert; @@ -154,11 +154,11 @@ public class DecoderReaderTest private static class QuoteServer implements Runnable { - private BlockheadServer server; + private XBlockheadServer server; private IBlockheadServerConnection sconnection; private CountDownLatch connectLatch = new CountDownLatch(1); - public QuoteServer(BlockheadServer server) + public QuoteServer(XBlockheadServer server) { this.server = server; } @@ -230,7 +230,7 @@ public class DecoderReaderTest @Rule public TestTracker tt = new TestTracker(); - private BlockheadServer server; + private XBlockheadServer server; private WebSocketContainer client; @Before @@ -242,7 +242,7 @@ public class DecoderReaderTest @Before public void startServer() throws Exception { - server = new BlockheadServer(); + server = new XBlockheadServer(); server.start(); } diff --git a/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/EncoderTest.java b/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/EncoderTest.java index 8d37f509e1b..eedce649def 100644 --- a/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/EncoderTest.java +++ b/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/EncoderTest.java @@ -44,7 +44,7 @@ import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.toolchain.test.TestTracker; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; -import org.eclipse.jetty.websocket.common.test.BlockheadServer; +import org.eclipse.jetty.websocket.common.test.XBlockheadServer; import org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection; import org.junit.After; import org.junit.Assert; @@ -57,11 +57,11 @@ public class EncoderTest private static class EchoServer implements Runnable { private Thread thread; - private BlockheadServer server; + private XBlockheadServer server; private IBlockheadServerConnection sconnection; private CountDownLatch connectLatch = new CountDownLatch(1); - public EchoServer(BlockheadServer server) + public EchoServer(XBlockheadServer server) { this.server = server; } @@ -192,7 +192,7 @@ public class EncoderTest @Rule public TestTracker tt = new TestTracker(); - private BlockheadServer server; + private XBlockheadServer server; private WebSocketContainer client; @@ -241,7 +241,7 @@ public class EncoderTest @Before public void startServer() throws Exception { - server = new BlockheadServer(); + server = new XBlockheadServer(); server.start(); } diff --git a/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/misbehaving/MisbehavingClassTest.java b/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/misbehaving/MisbehavingClassTest.java index dcb92a76a4a..c5077b0bc9c 100644 --- a/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/misbehaving/MisbehavingClassTest.java +++ b/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/misbehaving/MisbehavingClassTest.java @@ -97,7 +97,7 @@ public class MisbehavingClassTest WebSocketContainer container = ContainerProvider.getWebSocketContainer(); EndpointRuntimeOnOpen socket = new EndpointRuntimeOnOpen(); - try (StacklessLogging logging = new StacklessLogging(EndpointRuntimeOnOpen.class, WebSocketSession.class)) + try (StacklessLogging ignored = new StacklessLogging(EndpointRuntimeOnOpen.class, WebSocketSession.class)) { // expecting IOException during onOpen expectedException.expect(IOException.class); @@ -119,7 +119,7 @@ public class MisbehavingClassTest WebSocketContainer container = ContainerProvider.getWebSocketContainer(); AnnotatedRuntimeOnOpen socket = new AnnotatedRuntimeOnOpen(); - try (StacklessLogging logging = new StacklessLogging(AnnotatedRuntimeOnOpen.class, WebSocketSession.class)) + try (StacklessLogging ignored = new StacklessLogging(AnnotatedRuntimeOnOpen.class, WebSocketSession.class)) { // expecting IOException during onOpen expectedException.expect(IOException.class); diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/ConfiguratorTest.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/ConfiguratorTest.java index 1e1060e3c0b..17d96492490 100644 --- a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/ConfiguratorTest.java +++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/ConfiguratorTest.java @@ -60,7 +60,7 @@ import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.websocket.api.util.QuoteUtil; import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame; -import org.eclipse.jetty.websocket.common.test.BlockheadClient; +import org.eclipse.jetty.websocket.common.test.XBlockheadClient; import org.eclipse.jetty.websocket.common.test.HttpResponse; import org.eclipse.jetty.websocket.common.test.IBlockheadClient; import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer; @@ -413,7 +413,7 @@ public class ConfiguratorTest { URI uri = baseServerUri.resolve("/empty"); - try (IBlockheadClient client = new BlockheadClient(uri)) + try (IBlockheadClient client = new XBlockheadClient(uri)) { client.addExtensions("identity"); client.connect(); @@ -428,7 +428,7 @@ public class ConfiguratorTest { URI uri = baseServerUri.resolve("/no-extensions"); - try (IBlockheadClient client = new BlockheadClient(uri)) + try (IBlockheadClient client = new XBlockheadClient(uri)) { client.addExtensions("identity"); client.connect(); @@ -448,7 +448,7 @@ public class ConfiguratorTest { URI uri = baseServerUri.resolve("/capture-request-headers"); - try (IBlockheadClient client = new BlockheadClient(uri)) + try (IBlockheadClient client = new XBlockheadClient(uri)) { client.addHeader("X-Dummy: Bogus\r\n"); client.connect(); @@ -468,7 +468,7 @@ public class ConfiguratorTest URI uri = baseServerUri.resolve("/unique-user-props"); // First request - try (IBlockheadClient client = new BlockheadClient(uri)) + try (IBlockheadClient client = new XBlockheadClient(uri)) { client.connect(); client.sendStandardRequest(); @@ -481,7 +481,7 @@ public class ConfiguratorTest } // Second request - try (IBlockheadClient client = new BlockheadClient(uri)) + try (IBlockheadClient client = new XBlockheadClient(uri)) { client.connect(); client.sendStandardRequest(); @@ -505,7 +505,7 @@ public class ConfiguratorTest URI uri = baseServerUri.resolve("/addr"); // First request - try (IBlockheadClient client = new BlockheadClient(uri)) + try (IBlockheadClient client = new XBlockheadClient(uri)) { client.connect(); client.sendStandardRequest(); @@ -540,7 +540,7 @@ public class ConfiguratorTest URI uri = baseServerUri.resolve("/protocols"); ProtocolsConfigurator.seenProtocols.set(null); - try (IBlockheadClient client = new BlockheadClient(uri)) + try (IBlockheadClient client = new XBlockheadClient(uri)) { client.addHeader("Sec-WebSocket-Protocol: echo\r\n"); client.connect(); @@ -564,7 +564,7 @@ public class ConfiguratorTest URI uri = baseServerUri.resolve("/protocols"); ProtocolsConfigurator.seenProtocols.set(null); - try (IBlockheadClient client = new BlockheadClient(uri)) + try (IBlockheadClient client = new XBlockheadClient(uri)) { client.addHeader("Sec-WebSocket-Protocol: echo, chat, status\r\n"); client.connect(); @@ -588,7 +588,7 @@ public class ConfiguratorTest URI uri = baseServerUri.resolve("/protocols"); ProtocolsConfigurator.seenProtocols.set(null); - try (IBlockheadClient client = new BlockheadClient(uri)) + try (IBlockheadClient client = new XBlockheadClient(uri)) { client.addHeader("sec-websocket-protocol: echo, chat, status\r\n"); client.connect(); @@ -612,7 +612,7 @@ public class ConfiguratorTest URI uri = baseServerUri.resolve("/protocols"); ProtocolsConfigurator.seenProtocols.set(null); - try (IBlockheadClient client = new BlockheadClient(uri)) + try (IBlockheadClient client = new XBlockheadClient(uri)) { client.addHeader("Sec-Websocket-Protocol: echo, chat, status\r\n"); client.connect(); @@ -634,7 +634,7 @@ public class ConfiguratorTest { URI uri = baseServerUri.resolve("/timedecoder"); - try (BlockheadClient client = new BlockheadClient(uri)) + try (XBlockheadClient client = new XBlockheadClient(uri)) { client.addHeader("Sec-Websocket-Protocol: gmt\r\n"); client.connect(); diff --git a/jetty-websocket/pom.xml b/jetty-websocket/pom.xml index f3db3519a5e..d74b303c1ae 100644 --- a/jetty-websocket/pom.xml +++ b/jetty-websocket/pom.xml @@ -19,6 +19,7 @@ websocket-client websocket-server websocket-servlet + websocket-tests javax-websocket-client-impl javax-websocket-server-impl diff --git a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java index b1aa1d46c76..ec4d425050b 100644 --- a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java +++ b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java @@ -45,7 +45,6 @@ import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.api.WebSocketPolicy; import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig; import org.eclipse.jetty.websocket.api.extensions.ExtensionFactory; -import org.eclipse.jetty.websocket.client.io.ConnectionManager; import org.eclipse.jetty.websocket.client.io.UpgradeListener; import org.eclipse.jetty.websocket.client.masks.Masker; import org.eclipse.jetty.websocket.client.masks.RandomMasker; @@ -400,12 +399,6 @@ public class WebSocketClient extends ContainerLifeCycle implements WebSocketCont return httpClient.getByteBufferPool(); } - @Deprecated - public ConnectionManager getConnectionManager() - { - throw new UnsupportedOperationException("ConnectionManager is no longer supported"); - } - public long getConnectTimeout() { return httpClient.getConnectTimeout(); @@ -528,18 +521,6 @@ public class WebSocketClient extends ContainerLifeCycle implements WebSocketCont } } - /** - * Factory method for new ConnectionManager - * - * @return the ConnectionManager instance to use - * @deprecated use HttpClient instead - */ - @Deprecated - protected ConnectionManager newConnectionManager() - { - throw new UnsupportedOperationException("ConnectionManager is no longer supported"); - } - @Override public void onSessionClosed(WebSocketSession session) { diff --git a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/io/ConnectionManager.java b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/io/ConnectionManager.java deleted file mode 100644 index 1a857e65d35..00000000000 --- a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/io/ConnectionManager.java +++ /dev/null @@ -1,70 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd. -// ------------------------------------------------------------------------ -// All rights reserved. This program and the accompanying materials -// are made available under the terms of the Eclipse Public License v1.0 -// and Apache License v2.0 which accompanies this distribution. -// -// The Eclipse Public License is available at -// http://www.eclipse.org/legal/epl-v10.html -// -// The Apache License v2.0 is available at -// http://www.opensource.org/licenses/apache2.0.php -// -// You may elect to redistribute this code under either of these licenses. -// ======================================================================== -// - -package org.eclipse.jetty.websocket.client.io; - -import java.net.InetSocketAddress; -import java.net.URI; -import java.util.Locale; - -import org.eclipse.jetty.client.HttpClient; -import org.eclipse.jetty.util.component.ContainerLifeCycle; -import org.eclipse.jetty.websocket.client.WebSocketClient; - -/** - * Deprecated ConnectionManager - * @deprecated use {@link HttpClient} with WebSocketClient directly - */ -@Deprecated -public class ConnectionManager extends ContainerLifeCycle -{ - public static InetSocketAddress toSocketAddress(URI uri) - { - if (!uri.isAbsolute()) - { - throw new IllegalArgumentException("Cannot get InetSocketAddress of non-absolute URIs"); - } - - int port = uri.getPort(); - String scheme = uri.getScheme().toLowerCase(Locale.ENGLISH); - if ("ws".equals(scheme)) - { - if (port == (-1)) - { - port = 80; - } - } - else if ("wss".equals(scheme)) - { - if (port == (-1)) - { - port = 443; - } - } - else - { - throw new IllegalArgumentException("Only support ws:// and wss:// URIs"); - } - - return new InetSocketAddress(uri.getHost(),port); - } - - public ConnectionManager(WebSocketClient client) - { - } -} diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/BadNetworkTest.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/BadNetworkTest.java index dab0a256579..61d6a18794c 100644 --- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/BadNetworkTest.java +++ b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/BadNetworkTest.java @@ -27,9 +27,9 @@ import java.util.concurrent.TimeUnit; import org.eclipse.jetty.toolchain.test.TestTracker; import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.api.StatusCode; -import org.eclipse.jetty.websocket.common.test.BlockheadServer; import org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection; import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPoolRule; +import org.eclipse.jetty.websocket.common.test.XBlockheadServer; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -46,7 +46,7 @@ public class BadNetworkTest @Rule public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); - private BlockheadServer server; + private XBlockheadServer server; private WebSocketClient client; @Before @@ -60,7 +60,7 @@ public class BadNetworkTest @Before public void startServer() throws Exception { - server = new BlockheadServer(); + server = new XBlockheadServer(); server.start(); } diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/ClientCloseTest.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/ClientCloseTest.java index 76d5336e4df..032eddac3f4 100644 --- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/ClientCloseTest.java +++ b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/ClientCloseTest.java @@ -67,10 +67,10 @@ import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.WebSocketSession; import org.eclipse.jetty.websocket.common.frames.TextFrame; import org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection; -import org.eclipse.jetty.websocket.common.test.BlockheadServer; import org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection; import org.eclipse.jetty.websocket.common.test.IncomingFramesCapture; import org.eclipse.jetty.websocket.common.test.RawFrameBuilder; +import org.eclipse.jetty.websocket.common.test.XBlockheadServer; import org.hamcrest.Matcher; import org.junit.After; import org.junit.Before; @@ -188,7 +188,7 @@ public class ClientCloseTest @Rule public TestTracker tt = new TestTracker(); - private BlockheadServer server; + private XBlockheadServer server; private WebSocketClient client; private void confirmConnection(CloseTrackingSocket clientSocket, Future clientFuture, IBlockheadServerConnection serverConns) throws Exception @@ -301,7 +301,7 @@ public class ClientCloseTest @Before public void startServer() throws Exception { - server = new BlockheadServer(); + server = new XBlockheadServer(); server.start(); } @@ -442,7 +442,7 @@ public class ClientCloseTest bad.putShort((short)StatusCode.NORMAL); bad.put(msg); BufferUtil.flipToFlush(bad,0); - try (StacklessLogging quiet = new StacklessLogging(Parser.class)) + try (StacklessLogging ignored = new StacklessLogging(Parser.class)) { serverConn.write(bad); @@ -480,7 +480,7 @@ public class ClientCloseTest // client confirms connection via echo confirmConnection(clientSocket,clientConnectFuture,serverConn); - try(StacklessLogging scope = new StacklessLogging(CloseTrackingSocket.class)) + try(StacklessLogging ignored = new StacklessLogging(CloseTrackingSocket.class)) { // client sends close frame final String origCloseReason = "Normal Close"; diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/ClientConnectTest.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/ClientConnectTest.java index 35ea903a042..499d4875df2 100644 --- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/ClientConnectTest.java +++ b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/ClientConnectTest.java @@ -41,9 +41,9 @@ import org.eclipse.jetty.toolchain.test.TestTracker; import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.api.UpgradeException; import org.eclipse.jetty.websocket.common.AcceptHash; -import org.eclipse.jetty.websocket.common.test.BlockheadServer; import org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection; import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPoolRule; +import org.eclipse.jetty.websocket.common.test.XBlockheadServer; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -63,7 +63,7 @@ public class ClientConnectTest public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); private final int timeout = 500; - private BlockheadServer server; + private XBlockheadServer server; private WebSocketClient client; @SuppressWarnings("unchecked") @@ -109,7 +109,7 @@ public class ClientConnectTest @Before public void startServer() throws Exception { - server = new BlockheadServer(); + server = new XBlockheadServer(); server.start(); } diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/ConnectionManagerTest.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/ConnectionManagerTest.java deleted file mode 100644 index 8e84e4164f7..00000000000 --- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/ConnectionManagerTest.java +++ /dev/null @@ -1,82 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd. -// ------------------------------------------------------------------------ -// All rights reserved. This program and the accompanying materials -// are made available under the terms of the Eclipse Public License v1.0 -// and Apache License v2.0 which accompanies this distribution. -// -// The Eclipse Public License is available at -// http://www.eclipse.org/legal/epl-v10.html -// -// The Apache License v2.0 is available at -// http://www.opensource.org/licenses/apache2.0.php -// -// You may elect to redistribute this code under either of these licenses. -// ======================================================================== -// - -package org.eclipse.jetty.websocket.client; - -import static org.hamcrest.Matchers.is; - -import java.net.InetSocketAddress; -import java.net.URI; -import java.net.URISyntaxException; - -import org.eclipse.jetty.toolchain.test.TestTracker; -import org.eclipse.jetty.websocket.client.io.ConnectionManager; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; - -public class ConnectionManagerTest -{ - @Rule - public TestTracker tt = new TestTracker(); - - private void assertToSocketAddress(String uriStr, String expectedHost, int expectedPort) throws URISyntaxException - { - URI uri = new URI(uriStr); - - InetSocketAddress addr = ConnectionManager.toSocketAddress(uri); - Assert.assertThat("URI (" + uri + ").host",addr.getHostName(),is(expectedHost)); - Assert.assertThat("URI (" + uri + ").port",addr.getPort(),is(expectedPort)); - } - - @Test - public void testToSocketAddress_AltWsPort() throws Exception - { - assertToSocketAddress("ws://localhost:8099","localhost",8099); - } - - @Test - public void testToSocketAddress_AltWssPort() throws Exception - { - assertToSocketAddress("wss://localhost","localhost",443); - } - - @Test - public void testToSocketAddress_DefaultWsPort() throws Exception - { - assertToSocketAddress("ws://localhost","localhost",80); - } - - @Test - public void testToSocketAddress_DefaultWsPort_Path() throws Exception - { - assertToSocketAddress("ws://localhost/sockets/chat","localhost",80); - } - - @Test - public void testToSocketAddress_DefaultWssPort() throws Exception - { - assertToSocketAddress("wss://localhost:9443","localhost",9443); - } - - @Test - public void testToSocketAddress_DefaultWssPort_Path() throws Exception - { - assertToSocketAddress("wss://localhost/sockets/chat","localhost",443); - } -} diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/CookieTest.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/CookieTest.java index 101bc596392..a075207fffa 100644 --- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/CookieTest.java +++ b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/CookieTest.java @@ -40,8 +40,8 @@ import org.eclipse.jetty.websocket.api.StatusCode; import org.eclipse.jetty.websocket.api.WebSocketAdapter; import org.eclipse.jetty.websocket.api.util.QuoteUtil; import org.eclipse.jetty.websocket.common.frames.TextFrame; -import org.eclipse.jetty.websocket.common.test.BlockheadServer; import org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection; +import org.eclipse.jetty.websocket.common.test.XBlockheadServer; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -85,7 +85,7 @@ public class CookieTest } private WebSocketClient client; - private BlockheadServer server; + private XBlockheadServer server; @Before public void startClient() throws Exception @@ -97,7 +97,7 @@ public class CookieTest @Before public void startServer() throws Exception { - server = new BlockheadServer(); + server = new XBlockheadServer(); server.start(); } diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/ServerReadThread.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/ServerReadThread.java index 5c1be8b229e..956010735ce 100644 --- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/ServerReadThread.java +++ b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/ServerReadThread.java @@ -18,7 +18,7 @@ package org.eclipse.jetty.websocket.client; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.is; import java.io.IOException; import java.nio.ByteBuffer; diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SessionTest.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SessionTest.java index 8cfe115f7ee..227c95daa58 100644 --- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SessionTest.java +++ b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SessionTest.java @@ -31,8 +31,8 @@ import org.eclipse.jetty.websocket.api.BatchMode; import org.eclipse.jetty.websocket.api.RemoteEndpoint; import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.common.WebSocketSession; -import org.eclipse.jetty.websocket.common.test.BlockheadServer; import org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection; +import org.eclipse.jetty.websocket.common.test.XBlockheadServer; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -40,12 +40,12 @@ import org.junit.Test; public class SessionTest { - private BlockheadServer server; + private XBlockheadServer server; @Before public void startServer() throws Exception { - server = new BlockheadServer(); + server = new XBlockheadServer(); server.start(); } diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SlowClientTest.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SlowClientTest.java index 966a5d1d61c..b9c22128caf 100644 --- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SlowClientTest.java +++ b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SlowClientTest.java @@ -18,7 +18,7 @@ package org.eclipse.jetty.websocket.client; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.is; import java.net.URI; import java.util.concurrent.Future; @@ -28,8 +28,8 @@ import org.eclipse.jetty.toolchain.test.TestTracker; import org.eclipse.jetty.toolchain.test.annotation.Slow; import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.api.StatusCode; -import org.eclipse.jetty.websocket.common.test.BlockheadServer; import org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection; +import org.eclipse.jetty.websocket.common.test.XBlockheadServer; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -41,7 +41,7 @@ public class SlowClientTest @Rule public TestTracker tt = new TestTracker(); - private BlockheadServer server; + private XBlockheadServer server; private WebSocketClient client; @Before @@ -55,7 +55,7 @@ public class SlowClientTest @Before public void startServer() throws Exception { - server = new BlockheadServer(); + server = new XBlockheadServer(); server.start(); } diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SlowServerTest.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SlowServerTest.java index f2d76a2de35..737ecc164ae 100644 --- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SlowServerTest.java +++ b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SlowServerTest.java @@ -18,7 +18,7 @@ package org.eclipse.jetty.websocket.client; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.is; import java.net.URI; import java.util.concurrent.Future; @@ -29,8 +29,8 @@ import org.eclipse.jetty.toolchain.test.annotation.Slow; import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.api.StatusCode; import org.eclipse.jetty.websocket.client.masks.ZeroMasker; -import org.eclipse.jetty.websocket.common.test.BlockheadServer; import org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection; +import org.eclipse.jetty.websocket.common.test.XBlockheadServer; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -42,7 +42,7 @@ public class SlowServerTest @Rule public TestTracker tt = new TestTracker(); - private BlockheadServer server; + private XBlockheadServer server; private WebSocketClient client; @Before @@ -56,7 +56,7 @@ public class SlowServerTest @Before public void startServer() throws Exception { - server = new BlockheadServer(); + server = new XBlockheadServer(); server.start(); } diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/TomcatServerQuirksTest.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/TomcatServerQuirksTest.java index 5ae8ade0870..dadb0ae7503 100644 --- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/TomcatServerQuirksTest.java +++ b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/TomcatServerQuirksTest.java @@ -27,8 +27,8 @@ import java.util.concurrent.TimeUnit; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.api.WebSocketAdapter; -import org.eclipse.jetty.websocket.common.test.BlockheadServer; import org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection; +import org.eclipse.jetty.websocket.common.test.XBlockheadServer; import org.junit.Assert; import org.junit.Test; @@ -71,7 +71,7 @@ public class TomcatServerQuirksTest @Test public void testTomcat7_0_32_WithTransferEncoding() throws Exception { - BlockheadServer server = new BlockheadServer(); + XBlockheadServer server = new XBlockheadServer(); WebSocketClient client = new WebSocketClient(); try diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/WebSocketClientTest.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/WebSocketClientTest.java index 3c832f7ae9d..03dc974cd5c 100644 --- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/WebSocketClientTest.java +++ b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/WebSocketClientTest.java @@ -41,8 +41,8 @@ import org.eclipse.jetty.websocket.api.UpgradeRequest; import org.eclipse.jetty.websocket.common.WebSocketSession; import org.eclipse.jetty.websocket.common.frames.TextFrame; import org.eclipse.jetty.websocket.common.io.FutureWriteCallback; -import org.eclipse.jetty.websocket.common.test.BlockheadServer; import org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection; +import org.eclipse.jetty.websocket.common.test.XBlockheadServer; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -52,7 +52,7 @@ import org.junit.runner.RunWith; @RunWith(AdvancedRunner.class) public class WebSocketClientTest { - private BlockheadServer server; + private XBlockheadServer server; private WebSocketClient client; @Before @@ -60,7 +60,7 @@ public class WebSocketClientTest { client = new WebSocketClient(); client.start(); - server = new BlockheadServer(); + server = new XBlockheadServer(); server.start(); } diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/Generator.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/Generator.java index 5964b452213..d8ddaf00c65 100644 --- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/Generator.java +++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/Generator.java @@ -212,15 +212,15 @@ public class Generator public ByteBuffer generateHeaderBytes(Frame frame) { - ByteBuffer buffer = bufferPool.acquire(MAX_HEADER_LENGTH,true); + ByteBuffer buffer = bufferPool.acquire(MAX_HEADER_LENGTH,false); + int p = BufferUtil.flipToFill(buffer); generateHeaderBytes(frame,buffer); + BufferUtil.flipToFlush(buffer,p); return buffer; } public void generateHeaderBytes(Frame frame, ByteBuffer buffer) { - int p = BufferUtil.flipToFill(buffer); - // we need a framing header assertFrameValid(frame); @@ -337,8 +337,6 @@ public class Generator } } } - - BufferUtil.flipToFlush(buffer,p); } /** diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/Parser.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/Parser.java index 6a00b706012..3986222f600 100644 --- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/Parser.java +++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/Parser.java @@ -269,6 +269,8 @@ public class Parser { case START: { + payload = null; + // peek at byte byte b = buffer.get(); boolean fin = ((b & 0x80) != 0); @@ -579,31 +581,22 @@ public class Parser maskProcessor.process(window); - if (window.remaining() == payloadLength) + if (payload == null) { - // We have the whole content, no need to copy. - frame.setPayload(window); - return true; + payload = bufferPool.acquire(payloadLength,false); + BufferUtil.clearToFill(payload); } - else - { - if (payload == null) - { - payload = bufferPool.acquire(payloadLength,false); - BufferUtil.clearToFill(payload); - } - - // Copy the payload. - payload.put(window); + + // Copy the payload. + payload.put(window); - // if the payload is complete - if (payload.position() == payloadLength) - { - BufferUtil.flipToFlush(payload, 0); - frame.setPayload(payload); - // notify that frame is complete - return true; - } + // if the payload is complete + if (payload.position() == payloadLength) + { + BufferUtil.flipToFlush(payload, 0); + frame.setPayload(payload); + // notify that frame is complete + return true; } } // frame not (yet) complete diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSessionFactory.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSessionFactory.java index cff6d58b86b..1bd04d3515b 100644 --- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSessionFactory.java +++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSessionFactory.java @@ -30,18 +30,18 @@ import org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope; public class WebSocketSessionFactory implements SessionFactory { private final WebSocketContainerScope containerScope; - + public WebSocketSessionFactory(WebSocketContainerScope containerScope) { this.containerScope = containerScope; - } - + } + @Override public boolean supports(Object websocket) { return (websocket instanceof WebSocketConnectionListener) || (websocket.getClass().getAnnotation(WebSocket.class) != null); } - + @Override public WebSocketSession createSession(URI requestURI, Object websocket, LogicalConnection connection) { diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/io/AbstractWebSocketConnection.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/io/AbstractWebSocketConnection.java index fb7497e43cb..c84023953fc 100644 --- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/io/AbstractWebSocketConnection.java +++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/io/AbstractWebSocketConnection.java @@ -18,7 +18,6 @@ package org.eclipse.jetty.websocket.common.io; -import java.io.EOFException; import java.io.IOException; import java.net.InetSocketAddress; import java.net.SocketTimeoutException; @@ -171,8 +170,8 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp } private static final Logger LOG = Log.getLogger(AbstractWebSocketConnection.class); - private static final Logger LOG_OPEN = Log.getLogger(AbstractWebSocketConnection.class.getName() + "_OPEN"); - private static final Logger LOG_CLOSE = Log.getLogger(AbstractWebSocketConnection.class.getName() + "_CLOSE"); + private static final Logger LOG_OPEN = Log.getLogger(AbstractWebSocketConnection.class.getName() + ".OPEN"); + private static final Logger LOG_CLOSE = Log.getLogger(AbstractWebSocketConnection.class.getName() + ".CLOSE"); /** * Minimum size of a buffer is the determined to be what would be the maximum framing header size (not including payload) @@ -518,7 +517,7 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp if (filled < 0) { bufferPool.release(networkBuffer); - notifyError(new EOFException("Read EOF")); +// notifyError(new EOFException("Read EOF")); return; } diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/BlockheadClientConstructionTest.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/BlockheadClientConstructionTest.java index 91b57d31906..05380bdabe6 100644 --- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/BlockheadClientConstructionTest.java +++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/BlockheadClientConstructionTest.java @@ -64,7 +64,7 @@ public class BlockheadClientConstructionTest public void testURIs() throws URISyntaxException { @SuppressWarnings("resource") - BlockheadClient client = new BlockheadClient(expectedWsUri); + XBlockheadClient client = new XBlockheadClient(expectedWsUri); Assert.assertThat("Websocket URI",client.getWebsocketURI(),is(expectedWsUri)); Assert.assertThat("Websocket URI",client.getHttpURI(),is(expectedHttpUri)); } diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/EventTracker.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/EventTracker.java index a27278c354e..94ae73112df 100644 --- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/EventTracker.java +++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/EventTracker.java @@ -18,7 +18,7 @@ package org.eclipse.jetty.websocket.common.test; -import static org.eclipse.jetty.websocket.common.test.RegexMatcher.matchesPattern; +import static org.eclipse.jetty.toolchain.test.matchers.RegexMatcher.matchesPattern; import static org.junit.Assert.assertThat; import java.util.Iterator; diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/RegexMatcher.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/RegexMatcher.java deleted file mode 100644 index efd44c876eb..00000000000 --- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/RegexMatcher.java +++ /dev/null @@ -1,66 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd. -// ------------------------------------------------------------------------ -// All rights reserved. This program and the accompanying materials -// are made available under the terms of the Eclipse Public License v1.0 -// and Apache License v2.0 which accompanies this distribution. -// -// The Eclipse Public License is available at -// http://www.eclipse.org/legal/epl-v10.html -// -// The Apache License v2.0 is available at -// http://www.opensource.org/licenses/apache2.0.php -// -// You may elect to redistribute this code under either of these licenses. -// ======================================================================== -// - -package org.eclipse.jetty.websocket.common.test; - -import java.util.regex.Pattern; - -import org.hamcrest.Description; -import org.hamcrest.Factory; -import org.hamcrest.TypeSafeMatcher; - -public class RegexMatcher extends TypeSafeMatcher -{ - private final Pattern pattern; - - public RegexMatcher(String pattern) - { - this(Pattern.compile(pattern)); - } - - public RegexMatcher(Pattern pattern) - { - this.pattern = pattern; - } - - @Override - public void describeTo(Description description) - { - description.appendText("matches regular expression ").appendValue(pattern); - } - - @Override - protected boolean matchesSafely(Object item) - { - if(item == null) return false; - return pattern.matcher(item.toString()).matches(); - } - - @Factory - public static RegexMatcher matchesPattern(Pattern pattern) - { - return new RegexMatcher(pattern); - } - - @Factory - public static RegexMatcher matchesPattern(String pattern) - { - return new RegexMatcher(pattern); - } - -} diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/UnitParser.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/UnitParser.java index 018948b6dfa..f0f625e4b51 100644 --- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/UnitParser.java +++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/UnitParser.java @@ -50,7 +50,7 @@ public class UnitParser extends Parser @Deprecated public void parseQuietly(ByteBuffer buf) { - try (StacklessLogging suppress = new StacklessLogging(Parser.class)) + try (StacklessLogging ignored = new StacklessLogging(Parser.class)) { parse(buf); } diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/BlockheadClient.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/XBlockheadClient.java similarity index 98% rename from jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/BlockheadClient.java rename to jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/XBlockheadClient.java index 7cd5cfb1fdb..c81d503e1ac 100644 --- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/BlockheadClient.java +++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/XBlockheadClient.java @@ -88,7 +88,7 @@ import org.junit.Assert; * with regards to basic IO behavior, a write should work as expected, a read should work as expected, but what byte it sends or reads is not within its * scope. */ -public class BlockheadClient implements OutgoingFrames, ConnectionStateListener, AutoCloseable, IBlockheadClient, Parser.Handler +public class XBlockheadClient implements OutgoingFrames, ConnectionStateListener, AutoCloseable, IBlockheadClient, Parser.Handler { private class FrameReadingThread extends Thread implements Runnable, IncomingFrames { @@ -172,7 +172,7 @@ public class BlockheadClient implements OutgoingFrames, ConnectionStateListener, private static final String REQUEST_HASH_KEY = "dGhlIHNhbXBsZSBub25jZQ=="; private static final int BUFFER_SIZE = 64 * 1024; - private static final Logger LOG = Log.getLogger(BlockheadClient.class); + private static final Logger LOG = Log.getLogger(XBlockheadClient.class); private final URI destHttpURI; private final URI destWebsocketURI; private final ByteBufferPool bufferPool; @@ -201,12 +201,12 @@ public class BlockheadClient implements OutgoingFrames, ConnectionStateListener, private String connectionValue = "Upgrade"; - public BlockheadClient(URI destWebsocketURI) throws URISyntaxException + public XBlockheadClient(URI destWebsocketURI) throws URISyntaxException { this(WebSocketPolicy.newClientPolicy(),destWebsocketURI); } - public BlockheadClient(WebSocketPolicy policy, URI destWebsocketURI) throws URISyntaxException + public XBlockheadClient(WebSocketPolicy policy, URI destWebsocketURI) throws URISyntaxException { Assert.assertThat("Websocket URI scheme",destWebsocketURI.getScheme(),anyOf(is("ws"),is("wss"))); this.destWebsocketURI = destWebsocketURI; diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/BlockheadServer.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/XBlockheadServer.java similarity index 94% rename from jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/BlockheadServer.java rename to jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/XBlockheadServer.java index c29186d58eb..9e6558bcd12 100644 --- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/BlockheadServer.java +++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/XBlockheadServer.java @@ -36,9 +36,9 @@ import org.junit.Assert; *

* This is not meant to be performant or accurate. In fact, having the server misbehave is a useful trait during testing. */ -public class BlockheadServer +public class XBlockheadServer { - private static final Logger LOG = Log.getLogger(BlockheadServer.class); + private static final Logger LOG = Log.getLogger(XBlockheadServer.class); private ServerSocket serverSocket; private URI wsUri; @@ -47,7 +47,7 @@ public class BlockheadServer LOG.debug(".accept()"); assertIsStarted(); Socket socket = serverSocket.accept(); - return new BlockheadServerConnection(socket); + return new XBlockheadServerConnection(socket); } private void assertIsStarted() diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/BlockheadServerConnection.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/XBlockheadServerConnection.java similarity index 98% rename from jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/BlockheadServerConnection.java rename to jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/XBlockheadServerConnection.java index bc455392f77..5a39574f623 100644 --- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/BlockheadServerConnection.java +++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/XBlockheadServerConnection.java @@ -66,9 +66,9 @@ import org.eclipse.jetty.websocket.common.frames.CloseFrame; import org.eclipse.jetty.websocket.common.scopes.SimpleContainerScope; import org.junit.Assert; -public class BlockheadServerConnection implements IncomingFrames, OutgoingFrames, Runnable, IBlockheadServerConnection +public class XBlockheadServerConnection implements IncomingFrames, OutgoingFrames, Runnable, IBlockheadServerConnection { - private static final Logger LOG = Log.getLogger(BlockheadServerConnection.class); + private static final Logger LOG = Log.getLogger(XBlockheadServerConnection.class); private final int BUFFER_SIZE = 8192; private final Socket socket; @@ -91,7 +91,7 @@ public class BlockheadServerConnection implements IncomingFrames, OutgoingFrames private OutgoingFrames outgoing = this; private ExtensionStack extensionStack; - public BlockheadServerConnection(Socket socket) + public XBlockheadServerConnection(Socket socket) { this.socket = socket; this.incomingFrames = new IncomingFramesCapture(); diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/Fuzzer.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/XFuzzer.java similarity index 97% rename from jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/Fuzzer.java rename to jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/XFuzzer.java index 5579b538e3f..2e4d7405f51 100644 --- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/Fuzzer.java +++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/XFuzzer.java @@ -45,7 +45,7 @@ import org.junit.Assert; /** * Fuzzing utility for the AB tests. */ -public class Fuzzer implements AutoCloseable +public class XFuzzer implements AutoCloseable { public static enum CloseState { @@ -72,19 +72,19 @@ public class Fuzzer implements AutoCloseable private static final int KBYTE = 1024; private static final int MBYTE = KBYTE * KBYTE; - private static final Logger LOG = Log.getLogger(Fuzzer.class); + private static final Logger LOG = Log.getLogger(XFuzzer.class); // Client side framing mask protected static final byte[] MASK = { 0x11, 0x22, 0x33, 0x44 }; - private final BlockheadClient client; + private final XBlockheadClient client; private final Generator generator; private final String testname; private SendMode sendMode = SendMode.BULK; private int slowSendSegmentSize = 5; - public Fuzzer(Fuzzed testcase) throws Exception + public XFuzzer(Fuzzed testcase) throws Exception { WebSocketPolicy policy = WebSocketPolicy.newClientPolicy(); @@ -94,7 +94,7 @@ public class Fuzzer implements AutoCloseable policy.setMaxBinaryMessageSize(bigMessageSize); policy.setIdleTimeout(5000); - this.client = new BlockheadClient(policy,testcase.getServerURI()); + this.client = new XBlockheadClient(policy,testcase.getServerURI()); this.client.setTimeout(2,TimeUnit.SECONDS); this.generator = testcase.getLaxGenerator(); this.testname = testcase.getTestMethodName(); diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/AnnotatedMaxMessageSizeTest.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/AnnotatedMaxMessageSizeTest.java index 5fb63df837d..e75e60b3354 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/AnnotatedMaxMessageSizeTest.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/AnnotatedMaxMessageSizeTest.java @@ -37,7 +37,7 @@ import org.eclipse.jetty.websocket.common.OpCode; import org.eclipse.jetty.websocket.common.Parser; import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame; -import org.eclipse.jetty.websocket.common.test.BlockheadClient; +import org.eclipse.jetty.websocket.common.test.XBlockheadClient; import org.eclipse.jetty.websocket.server.examples.echo.BigEchoSocket; import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; import org.junit.AfterClass; @@ -92,7 +92,7 @@ public class AnnotatedMaxMessageSizeTest @Test public void testEchoGood() throws IOException, Exception { - BlockheadClient client = new BlockheadClient(serverUri); + XBlockheadClient client = new XBlockheadClient(serverUri); try { client.setProtocols("echo"); @@ -118,8 +118,8 @@ public class AnnotatedMaxMessageSizeTest @Test(timeout=8000) public void testEchoTooBig() throws IOException, Exception { - BlockheadClient client = new BlockheadClient(serverUri); - try(StacklessLogging logging = new StacklessLogging(Parser.class)) + XBlockheadClient client = new XBlockheadClient(serverUri); + try(StacklessLogging ignored = new StacklessLogging(Parser.class)) { client.setProtocols("echo"); client.connect(); diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ChromeTest.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ChromeTest.java index 0a44f6463cc..cd597e427f3 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ChromeTest.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ChromeTest.java @@ -26,7 +26,7 @@ import java.util.concurrent.TimeUnit; import org.eclipse.jetty.toolchain.test.EventQueue; import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame; -import org.eclipse.jetty.websocket.common.test.BlockheadClient; +import org.eclipse.jetty.websocket.common.test.XBlockheadClient; import org.eclipse.jetty.websocket.common.test.HttpResponse; import org.eclipse.jetty.websocket.server.examples.MyEchoServlet; import org.junit.AfterClass; @@ -58,7 +58,7 @@ public class ChromeTest Assume.assumeTrue("Server has x-webkit-deflate-frame registered", server.getWebSocketServletFactory().getExtensionFactory().isAvailable("x-webkit-deflate-frame")); - BlockheadClient client = new BlockheadClient(server.getServerUri()); + XBlockheadClient client = new XBlockheadClient(server.getServerUri()); try { client.addExtensions("x-webkit-deflate-frame"); diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/DecoratorsLegacyTest.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/DecoratorsLegacyTest.java index c3b65de9a70..5c2bfce2190 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/DecoratorsLegacyTest.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/DecoratorsLegacyTest.java @@ -35,7 +35,7 @@ import org.eclipse.jetty.util.Decorator; import org.eclipse.jetty.websocket.api.WebSocketAdapter; import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame; -import org.eclipse.jetty.websocket.common.test.BlockheadClient; +import org.eclipse.jetty.websocket.common.test.XBlockheadClient; import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest; import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse; import org.eclipse.jetty.websocket.servlet.WebSocketCreator; @@ -154,7 +154,7 @@ public class DecoratorsLegacyTest @Test public void testAccessRequestCookies() throws Exception { - BlockheadClient client = new BlockheadClient(server.getServerUri()); + XBlockheadClient client = new XBlockheadClient(server.getServerUri()); client.setTimeout(1,TimeUnit.SECONDS); try diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/DecoratorsTest.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/DecoratorsTest.java index 3a353d787b7..6a31055c3b0 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/DecoratorsTest.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/DecoratorsTest.java @@ -35,7 +35,7 @@ import org.eclipse.jetty.util.Decorator; import org.eclipse.jetty.websocket.api.WebSocketAdapter; import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame; -import org.eclipse.jetty.websocket.common.test.BlockheadClient; +import org.eclipse.jetty.websocket.common.test.XBlockheadClient; import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest; import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse; import org.eclipse.jetty.websocket.servlet.WebSocketCreator; @@ -152,7 +152,7 @@ public class DecoratorsTest @Test public void testAccessRequestCookies() throws Exception { - BlockheadClient client = new BlockheadClient(server.getServerUri()); + XBlockheadClient client = new XBlockheadClient(server.getServerUri()); client.setTimeout(1,TimeUnit.SECONDS); try diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/FirefoxTest.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/FirefoxTest.java index 6b41b724a6e..d498b94807f 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/FirefoxTest.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/FirefoxTest.java @@ -25,7 +25,7 @@ import java.util.concurrent.TimeUnit; import org.eclipse.jetty.toolchain.test.EventQueue; import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame; -import org.eclipse.jetty.websocket.common.test.BlockheadClient; +import org.eclipse.jetty.websocket.common.test.XBlockheadClient; import org.eclipse.jetty.websocket.common.test.IBlockheadClient; import org.eclipse.jetty.websocket.server.examples.MyEchoServlet; import org.junit.AfterClass; @@ -53,7 +53,7 @@ public class FirefoxTest @Test public void testConnectionKeepAlive() throws Exception { - try (IBlockheadClient client = new BlockheadClient(server.getServerUri())) + try (IBlockheadClient client = new XBlockheadClient(server.getServerUri())) { // Odd Connection Header value seen in Firefox client.setConnectionValue("keep-alive, Upgrade"); diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/FragmentExtensionTest.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/FragmentExtensionTest.java index 3da69abe4c4..9ed72a8b047 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/FragmentExtensionTest.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/FragmentExtensionTest.java @@ -26,7 +26,7 @@ import java.util.concurrent.TimeUnit; import org.eclipse.jetty.toolchain.test.EventQueue; import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame; -import org.eclipse.jetty.websocket.common.test.BlockheadClient; +import org.eclipse.jetty.websocket.common.test.XBlockheadClient; import org.eclipse.jetty.websocket.common.test.HttpResponse; import org.eclipse.jetty.websocket.server.helper.EchoServlet; import org.junit.AfterClass; @@ -70,7 +70,7 @@ public class FragmentExtensionTest { int fragSize = 4; - BlockheadClient client = new BlockheadClient(server.getServerUri()); + XBlockheadClient client = new XBlockheadClient(server.getServerUri()); client.clearExtensions(); client.addExtensions("fragment;maxLength=" + fragSize); client.setProtocols("onConnect"); diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/IdentityExtensionTest.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/IdentityExtensionTest.java index 739a0e5e92b..07eedbf9eb7 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/IdentityExtensionTest.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/IdentityExtensionTest.java @@ -26,7 +26,7 @@ import java.util.concurrent.TimeUnit; import org.eclipse.jetty.toolchain.test.EventQueue; import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame; -import org.eclipse.jetty.websocket.common.test.BlockheadClient; +import org.eclipse.jetty.websocket.common.test.XBlockheadClient; import org.eclipse.jetty.websocket.common.test.HttpResponse; import org.eclipse.jetty.websocket.server.helper.EchoServlet; import org.junit.AfterClass; @@ -54,7 +54,7 @@ public class IdentityExtensionTest @Test(timeout = 10000) public void testIdentityExtension() throws Exception { - BlockheadClient client = new BlockheadClient(server.getServerUri()); + XBlockheadClient client = new XBlockheadClient(server.getServerUri()); client.clearExtensions(); client.addExtensions("identity;param=0"); client.addExtensions("identity;param=1, identity ; param = '2' ; other = ' some = value '"); diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/IdleTimeoutTest.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/IdleTimeoutTest.java index d5b0362eb06..68d2c0884cf 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/IdleTimeoutTest.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/IdleTimeoutTest.java @@ -30,7 +30,7 @@ import org.eclipse.jetty.websocket.common.CloseInfo; import org.eclipse.jetty.websocket.common.OpCode; import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame; -import org.eclipse.jetty.websocket.common.test.BlockheadClient; +import org.eclipse.jetty.websocket.common.test.XBlockheadClient; import org.eclipse.jetty.websocket.server.helper.RFCSocket; import org.eclipse.jetty.websocket.servlet.WebSocketServlet; import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; @@ -78,7 +78,7 @@ public class IdleTimeoutTest @Test public void testIdleTimeout() throws Exception { - BlockheadClient client = new BlockheadClient(server.getServerUri()); + XBlockheadClient client = new XBlockheadClient(server.getServerUri()); client.setProtocols("onConnect"); client.setTimeout(2500,TimeUnit.MILLISECONDS); try diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ManyConnectionsCleanupTest.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ManyConnectionsCleanupTest.java index 2492755a685..eaf94b00384 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ManyConnectionsCleanupTest.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ManyConnectionsCleanupTest.java @@ -41,7 +41,7 @@ import org.eclipse.jetty.websocket.common.OpCode; import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.WebSocketSession; import org.eclipse.jetty.websocket.common.frames.TextFrame; -import org.eclipse.jetty.websocket.common.test.BlockheadClient; +import org.eclipse.jetty.websocket.common.test.XBlockheadClient; import org.eclipse.jetty.websocket.common.test.IBlockheadClient; import org.eclipse.jetty.websocket.server.helper.RFCSocket; import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest; @@ -261,7 +261,7 @@ public class ManyConnectionsCleanupTest sessLog.setLevel(oldLevel); - try (IBlockheadClient client = new BlockheadClient(server.getServerUri())) + try (IBlockheadClient client = new XBlockheadClient(server.getServerUri())) { client.setProtocols("container"); client.setTimeout(1,TimeUnit.SECONDS); @@ -301,11 +301,11 @@ public class ManyConnectionsCleanupTest private void fastClose() throws Exception { - try (IBlockheadClient client = new BlockheadClient(server.getServerUri())) + try (IBlockheadClient client = new XBlockheadClient(server.getServerUri())) { client.setProtocols("fastclose"); client.setTimeout(1,TimeUnit.SECONDS); - try (StacklessLogging scope = new StacklessLogging(WebSocketSession.class)) + try (StacklessLogging ignored = new StacklessLogging(WebSocketSession.class)) { client.connect(); client.sendStandardRequest(); @@ -328,11 +328,11 @@ public class ManyConnectionsCleanupTest private void fastFail() throws Exception { - try (IBlockheadClient client = new BlockheadClient(server.getServerUri())) + try (IBlockheadClient client = new XBlockheadClient(server.getServerUri())) { client.setProtocols("fastfail"); client.setTimeout(1,TimeUnit.SECONDS); - try (StacklessLogging scope = new StacklessLogging(WebSocketSession.class)) + try (StacklessLogging ignored = new StacklessLogging(WebSocketSession.class)) { client.connect(); client.sendStandardRequest(); @@ -353,11 +353,11 @@ public class ManyConnectionsCleanupTest private void dropConnection() throws Exception { - try (IBlockheadClient client = new BlockheadClient(server.getServerUri())) + try (IBlockheadClient client = new XBlockheadClient(server.getServerUri())) { client.setProtocols("container"); client.setTimeout(1,TimeUnit.SECONDS); - try (StacklessLogging scope = new StacklessLogging(WebSocketSession.class)) + try (StacklessLogging ignored = new StacklessLogging(WebSocketSession.class)) { client.connect(); client.sendStandardRequest(); diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/RequestHeadersTest.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/RequestHeadersTest.java index c0eadaec199..bcff8e4ce4d 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/RequestHeadersTest.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/RequestHeadersTest.java @@ -28,8 +28,7 @@ import java.util.concurrent.TimeUnit; import org.eclipse.jetty.websocket.api.UpgradeRequest; import org.eclipse.jetty.websocket.api.UpgradeResponse; -import org.eclipse.jetty.websocket.common.UpgradeRequestAdapter; -import org.eclipse.jetty.websocket.common.test.BlockheadClient; +import org.eclipse.jetty.websocket.common.test.XBlockheadClient; import org.eclipse.jetty.websocket.server.helper.EchoSocket; import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest; import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse; @@ -109,7 +108,7 @@ public class RequestHeadersTest @Test public void testAccessRequestCookies() throws Exception { - BlockheadClient client = new BlockheadClient(server.getServerUri()); + XBlockheadClient client = new XBlockheadClient(server.getServerUri()); client.setTimeout(1,TimeUnit.SECONDS); try diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/SubProtocolTest.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/SubProtocolTest.java index aa2b2834a83..db0f2306ef8 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/SubProtocolTest.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/SubProtocolTest.java @@ -30,7 +30,7 @@ import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage; import org.eclipse.jetty.websocket.api.annotations.WebSocket; import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame; -import org.eclipse.jetty.websocket.common.test.BlockheadClient; +import org.eclipse.jetty.websocket.common.test.XBlockheadClient; import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest; import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse; import org.eclipse.jetty.websocket.servlet.WebSocketCreator; @@ -119,7 +119,7 @@ public class SubProtocolTest private void testSubProtocol(String requestProtocols, String acceptedSubProtocols) throws Exception { - try (BlockheadClient client = new BlockheadClient(server.getServerUri())) + try (XBlockheadClient client = new XBlockheadClient(server.getServerUri())) { client.setTimeout(1, TimeUnit.SECONDS); diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/SuspendResumeTest.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/SuspendResumeTest.java index a707bc58a45..5464d9d2224 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/SuspendResumeTest.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/SuspendResumeTest.java @@ -32,7 +32,7 @@ import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage; import org.eclipse.jetty.websocket.api.annotations.WebSocket; import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame; -import org.eclipse.jetty.websocket.common.test.BlockheadClient; +import org.eclipse.jetty.websocket.common.test.XBlockheadClient; import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest; import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse; import org.eclipse.jetty.websocket.servlet.WebSocketCreator; @@ -117,7 +117,7 @@ public class SuspendResumeTest @Test public void testSuspendResume() throws Exception { - try (BlockheadClient client = new BlockheadClient(server.getServerUri())) + try (XBlockheadClient client = new XBlockheadClient(server.getServerUri())) { client.setTimeout(1, TimeUnit.SECONDS); diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/TooFastClientTest.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/TooFastClientTest.java index 8337ddcc1c9..f266acc586f 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/TooFastClientTest.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/TooFastClientTest.java @@ -33,7 +33,7 @@ import org.eclipse.jetty.websocket.api.WebSocketPolicy; import org.eclipse.jetty.websocket.common.Generator; import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame; -import org.eclipse.jetty.websocket.common.test.BlockheadClient; +import org.eclipse.jetty.websocket.common.test.XBlockheadClient; import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPoolRule; import org.eclipse.jetty.websocket.server.examples.MyEchoServlet; import org.junit.AfterClass; @@ -69,7 +69,7 @@ public class TooFastClientTest @Ignore("RELEASE") public void testUpgradeWithSmallFrames() throws Exception { - BlockheadClient client = new BlockheadClient(server.getServerUri()); + XBlockheadClient client = new XBlockheadClient(server.getServerUri()); try { client.connect(); @@ -132,7 +132,7 @@ public class TooFastClientTest @Ignore("RELEASE") public void testUpgradeWithLargeFrame() throws Exception { - BlockheadClient client = new BlockheadClient(server.getServerUri()); + XBlockheadClient client = new XBlockheadClient(server.getServerUri()); try { client.connect(); diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketCloseTest.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketCloseTest.java index b73fbb580e8..fae20167eb6 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketCloseTest.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketCloseTest.java @@ -40,7 +40,7 @@ import org.eclipse.jetty.websocket.common.OpCode; import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.WebSocketSession; import org.eclipse.jetty.websocket.common.frames.TextFrame; -import org.eclipse.jetty.websocket.common.test.BlockheadClient; +import org.eclipse.jetty.websocket.common.test.XBlockheadClient; import org.eclipse.jetty.websocket.common.test.IBlockheadClient; import org.eclipse.jetty.websocket.server.helper.RFCSocket; import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest; @@ -220,7 +220,7 @@ public class WebSocketCloseTest @Test public void testFastClose() throws Exception { - try (IBlockheadClient client = new BlockheadClient(server.getServerUri())) + try (IBlockheadClient client = new XBlockheadClient(server.getServerUri())) { client.setProtocols("fastclose"); client.setTimeout(5,TimeUnit.SECONDS); @@ -253,11 +253,11 @@ public class WebSocketCloseTest @Test public void testFastFail() throws Exception { - try (IBlockheadClient client = new BlockheadClient(server.getServerUri())) + try (IBlockheadClient client = new XBlockheadClient(server.getServerUri())) { client.setProtocols("fastfail"); client.setTimeout(1,TimeUnit.SECONDS); - try (StacklessLogging scope = new StacklessLogging(CloseServlet.class)) + try (StacklessLogging ignored = new StacklessLogging(CloseServlet.class)) { client.connect(); client.sendStandardRequest(); @@ -292,7 +292,7 @@ public class WebSocketCloseTest fastClose(); dropConnection(); - try (IBlockheadClient client = new BlockheadClient(server.getServerUri())) + try (IBlockheadClient client = new XBlockheadClient(server.getServerUri())) { client.setProtocols("container"); client.setTimeout(1,TimeUnit.SECONDS); @@ -327,11 +327,11 @@ public class WebSocketCloseTest @SuppressWarnings("Duplicates") private void fastClose() throws Exception { - try (IBlockheadClient client = new BlockheadClient(server.getServerUri())) + try (IBlockheadClient client = new XBlockheadClient(server.getServerUri())) { client.setProtocols("fastclose"); client.setTimeout(1,TimeUnit.SECONDS); - try (StacklessLogging scope = new StacklessLogging(WebSocketSession.class)) + try (StacklessLogging ignored = new StacklessLogging(WebSocketSession.class)) { client.connect(); client.sendStandardRequest(); @@ -354,11 +354,11 @@ public class WebSocketCloseTest private void fastFail() throws Exception { - try (IBlockheadClient client = new BlockheadClient(server.getServerUri())) + try (IBlockheadClient client = new XBlockheadClient(server.getServerUri())) { client.setProtocols("fastfail"); client.setTimeout(1,TimeUnit.SECONDS); - try (StacklessLogging scope = new StacklessLogging(WebSocketSession.class)) + try (StacklessLogging ignored = new StacklessLogging(WebSocketSession.class)) { client.connect(); client.sendStandardRequest(); @@ -380,11 +380,11 @@ public class WebSocketCloseTest @SuppressWarnings("Duplicates") private void dropConnection() throws Exception { - try (IBlockheadClient client = new BlockheadClient(server.getServerUri())) + try (IBlockheadClient client = new XBlockheadClient(server.getServerUri())) { client.setProtocols("container"); client.setTimeout(1,TimeUnit.SECONDS); - try (StacklessLogging scope = new StacklessLogging(WebSocketSession.class)) + try (StacklessLogging ignored = new StacklessLogging(WebSocketSession.class)) { client.connect(); client.sendStandardRequest(); diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketInvalidVersionTest.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketInvalidVersionTest.java index 8594df852a0..a0e0091e69b 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketInvalidVersionTest.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketInvalidVersionTest.java @@ -21,7 +21,7 @@ package org.eclipse.jetty.websocket.server; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.is; -import org.eclipse.jetty.websocket.common.test.BlockheadClient; +import org.eclipse.jetty.websocket.common.test.XBlockheadClient; import org.eclipse.jetty.websocket.common.test.HttpResponse; import org.eclipse.jetty.websocket.server.examples.MyEchoServlet; import org.junit.AfterClass; @@ -54,7 +54,7 @@ public class WebSocketInvalidVersionTest public void testRequestVersion29() throws Exception { @SuppressWarnings("resource") - BlockheadClient client = new BlockheadClient(server.getServerUri()); + XBlockheadClient client = new XBlockheadClient(server.getServerUri()); client.setVersion(29); // intentionally bad version try { diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketServerSessionTest.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketServerSessionTest.java index 34f2f8cfe41..b34894bf15d 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketServerSessionTest.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketServerSessionTest.java @@ -27,7 +27,7 @@ import org.eclipse.jetty.toolchain.test.AdvancedRunner; import org.eclipse.jetty.toolchain.test.EventQueue; import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame; -import org.eclipse.jetty.websocket.common.test.BlockheadClient; +import org.eclipse.jetty.websocket.common.test.XBlockheadClient; import org.eclipse.jetty.websocket.common.test.IBlockheadClient; import org.eclipse.jetty.websocket.server.helper.SessionServlet; import org.junit.AfterClass; @@ -61,7 +61,7 @@ public class WebSocketServerSessionTest public void testDisconnect() throws Exception { URI uri = server.getServerUri().resolve("/test/disconnect"); - try (IBlockheadClient client = new BlockheadClient(uri)) + try (IBlockheadClient client = new XBlockheadClient(uri)) { client.connect(); client.sendStandardRequest(); @@ -77,7 +77,7 @@ public class WebSocketServerSessionTest public void testUpgradeRequestResponse() throws Exception { URI uri = server.getServerUri().resolve("/test?snack=cashews&amount=handful&brand=off"); - try (IBlockheadClient client = new BlockheadClient(uri)) + try (IBlockheadClient client = new XBlockheadClient(uri)) { client.connect(); client.sendStandardRequest(); diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketServletRFCTest.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketServletRFCTest.java index e7ab4c0addd..beb4bc664f4 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketServletRFCTest.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketServletRFCTest.java @@ -40,7 +40,7 @@ import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.frames.BinaryFrame; import org.eclipse.jetty.websocket.common.frames.ContinuationFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame; -import org.eclipse.jetty.websocket.common.test.BlockheadClient; +import org.eclipse.jetty.websocket.common.test.XBlockheadClient; import org.eclipse.jetty.websocket.common.test.UnitGenerator; import org.eclipse.jetty.websocket.common.util.Hex; import org.eclipse.jetty.websocket.server.helper.RFCServlet; @@ -93,7 +93,7 @@ public class WebSocketServletRFCTest @Test public void testBinaryAggregate() throws Exception { - BlockheadClient client = new BlockheadClient(server.getServerUri()); + XBlockheadClient client = new XBlockheadClient(server.getServerUri()); try { client.connect(); @@ -179,7 +179,7 @@ public class WebSocketServletRFCTest @Test public void testEcho() throws Exception { - BlockheadClient client = new BlockheadClient(server.getServerUri()); + XBlockheadClient client = new XBlockheadClient(server.getServerUri()); try { client.connect(); @@ -209,7 +209,7 @@ public class WebSocketServletRFCTest @Test public void testInternalError() throws Exception { - try (BlockheadClient client = new BlockheadClient(server.getServerUri()); + try (XBlockheadClient client = new XBlockheadClient(server.getServerUri()); StacklessLogging stackless=new StacklessLogging(RFCSocket.class)) { client.connect(); @@ -236,7 +236,7 @@ public class WebSocketServletRFCTest @Test public void testLowercaseUpgrade() throws Exception { - BlockheadClient client = new BlockheadClient(server.getServerUri()); + XBlockheadClient client = new XBlockheadClient(server.getServerUri()); try { client.connect(); @@ -274,7 +274,7 @@ public class WebSocketServletRFCTest public void testTextNotUTF8() throws Exception { try (StacklessLogging stackless=new StacklessLogging(Parser.class); - BlockheadClient client = new BlockheadClient(server.getServerUri())) + XBlockheadClient client = new XBlockheadClient(server.getServerUri())) { client.setProtocols("other"); client.connect(); @@ -307,7 +307,7 @@ public class WebSocketServletRFCTest @Test public void testUppercaseUpgrade() throws Exception { - BlockheadClient client = new BlockheadClient(server.getServerUri()); + XBlockheadClient client = new XBlockheadClient(server.getServerUri()); try { client.connect(); diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketUpgradeFilterTest.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketUpgradeFilterTest.java index bfb82a1a2bc..f92bdcc9ed1 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketUpgradeFilterTest.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketUpgradeFilterTest.java @@ -41,7 +41,7 @@ import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.webapp.WebAppContext; import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame; -import org.eclipse.jetty.websocket.common.test.BlockheadClient; +import org.eclipse.jetty.websocket.common.test.XBlockheadClient; import org.eclipse.jetty.websocket.servlet.WebSocketCreator; import org.junit.Test; import org.junit.runner.RunWith; @@ -304,7 +304,7 @@ public class WebSocketUpgradeFilterTest { URI destUri = serverUri.resolve("/info/"); - try (BlockheadClient client = new BlockheadClient(destUri)) + try (XBlockheadClient client = new XBlockheadClient(destUri)) { client.connect(); client.sendStandardRequest(); @@ -326,7 +326,7 @@ public class WebSocketUpgradeFilterTest { URI destUri = serverUri.resolve("/info/"); - try (BlockheadClient client = new BlockheadClient(destUri)) + try (XBlockheadClient client = new XBlockheadClient(destUri)) { client.connect(); client.sendStandardRequest(); @@ -345,7 +345,7 @@ public class WebSocketUpgradeFilterTest server.getHandler().stop(); server.getHandler().start(); - try (BlockheadClient client = new BlockheadClient(destUri)) + try (XBlockheadClient client = new XBlockheadClient(destUri)) { client.connect(); client.sendStandardRequest(); diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase6_GoodUTF.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase6_GoodUTF.java deleted file mode 100644 index 1d11260af21..00000000000 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase6_GoodUTF.java +++ /dev/null @@ -1,150 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd. -// ------------------------------------------------------------------------ -// All rights reserved. This program and the accompanying materials -// are made available under the terms of the Eclipse Public License v1.0 -// and Apache License v2.0 which accompanies this distribution. -// -// The Eclipse Public License is available at -// http://www.eclipse.org/legal/epl-v10.html -// -// The Apache License v2.0 is available at -// http://www.opensource.org/licenses/apache2.0.php -// -// You may elect to redistribute this code under either of these licenses. -// ======================================================================== -// - -package org.eclipse.jetty.websocket.server.ab; - -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.Logger; -import org.eclipse.jetty.websocket.api.StatusCode; -import org.eclipse.jetty.websocket.common.CloseInfo; -import org.eclipse.jetty.websocket.common.WebSocketFrame; -import org.eclipse.jetty.websocket.common.frames.TextFrame; -import org.eclipse.jetty.websocket.common.test.Fuzzer; -import org.eclipse.jetty.websocket.common.util.Hex; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; - -/** - * Tests of Known Good UTF8 sequences. - *

- * Should be preserved / echoed back, with normal close code. - */ -@RunWith(Parameterized.class) -public class TestABCase6_GoodUTF extends AbstractABCase -{ - private static final Logger LOG = Log.getLogger(TestABCase6_GoodUTF.class); - - @Parameters(name = "{0} - {1}") - public static Collection data() - { - // The various Good UTF8 sequences as a String (hex form) - List data = new ArrayList<>(); - - // @formatter:off - // - combination of simple 1 byte characters and unicode code points - data.add(new String[]{ "6.2.1", "48656C6C6F2DC2B540C39FC3B6C3A4C3BCC3A0C3A12D5554462D382121" }); - // - simple valid UTF8 sequence - data.add(new String[]{ "6.5.1", "CEBAE1BDB9CF83CEBCCEB5" }); - // - multi-byte code points - data.add(new String[]{ "6.6.11", "CEBAE1BDB9CF83CEBCCEB5" }); - data.add(new String[]{ "6.6.2", "CEBA" }); - data.add(new String[]{ "6.6.5", "CEBAE1BDB9" }); - data.add(new String[]{ "6.6.7", "CEBAE1BDB9CF83" }); - data.add(new String[]{ "6.6.9", "CEBAE1BDB9CF83CEBC" }); - // - first possible sequence of a certain length (1 code point) - data.add(new String[]{ "6.7.1", "00" }); - data.add(new String[]{ "6.7.2", "C280" }); - data.add(new String[]{ "6.7.3", "E0A080" }); - data.add(new String[]{ "6.7.4", "F0908080" }); - // - last possible sequence of a certain length (1 code point) - data.add(new String[]{ "6.9.1", "7F" }); - data.add(new String[]{ "6.9.2", "DFBF" }); - data.add(new String[]{ "6.9.3", "EFBFBF" }); - data.add(new String[]{ "6.9.4", "F48FBFBF" }); - // - other boundary conditions - data.add(new String[]{ "6.11.1", "ED9FBF" }); - data.add(new String[]{ "6.11.2", "EE8080" }); - data.add(new String[]{ "6.11.3", "EFBFBD" }); - data.add(new String[]{ "6.11.4", "F48FBFBF" }); - // - non character code points - data.add(new String[]{ "6.22.1", "EFBFBE" }); - data.add(new String[]{ "6.22.2", "EFBFBF" }); - data.add(new String[]{ "6.22.3", "F09FBFBE" }); - data.add(new String[]{ "6.22.4", "F09FBFBF" }); - data.add(new String[]{ "6.22.5", "F0AFBFBE" }); - data.add(new String[]{ "6.22.6", "F0AFBFBF" }); - data.add(new String[]{ "6.22.7", "F0BFBFBE" }); - data.add(new String[]{ "6.22.8", "F0BFBFBF" }); - data.add(new String[]{ "6.22.9", "F18FBFBE" }); - data.add(new String[]{ "6.22.10", "F18FBFBF" }); - data.add(new String[]{ "6.22.11", "F19FBFBE" }); - data.add(new String[]{ "6.22.12", "F19FBFBF" }); - data.add(new String[]{ "6.22.13", "F1AFBFBE" }); - data.add(new String[]{ "6.22.14", "F1AFBFBF" }); - data.add(new String[]{ "6.22.15", "F1BFBFBE" }); - data.add(new String[]{ "6.22.16", "F1BFBFBF" }); - data.add(new String[]{ "6.22.17", "F28FBFBE" }); - data.add(new String[]{ "6.22.18", "F28FBFBF" }); - data.add(new String[]{ "6.22.19", "F29FBFBE" }); - data.add(new String[]{ "6.22.20", "F29FBFBF" }); - data.add(new String[]{ "6.22.21", "F2AFBFBE" }); - data.add(new String[]{ "6.22.22", "F2AFBFBF" }); - data.add(new String[]{ "6.22.23", "F2BFBFBE" }); - data.add(new String[]{ "6.22.24", "F2BFBFBF" }); - data.add(new String[]{ "6.22.25", "F38FBFBE" }); - data.add(new String[]{ "6.22.26", "F38FBFBF" }); - data.add(new String[]{ "6.22.27", "F39FBFBE" }); - data.add(new String[]{ "6.22.28", "F39FBFBF" }); - data.add(new String[]{ "6.22.29", "F3AFBFBE" }); - data.add(new String[]{ "6.22.30", "F3AFBFBF" }); - data.add(new String[]{ "6.22.31", "F3BFBFBE" }); - data.add(new String[]{ "6.22.32", "F3BFBFBF" }); - data.add(new String[]{ "6.22.33", "F48FBFBE" }); - data.add(new String[]{ "6.22.34", "F48FBFBF" }); - // - unicode replacement character - data.add(new String[]{ "6.23.1", "EFBFBD" }); - // @formatter:on - - return data; - } - - private final ByteBuffer msg; - - public TestABCase6_GoodUTF(String testId, String hexMsg) - { - LOG.debug("Test ID: {}",testId); - this.msg = Hex.asByteBuffer(hexMsg); - } - - @Test - public void assertEchoTextMessage() throws Exception - { - List send = new ArrayList<>(); - send.add(new TextFrame().setPayload(msg)); - send.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - List expect = new ArrayList<>(); - expect.add(new TextFrame().setPayload(clone(msg))); - expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this)) - { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); - } - } -} diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/misbehaving/MisbehavingClassTest.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/misbehaving/MisbehavingClassTest.java index 43c3a6356d0..d822e279975 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/misbehaving/MisbehavingClassTest.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/misbehaving/MisbehavingClassTest.java @@ -30,7 +30,7 @@ import org.eclipse.jetty.websocket.api.StatusCode; import org.eclipse.jetty.websocket.common.CloseInfo; import org.eclipse.jetty.websocket.common.OpCode; import org.eclipse.jetty.websocket.common.WebSocketFrame; -import org.eclipse.jetty.websocket.common.test.BlockheadClient; +import org.eclipse.jetty.websocket.common.test.XBlockheadClient; import org.eclipse.jetty.websocket.common.test.IBlockheadClient; import org.eclipse.jetty.websocket.server.SimpleServletServer; import org.junit.AfterClass; @@ -63,8 +63,8 @@ public class MisbehavingClassTest @Test public void testListenerRuntimeOnConnect() throws Exception { - try (IBlockheadClient client = new BlockheadClient(server.getServerUri()); - StacklessLogging scope = new StacklessLogging(ListenerRuntimeOnConnectSocket.class)) + try (IBlockheadClient client = new XBlockheadClient(server.getServerUri()); + StacklessLogging ignored = new StacklessLogging(ListenerRuntimeOnConnectSocket.class)) { client.setProtocols("listener-runtime-connect"); client.setTimeout(1,TimeUnit.SECONDS); @@ -97,8 +97,8 @@ public class MisbehavingClassTest @Test public void testAnnotatedRuntimeOnConnect() throws Exception { - try (IBlockheadClient client = new BlockheadClient(server.getServerUri()); - StacklessLogging scope = new StacklessLogging(AnnotatedRuntimeOnConnectSocket.class)) + try (IBlockheadClient client = new XBlockheadClient(server.getServerUri()); + StacklessLogging ignored = new StacklessLogging(AnnotatedRuntimeOnConnectSocket.class)) { client.setProtocols("annotated-runtime-connect"); client.setTimeout(1,TimeUnit.SECONDS); diff --git a/jetty-websocket/websocket-server/src/test/resources/jetty-logging.properties b/jetty-websocket/websocket-server/src/test/resources/jetty-logging.properties index 924d0006cbb..c454c69fff6 100644 --- a/jetty-websocket/websocket-server/src/test/resources/jetty-logging.properties +++ b/jetty-websocket/websocket-server/src/test/resources/jetty-logging.properties @@ -25,5 +25,5 @@ org.eclipse.jetty.websocket.server.browser.LEVEL=DEBUG org.eclipse.jetty.websocket.server.helper.RFCSocket.LEVEL=OFF ### Hiding Stack Traces from various test cases -org.eclipse.jetty.websocket.server.ab.ABSocket.STACKS=OFF +org.eclipse.jetty.websocket.tests.server.ABSocket.STACKS=OFF org.eclipse.jetty.websocket.server.WebSocketCloseTest$FastFailSocket.STACKS=OFF \ No newline at end of file diff --git a/jetty-websocket/websocket-tests/pom.xml b/jetty-websocket/websocket-tests/pom.xml new file mode 100644 index 00000000000..d03ef57d360 --- /dev/null +++ b/jetty-websocket/websocket-tests/pom.xml @@ -0,0 +1,86 @@ + + + + org.eclipse.jetty.websocket + websocket-parent + 9.4.3-SNAPSHOT + + + 4.0.0 + websocket-tests + Jetty :: Websocket :: Tests + + + ${project.groupId}.tests + + + + + org.eclipse.jetty.websocket + websocket-api + ${project.version} + + + org.eclipse.jetty.websocket + websocket-client + ${project.version} + + + org.eclipse.jetty.websocket + websocket-server + ${project.version} + + + org.eclipse.jetty + jetty-util + ${project.version} + + + org.eclipse.jetty + jetty-io + ${project.version} + + + org.eclipse.jetty.toolchain + jetty-test-helper + compile + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + + + ban-java-servlet-api + + enforce + + + + + + javax.servlet + servletapi + org.eclipse.jetty.orbit:javax.servlet + org.mortbay.jetty:servlet-api + jetty:servlet-api + + + + + + + + + org.apache.maven.plugins + maven-deploy-plugin + + true + + + + + diff --git a/jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/CloseState.java b/jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/CloseState.java new file mode 100644 index 00000000000..2c6f24c66ef --- /dev/null +++ b/jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/CloseState.java @@ -0,0 +1,44 @@ +// +// ======================================================================== +// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.eclipse.jetty.websocket.tests; + +import org.eclipse.jetty.websocket.common.io.IOState; + +public enum CloseState +{ + OPEN, + REMOTE_INITIATED, + LOCAL_INITIATED; + + public static CloseState from(IOState ios) + { + if (ios.wasLocalCloseInitiated()) + { + return CloseState.LOCAL_INITIATED; + } + else if (ios.wasRemoteCloseInitiated()) + { + return CloseState.REMOTE_INITIATED; + } + else + { + return CloseState.OPEN; + } + } +} diff --git a/jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/Fuzzed.java b/jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/Fuzzed.java new file mode 100644 index 00000000000..2214164ff60 --- /dev/null +++ b/jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/Fuzzed.java @@ -0,0 +1,32 @@ +// +// ======================================================================== +// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.eclipse.jetty.websocket.tests; + +import java.net.URI; + +import org.eclipse.jetty.websocket.common.Generator; + +public interface Fuzzed +{ + URI getServerURI(); + + Generator getLaxGenerator(); + + String getTestMethodName(); +} diff --git a/jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/Fuzzer.java b/jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/Fuzzer.java new file mode 100644 index 00000000000..9dae2498e69 --- /dev/null +++ b/jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/Fuzzer.java @@ -0,0 +1,368 @@ +// +// ======================================================================== +// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.eclipse.jetty.websocket.tests; + +import static org.eclipse.jetty.websocket.tests.Fuzzer.SendMode.BULK; +import static org.eclipse.jetty.websocket.tests.Fuzzer.SendMode.PER_FRAME; +import static org.eclipse.jetty.websocket.tests.Fuzzer.SendMode.SLOW; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.junit.Assert.assertThat; + +import java.io.IOException; +import java.net.SocketException; +import java.nio.ByteBuffer; +import java.util.Collections; +import java.util.List; +import java.util.Locale; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; + +import org.eclipse.jetty.toolchain.test.ByteBufferAssert; +import org.eclipse.jetty.util.BufferUtil; +import org.eclipse.jetty.util.component.ContainerLifeCycle; +import org.eclipse.jetty.util.log.Log; +import org.eclipse.jetty.util.log.Logger; +import org.eclipse.jetty.websocket.api.extensions.Frame; +import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; +import org.eclipse.jetty.websocket.common.CloseInfo; +import org.eclipse.jetty.websocket.common.Generator; +import org.eclipse.jetty.websocket.common.OpCode; +import org.eclipse.jetty.websocket.common.WebSocketFrame; + +/** + * Fuzzing utility for the AB tests. + */ +public class Fuzzer extends ContainerLifeCycle +{ + public static class Session implements AutoCloseable + { + // Client side framing mask + private static final byte[] MASK = {0x11, 0x22, 0x33, 0x44}; + + private final Fuzzed testcase; + private final UntrustedWSSession session; + private final Generator generator; + private SendMode sendMode = SendMode.BULK; + private int slowSendSegmentSize = 5; + private boolean ignoreBrokenPipe = false; + + public Session(Fuzzed testcase, UntrustedWSSession session) + { + this.testcase = testcase; + this.session = session; + this.generator = testcase.getLaxGenerator(); + } + + @Override + public void close() throws Exception + { + session.close(); + } + + public Session slowMode(int slowSendSegmentSize) + { + this.sendMode = SLOW; + this.slowSendSegmentSize = slowSendSegmentSize; + return this; + } + + public Session bulkMode() + { + this.sendMode = BULK; + return this; + } + + public Session perFrameMode() + { + this.sendMode = PER_FRAME; + return this; + } + + public Session ignoreBrokenPipe() + { + this.ignoreBrokenPipe = true; + return this; + } + + private void assertIsOpen() + { + assertThat("Session exists", session, notNullValue()); + assertThat("Session is open", session.isOpen(), is(true)); + } + + public ByteBuffer asNetworkBuffer(List send) + { + int buflen = 0; + for (Frame f : send) + { + buflen += f.getPayloadLength() + Generator.MAX_HEADER_LENGTH; + } + ByteBuffer buf = session.getBufferPool().acquire(buflen, false); + BufferUtil.clearToFill(buf); + + // Generate frames + for (WebSocketFrame f : send) + { + setClientMask(f); + generator.generateWholeFrame(f, buf); + } + buf.flip(); + return buf; + } + + private void setClientMask(WebSocketFrame f) + { + if (LOG.isDebugEnabled()) + { + f.setMask(new byte[] + {0x00, 0x00, 0x00, 0x00}); + } + else + { + f.setMask(MASK); // make sure we have mask set + } + } + + public void expect(List expect) throws Exception + { + expect(expect, 10, TimeUnit.SECONDS); + } + + public void expect(List expect, int duration, TimeUnit unit) throws Exception + { + int expectedCount = expect.size(); + LOG.debug("expect() {} frame(s)", expect.size()); + + // Read frames + Future> futFrames = session.getUntrustedEndpoint().expectedFrames(expectedCount); + + List frames = futFrames.get(duration, unit); + + String prefix = ""; + for (int i = 0; i < expectedCount; i++) + { + WebSocketFrame expected = expect.get(i); + WebSocketFrame actual = frames.get(i); + + prefix = "Frame[" + i + "]"; + + LOG.debug("{} {}", prefix, actual); + + assertThat(prefix + ".opcode", OpCode.name(actual.getOpCode()), is(OpCode.name(expected.getOpCode()))); + prefix += "/" + actual.getOpCode(); + if (expected.getOpCode() == OpCode.CLOSE) + { + CloseInfo expectedClose = new CloseInfo(expected); + CloseInfo actualClose = new CloseInfo(actual); + assertThat(prefix + ".statusCode", actualClose.getStatusCode(), is(expectedClose.getStatusCode())); + } + else + { + assertThat(prefix + ".payloadLength", actual.getPayloadLength(), is(expected.getPayloadLength())); + ByteBufferAssert.assertEquals(prefix + ".payload", expected.getPayload(), actual.getPayload()); + } + } + } + + public void expect(WebSocketFrame expect) throws Exception + { + expect(Collections.singletonList(expect)); + } + + public Session send(WebSocketFrame send) throws IOException + { + send(Collections.singletonList(send)); + return this; + } + + public Session send(ByteBuffer buf) throws IOException + { + assertIsOpen(); + LOG.debug("Sending bytes {}", BufferUtil.toDetailString(buf)); + if (sendMode == SLOW) + { + session.getUntrustedConnection().writeRawSlowly(buf, slowSendSegmentSize); + } + else + { + session.getUntrustedConnection().writeRaw(buf); + } + return this; + } + + public Session send(ByteBuffer buf, int numBytes) throws IOException + { + session.getUntrustedConnection().writeRaw(buf, numBytes); + return this; + } + + public Session send(List send) throws IOException + { + assertIsOpen(); + LOG.debug("[{}] Sending {} frames (mode {})", testcase.getTestMethodName(), send.size(), sendMode); + + try + { + if ((sendMode == SendMode.BULK) || (sendMode == SLOW)) + { + int bufferLen = 0; + for (Frame f : send) + { + bufferLen += f.getPayloadLength() + Generator.MAX_HEADER_LENGTH; + } + + ByteBuffer buffer = null; + try + { + buffer = session.getBufferPool().acquire(bufferLen, false); + BufferUtil.clearToFill(buffer); + + // Generate frames + for (WebSocketFrame f : send) + { + setClientMask(f); + generator.generateHeaderBytes(f, buffer); + if (f.hasPayload()) + { + buffer.put(f.getPayload()); + } + } + BufferUtil.flipToFlush(buffer, 0); + + // Write Data Frame + switch (sendMode) + { + case BULK: + session.getUntrustedConnection().writeRaw(buffer); + break; + case SLOW: + session.getUntrustedConnection().writeRawSlowly(buffer, slowSendSegmentSize); + break; + default: + throw new RuntimeException("Whoops, unsupported sendMode: " + sendMode); + } + } + finally + { + session.getBufferPool().release(buffer); + } + } + else if (sendMode == SendMode.PER_FRAME) + { + for (WebSocketFrame f : send) + { + f.setMask(MASK); // make sure we have mask set + // Using lax generator, generate and send + + ByteBuffer buffer = null; + try + { + buffer = session.getBufferPool().acquire(f.getPayloadLength() + Generator.MAX_HEADER_LENGTH, false); + BufferUtil.clearToFill(buffer); + generator.generateWholeFrame(f, buffer); + BufferUtil.flipToFlush(buffer, 0); + session.getUntrustedConnection().writeRaw(buffer); + } + finally + { + session.getBufferPool().release(buffer); + } + } + } + } + catch (SocketException e) + { + if (ignoreBrokenPipe) + { + // Potential for SocketException (Broken Pipe) here. + // But not in 100% of testing scenarios. It is a safe + // exception to ignore in this testing scenario, as the + // slow writing of the frames can result in the server + // throwing a PROTOCOL ERROR termination/close when it + // encounters the bad continuation frame above (this + // termination is the expected behavior), and this + // early socket close can propagate back to the client + // before it has a chance to finish writing out the + // remaining frame octets + assertThat("Allowed to be a broken pipe", e.getMessage().toLowerCase(Locale.ENGLISH), containsString("broken pipe")); + } + else + { + throw e; + } + } + return this; + } + } + + public enum SendMode + { + BULK, + PER_FRAME, + SLOW + } + + public enum DisconnectMode + { + /** Disconnect occurred after a proper close handshake */ + CLEAN, + /** Disconnect occurred in a harsh manner, without a close handshake */ + UNCLEAN + } + + private static final int KBYTE = 1024; + private static final int MBYTE = KBYTE * KBYTE; + + private static final Logger LOG = Log.getLogger(Fuzzer.class); + + private final UntrustedWSClient client; + + private long connectTimeout = 2; + private TimeUnit connectTimeoutUnit = TimeUnit.SECONDS; + + public Fuzzer() throws Exception + { + this.client = new UntrustedWSClient(); + + int bigMessageSize = 20 * MBYTE; + + this.client.getPolicy().setMaxTextMessageSize(bigMessageSize); + this.client.getPolicy().setMaxBinaryMessageSize(bigMessageSize); + this.client.getPolicy().setIdleTimeout(5000); + + this.client.setMaxIdleTimeout(TimeUnit.SECONDS.toMillis(2)); + + addBean(this.client); + } + + public UntrustedWSClient getWSClient() + { + return this.client; + } + + public Fuzzer.Session connect(Fuzzed testcase) throws Exception + { + ClientUpgradeRequest upgradeRequest = new ClientUpgradeRequest(); + upgradeRequest.setHeader("X-TestCase", testcase.getTestMethodName()); + UntrustedWSSession session = client.connect(testcase.getServerURI(), upgradeRequest).get(connectTimeout, connectTimeoutUnit); + return new Fuzzer.Session(testcase, session); + } +} diff --git a/jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/LeakTrackingBufferPoolRule.java b/jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/LeakTrackingBufferPoolRule.java new file mode 100644 index 00000000000..ee39f78e75e --- /dev/null +++ b/jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/LeakTrackingBufferPoolRule.java @@ -0,0 +1,61 @@ +// +// ======================================================================== +// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.eclipse.jetty.websocket.tests; + +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +import org.eclipse.jetty.io.LeakTrackingByteBufferPool; +import org.eclipse.jetty.io.MappedByteBufferPool; +import org.junit.rules.TestRule; +import org.junit.runner.Description; +import org.junit.runners.model.Statement; + +public class LeakTrackingBufferPoolRule extends LeakTrackingByteBufferPool implements TestRule +{ + private final String id; + + public LeakTrackingBufferPoolRule(String id) + { + super(new MappedByteBufferPool.Tagged()); + this.id = id; + } + + public void assertNoLeaks() + { + assertThat("Leaked Acquires Count for [" + id + "]", getLeakedAcquires(), is(0L)); + assertThat("Leaked Releases Count for [" + id + "]", getLeakedReleases(), is(0L)); + assertThat("Leaked Resource Count for [" + id + "]", getLeakedResources(), is(0L)); + } + + @Override + public Statement apply(final Statement statement, Description description) + { + return new Statement() + { + @Override + public void evaluate() throws Throwable + { + clearTracking(); + statement.evaluate(); + assertNoLeaks(); + } + }; + } +} diff --git a/jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/RawFrameBuilder.java b/jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/RawFrameBuilder.java new file mode 100644 index 00000000000..6a880bdcbc3 --- /dev/null +++ b/jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/RawFrameBuilder.java @@ -0,0 +1,110 @@ +// +// ======================================================================== +// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.eclipse.jetty.websocket.tests; + +import static org.hamcrest.Matchers.is; + +import java.nio.ByteBuffer; + +import org.junit.Assert; + +public class RawFrameBuilder +{ + public static void putOpFin(ByteBuffer buf, byte opcode, boolean fin) + { + byte b = 0x00; + if (fin) + { + b |= 0x80; + } + b |= opcode & 0x0F; + buf.put(b); + } + + public static void putLengthAndMask(ByteBuffer buf, int length, byte mask[]) + { + if (mask != null) + { + Assert.assertThat("Mask.length",mask.length,is(4)); + putLength(buf,length,(mask != null)); + buf.put(mask); + } + else + { + putLength(buf,length,false); + } + } + + public static byte[] mask(final byte[] data, final byte mask[]) + { + Assert.assertThat("Mask.length",mask.length,is(4)); + int len = data.length; + byte ret[] = new byte[len]; + System.arraycopy(data,0,ret,0,len); + for (int i = 0; i < len; i++) + { + ret[i] ^= mask[i % 4]; + } + return ret; + } + + public static void putLength(ByteBuffer buf, int length, boolean masked) + { + if (length < 0) + { + throw new IllegalArgumentException("Length cannot be negative"); + } + byte b = (masked?(byte)0x80:0x00); + + // write the uncompressed length + if (length > 0xFF_FF) + { + buf.put((byte)(b | 0x7F)); + buf.put((byte)0x00); + buf.put((byte)0x00); + buf.put((byte)0x00); + buf.put((byte)0x00); + buf.put((byte)((length >> 24) & 0xFF)); + buf.put((byte)((length >> 16) & 0xFF)); + buf.put((byte)((length >> 8) & 0xFF)); + buf.put((byte)(length & 0xFF)); + } + else if (length >= 0x7E) + { + buf.put((byte)(b | 0x7E)); + buf.put((byte)(length >> 8)); + buf.put((byte)(length & 0xFF)); + } + else + { + buf.put((byte)(b | length)); + } + } + + public static void putMask(ByteBuffer buf, byte mask[]) + { + Assert.assertThat("Mask.length",mask.length,is(4)); + buf.put(mask); + } + + public static void putPayloadLength(ByteBuffer buf, int length) + { + putLength(buf,length,true); + } +} diff --git a/jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/SimpleServletServer.java b/jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/SimpleServletServer.java new file mode 100644 index 00000000000..2453adf3fcd --- /dev/null +++ b/jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/SimpleServletServer.java @@ -0,0 +1,163 @@ +// +// ======================================================================== +// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.eclipse.jetty.websocket.tests; + +import java.net.URI; + +import javax.servlet.http.HttpServlet; + +import org.eclipse.jetty.http.HttpVersion; +import org.eclipse.jetty.server.HttpConfiguration; +import org.eclipse.jetty.server.HttpConnectionFactory; +import org.eclipse.jetty.server.SecureRequestCustomizer; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.ServerConnector; +import org.eclipse.jetty.server.SslConnectionFactory; +import org.eclipse.jetty.servlet.ServletContextHandler; +import org.eclipse.jetty.servlet.ServletHolder; +import org.eclipse.jetty.toolchain.test.MavenTestingUtils; +import org.eclipse.jetty.util.component.ContainerLifeCycle; +import org.eclipse.jetty.util.log.Log; +import org.eclipse.jetty.util.log.Logger; +import org.eclipse.jetty.util.ssl.SslContextFactory; +import org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter; +import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; + +public class SimpleServletServer extends ContainerLifeCycle +{ + private static final Logger LOG = Log.getLogger(SimpleServletServer.class); + private Server server; + private ServerConnector connector; + private URI serverUri; + private HttpServlet servlet; + private boolean ssl = false; + private SslContextFactory sslContextFactory; + + public SimpleServletServer(HttpServlet servlet) + { + this.servlet = servlet; + } + + public void enableSsl(boolean ssl) + { + this.ssl = ssl; + } + + public URI getServerUri() + { + return serverUri; + } + + public SslContextFactory getSslContextFactory() + { + return sslContextFactory; + } + + public boolean isSslEnabled() + { + return ssl; + } + + @Override + protected void doStart() throws Exception + { + // Configure Server + server = new Server(); + if (ssl) + { + // HTTP Configuration + HttpConfiguration http_config = new HttpConfiguration(); + http_config.setSecureScheme("https"); + http_config.setSecurePort(0); + http_config.setOutputBufferSize(32768); + http_config.setRequestHeaderSize(8192); + http_config.setResponseHeaderSize(8192); + http_config.setSendServerVersion(true); + http_config.setSendDateHeader(false); + + sslContextFactory = new SslContextFactory(); + sslContextFactory.setKeyStorePath(MavenTestingUtils.getTestResourceFile("keystore").getAbsolutePath()); + sslContextFactory.setKeyStorePassword("storepwd"); + sslContextFactory.setKeyManagerPassword("keypwd"); + sslContextFactory.setExcludeCipherSuites("SSL_RSA_WITH_DES_CBC_SHA","SSL_DHE_RSA_WITH_DES_CBC_SHA","SSL_DHE_DSS_WITH_DES_CBC_SHA", + "SSL_RSA_EXPORT_WITH_RC4_40_MD5","SSL_RSA_EXPORT_WITH_DES40_CBC_SHA","SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA", + "SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA"); + + // SSL HTTP Configuration + HttpConfiguration https_config = new HttpConfiguration(http_config); + https_config.addCustomizer(new SecureRequestCustomizer()); + + // SSL Connector + connector = new ServerConnector(server,new SslConnectionFactory(sslContextFactory,HttpVersion.HTTP_1_1.asString()),new HttpConnectionFactory(https_config)); + connector.setPort(0); + } + else + { + // Basic HTTP connector + connector = new ServerConnector(server); + connector.setPort(0); + } + server.addConnector(connector); + + ServletContextHandler context = new ServletContextHandler(); + context.setContextPath("/"); + configureServletContextHandler(context); + server.setHandler(context); + + // Serve capture servlet + context.addServlet(new ServletHolder(servlet),"/*"); + + // Start Server + addBean(server); + + super.doStart(); + + // Establish the Server URI + String host = connector.getHost(); + if (host == null) + { + host = "localhost"; + } + int port = connector.getLocalPort(); + serverUri = new URI(String.format("%s://%s:%d/",ssl?"wss":"ws",host,port)); + + // Some debugging + if (LOG.isDebugEnabled()) + { + LOG.debug(server.dump()); + } + } + + protected void configureServletContextHandler(ServletContextHandler context) + { + } + + public WebSocketServletFactory getWebSocketServletFactory() + { + // Try filter approach first + WebSocketUpgradeFilter filter = (WebSocketUpgradeFilter)this.servlet.getServletContext().getAttribute(WebSocketUpgradeFilter.class.getName()); + if (filter != null) + { + return filter.getFactory(); + } + + // Try servlet next + return (WebSocketServletFactory)this.servlet.getServletContext().getAttribute(WebSocketServletFactory.class.getName()); + } +} diff --git a/jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/UntrustedWSClient.java b/jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/UntrustedWSClient.java new file mode 100644 index 00000000000..e281012e0f8 --- /dev/null +++ b/jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/UntrustedWSClient.java @@ -0,0 +1,69 @@ +// +// ======================================================================== +// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.eclipse.jetty.websocket.tests; + +import java.io.IOException; +import java.net.URI; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +import org.eclipse.jetty.client.HttpClient; +import org.eclipse.jetty.util.log.Log; +import org.eclipse.jetty.util.log.Logger; +import org.eclipse.jetty.websocket.api.Session; +import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; +import org.eclipse.jetty.websocket.client.WebSocketClient; + +public class UntrustedWSClient extends WebSocketClient +{ + private static final Logger LOG = Log.getLogger(UntrustedWSClient.class); + + public UntrustedWSClient() + { + super(); + setSessionFactory(new UntrustedWSSessionFactory(this)); + } + + public UntrustedWSClient(HttpClient httpClient) + { + super(httpClient); + setSessionFactory(new UntrustedWSSessionFactory(this)); + } + + public Future connect(URI toUri, ClientUpgradeRequest req) throws IOException + { + final Future connectFut = super.connect(new UntrustedWSEndpoint(), toUri, req); + return new CompletableFuture() { + @Override + public UntrustedWSSession get() throws InterruptedException, ExecutionException + { + return (UntrustedWSSession) connectFut.get(); + } + + @Override + public UntrustedWSSession get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException + { + return (UntrustedWSSession) connectFut.get(timeout, unit); + } + }; + } +} diff --git a/jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/UntrustedWSConnection.java b/jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/UntrustedWSConnection.java new file mode 100644 index 00000000000..a2c3b1ec07f --- /dev/null +++ b/jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/UntrustedWSConnection.java @@ -0,0 +1,124 @@ +// +// ======================================================================== +// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.eclipse.jetty.websocket.tests; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; + +import org.eclipse.jetty.util.BufferUtil; +import org.eclipse.jetty.util.SharedBlockingCallback; +import org.eclipse.jetty.util.SharedBlockingCallback.Blocker; +import org.eclipse.jetty.util.log.Log; +import org.eclipse.jetty.util.log.Logger; +import org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection; + +/** + * A wrapper for {@link org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection} to + * allow for untrusted behaviors, such as arbitrary writes and flushes on network. + */ +public class UntrustedWSConnection +{ + private static final Logger LOG = Log.getLogger(UntrustedWSConnection.class); + private final AbstractWebSocketConnection internalConnection; + private final SharedBlockingCallback writeBlocker; + + public UntrustedWSConnection(AbstractWebSocketConnection connection) + { + this.internalConnection = connection; + this.writeBlocker = new SharedBlockingCallback(); + } + + /** + * Perform write flush. + */ + public void flush() throws IOException + { + internalConnection.getEndPoint().flush(); + } + + /** + * Write arbitrary bytes out the active connection. + * + * @param buf the buffer to write + * @throws IOException + */ + public void writeRaw(ByteBuffer buf) throws IOException + { + try(Blocker blocker = writeBlocker.acquire()) + { + internalConnection.getEndPoint().write(blocker, buf); + blocker.block(); + } + } + + /** + * Write arbitrary bytes out the active connection. + * + * @param buf the buffer to write + * @param numBytes the number of bytes from the buffer to write + * @throws IOException + */ + public void writeRaw(ByteBuffer buf, int numBytes) throws IOException + { + try(Blocker blocker = writeBlocker.acquire()) + { + ByteBuffer slice = buf.slice(); + + int writeLen = Math.min(buf.remaining(), numBytes); + slice.limit(writeLen); + internalConnection.getEndPoint().write(blocker, slice); + blocker.block(); + buf.position(buf.position() + writeLen); + } + } + + /** + * Write arbitrary String out the active connection. + * + * @param str the string, converted to UTF8 bytes, then written + * @throws IOException + */ + public void writeRaw(String str) throws IOException + { + LOG.debug("write((String)[{}]){}{})",str.length(),'\n',str); + writeRaw(BufferUtil.toBuffer(str, StandardCharsets.UTF_8)); + } + + /** + * Write arbitrary buffer out the active connection, slowly. + * + * @param buf the buffer to write + * @param segmentSize the segment size to write, with a {@link #flush()} after each segment + * @throws IOException + */ + public void writeRawSlowly(ByteBuffer buf, int segmentSize) throws IOException + { + while (buf.remaining() > 0) + { + writeRaw(buf,segmentSize); + flush(); + } + } + + public boolean isConnected() + { + return internalConnection.getEndPoint().isOpen(); + } +} diff --git a/jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/UntrustedWSEndpoint.java b/jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/UntrustedWSEndpoint.java new file mode 100644 index 00000000000..7bba3e91591 --- /dev/null +++ b/jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/UntrustedWSEndpoint.java @@ -0,0 +1,157 @@ +// +// ======================================================================== +// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.eclipse.jetty.websocket.tests; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.Future; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicReference; + +import org.eclipse.jetty.websocket.api.Session; +import org.eclipse.jetty.websocket.api.WebSocketFrameListener; +import org.eclipse.jetty.websocket.api.WebSocketListener; +import org.eclipse.jetty.websocket.api.extensions.Frame; +import org.eclipse.jetty.websocket.common.CloseInfo; +import org.eclipse.jetty.websocket.common.WebSocketFrame; + +public class UntrustedWSEndpoint implements WebSocketListener, WebSocketFrameListener +{ + @SuppressWarnings("unused") + private Session session; + public CountDownLatch openLatch = new CountDownLatch(1); + public CountDownLatch closeLatch = new CountDownLatch(1); + public AtomicReference closeInfo = new AtomicReference<>(); + public AtomicReference error = new AtomicReference<>(); + + private CompletableFuture> expectedMessagesFuture; + private AtomicInteger expectedMessageCount; + private List messages = new ArrayList<>(); + + private CompletableFuture> expectedFramesFuture; + private AtomicInteger expectedFramesCount; + private List frames = new ArrayList<>(); + + public Future> expectedFrames(int expectedCount) + { + expectedFramesFuture = new CompletableFuture<>(); + expectedFramesCount = new AtomicInteger(expectedCount); + return expectedFramesFuture; + } + + public Future> expectedMessages(int expected) + { + expectedMessagesFuture = new CompletableFuture<>(); + expectedMessageCount = new AtomicInteger(expected); + return expectedMessagesFuture; + } + + @Override + public void onWebSocketConnect(Session session) + { + this.session = session; + this.openLatch.countDown(); + } + + @Override + public void onWebSocketClose(int statusCode, String reason) + { + this.closeLatch.countDown(); + CloseInfo close = new CloseInfo(statusCode, reason); + assertThat("Close only happened once", closeInfo.compareAndSet(null, close), is(true)); + } + + @Override + public void onWebSocketError(Throwable cause) + { + assertThat("Error must have value", cause, notNullValue()); + if (error.compareAndSet(null, cause) == false) + { + System.err.println("Original Cause"); + error.get().printStackTrace(System.err); + System.err.println("Extra/Excess Cause"); + cause.printStackTrace(System.err); + fail("onError should only happen once!"); + } + + if(expectedMessagesFuture != null) + { + synchronized (expectedMessagesFuture) + { + if (expectedMessagesFuture != null) + expectedMessagesFuture.completeExceptionally(cause); + } + } + + if(expectedFramesFuture != null) + { + synchronized (expectedFramesFuture) + { + if (expectedFramesFuture != null) + expectedFramesFuture.completeExceptionally(cause); + } + } + } + + @Override + public void onWebSocketBinary(byte[] payload, int offset, int len) + { + // TODO + } + + @Override + public void onWebSocketText(String text) + { + if(expectedMessagesFuture == null) + return; + + messages.add(text); + synchronized (expectedMessagesFuture) + { + if (expectedMessageCount.decrementAndGet() <= 0) + { + expectedMessagesFuture.complete(messages); + } + } + } + + @Override + public void onWebSocketFrame(Frame frame) + { + if (expectedFramesFuture == null) + return; + + frames.add(WebSocketFrame.copy(frame)); + + synchronized (expectedFramesFuture) + { + if (expectedFramesCount.decrementAndGet() <= 0) + { + expectedFramesFuture.complete(frames); + } + } + } +} diff --git a/jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/UntrustedWSSession.java b/jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/UntrustedWSSession.java new file mode 100644 index 00000000000..11c36098285 --- /dev/null +++ b/jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/UntrustedWSSession.java @@ -0,0 +1,49 @@ +// +// ======================================================================== +// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.eclipse.jetty.websocket.tests; + +import java.net.URI; + +import org.eclipse.jetty.websocket.common.LogicalConnection; +import org.eclipse.jetty.websocket.common.WebSocketSession; +import org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection; +import org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope; + +public class UntrustedWSSession extends WebSocketSession implements AutoCloseable +{ + private final UntrustedWSConnection untrustedConnection; + private final UntrustedWSEndpoint untrustedEndpoint; + + public UntrustedWSSession(WebSocketContainerScope containerScope, URI requestURI, Object endpoint, LogicalConnection connection) + { + super(containerScope, requestURI, endpoint, connection); + this.untrustedConnection = new UntrustedWSConnection((AbstractWebSocketConnection) connection); + this.untrustedEndpoint = (UntrustedWSEndpoint) endpoint; + } + + public UntrustedWSConnection getUntrustedConnection() + { + return untrustedConnection; + } + + public UntrustedWSEndpoint getUntrustedEndpoint() + { + return untrustedEndpoint; + } +} diff --git a/jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/UntrustedWSSessionFactory.java b/jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/UntrustedWSSessionFactory.java new file mode 100644 index 00000000000..12552b2e8e2 --- /dev/null +++ b/jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/UntrustedWSSessionFactory.java @@ -0,0 +1,50 @@ +// +// ======================================================================== +// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.eclipse.jetty.websocket.tests; + +import java.net.URI; + +import org.eclipse.jetty.websocket.api.WebSocketConnectionListener; +import org.eclipse.jetty.websocket.api.annotations.WebSocket; +import org.eclipse.jetty.websocket.common.LogicalConnection; +import org.eclipse.jetty.websocket.common.SessionFactory; +import org.eclipse.jetty.websocket.common.WebSocketSession; +import org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope; + +public class UntrustedWSSessionFactory implements SessionFactory +{ + private final WebSocketContainerScope containerScope; + + public UntrustedWSSessionFactory(WebSocketContainerScope containerScope) + { + this.containerScope = containerScope; + } + + @Override + public boolean supports(Object websocket) + { + return (websocket instanceof WebSocketConnectionListener) || (websocket.getClass().getAnnotation(WebSocket.class) != null); + } + + @Override + public WebSocketSession createSession(URI requestURI, Object websocket, LogicalConnection connection) + { + return new UntrustedWSSession(containerScope, requestURI, websocket, connection); + } +} diff --git a/jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/UntrustedWSClientTest.java b/jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/UntrustedWSClientTest.java new file mode 100644 index 00000000000..cee3bd95bcc --- /dev/null +++ b/jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/UntrustedWSClientTest.java @@ -0,0 +1,126 @@ +// +// ======================================================================== +// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.eclipse.jetty.websocket.tests; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.io.IOException; +import java.net.URI; +import java.util.List; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; + +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.servlet.ServletContextHandler; +import org.eclipse.jetty.websocket.api.Session; +import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage; +import org.eclipse.jetty.websocket.api.annotations.WebSocket; +import org.eclipse.jetty.websocket.api.util.WSURI; +import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; +import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest; +import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse; +import org.eclipse.jetty.websocket.servlet.WebSocketCreator; +import org.eclipse.jetty.websocket.servlet.WebSocketServlet; +import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +public class UntrustedWSClientTest +{ + @WebSocket + public static class StatusSocket + { + @OnWebSocketMessage + public void onMessage(Session session, String msg) throws IOException + { + session.getRemote().sendString(msg); + } + } + + public static class StatusServlet extends WebSocketServlet implements WebSocketCreator + { + @Override + public void configure(WebSocketServletFactory factory) + { + factory.setCreator(this); + } + + @Override + public Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp) + { + return new StatusSocket(); + } + } + + private static Server server; + private static URI wsServerURI; + + @BeforeClass + public static void startServer() throws Exception + { + server = new Server(0); + + ServletContextHandler context = new ServletContextHandler(); + context.setContextPath("/"); + + context.addServlet(StatusServlet.class, "/status"); + + server.setHandler(context); + server.start(); + + URI serverURI = server.getURI(); + wsServerURI = WSURI.toWebsocket(serverURI); + } + + @AfterClass + public static void stopServer() throws Exception + { + server.stop(); + } + + @Test + public void testConnect() throws Exception + { + UntrustedWSClient client = new UntrustedWSClient(); + try + { + client.start(); + ClientUpgradeRequest request = new ClientUpgradeRequest(); + Future fut = client.connect(wsServerURI.resolve("/status"), request); + try (UntrustedWSSession session = fut.get(5, TimeUnit.SECONDS)) + { + UntrustedWSEndpoint endpoint = session.getUntrustedEndpoint(); + + Future> futMessages = endpoint.expectedMessages(1); + + session.getRemote().sendString("hello"); + + List messages = futMessages.get(); + assertThat("Messages.size", messages.size(), is(1)); + assertThat("Messages[0]", messages.get(0), is("hello")); + } + } + finally + { + client.stop(); + } + } +} diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/ABServlet.java b/jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ABServlet.java similarity index 96% rename from jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/ABServlet.java rename to jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ABServlet.java index bca10a6b162..912d7cea73c 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/ABServlet.java +++ b/jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ABServlet.java @@ -16,7 +16,7 @@ // ======================================================================== // -package org.eclipse.jetty.websocket.server.ab; +package org.eclipse.jetty.websocket.tests.server; import org.eclipse.jetty.websocket.servlet.WebSocketServlet; import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/ABSocket.java b/jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ABSocket.java similarity index 98% rename from jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/ABSocket.java rename to jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ABSocket.java index fbfc264ccc3..93f2f97cca1 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/ABSocket.java +++ b/jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ABSocket.java @@ -16,7 +16,7 @@ // ======================================================================== // -package org.eclipse.jetty.websocket.server.ab; +package org.eclipse.jetty.websocket.tests.server; import java.nio.ByteBuffer; diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/AbstractABCase.java b/jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/AbstractABCase.java similarity index 89% rename from jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/AbstractABCase.java rename to jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/AbstractABCase.java index 5dea3e36a44..566307f1d68 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/AbstractABCase.java +++ b/jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/AbstractABCase.java @@ -16,7 +16,7 @@ // ======================================================================== // -package org.eclipse.jetty.websocket.server.ab; +package org.eclipse.jetty.websocket.tests.server; import java.net.URI; import java.nio.ByteBuffer; @@ -30,10 +30,12 @@ import org.eclipse.jetty.websocket.api.WebSocketPolicy; import org.eclipse.jetty.websocket.common.Generator; import org.eclipse.jetty.websocket.common.OpCode; import org.eclipse.jetty.websocket.common.WebSocketFrame; -import org.eclipse.jetty.websocket.common.test.Fuzzed; -import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPoolRule; -import org.eclipse.jetty.websocket.common.test.RawFrameBuilder; -import org.eclipse.jetty.websocket.server.SimpleServletServer; +import org.eclipse.jetty.websocket.tests.Fuzzed; +import org.eclipse.jetty.websocket.tests.Fuzzer; +import org.eclipse.jetty.websocket.tests.LeakTrackingBufferPoolRule; +import org.eclipse.jetty.websocket.tests.RawFrameBuilder; +import org.eclipse.jetty.websocket.tests.SimpleServletServer; +import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; @@ -78,27 +80,38 @@ public abstract class AbstractABCase implements Fuzzed protected Generator strictGenerator; protected Generator laxGenerator; protected static SimpleServletServer server; + protected Fuzzer fuzzer; @Rule public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); @Before - public void initGenerators() + public void setup() throws Exception { + fuzzer = new Fuzzer(); + fuzzer.getWSClient().setBufferPool(bufferPool); + fuzzer.start(); + WebSocketPolicy policy = WebSocketPolicy.newClientPolicy(); strictGenerator = new Generator(policy,bufferPool,true); laxGenerator = new Generator(policy,bufferPool,false); } + + @After + public void tearDown() throws Exception + { + fuzzer.stop(); + } @BeforeClass - public static void startServer() throws Exception + public static void startEnv() throws Exception { server = new SimpleServletServer(new ABServlet()); server.start(); } @AfterClass - public static void stopServer() + public static void stopEnv() throws Exception { server.stop(); } diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase1.java b/jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/TestABCase1.java similarity index 75% rename from jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase1.java rename to jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/TestABCase1.java index 5d79050585b..257ed226dfc 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase1.java +++ b/jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/TestABCase1.java @@ -16,7 +16,7 @@ // ======================================================================== // -package org.eclipse.jetty.websocket.server.ab; +package org.eclipse.jetty.websocket.tests.server; import java.nio.ByteBuffer; import java.util.ArrayList; @@ -28,8 +28,7 @@ import org.eclipse.jetty.websocket.common.CloseInfo; import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.frames.BinaryFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame; -import org.eclipse.jetty.websocket.common.test.Fuzzer; -import org.eclipse.jetty.websocket.common.test.Fuzzer.SendMode; +import org.eclipse.jetty.websocket.tests.Fuzzer; import org.junit.Test; @SuppressWarnings("Duplicates") @@ -37,6 +36,7 @@ public class TestABCase1 extends AbstractABCase { /** * Echo 0 byte TEXT message + * * @throws Exception on test failure */ @Test @@ -45,224 +45,223 @@ public class TestABCase1 extends AbstractABCase List send = new ArrayList<>(); send.add(new TextFrame()); send.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - + List expect = new ArrayList<>(); expect.add(new TextFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this)) + + try(Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } - + /** * Echo 125 byte TEXT message (uses small 7-bit payload length) + * * @throws Exception on test failure */ @Test public void testCase1_1_2() throws Exception { byte payload[] = new byte[125]; - Arrays.fill(payload,(byte)'*'); + Arrays.fill(payload, (byte) '*'); ByteBuffer buf = ByteBuffer.wrap(payload); - + List send = new ArrayList<>(); send.add(new TextFrame().setPayload(buf)); send.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - + List expect = new ArrayList<>(); expect.add(new TextFrame().setPayload(clone(buf))); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this)) + + try(Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } - + /** * Echo 126 byte TEXT message (uses medium 2 byte payload length) + * * @throws Exception on test failure */ @Test public void testCase1_1_3() throws Exception { byte payload[] = new byte[126]; - Arrays.fill(payload,(byte)'*'); + Arrays.fill(payload, (byte) '*'); ByteBuffer buf = ByteBuffer.wrap(payload); - + List send = new ArrayList<>(); send.add(new TextFrame().setPayload(buf)); send.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - + List expect = new ArrayList<>(); expect.add(new TextFrame().setPayload(clone(buf))); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this)) + + try(Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } - + /** * Echo 127 byte TEXT message (uses medium 2 byte payload length) + * * @throws Exception on test failure */ @Test public void testCase1_1_4() throws Exception { byte payload[] = new byte[127]; - Arrays.fill(payload,(byte)'*'); + Arrays.fill(payload, (byte) '*'); ByteBuffer buf = ByteBuffer.wrap(payload); - + List send = new ArrayList<>(); send.add(new TextFrame().setPayload(buf)); send.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - + List expect = new ArrayList<>(); expect.add(new TextFrame().setPayload(clone(buf))); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this)) + + try(Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } - + /** * Echo 128 byte TEXT message (uses medium 2 byte payload length) + * * @throws Exception on test failure */ @Test public void testCase1_1_5() throws Exception { byte payload[] = new byte[128]; - Arrays.fill(payload,(byte)'*'); + Arrays.fill(payload, (byte) '*'); ByteBuffer buf = ByteBuffer.wrap(payload); - + List send = new ArrayList<>(); send.add(new TextFrame().setPayload(buf)); send.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - + List expect = new ArrayList<>(); expect.add(new TextFrame().setPayload(clone(buf))); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this)) + + try(Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } - + /** * Echo 65535 byte TEXT message (uses medium 2 byte payload length) + * * @throws Exception on test failure */ @Test public void testCase1_1_6() throws Exception { byte payload[] = new byte[65535]; - Arrays.fill(payload,(byte)'*'); + Arrays.fill(payload, (byte) '*'); ByteBuffer buf = ByteBuffer.wrap(payload); - + List send = new ArrayList<>(); send.add(new TextFrame().setPayload(buf)); send.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - + List expect = new ArrayList<>(); expect.add(new TextFrame().setPayload(clone(buf))); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this)) + + try(Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } - + /** * Echo 65536 byte TEXT message (uses large 8 byte payload length) + * * @throws Exception on test failure */ @Test public void testCase1_1_7() throws Exception { byte payload[] = new byte[65536]; - Arrays.fill(payload,(byte)'*'); + Arrays.fill(payload, (byte) '*'); ByteBuffer buf = ByteBuffer.wrap(payload); - + List send = new ArrayList<>(); send.add(new TextFrame().setPayload(buf)); send.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - + List expect = new ArrayList<>(); expect.add(new TextFrame().setPayload(clone(buf))); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this)) + + try(Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } - + /** * Echo 65536 byte TEXT message (uses large 8 byte payload length). *

* Only send 1 TEXT frame from client, but in small segments (flushed after each). *

* This is done to test the parsing together of the frame on the server side. + * * @throws Exception on test failure */ @Test public void testCase1_1_8() throws Exception { byte payload[] = new byte[65536]; - Arrays.fill(payload,(byte)'*'); + Arrays.fill(payload, (byte) '*'); ByteBuffer buf = ByteBuffer.wrap(payload); int segmentSize = 997; - + List send = new ArrayList<>(); send.add(new TextFrame().setPayload(buf)); send.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - + List expect = new ArrayList<>(); expect.add(new TextFrame().setPayload(clone(buf))); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this)) + + try(Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(SendMode.SLOW); - fuzzer.setSlowSendSegmentSize(segmentSize); - fuzzer.send(send); - fuzzer.expect(expect); + session.slowMode(segmentSize); + session.send(send); + session.expect(expect); } } - + /** * Echo 0 byte BINARY message + * * @throws Exception on test failure */ @Test @@ -271,219 +270,217 @@ public class TestABCase1 extends AbstractABCase List send = new ArrayList<>(); send.add(new BinaryFrame()); send.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - + List expect = new ArrayList<>(); expect.add(new BinaryFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this)) + + try(Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } - + /** * Echo 125 byte BINARY message (uses small 7-bit payload length) + * * @throws Exception on test failure */ @Test public void testCase1_2_2() throws Exception { byte payload[] = new byte[125]; - Arrays.fill(payload,(byte)0xFE); + Arrays.fill(payload, (byte) 0xFE); ByteBuffer buf = ByteBuffer.wrap(payload); - + List send = new ArrayList<>(); send.add(new BinaryFrame().setPayload(buf)); send.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - + List expect = new ArrayList<>(); expect.add(new BinaryFrame().setPayload(clone(buf))); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this)) + + try(Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } - + /** * Echo 126 byte BINARY message (uses medium 2 byte payload length) + * * @throws Exception on test failure */ @Test public void testCase1_2_3() throws Exception { byte payload[] = new byte[126]; - Arrays.fill(payload,(byte)0xFE); + Arrays.fill(payload, (byte) 0xFE); ByteBuffer buf = ByteBuffer.wrap(payload); - + List send = new ArrayList<>(); send.add(new BinaryFrame().setPayload(buf)); send.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - + List expect = new ArrayList<>(); expect.add(new BinaryFrame().setPayload(clone(buf))); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this)) + + try(Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } - + /** * Echo 127 byte BINARY message (uses medium 2 byte payload length) + * * @throws Exception on test failure */ @Test public void testCase1_2_4() throws Exception { byte payload[] = new byte[127]; - Arrays.fill(payload,(byte)0xFE); + Arrays.fill(payload, (byte) 0xFE); ByteBuffer buf = ByteBuffer.wrap(payload); - + List send = new ArrayList<>(); send.add(new BinaryFrame().setPayload(buf)); send.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - + List expect = new ArrayList<>(); expect.add(new BinaryFrame().setPayload(clone(buf))); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this)) + + try(Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } - + /** * Echo 128 byte BINARY message (uses medium 2 byte payload length) + * * @throws Exception on test failure */ @Test public void testCase1_2_5() throws Exception { byte payload[] = new byte[128]; - Arrays.fill(payload,(byte)0xFE); + Arrays.fill(payload, (byte) 0xFE); ByteBuffer buf = ByteBuffer.wrap(payload); - + List send = new ArrayList<>(); send.add(new BinaryFrame().setPayload(buf)); send.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - + List expect = new ArrayList<>(); expect.add(new BinaryFrame().setPayload(clone(buf))); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this)) + + try(Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } - + /** * Echo 65535 byte BINARY message (uses medium 2 byte payload length) + * * @throws Exception on test failure */ @Test public void testCase1_2_6() throws Exception { byte payload[] = new byte[65535]; - Arrays.fill(payload,(byte)0xFE); + Arrays.fill(payload, (byte) 0xFE); ByteBuffer buf = ByteBuffer.wrap(payload); - + List send = new ArrayList<>(); send.add(new BinaryFrame().setPayload(buf)); send.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - + List expect = new ArrayList<>(); expect.add(new BinaryFrame().setPayload(clone(buf))); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this)) + + try(Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } - + /** * Echo 65536 byte BINARY message (uses large 8 byte payload length) + * * @throws Exception on test failure */ @Test public void testCase1_2_7() throws Exception { byte payload[] = new byte[65536]; - Arrays.fill(payload,(byte)0xFE); + Arrays.fill(payload, (byte) 0xFE); ByteBuffer buf = ByteBuffer.wrap(payload); - + List send = new ArrayList<>(); send.add(new BinaryFrame().setPayload(buf)); send.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - + List expect = new ArrayList<>(); expect.add(new BinaryFrame().setPayload(clone(buf))); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this)) + + try(Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } - + /** * Echo 65536 byte BINARY message (uses large 8 byte payload length). *

* Only send 1 BINARY frame from client, but in small segments (flushed after each). *

* This is done to test the parsing together of the frame on the server side. + * * @throws Exception on test failure */ @Test public void testCase1_2_8() throws Exception { byte payload[] = new byte[65536]; - Arrays.fill(payload,(byte)0xFE); + Arrays.fill(payload, (byte) 0xFE); ByteBuffer buf = ByteBuffer.wrap(payload); int segmentSize = 997; - + List send = new ArrayList<>(); send.add(new BinaryFrame().setPayload(buf)); send.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - + List expect = new ArrayList<>(); expect.add(new BinaryFrame().setPayload(clone(buf))); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this)) + + try(Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(SendMode.SLOW); - fuzzer.setSlowSendSegmentSize(segmentSize); - fuzzer.send(send); - fuzzer.expect(expect); + session.slowMode(segmentSize); + session.send(send); + session.expect(expect); } } } diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase2.java b/jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/TestABCase2.java similarity index 76% rename from jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase2.java rename to jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/TestABCase2.java index 2415457df3e..6a8f7c3935c 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase2.java +++ b/jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/TestABCase2.java @@ -16,7 +16,7 @@ // ======================================================================== // -package org.eclipse.jetty.websocket.server.ab; +package org.eclipse.jetty.websocket.tests.server; import java.nio.ByteBuffer; import java.util.ArrayList; @@ -33,7 +33,7 @@ import org.eclipse.jetty.websocket.common.Parser; import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.frames.PingFrame; import org.eclipse.jetty.websocket.common.frames.PongFrame; -import org.eclipse.jetty.websocket.common.test.Fuzzer; +import org.eclipse.jetty.websocket.tests.Fuzzer; import org.junit.Test; import org.junit.runner.RunWith; @@ -47,16 +47,17 @@ public class TestABCase2 extends AbstractABCase @Test public void testCase2_1() throws Exception { - WebSocketFrame send = new PingFrame(); - - WebSocketFrame expect = new PongFrame(); - - try (Fuzzer fuzzer = new Fuzzer(this)) + List send = new ArrayList<>(); + send.add(new PingFrame()); + + List expect = new ArrayList<>(); + expect.add(new PongFrame()); + + try(Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -85,13 +86,12 @@ public class TestABCase2 extends AbstractABCase } send.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this)) + + try(Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -120,14 +120,12 @@ public class TestABCase2 extends AbstractABCase } send.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this)) + + try(Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.SLOW); - fuzzer.setSlowSendSegmentSize(5); - fuzzer.send(send); - fuzzer.expect(expect); + session.slowMode(5); + session.send(send); + session.expect(expect); } } @@ -147,13 +145,12 @@ public class TestABCase2 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new PongFrame().setPayload(copyOf(payload))); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this)) + + try(Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -173,13 +170,12 @@ public class TestABCase2 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new PongFrame().setPayload(copyOf(payload))); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this)) + + try(Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -200,13 +196,12 @@ public class TestABCase2 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new PongFrame().setPayload(copyOf(payload))); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this)) + + try(Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -217,7 +212,7 @@ public class TestABCase2 extends AbstractABCase @Test public void testCase2_5() throws Exception { - try (StacklessLogging scope = new StacklessLogging(Parser.class)) + try (StacklessLogging ignored = new StacklessLogging(Parser.class)) { byte payload[] = new byte[126]; // intentionally too big Arrays.fill(payload,(byte)'5'); @@ -230,13 +225,12 @@ public class TestABCase2 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this)) + + try(Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } } @@ -258,14 +252,12 @@ public class TestABCase2 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new PongFrame().setPayload(copyOf(payload))); expect.add(new CloseInfo(StatusCode.NORMAL,"Test 2.6").asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this)) + + try(Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.SLOW); - fuzzer.setSlowSendSegmentSize(1); - fuzzer.send(send); - fuzzer.expect(expect); + session.slowMode(1); + session.send(send); + session.expect(expect); } } @@ -282,13 +274,12 @@ public class TestABCase2 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this)) + + try(Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -305,13 +296,12 @@ public class TestABCase2 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this)) + + try(Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -330,13 +320,12 @@ public class TestABCase2 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new PongFrame().setPayload("our ping")); // our pong expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this)) + + try(Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } } diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase3.java b/jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/TestABCase3.java similarity index 75% rename from jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase3.java rename to jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/TestABCase3.java index 00f93eb942f..3984acd32cb 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase3.java +++ b/jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/TestABCase3.java @@ -16,7 +16,7 @@ // ======================================================================== // -package org.eclipse.jetty.websocket.server.ab; +package org.eclipse.jetty.websocket.tests.server; import java.util.ArrayList; import java.util.Arrays; @@ -31,7 +31,7 @@ import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.frames.BinaryFrame; import org.eclipse.jetty.websocket.common.frames.PingFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame; -import org.eclipse.jetty.websocket.common.test.Fuzzer; +import org.eclipse.jetty.websocket.tests.Fuzzer; import org.junit.Test; import org.junit.runner.RunWith; @@ -51,13 +51,13 @@ public class TestABCase3 extends AbstractABCase WebSocketFrame send = new TextFrame().setPayload("small").setRsv1(true); // intentionally bad WebSocketFrame expect = new CloseInfo(StatusCode.PROTOCOL).asFrame(); - - try (Fuzzer fuzzer = new Fuzzer(this); StacklessLogging logging = new StacklessLogging(Parser.class)) + + try (StacklessLogging ignored = new StacklessLogging(Parser.class); + Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -76,13 +76,13 @@ public class TestABCase3 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new TextFrame().setPayload("small")); // echo on good frame expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this); StacklessLogging logging = new StacklessLogging(Parser.class)) + + try (StacklessLogging ignored = new StacklessLogging(Parser.class); + Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -102,12 +102,12 @@ public class TestABCase3 extends AbstractABCase expect.add(new TextFrame().setPayload("small")); // echo on good frame expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); - try (Fuzzer fuzzer = new Fuzzer(this); StacklessLogging logging = new StacklessLogging(Parser.class)) + try (StacklessLogging ignored = new StacklessLogging(Parser.class); + Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.PER_FRAME); - fuzzer.send(send); - fuzzer.expect(expect); + session.perFrameMode(); + session.send(send); + session.expect(expect); } } @@ -127,13 +127,12 @@ public class TestABCase3 extends AbstractABCase expect.add(new TextFrame().setPayload("small")); // echo on good frame expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); - try (Fuzzer fuzzer = new Fuzzer(this); StacklessLogging logging = new StacklessLogging(Parser.class)) + try (StacklessLogging ignored = new StacklessLogging(Parser.class); + Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.SLOW); - fuzzer.setSlowSendSegmentSize(1); - fuzzer.send(send); - fuzzer.expect(expect); + session.slowMode(1); + session.send(send); + session.expect(expect); } } @@ -152,13 +151,13 @@ public class TestABCase3 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this); StacklessLogging logging = new StacklessLogging(Parser.class)) + + try (StacklessLogging ignored = new StacklessLogging(Parser.class); + Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -178,12 +177,12 @@ public class TestABCase3 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); - try (Fuzzer fuzzer = new Fuzzer(this); StacklessLogging logging = new StacklessLogging(Parser.class)) + try (StacklessLogging ignored = new StacklessLogging(Parser.class); + Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -206,13 +205,13 @@ public class TestABCase3 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this); StacklessLogging logging = new StacklessLogging(Parser.class)) + + try (StacklessLogging ignored = new StacklessLogging(Parser.class); + Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } } diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase4.java b/jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/TestABCase4.java similarity index 73% rename from jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase4.java rename to jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/TestABCase4.java index 731df156776..4e75730424b 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase4.java +++ b/jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/TestABCase4.java @@ -16,7 +16,7 @@ // ======================================================================== // -package org.eclipse.jetty.websocket.server.ab; +package org.eclipse.jetty.websocket.tests.server; import java.nio.ByteBuffer; import java.util.ArrayList; @@ -31,7 +31,7 @@ import org.eclipse.jetty.websocket.common.Parser; import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.frames.PingFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame; -import org.eclipse.jetty.websocket.common.test.Fuzzer; +import org.eclipse.jetty.websocket.tests.Fuzzer; import org.junit.Test; import org.junit.runner.RunWith; @@ -53,13 +53,13 @@ public class TestABCase4 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this); StacklessLogging logging = new StacklessLogging(Parser.class)) + + try (StacklessLogging ignored = new StacklessLogging(Parser.class); + Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -78,13 +78,13 @@ public class TestABCase4 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this); StacklessLogging logging = new StacklessLogging(Parser.class)) + + try (StacklessLogging ignored = new StacklessLogging(Parser.class); + Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -103,13 +103,13 @@ public class TestABCase4 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new TextFrame().setPayload("hello")); // echo expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this); StacklessLogging logging = new StacklessLogging(Parser.class)) + + try (StacklessLogging ignored = new StacklessLogging(Parser.class); + Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -130,13 +130,13 @@ public class TestABCase4 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new TextFrame().setPayload("hello")); // echo expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this); StacklessLogging logging = new StacklessLogging(Parser.class)) + + try (StacklessLogging ignored = new StacklessLogging(Parser.class); + Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -157,13 +157,13 @@ public class TestABCase4 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new TextFrame().setPayload("hello")); // echo expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this); StacklessLogging logging = new StacklessLogging(Parser.class)) + + try (StacklessLogging ignored = new StacklessLogging(Parser.class); + Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -179,13 +179,13 @@ public class TestABCase4 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this); StacklessLogging logging = new StacklessLogging(Parser.class)) + + try (StacklessLogging ignored = new StacklessLogging(Parser.class); + Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -203,13 +203,13 @@ public class TestABCase4 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this); StacklessLogging logging = new StacklessLogging(Parser.class)) + + try (StacklessLogging ignored = new StacklessLogging(Parser.class); + Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -228,13 +228,13 @@ public class TestABCase4 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new TextFrame().setPayload("hello")); // echo expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this); StacklessLogging logging = new StacklessLogging(Parser.class)) + + try (StacklessLogging ignored = new StacklessLogging(Parser.class); + Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -255,13 +255,13 @@ public class TestABCase4 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new TextFrame().setPayload("hello")); // echo expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this); StacklessLogging logging = new StacklessLogging(Parser.class)) + + try (StacklessLogging ignored = new StacklessLogging(Parser.class); + Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -282,13 +282,13 @@ public class TestABCase4 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new TextFrame().setPayload("hello")); // echo expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this); StacklessLogging logging = new StacklessLogging(Parser.class)) + + try (StacklessLogging ignored = new StacklessLogging(Parser.class); + Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } } diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase5.java b/jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/TestABCase5.java similarity index 73% rename from jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase5.java rename to jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/TestABCase5.java index 2b5c9be479c..8a56e065f74 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase5.java +++ b/jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/TestABCase5.java @@ -16,7 +16,7 @@ // ======================================================================== // -package org.eclipse.jetty.websocket.server.ab; +package org.eclipse.jetty.websocket.tests.server; import java.util.ArrayList; import java.util.List; @@ -33,7 +33,7 @@ import org.eclipse.jetty.websocket.common.frames.ContinuationFrame; import org.eclipse.jetty.websocket.common.frames.PingFrame; import org.eclipse.jetty.websocket.common.frames.PongFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame; -import org.eclipse.jetty.websocket.common.test.Fuzzer; +import org.eclipse.jetty.websocket.tests.Fuzzer; import org.junit.Test; import org.junit.runner.RunWith; @@ -45,6 +45,7 @@ public class TestABCase5 extends AbstractABCase { /** * Send ping fragmented in 2 packets + * * @throws Exception on test failure */ @Test @@ -54,21 +55,22 @@ public class TestABCase5 extends AbstractABCase send.add(new PingFrame().setPayload("hello, ").setFin(false)); send.add(new ContinuationFrame().setPayload("world")); send.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - + List expect = new ArrayList<>(); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this);StacklessLogging supress = new StacklessLogging(Parser.class)) + + try (StacklessLogging ignored = new StacklessLogging(Parser.class); + Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } - } - + } + /** * Send continuation+fin, then text+fin (framewise) + * * @throws Exception on test failure */ @Test @@ -78,21 +80,23 @@ public class TestABCase5 extends AbstractABCase send.add(new ContinuationFrame().setPayload("sorry").setFin(true)); send.add(new TextFrame().setPayload("hello, world")); send.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - + List expect = new ArrayList<>(); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this);StacklessLogging supress = new StacklessLogging(Parser.class)) + + try (StacklessLogging ignored = new StacklessLogging(Parser.class); + Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.PER_FRAME); - fuzzer.sendAndIgnoreBrokenPipe(send); - fuzzer.expect(expect); + session.perFrameMode(); + session.ignoreBrokenPipe(); + session.send(send); + session.expect(expect); } } - + /** * Send continuation+fin, then text+fin (slowly) + * * @throws Exception on test failure */ @Test @@ -102,22 +106,23 @@ public class TestABCase5 extends AbstractABCase send.add(new ContinuationFrame().setPayload("sorry").setFin(true)); send.add(new TextFrame().setPayload("hello, world")); send.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - + List expect = new ArrayList<>(); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this);StacklessLogging supress = new StacklessLogging(Parser.class)) + + try (StacklessLogging ignored = new StacklessLogging(Parser.class); + Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.SLOW); - fuzzer.setSlowSendSegmentSize(1); - fuzzer.sendAndIgnoreBrokenPipe(send); - fuzzer.expect(expect); + session.slowMode(1); + session.ignoreBrokenPipe(); + session.send(send); + session.expect(expect); } } - + /** * Send continuation+!fin, then text+fin + * * @throws Exception on test failure */ @Test @@ -127,21 +132,23 @@ public class TestABCase5 extends AbstractABCase send.add(new ContinuationFrame().setPayload("sorry").setFin(false)); send.add(new TextFrame().setPayload("hello, world")); send.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - + List expect = new ArrayList<>(); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this);StacklessLogging supress = new StacklessLogging(Parser.class)) + + try (StacklessLogging ignored = new StacklessLogging(Parser.class); + Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.sendAndIgnoreBrokenPipe(send); - fuzzer.expect(expect); + session.bulkMode(); + session.ignoreBrokenPipe(); + session.send(send); + session.expect(expect); } } - + /** * Send continuation+!fin, then text+fin (framewise) + * * @throws Exception on test failure */ @Test @@ -151,21 +158,23 @@ public class TestABCase5 extends AbstractABCase send.add(new ContinuationFrame().setPayload("sorry").setFin(false)); send.add(new TextFrame().setPayload("hello, world")); send.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - + List expect = new ArrayList<>(); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this);StacklessLogging supress = new StacklessLogging(Parser.class)) + + try (StacklessLogging ignored = new StacklessLogging(Parser.class); + Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.PER_FRAME); - fuzzer.sendAndIgnoreBrokenPipe(send); - fuzzer.expect(expect); + session.perFrameMode(); + session.ignoreBrokenPipe(); + session.send(send); + session.expect(expect); } } - + /** * Send continuation+!fin, then text+fin (slowly) + * * @throws Exception on test failure */ @Test @@ -175,22 +184,23 @@ public class TestABCase5 extends AbstractABCase send.add(new ContinuationFrame().setPayload("sorry").setFin(false)); send.add(new TextFrame().setPayload("hello, world")); send.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - + List expect = new ArrayList<>(); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this);StacklessLogging supress = new StacklessLogging(Parser.class)) + + try (StacklessLogging ignored = new StacklessLogging(Parser.class); + Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.SLOW); - fuzzer.setSlowSendSegmentSize(1); - fuzzer.sendAndIgnoreBrokenPipe(send); - fuzzer.expect(expect); + session.slowMode(1); + session.ignoreBrokenPipe(); + session.send(send); + session.expect(expect); } } - + /** * Send text fragmented properly in 2 frames, then continuation!fin, then text unfragmented. + * * @throws Exception on test failure */ @Test @@ -202,22 +212,23 @@ public class TestABCase5 extends AbstractABCase send.add(new ContinuationFrame().setPayload("fragment3").setFin(false)); // bad frame send.add(new TextFrame().setPayload("fragment4").setFin(true)); send.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - + List expect = new ArrayList<>(); expect.add(new TextFrame().setPayload("fragment1fragment2")); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this);StacklessLogging supress = new StacklessLogging(Parser.class)) + + try (StacklessLogging ignored = new StacklessLogging(Parser.class); + Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } - + /** * (continuation!fin, text!fin, continuation+fin) * 2 + * * @throws Exception on test failure */ @Test @@ -231,21 +242,23 @@ public class TestABCase5 extends AbstractABCase send.add(new TextFrame().setPayload("fragment5").setFin(false)); send.add(new ContinuationFrame().setPayload("fragment6").setFin(true)); send.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - + List expect = new ArrayList<>(); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this);StacklessLogging supress = new StacklessLogging(Parser.class)) + + try (StacklessLogging ignored = new StacklessLogging(Parser.class); + Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.sendAndIgnoreBrokenPipe(send); - fuzzer.expect(expect); + session.bulkMode(); + session.ignoreBrokenPipe(); + session.send(send); + session.expect(expect); } } - + /** * (continuation+fin, text!fin, continuation+fin) * 2 + * * @throws Exception on test failure */ @Test @@ -259,21 +272,22 @@ public class TestABCase5 extends AbstractABCase send.add(new TextFrame().setPayload("fragment5").setFin(false)); send.add(new ContinuationFrame().setPayload("fragment6").setFin(true)); send.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - + List expect = new ArrayList<>(); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this);StacklessLogging supress = new StacklessLogging(Parser.class)) + + try (StacklessLogging ignored = new StacklessLogging(Parser.class); + Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } - + /** * text message fragmented in 2 frames, both frames as opcode=TEXT + * * @throws Exception on test failure */ @Test @@ -283,21 +297,22 @@ public class TestABCase5 extends AbstractABCase send.add(new TextFrame().setPayload("fragment1").setFin(false)); send.add(new TextFrame().setPayload("fragment2").setFin(true)); // bad frame, must be continuation send.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - + List expect = new ArrayList<>(); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this);StacklessLogging supress = new StacklessLogging(Parser.class)) + + try (StacklessLogging ignored = new StacklessLogging(Parser.class); + Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } - + /** * send text message fragmented in 5 frames, with 2 pings and wait between. + * * @throws Exception on test failure */ @Test @@ -309,10 +324,10 @@ public class TestABCase5 extends AbstractABCase send1.add(new TextFrame().setPayload("f1").setFin(false)); send1.add(new ContinuationFrame().setPayload(",f2").setFin(false)); send1.add(new PingFrame().setPayload("pong-1")); - + List expect1 = new ArrayList<>(); expect1.add(new PongFrame().setPayload("pong-1")); - + // phase 2 List send2 = new ArrayList<>(); send2.add(new ContinuationFrame().setPayload(",f3").setFin(false)); @@ -320,32 +335,33 @@ public class TestABCase5 extends AbstractABCase send2.add(new PingFrame().setPayload("pong-2")); send2.add(new ContinuationFrame().setPayload(",f5").setFin(true)); send2.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - + List expect2 = new ArrayList<>(); expect2.add(new PongFrame().setPayload("pong-2")); expect2.add(new TextFrame().setPayload("f1,f2,f3,f4,f5")); expect2.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this);StacklessLogging supress = new StacklessLogging(Parser.class)) + + try (StacklessLogging ignored = new StacklessLogging(Parser.class); + Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - + session.bulkMode(); + // phase 1 - fuzzer.send(send1); - fuzzer.expect(expect1); - + session.send(send1); + session.expect(expect1); + // delay TimeUnit.SECONDS.sleep(1); - + // phase 2 - fuzzer.send(send2); - fuzzer.expect(expect2); + session.send(send2); + session.expect(expect2); } } - + /** * Send pong fragmented in 2 packets + * * @throws Exception on test failure */ @Test @@ -355,21 +371,22 @@ public class TestABCase5 extends AbstractABCase send.add(new PongFrame().setPayload("hello, ").setFin(false)); send.add(new ContinuationFrame().setPayload("world")); send.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - + List expect = new ArrayList<>(); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this);StacklessLogging supress = new StacklessLogging(Parser.class)) + + try (StacklessLogging ignored = new StacklessLogging(Parser.class); + Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } - + /** * send text message fragmented in 5 frames, with 2 pings and wait between. (framewise) + * * @throws Exception on test failure */ @Test @@ -379,39 +396,39 @@ public class TestABCase5 extends AbstractABCase send1.add(new TextFrame().setPayload("f1").setFin(false)); send1.add(new ContinuationFrame().setPayload(",f2").setFin(false)); send1.add(new PingFrame().setPayload("pong-1")); - + List send2 = new ArrayList<>(); send2.add(new ContinuationFrame().setPayload(",f3").setFin(false)); send2.add(new ContinuationFrame().setPayload(",f4").setFin(false)); send2.add(new PingFrame().setPayload("pong-2")); send2.add(new ContinuationFrame().setPayload(",f5").setFin(true)); send2.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - + List expect1 = new ArrayList<>(); expect1.add(new PongFrame().setPayload("pong-1")); - + List expect2 = new ArrayList<>(); expect2.add(new PongFrame().setPayload("pong-2")); expect2.add(new TextFrame().setPayload("f1,f2,f3,f4,f5")); expect2.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this);StacklessLogging supress = new StacklessLogging(Parser.class)) + + try (StacklessLogging ignored = new StacklessLogging(Parser.class); + Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.PER_FRAME); - - fuzzer.send(send1); - fuzzer.expect(expect1); - + session.perFrameMode(); + session.send(send1); + session.expect(expect1); + TimeUnit.SECONDS.sleep(1); - - fuzzer.send(send2); - fuzzer.expect(expect2); + + session.send(send2); + session.expect(expect2); } } - + /** * send text message fragmented in 5 frames, with 2 pings and wait between. (framewise) + * * @throws Exception on test failure */ @Test @@ -421,40 +438,39 @@ public class TestABCase5 extends AbstractABCase send1.add(new TextFrame().setPayload("f1").setFin(false)); send1.add(new ContinuationFrame().setPayload(",f2").setFin(false)); send1.add(new PingFrame().setPayload("pong-1")); - + List send2 = new ArrayList<>(); send2.add(new ContinuationFrame().setPayload(",f3").setFin(false)); send2.add(new ContinuationFrame().setPayload(",f4").setFin(false)); send2.add(new PingFrame().setPayload("pong-2")); send2.add(new ContinuationFrame().setPayload(",f5").setFin(true)); send2.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - + List expect1 = new ArrayList<>(); expect1.add(new PongFrame().setPayload("pong-1")); - + List expect2 = new ArrayList<>(); expect2.add(new PongFrame().setPayload("pong-2")); expect2.add(new TextFrame().setPayload("f1,f2,f3,f4,f5")); expect2.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this);StacklessLogging supress = new StacklessLogging(Parser.class)) + + try (StacklessLogging ignored = new StacklessLogging(Parser.class); + Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.SLOW); - fuzzer.setSlowSendSegmentSize(1); - - fuzzer.send(send1); - fuzzer.expect(expect1); - + session.slowMode(1); + session.send(send1); + session.expect(expect1); + TimeUnit.SECONDS.sleep(1); - - fuzzer.send(send2); - fuzzer.expect(expect2); + + session.send(send2); + session.expect(expect2); } } - + /** * Send text fragmented in 2 packets + * * @throws Exception on test failure */ @Test @@ -464,22 +480,23 @@ public class TestABCase5 extends AbstractABCase send.add(new TextFrame().setPayload("hello, ").setFin(false)); send.add(new ContinuationFrame().setPayload("world").setFin(true)); send.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - + List expect = new ArrayList<>(); expect.add(new TextFrame().setPayload("hello, world")); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this);StacklessLogging supress = new StacklessLogging(Parser.class)) + + try (StacklessLogging ignored = new StacklessLogging(Parser.class); + Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } - + /** * Send text fragmented in 2 packets (framewise) + * * @throws Exception on test failure */ @Test @@ -489,22 +506,23 @@ public class TestABCase5 extends AbstractABCase send.add(new TextFrame().setPayload("hello, ").setFin(false)); send.add(new ContinuationFrame().setPayload("world").setFin(true)); send.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - + List expect = new ArrayList<>(); expect.add(new TextFrame().setPayload("hello, world")); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this);StacklessLogging supress = new StacklessLogging(Parser.class)) + + try (StacklessLogging ignored = new StacklessLogging(Parser.class); + Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.PER_FRAME); - fuzzer.send(send); - fuzzer.expect(expect); + session.perFrameMode(); + session.send(send); + session.expect(expect); } } - + /** * Send text fragmented in 2 packets (slowly) + * * @throws Exception on test failure */ @Test @@ -514,23 +532,23 @@ public class TestABCase5 extends AbstractABCase send.add(new TextFrame().setPayload("hello, ").setFin(false)); send.add(new ContinuationFrame().setPayload("world").setFin(true)); send.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - + List expect = new ArrayList<>(); expect.add(new TextFrame().setPayload("hello, world")); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this);StacklessLogging supress = new StacklessLogging(Parser.class)) + + try (StacklessLogging ignored = new StacklessLogging(Parser.class); + Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.SLOW); - fuzzer.setSlowSendSegmentSize(1); - fuzzer.send(send); - fuzzer.expect(expect); + session.slowMode(1); + session.send(send); + session.expect(expect); } } - + /** * Send text fragmented in 2 packets, with ping between them + * * @throws Exception on test failure */ @Test @@ -541,23 +559,24 @@ public class TestABCase5 extends AbstractABCase send.add(new PingFrame().setPayload("ping")); send.add(new ContinuationFrame().setPayload("world").setFin(true)); send.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - + List expect = new ArrayList<>(); expect.add(new PongFrame().setPayload("ping")); expect.add(new TextFrame().setPayload("hello, world")); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this);StacklessLogging supress = new StacklessLogging(Parser.class)) + + try (StacklessLogging ignored = new StacklessLogging(Parser.class); + Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } - + /** * Send text fragmented in 2 packets, with ping between them (frame wise) + * * @throws Exception on test failure */ @Test @@ -568,23 +587,24 @@ public class TestABCase5 extends AbstractABCase send.add(new PingFrame().setPayload("ping")); send.add(new ContinuationFrame().setPayload("world").setFin(true)); send.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - + List expect = new ArrayList<>(); expect.add(new PongFrame().setPayload("ping")); expect.add(new TextFrame().setPayload("hello, world")); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this);StacklessLogging supress = new StacklessLogging(Parser.class)) + + try (StacklessLogging ignored = new StacklessLogging(Parser.class); + Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.PER_FRAME); - fuzzer.send(send); - fuzzer.expect(expect); + session.perFrameMode(); + session.send(send); + session.expect(expect); } } - + /** * Send text fragmented in 2 packets, with ping between them (slowly) + * * @throws Exception on test failure */ @Test @@ -595,44 +615,44 @@ public class TestABCase5 extends AbstractABCase send.add(new PingFrame().setPayload("ping")); send.add(new ContinuationFrame().setPayload("world").setFin(true)); send.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - + List expect = new ArrayList<>(); expect.add(new PongFrame().setPayload("ping")); expect.add(new TextFrame().setPayload("hello, world")); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this);StacklessLogging supress = new StacklessLogging(Parser.class)) + + try (StacklessLogging ignored = new StacklessLogging(Parser.class); + Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.SLOW); - fuzzer.setSlowSendSegmentSize(1); - fuzzer.send(send); - fuzzer.expect(expect); + session.slowMode(1); + session.send(send); + session.expect(expect); } } - + /** * Send continuation+fin, then text+fin + * * @throws Exception on test failure */ @Test public void testCase5_9() throws Exception { - + List send = new ArrayList<>(); send.add(new ContinuationFrame().setPayload("sorry").setFin(true)); send.add(new TextFrame().setPayload("hello, world")); send.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - + List expect = new ArrayList<>(); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this);StacklessLogging supress = new StacklessLogging(Parser.class)) + + try (StacklessLogging ignored = new StacklessLogging(Parser.class); + Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } } diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase6.java b/jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/TestABCase6.java similarity index 77% rename from jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase6.java rename to jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/TestABCase6.java index 54382e1a100..2367638e0f0 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase6.java +++ b/jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/TestABCase6.java @@ -16,7 +16,7 @@ // ======================================================================== // -package org.eclipse.jetty.websocket.server.ab; +package org.eclipse.jetty.websocket.tests.server; import java.nio.ByteBuffer; import java.util.ArrayList; @@ -24,6 +24,7 @@ import java.util.List; import java.util.concurrent.TimeUnit; import org.eclipse.jetty.toolchain.test.AdvancedRunner; +import org.eclipse.jetty.toolchain.test.Hex; import org.eclipse.jetty.toolchain.test.annotation.Slow; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.StringUtil; @@ -36,8 +37,7 @@ import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.frames.ContinuationFrame; import org.eclipse.jetty.websocket.common.frames.DataFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame; -import org.eclipse.jetty.websocket.common.test.Fuzzer; -import org.eclipse.jetty.websocket.common.util.Hex; +import org.eclipse.jetty.websocket.tests.Fuzzer; import org.junit.Test; import org.junit.runner.RunWith; @@ -92,13 +92,12 @@ public class TestABCase6 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new TextFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this)) + + try (Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -118,13 +117,12 @@ public class TestABCase6 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new TextFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this)) + + try (Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -144,13 +142,12 @@ public class TestABCase6 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new TextFrame().setPayload("middle")); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this)) + + try (Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -179,13 +176,12 @@ public class TestABCase6 extends AbstractABCase e1.flip(); expect.add(new TextFrame().setPayload(e1)); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this)) + + try (Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -206,13 +202,12 @@ public class TestABCase6 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new TextFrame().setPayload(ByteBuffer.wrap(msg))); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this)) + + try (Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -232,13 +227,12 @@ public class TestABCase6 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new TextFrame().setPayload(ByteBuffer.wrap(msg))); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this)) + + try (Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -257,13 +251,12 @@ public class TestABCase6 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this)) + + try (Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -285,19 +278,17 @@ public class TestABCase6 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this)) + + try (Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - - fuzzer.send(new TextFrame().setPayload(ByteBuffer.wrap(part1)).setFin(false)); + session.bulkMode(); + session.send(new TextFrame().setPayload(ByteBuffer.wrap(part1)).setFin(false)); TimeUnit.SECONDS.sleep(1); - fuzzer.send(new ContinuationFrame().setPayload(ByteBuffer.wrap(part2)).setFin(false)); + session.send(new ContinuationFrame().setPayload(ByteBuffer.wrap(part2)).setFin(false)); TimeUnit.SECONDS.sleep(1); - fuzzer.send(new ContinuationFrame().setPayload(ByteBuffer.wrap(part3)).setFin(true)); - - fuzzer.expect(expect); + session.send(new ContinuationFrame().setPayload(ByteBuffer.wrap(part3)).setFin(true)); + + session.expect(expect); } } @@ -321,17 +312,16 @@ public class TestABCase6 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this)) + + try (Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(new TextFrame().setPayload(ByteBuffer.wrap(part1)).setFin(false)); + session.bulkMode(); + session.send(new TextFrame().setPayload(ByteBuffer.wrap(part1)).setFin(false)); TimeUnit.SECONDS.sleep(1); - fuzzer.send(new ContinuationFrame().setPayload(ByteBuffer.wrap(part2)).setFin(false)); + session.send(new ContinuationFrame().setPayload(ByteBuffer.wrap(part2)).setFin(false)); TimeUnit.SECONDS.sleep(1); - fuzzer.send(new ContinuationFrame().setPayload(ByteBuffer.wrap(part3)).setFin(true)); - fuzzer.expect(expect); + session.send(new ContinuationFrame().setPayload(ByteBuffer.wrap(part3)).setFin(true)); + session.expect(expect); } } @@ -344,7 +334,7 @@ public class TestABCase6 extends AbstractABCase public void testCase6_4_3() throws Exception { // Disable Long Stacks from Parser (we know this test will throw an exception) - try (StacklessLogging scope = new StacklessLogging(Parser.class)) + try (StacklessLogging ignored = new StacklessLogging(Parser.class)) { ByteBuffer payload = ByteBuffer.allocate(64); BufferUtil.clearToFill(payload); @@ -359,12 +349,11 @@ public class TestABCase6 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame()); - - try (Fuzzer fuzzer = new Fuzzer(this)) + + try (Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - - ByteBuffer net = fuzzer.asNetworkBuffer(send); + session.bulkMode(); + ByteBuffer net = session.asNetworkBuffer(send); int splits[] = { 17, 21, net.limit() }; @@ -376,14 +365,14 @@ public class TestABCase6 extends AbstractABCase ByteBuffer part3 = net.slice(); // good UTF part3.position(splits[1]); part3.limit(splits[2]); - - fuzzer.send(part1); // the header + good utf + + session.send(part1); // the header + good utf TimeUnit.MILLISECONDS.sleep(500); - fuzzer.send(part2); // the bad UTF + session.send(part2); // the bad UTF TimeUnit.MILLISECONDS.sleep(500); - fuzzer.send(part3); // the rest (shouldn't work) - - fuzzer.expect(expect); + session.send(part3); // the rest (shouldn't work) + + session.expect(expect); } } } @@ -405,20 +394,19 @@ public class TestABCase6 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame()); - try (Fuzzer fuzzer = new Fuzzer(this); - StacklessLogging scope = new StacklessLogging(Parser.class)) + try (StacklessLogging ignored = new StacklessLogging(Parser.class); + Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - - ByteBuffer net = fuzzer.asNetworkBuffer(send); - fuzzer.send(net,6); - fuzzer.send(net,11); + session.bulkMode(); + ByteBuffer net = session.asNetworkBuffer(send); + session.send(net,6); + session.send(net,11); TimeUnit.SECONDS.sleep(1); - fuzzer.send(net,1); + session.send(net,1); TimeUnit.SECONDS.sleep(1); - fuzzer.send(net,100); // the rest - - fuzzer.expect(expect); + session.send(net,100); // the rest + + session.expect(expect); } } } diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase6_BadUTF.java b/jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/TestABCase6_BadUTF.java similarity index 94% rename from jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase6_BadUTF.java rename to jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/TestABCase6_BadUTF.java index 997110cf903..6a41f129bed 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase6_BadUTF.java +++ b/jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/TestABCase6_BadUTF.java @@ -16,13 +16,14 @@ // ======================================================================== // -package org.eclipse.jetty.websocket.server.ab; +package org.eclipse.jetty.websocket.tests.server; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import org.eclipse.jetty.toolchain.test.Hex; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.StacklessLogging; @@ -31,8 +32,7 @@ import org.eclipse.jetty.websocket.common.CloseInfo; import org.eclipse.jetty.websocket.common.Parser; import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame; -import org.eclipse.jetty.websocket.common.test.Fuzzer; -import org.eclipse.jetty.websocket.common.util.Hex; +import org.eclipse.jetty.websocket.tests.Fuzzer; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -163,13 +163,12 @@ public class TestABCase6_BadUTF extends AbstractABCase List expect = new ArrayList<>(); expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame()); - try (Fuzzer fuzzer = new Fuzzer(this); - StacklessLogging ignored = new StacklessLogging(Parser.class) ) + try (StacklessLogging ignored = new StacklessLogging(Parser.class); + Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } } diff --git a/jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/TestABCase6_GoodUTF.java b/jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/TestABCase6_GoodUTF.java new file mode 100644 index 00000000000..d3861e4f2c0 --- /dev/null +++ b/jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/TestABCase6_GoodUTF.java @@ -0,0 +1,149 @@ +// +// ======================================================================== +// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.eclipse.jetty.websocket.tests.server; + +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.eclipse.jetty.toolchain.test.Hex; +import org.eclipse.jetty.util.log.Log; +import org.eclipse.jetty.util.log.Logger; +import org.eclipse.jetty.websocket.api.StatusCode; +import org.eclipse.jetty.websocket.common.CloseInfo; +import org.eclipse.jetty.websocket.common.WebSocketFrame; +import org.eclipse.jetty.websocket.common.frames.TextFrame; +import org.eclipse.jetty.websocket.tests.Fuzzer; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +/** + * Tests of Known Good UTF8 sequences. + *

+ * Should be preserved / echoed back, with normal close code. + */ +@RunWith(Parameterized.class) +public class TestABCase6_GoodUTF extends AbstractABCase +{ + private static final Logger LOG = Log.getLogger(TestABCase6_GoodUTF.class); + + @Parameters(name = "{0} - {1}") + public static Collection data() + { + // The various Good UTF8 sequences as a String (hex form) + List data = new ArrayList<>(); + + // @formatter:off + // - combination of simple 1 byte characters and unicode code points + data.add(new String[]{"6.2.1", "48656C6C6F2DC2B540C39FC3B6C3A4C3BCC3A0C3A12D5554462D382121"}); + // - simple valid UTF8 sequence + data.add(new String[]{"6.5.1", "CEBAE1BDB9CF83CEBCCEB5"}); + // - multi-byte code points + data.add(new String[]{"6.6.11", "CEBAE1BDB9CF83CEBCCEB5"}); + data.add(new String[]{"6.6.2", "CEBA"}); + data.add(new String[]{"6.6.5", "CEBAE1BDB9"}); + data.add(new String[]{"6.6.7", "CEBAE1BDB9CF83"}); + data.add(new String[]{"6.6.9", "CEBAE1BDB9CF83CEBC"}); + // - first possible sequence of a certain length (1 code point) + data.add(new String[]{"6.7.1", "00"}); + data.add(new String[]{"6.7.2", "C280"}); + data.add(new String[]{"6.7.3", "E0A080"}); + data.add(new String[]{"6.7.4", "F0908080"}); + // - last possible sequence of a certain length (1 code point) + data.add(new String[]{"6.9.1", "7F"}); + data.add(new String[]{"6.9.2", "DFBF"}); + data.add(new String[]{"6.9.3", "EFBFBF"}); + data.add(new String[]{"6.9.4", "F48FBFBF"}); + // - other boundary conditions + data.add(new String[]{"6.11.1", "ED9FBF"}); + data.add(new String[]{"6.11.2", "EE8080"}); + data.add(new String[]{"6.11.3", "EFBFBD"}); + data.add(new String[]{"6.11.4", "F48FBFBF"}); + // - non character code points + data.add(new String[]{"6.22.1", "EFBFBE"}); + data.add(new String[]{"6.22.2", "EFBFBF"}); + data.add(new String[]{"6.22.3", "F09FBFBE"}); + data.add(new String[]{"6.22.4", "F09FBFBF"}); + data.add(new String[]{"6.22.5", "F0AFBFBE"}); + data.add(new String[]{"6.22.6", "F0AFBFBF"}); + data.add(new String[]{"6.22.7", "F0BFBFBE"}); + data.add(new String[]{"6.22.8", "F0BFBFBF"}); + data.add(new String[]{"6.22.9", "F18FBFBE"}); + data.add(new String[]{"6.22.10", "F18FBFBF"}); + data.add(new String[]{"6.22.11", "F19FBFBE"}); + data.add(new String[]{"6.22.12", "F19FBFBF"}); + data.add(new String[]{"6.22.13", "F1AFBFBE"}); + data.add(new String[]{"6.22.14", "F1AFBFBF"}); + data.add(new String[]{"6.22.15", "F1BFBFBE"}); + data.add(new String[]{"6.22.16", "F1BFBFBF"}); + data.add(new String[]{"6.22.17", "F28FBFBE"}); + data.add(new String[]{"6.22.18", "F28FBFBF"}); + data.add(new String[]{"6.22.19", "F29FBFBE"}); + data.add(new String[]{"6.22.20", "F29FBFBF"}); + data.add(new String[]{"6.22.21", "F2AFBFBE"}); + data.add(new String[]{"6.22.22", "F2AFBFBF"}); + data.add(new String[]{"6.22.23", "F2BFBFBE"}); + data.add(new String[]{"6.22.24", "F2BFBFBF"}); + data.add(new String[]{"6.22.25", "F38FBFBE"}); + data.add(new String[]{"6.22.26", "F38FBFBF"}); + data.add(new String[]{"6.22.27", "F39FBFBE"}); + data.add(new String[]{"6.22.28", "F39FBFBF"}); + data.add(new String[]{"6.22.29", "F3AFBFBE"}); + data.add(new String[]{"6.22.30", "F3AFBFBF"}); + data.add(new String[]{"6.22.31", "F3BFBFBE"}); + data.add(new String[]{"6.22.32", "F3BFBFBF"}); + data.add(new String[]{"6.22.33", "F48FBFBE"}); + data.add(new String[]{"6.22.34", "F48FBFBF"}); + // - unicode replacement character + data.add(new String[]{"6.23.1", "EFBFBD"}); + // @formatter:on + + return data; + } + + private final ByteBuffer msg; + + public TestABCase6_GoodUTF(String testId, String hexMsg) + { + LOG.debug("Test ID: {}", testId); + this.msg = Hex.asByteBuffer(hexMsg); + } + + @Test + public void assertEchoTextMessage() throws Exception + { + List send = new ArrayList<>(); + send.add(new TextFrame().setPayload(msg)); + send.add(new CloseInfo(StatusCode.NORMAL).asFrame()); + + List expect = new ArrayList<>(); + expect.add(new TextFrame().setPayload(clone(msg))); + expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); + + try (Fuzzer.Session session = fuzzer.connect(this)) + { + session.bulkMode(); + session.send(send); + session.expect(expect); + } + } +} diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase7.java b/jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/TestABCase7.java similarity index 72% rename from jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase7.java rename to jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/TestABCase7.java index c7b37d05025..12d56ee27f7 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase7.java +++ b/jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/TestABCase7.java @@ -16,13 +16,14 @@ // ======================================================================== // -package org.eclipse.jetty.websocket.server.ab; +package org.eclipse.jetty.websocket.tests.server; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.eclipse.jetty.toolchain.test.Hex; import org.eclipse.jetty.toolchain.test.TestTracker; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.StringUtil; @@ -37,8 +38,7 @@ import org.eclipse.jetty.websocket.common.frames.ContinuationFrame; import org.eclipse.jetty.websocket.common.frames.PingFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame; import org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection; -import org.eclipse.jetty.websocket.common.test.Fuzzer; -import org.eclipse.jetty.websocket.common.util.Hex; +import org.eclipse.jetty.websocket.tests.Fuzzer; import org.junit.Rule; import org.junit.Test; @@ -64,13 +64,12 @@ public class TestABCase7 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new TextFrame().setPayload("Hello World")); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this)) + + try (Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -87,14 +86,12 @@ public class TestABCase7 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this)) + + try (Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); - fuzzer.expectNoMoreFrames(); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -111,14 +108,12 @@ public class TestABCase7 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this)) + + try (Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); - fuzzer.expectNoMoreFrames(); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -135,14 +130,12 @@ public class TestABCase7 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this)) + + try (Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); - fuzzer.expectNoMoreFrames(); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -160,14 +153,12 @@ public class TestABCase7 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this)) + + try (Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); - fuzzer.expectNoMoreFrames(); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -190,14 +181,12 @@ public class TestABCase7 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new TextFrame().setPayload(clone(buf))); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this)) + + try (Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); - fuzzer.expectNoMoreFrames(); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -213,14 +202,12 @@ public class TestABCase7 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new CloseFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this)) + + try (Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); - fuzzer.expectNoMoreFrames(); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -240,13 +227,12 @@ public class TestABCase7 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); - try (Fuzzer fuzzer = new Fuzzer(this); StacklessLogging scope = new StacklessLogging(Parser.class)) + try (StacklessLogging ignored = new StacklessLogging(Parser.class); + Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); - fuzzer.expectNoMoreFrames(); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -262,14 +248,12 @@ public class TestABCase7 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this)) + + try (Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); - fuzzer.expectNoMoreFrames(); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -285,14 +269,12 @@ public class TestABCase7 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new CloseInfo(StatusCode.NORMAL,"Hic").asFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this)) + + try (Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); - fuzzer.expectNoMoreFrames(); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -313,13 +295,12 @@ public class TestABCase7 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new CloseInfo(StatusCode.NORMAL,reason).asFrame()); - try (Fuzzer fuzzer = new Fuzzer(this); StacklessLogging logging = new StacklessLogging(AbstractWebSocketConnection.class)) + try (StacklessLogging ignored = new StacklessLogging(AbstractWebSocketConnection.class); + Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); - fuzzer.expectNoMoreFrames(); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -346,13 +327,12 @@ public class TestABCase7 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame()); - try (Fuzzer fuzzer = new Fuzzer(this); StacklessLogging scope = new StacklessLogging(Parser.class,CloseInfo.class)) + try (StacklessLogging ignored = new StacklessLogging(Parser.class,CloseInfo.class); + Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); - fuzzer.expectNoMoreFrames(); + session.bulkMode(); + session.send(send); + session.expect(expect); } } } diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase7_BadStatusCodes.java b/jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/TestABCase7_BadStatusCodes.java similarity index 67% rename from jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase7_BadStatusCodes.java rename to jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/TestABCase7_BadStatusCodes.java index a914953731a..703ef77ba9a 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase7_BadStatusCodes.java +++ b/jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/TestABCase7_BadStatusCodes.java @@ -16,7 +16,7 @@ // ======================================================================== // -package org.eclipse.jetty.websocket.server.ab; +package org.eclipse.jetty.websocket.tests.server; import java.nio.ByteBuffer; import java.util.ArrayList; @@ -31,7 +31,7 @@ import org.eclipse.jetty.websocket.api.StatusCode; import org.eclipse.jetty.websocket.common.CloseInfo; import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.frames.CloseFrame; -import org.eclipse.jetty.websocket.common.test.Fuzzer; +import org.eclipse.jetty.websocket.tests.Fuzzer; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -44,45 +44,46 @@ import org.junit.runners.Parameterized.Parameters; public class TestABCase7_BadStatusCodes extends AbstractABCase { private static final Logger LOG = Log.getLogger(TestABCase7_GoodStatusCodes.class); - + @Parameters public static Collection data() { // The various Good UTF8 sequences as a String (hex form) List data = new ArrayList<>(); - + // @formatter:off - data.add(new Object[] { "7.9.1", 0 }); - data.add(new Object[] { "7.9.2", 999 }); - data.add(new Object[] { "7.9.3", 1004 }); - data.add(new Object[] { "7.9.4", 1005 }); - data.add(new Object[] { "7.9.5", 1006 }); - data.add(new Object[] { "7.9.6", 1012 }); - data.add(new Object[] { "7.9.7", 1013 }); - data.add(new Object[] { "7.9.8", 1014 }); - data.add(new Object[] { "7.9.9", 1015 }); - data.add(new Object[] { "7.9.10", 1016 }); - data.add(new Object[] { "7.9.11", 1100 }); - data.add(new Object[] { "7.9.12", 2000 }); - data.add(new Object[] { "7.9.13", 2999 }); + data.add(new Object[]{"7.9.1", 0}); + data.add(new Object[]{"7.9.2", 999}); + data.add(new Object[]{"7.9.3", 1004}); + data.add(new Object[]{"7.9.4", 1005}); + data.add(new Object[]{"7.9.5", 1006}); + data.add(new Object[]{"7.9.6", 1012}); + data.add(new Object[]{"7.9.7", 1013}); + data.add(new Object[]{"7.9.8", 1014}); + data.add(new Object[]{"7.9.9", 1015}); + data.add(new Object[]{"7.9.10", 1016}); + data.add(new Object[]{"7.9.11", 1100}); + data.add(new Object[]{"7.9.12", 2000}); + data.add(new Object[]{"7.9.13", 2999}); // -- close status codes, with undefined events in spec - data.add(new Object[] { "7.13.1", 5000 }); - data.add(new Object[] { "7.13.2", 65536 }); + data.add(new Object[]{"7.13.1", 5000}); + data.add(new Object[]{"7.13.2", 65536}); // @formatter:on - + return data; } - + private final int statusCode; - + public TestABCase7_BadStatusCodes(String testId, int statusCode) { - LOG.debug("Test ID: {}",testId); + LOG.debug("Test ID: {}", testId); this.statusCode = statusCode; } - + /** * just the close code, no reason + * * @throws Exception on test failure */ @Test @@ -90,27 +91,26 @@ public class TestABCase7_BadStatusCodes extends AbstractABCase { ByteBuffer payload = ByteBuffer.allocate(256); BufferUtil.clearToFill(payload); - payload.putChar((char)statusCode); - BufferUtil.flipToFlush(payload,0); - + payload.putChar((char) statusCode); + BufferUtil.flipToFlush(payload, 0); + List send = new ArrayList<>(); send.add(new CloseFrame().setPayload(payload.slice())); - + List expect = new ArrayList<>(); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this)) + + try (Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); - fuzzer.expectNoMoreFrames(); + session.bulkMode(); + session.send(send); + session.expect(expect); } } - + /** * the bad close code, with reason + * * @throws Exception on test failure */ @Test @@ -118,23 +118,21 @@ public class TestABCase7_BadStatusCodes extends AbstractABCase { ByteBuffer payload = ByteBuffer.allocate(256); BufferUtil.clearToFill(payload); - payload.putChar((char)statusCode); + payload.putChar((char) statusCode); payload.put(StringUtil.getBytes("Reason")); - BufferUtil.flipToFlush(payload,0); - + BufferUtil.flipToFlush(payload, 0); + List send = new ArrayList<>(); send.add(new CloseFrame().setPayload(payload.slice())); - + List expect = new ArrayList<>(); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this)) + + try (Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); - fuzzer.expectNoMoreFrames(); + session.bulkMode(); + session.send(send); + session.expect(expect); } } } diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase7_GoodStatusCodes.java b/jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/TestABCase7_GoodStatusCodes.java similarity index 68% rename from jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase7_GoodStatusCodes.java rename to jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/TestABCase7_GoodStatusCodes.java index 7cb50f24b32..056b9959432 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase7_GoodStatusCodes.java +++ b/jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/TestABCase7_GoodStatusCodes.java @@ -16,7 +16,7 @@ // ======================================================================== // -package org.eclipse.jetty.websocket.server.ab; +package org.eclipse.jetty.websocket.tests.server; import java.nio.ByteBuffer; import java.util.ArrayList; @@ -29,7 +29,7 @@ import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.frames.CloseFrame; -import org.eclipse.jetty.websocket.common.test.Fuzzer; +import org.eclipse.jetty.websocket.tests.Fuzzer; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -42,42 +42,43 @@ import org.junit.runners.Parameterized.Parameters; public class TestABCase7_GoodStatusCodes extends AbstractABCase { private static final Logger LOG = Log.getLogger(TestABCase7_GoodStatusCodes.class); - + @Parameters public static Collection data() { // The various Good UTF8 sequences as a String (hex form) List data = new ArrayList<>(); - + // @formatter:off - data.add(new Object[] { "7.7.1", 1000 }); - data.add(new Object[] { "7.7.2", 1001 }); - data.add(new Object[] { "7.7.3", 1002 }); - data.add(new Object[] { "7.7.4", 1003 }); - data.add(new Object[] { "7.7.5", 1007 }); - data.add(new Object[] { "7.7.6", 1008 }); - data.add(new Object[] { "7.7.7", 1009 }); - data.add(new Object[] { "7.7.8", 1010 }); - data.add(new Object[] { "7.7.9", 1011 }); - data.add(new Object[] { "7.7.10", 3000 }); - data.add(new Object[] { "7.7.11", 3999 }); - data.add(new Object[] { "7.7.12", 4000 }); - data.add(new Object[] { "7.7.13", 4999 }); + data.add(new Object[]{"7.7.1", 1000}); + data.add(new Object[]{"7.7.2", 1001}); + data.add(new Object[]{"7.7.3", 1002}); + data.add(new Object[]{"7.7.4", 1003}); + data.add(new Object[]{"7.7.5", 1007}); + data.add(new Object[]{"7.7.6", 1008}); + data.add(new Object[]{"7.7.7", 1009}); + data.add(new Object[]{"7.7.8", 1010}); + data.add(new Object[]{"7.7.9", 1011}); + data.add(new Object[]{"7.7.10", 3000}); + data.add(new Object[]{"7.7.11", 3999}); + data.add(new Object[]{"7.7.12", 4000}); + data.add(new Object[]{"7.7.13", 4999}); // @formatter:on - + return data; } - + private final int statusCode; - + public TestABCase7_GoodStatusCodes(String testId, int statusCode) { - LOG.debug("Test ID: {}",testId); + LOG.debug("Test ID: {}", testId); this.statusCode = statusCode; } - + /** * just the close code, no reason + * * @throws Exception on test failure */ @Test @@ -85,50 +86,47 @@ public class TestABCase7_GoodStatusCodes extends AbstractABCase { ByteBuffer payload = ByteBuffer.allocate(256); BufferUtil.clearToFill(payload); - payload.putChar((char)statusCode); - BufferUtil.flipToFlush(payload,0); - + payload.putChar((char) statusCode); + BufferUtil.flipToFlush(payload, 0); + List send = new ArrayList<>(); send.add(new CloseFrame().setPayload(payload.slice())); - + List expect = new ArrayList<>(); expect.add(new CloseFrame().setPayload(clone(payload))); - - try(Fuzzer fuzzer = new Fuzzer(this)) + + try (Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); - fuzzer.expectNoMoreFrames(); + session.bulkMode(); + session.send(send); + session.expect(expect); } } - + /** * the good close code, with reason + * * @throws Exception on test failure */ @Test public void testStatusCodeWithReason() throws Exception { ByteBuffer payload = ByteBuffer.allocate(256); - payload.putChar((char)statusCode); + payload.putChar((char) statusCode); payload.put(StringUtil.getBytes("Reason")); payload.flip(); - + List send = new ArrayList<>(); send.add(new CloseFrame().setPayload(payload.slice())); - + List expect = new ArrayList<>(); expect.add(new CloseFrame().setPayload(clone(payload))); - - try(Fuzzer fuzzer = new Fuzzer(this)) + + try (Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); - fuzzer.expectNoMoreFrames(); + session.bulkMode(); + session.send(send); + session.expect(expect); } } } diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase9.java b/jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/TestABCase9.java similarity index 86% rename from jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase9.java rename to jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/TestABCase9.java index 75221aa5ccc..3d9dbf1c0ba 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase9.java +++ b/jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/TestABCase9.java @@ -16,7 +16,7 @@ // ======================================================================== // -package org.eclipse.jetty.websocket.server.ab; +package org.eclipse.jetty.websocket.tests.server; import java.nio.ByteBuffer; import java.util.ArrayList; @@ -35,7 +35,7 @@ import org.eclipse.jetty.websocket.common.frames.BinaryFrame; import org.eclipse.jetty.websocket.common.frames.ContinuationFrame; import org.eclipse.jetty.websocket.common.frames.DataFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame; -import org.eclipse.jetty.websocket.common.test.Fuzzer; +import org.eclipse.jetty.websocket.tests.Fuzzer; import org.junit.Test; import org.junit.runner.RunWith; @@ -95,13 +95,12 @@ public class TestABCase9 extends AbstractABCase List expect = new ArrayList<>(); expect.add(toDataFrame(opcode).setPayload(copyOf(msg))); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this)) + + try(Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect,8,TimeUnit.SECONDS); + session.bulkMode(); + session.send(send); + session.expect(expect, 32, TimeUnit.SECONDS); } } @@ -118,14 +117,12 @@ public class TestABCase9 extends AbstractABCase List expect = new ArrayList<>(); expect.add(toDataFrame(opcode).setPayload(clone(buf))); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this)) + + try(Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.SLOW); - fuzzer.setSlowSendSegmentSize(segmentSize); - fuzzer.send(send); - fuzzer.expect(expect,8,TimeUnit.SECONDS); + session.slowMode(segmentSize); + session.send(send); + session.expect(expect, 32, TimeUnit.SECONDS); } } @@ -147,13 +144,12 @@ public class TestABCase9 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new TextFrame().setPayload(msg)); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this)) + + try(Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -175,13 +171,12 @@ public class TestABCase9 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new TextFrame().setPayload(clone(buf))); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this)) + + try(Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -203,13 +198,12 @@ public class TestABCase9 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new TextFrame().setPayload(clone(buf))); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this)) + + try(Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect,4,TimeUnit.SECONDS); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -231,13 +225,12 @@ public class TestABCase9 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new TextFrame().setPayload(clone(buf))); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this)) + + try(Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect,8,TimeUnit.SECONDS); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -260,13 +253,12 @@ public class TestABCase9 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new TextFrame().setPayload(clone(buf))); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this)) + + try(Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect,16,TimeUnit.SECONDS); + session.bulkMode(); + session.send(send); + session.expect(expect, 16, TimeUnit.SECONDS); } } @@ -289,13 +281,12 @@ public class TestABCase9 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new TextFrame().setPayload(clone(buf))); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this)) + + try(Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect,32,TimeUnit.SECONDS); + session.bulkMode(); + session.send(send); + session.expect(expect, 32, TimeUnit.SECONDS); } } @@ -316,13 +307,12 @@ public class TestABCase9 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new BinaryFrame().setPayload(copyOf(data))); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this)) + + try(Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -344,13 +334,12 @@ public class TestABCase9 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new BinaryFrame().setPayload(clone(buf))); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this)) + + try(Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -373,13 +362,12 @@ public class TestABCase9 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new BinaryFrame().setPayload(clone(buf))); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this)) + + try(Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect,4,TimeUnit.SECONDS); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -402,13 +390,12 @@ public class TestABCase9 extends AbstractABCase List expect = new ArrayList<>(); expect.add(new BinaryFrame().setPayload(clone(buf))); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - - try(Fuzzer fuzzer = new Fuzzer(this)) + + try(Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect,8,TimeUnit.SECONDS); + session.bulkMode(); + session.send(send); + session.expect(expect); } } @@ -432,12 +419,11 @@ public class TestABCase9 extends AbstractABCase expect.add(new BinaryFrame().setPayload(clone(buf))); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - try(Fuzzer fuzzer = new Fuzzer(this)) + try(Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect,16,TimeUnit.SECONDS); + session.bulkMode(); + session.send(send); + session.expect(expect,16,TimeUnit.SECONDS); } } @@ -461,12 +447,11 @@ public class TestABCase9 extends AbstractABCase expect.add(new BinaryFrame().setPayload(clone(buf))); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); - try(Fuzzer fuzzer = new Fuzzer(this)) + try(Fuzzer.Session session = fuzzer.connect(this)) { - fuzzer.connect(); - fuzzer.setSendMode(Fuzzer.SendMode.BULK); - fuzzer.send(send); - fuzzer.expect(expect,32,TimeUnit.SECONDS); + session.bulkMode(); + session.send(send); + session.expect(expect,32,TimeUnit.SECONDS); } } diff --git a/jetty-websocket/websocket-tests/src/test/resources/jetty-logging.properties b/jetty-websocket/websocket-tests/src/test/resources/jetty-logging.properties new file mode 100644 index 00000000000..e040a748034 --- /dev/null +++ b/jetty-websocket/websocket-tests/src/test/resources/jetty-logging.properties @@ -0,0 +1,50 @@ +# +# +# ======================================================================== +# Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd. +# ------------------------------------------------------------------------ +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# and Apache License v2.0 which accompanies this distribution. +# +# The Eclipse Public License is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# The Apache License v2.0 is available at +# http://www.opensource.org/licenses/apache2.0.php +# +# You may elect to redistribute this code under either of these licenses. +# ======================================================================== +# +# + +org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +org.eclipse.jetty.LEVEL=WARN + +# org.eclipse.jetty.io.WriteFlusher.LEVEL=DEBUG +# org.eclipse.jetty.websocket.LEVEL=DEBUG +# org.eclipse.jetty.websocket.LEVEL=INFO +org.eclipse.jetty.websocket.common.io.LEVEL=DEBUG +# org.eclipse.jetty.websocket.server.ab.LEVEL=DEBUG +org.eclipse.jetty.websocket.common.WebSocketSession.LEVEL=DEBUG +# org.eclipse.jetty.websocket.common.Parser.LEVEL=DEBUG +# org.eclipse.jetty.websocket.common.Generator.LEVEL=DEBUG +# org.eclipse.jetty.websocket.server.ab.Fuzzer.LEVEL=DEBUG +# org.eclipse.jetty.websocket.server.blockhead.LEVEL=DEBUG +# org.eclipse.jetty.websocket.server.helper.LEVEL=DEBUG + +# org.eclipse.jetty.websocket.client.io.ConnectPromise.LEVEL=DEBUG +# org.eclipse.jetty.websocket.common.WebSocketSession_OPEN.LEVEL=DEBUG +# org.eclipse.jetty.websocket.common.io.IOState.LEVEL=DEBUG +# org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection_OPEN.LEVEL=DEBUG + +### Show state changes on BrowserDebugTool +# -- LEAVE THIS AT DEBUG LEVEL -- +org.eclipse.jetty.websocket.server.browser.LEVEL=DEBUG + +### Disabling intentional error out of RFCSocket +org.eclipse.jetty.websocket.server.helper.RFCSocket.LEVEL=OFF + +### Hiding Stack Traces from various test cases +org.eclipse.jetty.websocket.tests.server.ABSocket.STACKS=OFF +org.eclipse.jetty.websocket.server.WebSocketCloseTest$FastFailSocket.STACKS=OFF \ No newline at end of file diff --git a/pom.xml b/pom.xml index ed3d6dfda3f..2090f0bcb96 100644 --- a/pom.xml +++ b/pom.xml @@ -940,7 +940,7 @@ org.eclipse.jetty.toolchain jetty-test-helper - 4.0 + 4.1-SNAPSHOT org.eclipse.jetty.toolchain @@ -1536,6 +1536,17 @@ https://webtide.com + + + jetty-snapshots + jetty-snapshots + http://oss.sonatype.org/content/repositories/jetty-snapshots + + true + + + + oss.sonatype.org