Issue #207 - testcase rework due to new async behaviors

# Conflicts:
#	jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/io/ConnectionManager.java
#	jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/RegexMatcher.java
This commit is contained in:
Joakim Erdfelt 2017-04-11 15:46:47 -07:00
parent 3888cd5347
commit fcb8693c52
82 changed files with 2688 additions and 1575 deletions

View File

@ -42,7 +42,7 @@ import org.eclipse.jetty.util.component.LifeCycle;
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;
@ -113,11 +113,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;
}
@ -167,7 +167,7 @@ public class DecoderReaderManySmallTest
@Rule
public TestTracker tt = new TestTracker();
private BlockheadServer server;
private XBlockheadServer server;
private WebSocketContainer client;
@Before
@ -185,7 +185,7 @@ public class DecoderReaderManySmallTest
@Before
public void startServer() throws Exception
{
server = new BlockheadServer();
server = new XBlockheadServer();
server.start();
}

View File

@ -50,7 +50,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;
@ -155,11 +155,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;
}
@ -231,7 +231,7 @@ public class DecoderReaderTest
@Rule
public TestTracker tt = new TestTracker();
private BlockheadServer server;
private XBlockheadServer server;
private WebSocketContainer client;
@Before
@ -249,7 +249,7 @@ public class DecoderReaderTest
@Before
public void startServer() throws Exception
{
server = new BlockheadServer();
server = new XBlockheadServer();
server.start();
}

View File

@ -45,7 +45,7 @@ import org.eclipse.jetty.toolchain.test.TestTracker;
import org.eclipse.jetty.util.component.LifeCycle;
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;
@ -58,11 +58,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;
}
@ -193,7 +193,7 @@ public class EncoderTest
@Rule
public TestTracker tt = new TestTracker();
private BlockheadServer server;
private XBlockheadServer server;
private WebSocketContainer client;
@ -248,7 +248,7 @@ public class EncoderTest
@Before
public void startServer() throws Exception
{
server = new BlockheadServer();
server = new XBlockheadServer();
server.start();
}

View File

@ -98,7 +98,7 @@ public class MisbehavingClassTest
server.addBean(container); // allow to shutdown with server
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);
@ -121,7 +121,7 @@ public class MisbehavingClassTest
server.addBean(container); // allow to shutdown with server
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);

View File

@ -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();

View File

@ -19,6 +19,7 @@
<module>websocket-client</module>
<module>websocket-server</module>
<module>websocket-servlet</module>
<module>websocket-tests</module>
<module>javax-websocket-client-impl</module>
<module>javax-websocket-server-impl</module>
</modules>

View File

@ -47,7 +47,6 @@ import org.eclipse.jetty.websocket.api.WebSocketBehavior;
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;
@ -494,12 +493,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();
@ -626,18 +619,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)
{

View File

@ -1,172 +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
{
private class PhysicalConnect extends ConnectPromise
{
private SocketAddress bindAddress;
public PhysicalConnect(WebSocketClient client, ClientUpgradeRequest request, Object websocket)
{
super(client,request,websocket);
this.bindAddress = client.getBindAddress();
}
@Override
public void run()
{
SocketChannel channel = null;
try
{
channel = SocketChannel.open();
if (bindAddress != null)
{
channel.bind(bindAddress);
}
URI wsUri = getRequest().getRequestURI();
channel.socket().setTcpNoDelay(true); // disable nagle
channel.configureBlocking(false); // async always
InetSocketAddress address = toSocketAddress(wsUri);
if (channel.connect(address))
{
getSelector().accept(channel, this);
}
else
{
getSelector().connect(channel, this);
}
}
catch (Throwable t)
{
// close the socket channel
if (channel != null)
{
try
{
channel.close();
}
catch (IOException ignore)
{
LOG.ignore(ignore);
}
}
// notify the future
failed(t);
}
}
}
private static final Logger LOG = Log.getLogger(ConnectionManager.class);
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)
{
this.client = client;
}
public ConnectPromise connect(WebSocketClient client, ClientUpgradeRequest request, Object websocket)
{
return new PhysicalConnect(client,request,websocket);
}
@Override
protected void doStart() throws Exception
{
selector = newWebSocketClientSelectorManager(client);
selector.setSslContextFactory(client.getSslContextFactory());
selector.setConnectTimeout(client.getConnectTimeout());
addBean(selector);
super.doStart();
}
@Override
protected void doStop() throws Exception
{
super.doStop();
removeBean(selector);
}
public WebSocketClientSelectorManager getSelector()
{
return selector;
}
/**
* Factory method for new WebSocketClientSelectorManager (used by other projects like cometd)
*
* @param client
* the client used to create the WebSocketClientSelectorManager
* @return the new WebSocketClientSelectorManager
*/
protected WebSocketClientSelectorManager newWebSocketClientSelectorManager(WebSocketClient client)
{
return new WebSocketClientSelectorManager(client);
}
}

View File

@ -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();
}

View File

@ -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<Session> 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";

View File

@ -41,10 +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.hamcrest.Matcher;
import org.eclipse.jetty.websocket.common.test.XBlockheadServer;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
@ -64,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")
@ -110,7 +109,7 @@ public class ClientConnectTest
@Before
public void startServer() throws Exception
{
server = new BlockheadServer();
server = new XBlockheadServer();
server.start();
}

View File

@ -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);
}
}

View File

@ -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();
}

View File

@ -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;

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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;
@ -44,7 +44,7 @@ public class SlowServerTest
@Rule
public TestTracker tt = new TestTracker();
private BlockheadServer server;
private XBlockheadServer server;
private WebSocketClient client;
@Before
@ -58,7 +58,7 @@ public class SlowServerTest
@Before
public void startServer() throws Exception
{
server = new BlockheadServer();
server = new XBlockheadServer();
server.start();
}

View File

@ -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

View File

@ -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();
}

View File

@ -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);
}
/**

View File

@ -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

View File

@ -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)
{

View File

@ -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;
}

View File

@ -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));
}

View File

@ -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;

View File

@ -1,66 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2016 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);
}
}

View File

@ -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);
}

View File

@ -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 <u>what</u> 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;

View File

@ -36,9 +36,9 @@ import org.junit.Assert;
* <p>
* 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()

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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");

View File

@ -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

View File

@ -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 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

View File

@ -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");

View File

@ -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");

View File

@ -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 '");

View File

@ -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

View File

@ -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();

View File

@ -30,7 +30,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.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;
@ -106,7 +106,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

View File

@ -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);

View File

@ -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);

View File

@ -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();

View File

@ -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;
@ -222,7 +222,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);
@ -255,11 +255,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();
@ -294,7 +294,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);
@ -329,11 +329,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();
@ -356,11 +356,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();
@ -382,11 +382,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();

View File

@ -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
{

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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.
* <p>
* 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<String[]> data()
{
// The various Good UTF8 sequences as a String (hex form)
List<String[]> 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<WebSocketFrame> send = new ArrayList<>();
send.add(new TextFrame().setPayload(msg));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
List<WebSocketFrame> 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);
}
}
}

View File

@ -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);

View File

@ -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

View File

@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-parent</artifactId>
<version>9.4.3-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>websocket-tests</artifactId>
<name>Jetty :: Websocket :: Tests</name>
<properties>
<bundle-symbolic-name>${project.groupId}.tests</bundle-symbolic-name>
</properties>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-client</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-server</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-io</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-test-helper</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<executions>
<execution>
<id>ban-java-servlet-api</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<bannedDependencies>
<includes>
<include>javax.servlet</include>
<include>servletapi</include>
<include>org.eclipse.jetty.orbit:javax.servlet</include>
<include>org.mortbay.jetty:servlet-api</include>
<include>jetty:servlet-api</include>
</includes>
</bannedDependencies>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -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;
}
}
}

View File

@ -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();
}

View File

@ -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<WebSocketFrame> 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<WebSocketFrame> expect) throws Exception
{
expect(expect, 10, TimeUnit.SECONDS);
}
public void expect(List<WebSocketFrame> expect, int duration, TimeUnit unit) throws Exception
{
int expectedCount = expect.size();
LOG.debug("expect() {} frame(s)", expect.size());
// Read frames
Future<List<WebSocketFrame>> futFrames = session.getUntrustedEndpoint().expectedFrames(expectedCount);
List<WebSocketFrame> 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<WebSocketFrame> 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);
}
}

View File

@ -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();
}
};
}
}

View File

@ -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);
}
}

View File

@ -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());
}
}

View File

@ -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<UntrustedWSSession> connect(URI toUri, ClientUpgradeRequest req) throws IOException
{
final Future<Session> connectFut = super.connect(new UntrustedWSEndpoint(), toUri, req);
return new CompletableFuture<UntrustedWSSession>() {
@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);
}
};
}
}

View File

@ -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();
}
}

View File

@ -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> closeInfo = new AtomicReference<>();
public AtomicReference<Throwable> error = new AtomicReference<>();
private CompletableFuture<List<String>> expectedMessagesFuture;
private AtomicInteger expectedMessageCount;
private List<String> messages = new ArrayList<>();
private CompletableFuture<List<WebSocketFrame>> expectedFramesFuture;
private AtomicInteger expectedFramesCount;
private List<WebSocketFrame> frames = new ArrayList<>();
public Future<List<WebSocketFrame>> expectedFrames(int expectedCount)
{
expectedFramesFuture = new CompletableFuture<>();
expectedFramesCount = new AtomicInteger(expectedCount);
return expectedFramesFuture;
}
public Future<List<String>> 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);
}
}
}
}

View File

@ -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;
}
}

View File

@ -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);
}
}

View File

@ -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<UntrustedWSSession> fut = client.connect(wsServerURI.resolve("/status"), request);
try (UntrustedWSSession session = fut.get(5, TimeUnit.SECONDS))
{
UntrustedWSEndpoint endpoint = session.getUntrustedEndpoint();
Future<List<String>> futMessages = endpoint.expectedMessages(1);
session.getRemote().sendString("hello");
List<String> messages = futMessages.get();
assertThat("Messages.size", messages.size(), is(1));
assertThat("Messages[0]", messages.get(0), is("hello"));
}
}
finally
{
client.stop();
}
}
}

View File

@ -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;

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.server.ab;
package org.eclipse.jetty.websocket.tests.server;
import java.nio.ByteBuffer;

View File

@ -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();
}

View File

@ -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<WebSocketFrame> send = new ArrayList<>();
send.add(new TextFrame());
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
List<WebSocketFrame> 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<WebSocketFrame> send = new ArrayList<>();
send.add(new TextFrame().setPayload(buf));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
List<WebSocketFrame> 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<WebSocketFrame> send = new ArrayList<>();
send.add(new TextFrame().setPayload(buf));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
List<WebSocketFrame> 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<WebSocketFrame> send = new ArrayList<>();
send.add(new TextFrame().setPayload(buf));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
List<WebSocketFrame> 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<WebSocketFrame> send = new ArrayList<>();
send.add(new TextFrame().setPayload(buf));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
List<WebSocketFrame> 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<WebSocketFrame> send = new ArrayList<>();
send.add(new TextFrame().setPayload(buf));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
List<WebSocketFrame> 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<WebSocketFrame> send = new ArrayList<>();
send.add(new TextFrame().setPayload(buf));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
List<WebSocketFrame> 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).
* <p>
* Only send 1 TEXT frame from client, but in small segments (flushed after each).
* <p>
* 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<WebSocketFrame> send = new ArrayList<>();
send.add(new TextFrame().setPayload(buf));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
List<WebSocketFrame> 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<WebSocketFrame> send = new ArrayList<>();
send.add(new BinaryFrame());
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
List<WebSocketFrame> 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<WebSocketFrame> send = new ArrayList<>();
send.add(new BinaryFrame().setPayload(buf));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
List<WebSocketFrame> 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<WebSocketFrame> send = new ArrayList<>();
send.add(new BinaryFrame().setPayload(buf));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
List<WebSocketFrame> 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<WebSocketFrame> send = new ArrayList<>();
send.add(new BinaryFrame().setPayload(buf));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
List<WebSocketFrame> 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<WebSocketFrame> send = new ArrayList<>();
send.add(new BinaryFrame().setPayload(buf));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
List<WebSocketFrame> 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<WebSocketFrame> send = new ArrayList<>();
send.add(new BinaryFrame().setPayload(buf));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
List<WebSocketFrame> 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<WebSocketFrame> send = new ArrayList<>();
send.add(new BinaryFrame().setPayload(buf));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
List<WebSocketFrame> 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).
* <p>
* Only send 1 BINARY frame from client, but in small segments (flushed after each).
* <p>
* 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<WebSocketFrame> send = new ArrayList<>();
send.add(new BinaryFrame().setPayload(buf));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
List<WebSocketFrame> 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);
}
}
}

View File

@ -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<WebSocketFrame> send = new ArrayList<>();
send.add(new PingFrame());
List<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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);
}
}
}

View File

@ -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;
@ -30,7 +30,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;
/**
@ -48,13 +48,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);
}
}
@ -73,13 +73,13 @@ public class TestABCase3 extends AbstractABCase
List<WebSocketFrame> 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);
}
}
@ -99,12 +99,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);
}
}
@ -124,13 +124,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);
}
}
@ -149,13 +148,13 @@ public class TestABCase3 extends AbstractABCase
List<WebSocketFrame> 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);
}
}
@ -175,12 +174,12 @@ public class TestABCase3 extends AbstractABCase
List<WebSocketFrame> 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 +202,13 @@ public class TestABCase3 extends AbstractABCase
List<WebSocketFrame> 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);
}
}
}

View File

@ -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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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);
}
}
}

View File

@ -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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> expect1 = new ArrayList<>();
expect1.add(new PongFrame().setPayload("pong-1"));
// phase 2
List<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> expect1 = new ArrayList<>();
expect1.add(new PongFrame().setPayload("pong-1"));
List<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> expect1 = new ArrayList<>();
expect1.add(new PongFrame().setPayload("pong-1"));
List<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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);
}
}
}

View File

@ -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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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);
}
}
}

View File

@ -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<WebSocketFrame> 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);
}
}
}

View File

@ -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.
* <p>
* 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<String[]> data()
{
// The various Good UTF8 sequences as a String (hex form)
List<String[]> 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<WebSocketFrame> send = new ArrayList<>();
send.add(new TextFrame().setPayload(msg));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
List<WebSocketFrame> 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);
}
}
}

View File

@ -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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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);
}
}
}

View File

@ -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(name = "{1} / {0}")
@Parameters
public static Collection<Object[]> data()
{
// The various Good UTF8 sequences as a String (hex form)
List<Object[]> 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 }); // RFC6455/UNDEFINED
data.add(new Object[] { "7.9.4", 1005 }); // RFC6455/Cannot Be Transmitted
data.add(new Object[] { "7.9.5", 1006 }); // RFC6455/Cannot Be Transmitted
// data.add(new Object[] { "7.9.6", 1012 }); - IANA Defined
// data.add(new Object[] { "7.9.7", 1013 }); - IANA Defined
// data.add(new Object[] { "7.9.8", 1014 }); - IANA Defined
data.add(new Object[] { "7.9.9", 1015 }); // RFC6455/Cannot Be Transmitted
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<WebSocketFrame> send = new ArrayList<>();
send.add(new CloseFrame().setPayload(payload.slice()));
List<WebSocketFrame> 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<WebSocketFrame> send = new ArrayList<>();
send.add(new CloseFrame().setPayload(payload.slice()));
List<WebSocketFrame> 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);
}
}
}

View File

@ -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,45 +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(name = "{1} / {0}")
@Parameters
public static Collection<Object[]> data()
{
// The various Good UTF8 sequences as a String (hex form)
List<Object[]> 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[] { "IANA Assigned", 1012 });
data.add(new Object[] { "IANA Assigned", 1013 });
data.add(new Object[] { "IANA Assigned", 1014 });
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
@ -88,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<WebSocketFrame> send = new ArrayList<>();
send.add(new CloseFrame().setPayload(payload.slice()));
List<WebSocketFrame> 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<WebSocketFrame> send = new ArrayList<>();
send.add(new CloseFrame().setPayload(payload.slice()));
List<WebSocketFrame> 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);
}
}
}

View File

@ -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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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<WebSocketFrame> 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);
}
}

View File

@ -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

13
pom.xml
View File

@ -947,7 +947,7 @@
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-test-helper</artifactId>
<version>4.0</version>
<version>4.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
@ -1543,6 +1543,17 @@
<url>https://webtide.com</url>
</organization>
<repositories>
<repository>
<id>jetty-snapshots</id>
<name>jetty-snapshots</name>
<url>http://oss.sonatype.org/content/repositories/jetty-snapshots</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>oss.sonatype.org</id>