Merge branch 'jetty-9' into jetty-9-oneconnector
This commit is contained in:
commit
d6ef039f2c
|
@ -179,6 +179,7 @@ public abstract class Utf8Appendable
|
|||
return _state == UTF8_ACCEPT;
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public static class NotUtf8Exception extends IllegalArgumentException
|
||||
{
|
||||
public NotUtf8Exception(String reason)
|
||||
|
|
|
@ -72,6 +72,6 @@ public class Utf8StringBuilder extends Utf8Appendable
|
|||
private void checkState()
|
||||
{
|
||||
if (!isUtf8SequenceComplete())
|
||||
throw new IllegalArgumentException("Tried to read incomplete UTF8 decoded String");
|
||||
throw new NotUtf8Exception("Tried to read incomplete UTF8 decoded String");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,14 +45,14 @@ public class StdErrLogTest
|
|||
log.info("testing:{}",null,null);
|
||||
log.info("testing",null,null);
|
||||
|
||||
output.assertContains("INFO:oejul.LogTest:testing:test,format1");
|
||||
output.assertContains("INFO:oejul.LogTest:testing:test,format1");
|
||||
output.assertContains("INFO:oejul.LogTest:testing:test format2");
|
||||
output.assertContains("INFO:oejul.LogTest:testing test format3");
|
||||
output.assertContains("INFO:oejul.LogTest:testing:test,null");
|
||||
output.assertContains("INFO:oejul.LogTest:testing null null");
|
||||
output.assertContains("INFO:oejul.LogTest:testing:null");
|
||||
output.assertContains("INFO:oejul.LogTest:testing");
|
||||
output.assertContains("INFO:oejul.LogTest:1: testing:test,format1");
|
||||
output.assertContains("INFO:oejul.LogTest:1: testing:test,format1");
|
||||
output.assertContains("INFO:oejul.LogTest:1: testing:test format2");
|
||||
output.assertContains("INFO:oejul.LogTest:1: testing test format3");
|
||||
output.assertContains("INFO:oejul.LogTest:1: testing:test,null");
|
||||
output.assertContains("INFO:oejul.LogTest:1: testing null null");
|
||||
output.assertContains("INFO:oejul.LogTest:1: testing:null");
|
||||
output.assertContains("INFO:oejul.LogTest:1: testing");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -75,12 +75,12 @@ public class StdErrLogTest
|
|||
log.setDebugEnabled(false);
|
||||
log.debug("testing {} {}","test","debug-deprecated-false");
|
||||
|
||||
output.assertContains("DBUG:xxx:testing test debug");
|
||||
output.assertContains("INFO:xxx:testing test info");
|
||||
output.assertContains("WARN:xxx:testing test warn");
|
||||
output.assertContains("DBUG:xxx:1: testing test debug");
|
||||
output.assertContains("INFO:xxx:1: testing test info");
|
||||
output.assertContains("WARN:xxx:1: testing test warn");
|
||||
output.assertNotContains("YOU SHOULD NOT SEE THIS!");
|
||||
output.assertContains("DBUG:xxx:testing test debug-deprecated");
|
||||
output.assertNotContains("DBUG:xxx:testing test debug-depdeprecated-false");
|
||||
output.assertContains("DBUG:xxx:1: testing test debug-deprecated");
|
||||
output.assertNotContains("DBUG:xxx:1: testing test debug-depdeprecated-false");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -95,7 +95,7 @@ public class StdErrLogTest
|
|||
Assert.assertThat("Log.name(child)", next.getName(), is("test.next"));
|
||||
next.info("testing {} {}","next","info");
|
||||
|
||||
output.assertContains(":test.next:testing next info");
|
||||
output.assertContains(":test.next:1: testing next info");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -307,7 +307,7 @@ public class StdErrLogTest
|
|||
output.assertContains("Cheer Me");
|
||||
|
||||
// Validate Stack Traces
|
||||
output.assertContains(".StdErrLogTest:<zoom>");
|
||||
output.assertContains(".StdErrLogTest:1: <zoom>");
|
||||
output.assertContains("java.lang.Throwable: out of focus");
|
||||
output.assertContains("java.lang.Throwable: scene lost");
|
||||
}
|
||||
|
@ -354,7 +354,7 @@ public class StdErrLogTest
|
|||
output.assertNotContains("<spoken line>");
|
||||
output.assertNotContains("on editing room floor");
|
||||
|
||||
output.assertContains(".StdErrLogTest:<zoom>");
|
||||
output.assertContains(".StdErrLogTest:1: <zoom>");
|
||||
output.assertContains("java.lang.Throwable: out of focus");
|
||||
output.assertContains("java.lang.Throwable: scene lost");
|
||||
}
|
||||
|
@ -427,7 +427,7 @@ public class StdErrLogTest
|
|||
output.assertNotContains("<spoken line>");
|
||||
output.assertNotContains("on editing room floor");
|
||||
|
||||
output.assertContains(".StdErrLogTest:<zoom>");
|
||||
output.assertContains(".StdErrLogTest:1: <zoom>");
|
||||
output.assertContains("java.lang.Throwable: out of focus");
|
||||
output.assertContains("java.lang.Throwable: scene lost");
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.nio.ByteBuffer;
|
|||
|
||||
import org.eclipse.jetty.io.ByteBufferPool;
|
||||
import org.eclipse.jetty.io.StandardByteBufferPool;
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
import org.eclipse.jetty.websocket.protocol.Generator;
|
||||
import org.eclipse.jetty.websocket.server.SimpleServletServer;
|
||||
|
@ -44,6 +45,26 @@ public abstract class AbstractABCase
|
|||
server.stop();
|
||||
}
|
||||
|
||||
public static String toUtf8String(byte[] buf)
|
||||
{
|
||||
String raw = StringUtil.toUTF8String(buf,0,buf.length);
|
||||
StringBuilder ret = new StringBuilder();
|
||||
int len = raw.length();
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
int codepoint = raw.codePointAt(i);
|
||||
if (Character.isUnicodeIdentifierPart(codepoint))
|
||||
{
|
||||
ret.append(String.format("\\u%04X",codepoint));
|
||||
}
|
||||
else
|
||||
{
|
||||
ret.append(Character.toChars(codepoint));
|
||||
}
|
||||
}
|
||||
return ret.toString();
|
||||
}
|
||||
|
||||
public Generator getLaxGenerator()
|
||||
{
|
||||
return laxGenerator;
|
||||
|
|
|
@ -5,7 +5,7 @@ import org.junit.runners.Suite;
|
|||
|
||||
@RunWith(Suite.class)
|
||||
@Suite.SuiteClasses(
|
||||
{ TestABCase1.class, TestABCase2.class, TestABCase3.class, TestABCase4.class, TestABCase5.class, TestABCase7_9.class })
|
||||
{ TestABCase1.class, TestABCase2.class, TestABCase3.class, TestABCase4.class, TestABCase5.class, TestABCase6.class, TestABCase7_9.class })
|
||||
public class AllTests
|
||||
{
|
||||
/* let junit do the rest */
|
||||
|
|
|
@ -50,6 +50,26 @@ public class Fuzzer
|
|||
this.generator = testcase.getLaxGenerator();
|
||||
}
|
||||
|
||||
public ByteBuffer asNetworkBuffer(List<WebSocketFrame> send)
|
||||
{
|
||||
int buflen = 0;
|
||||
for (WebSocketFrame f : send)
|
||||
{
|
||||
buflen += f.getPayloadLength() + Generator.OVERHEAD;
|
||||
}
|
||||
ByteBuffer buf = ByteBuffer.allocate(buflen);
|
||||
BufferUtil.clearToFill(buf);
|
||||
|
||||
// Generate frames
|
||||
for (WebSocketFrame f : send)
|
||||
{
|
||||
f.setMask(MASK); // make sure we have mask set
|
||||
BufferUtil.put(generator.generate(f),buf);
|
||||
}
|
||||
BufferUtil.flipToFlush(buf,0);
|
||||
return buf;
|
||||
}
|
||||
|
||||
public void close()
|
||||
{
|
||||
this.client.disconnect();
|
||||
|
@ -80,7 +100,7 @@ public class Fuzzer
|
|||
|
||||
prefix = "Frame[" + i + "]";
|
||||
|
||||
Assert.assertThat(prefix + ".opcode",actual.getOpCode(),is(expected.getOpCode()));
|
||||
Assert.assertThat(prefix + ".opcode",OpCode.name(actual.getOpCode()),is(OpCode.name(expected.getOpCode())));
|
||||
prefix += "/" + actual.getOpCode();
|
||||
if (expected.getOpCode() == OpCode.CLOSE)
|
||||
{
|
||||
|
@ -125,6 +145,12 @@ public class Fuzzer
|
|||
}
|
||||
}
|
||||
|
||||
public void send(ByteBuffer buf, int numBytes) throws IOException
|
||||
{
|
||||
client.writeRaw(buf,numBytes);
|
||||
client.flush();
|
||||
}
|
||||
|
||||
public void send(List<WebSocketFrame> send) throws IOException
|
||||
{
|
||||
Assert.assertThat("Client connected",client.isConnected(),is(true));
|
||||
|
|
|
@ -1,3 +1,18 @@
|
|||
// ========================================================================
|
||||
// Copyright 2011-2012 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.util.ArrayList;
|
||||
|
|
|
@ -151,4 +151,143 @@ public class TestABCase4 extends AbstractABCase
|
|||
fuzzer.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send opcode 11 (reserved)
|
||||
*/
|
||||
@Test
|
||||
public void testCase4_2_1() throws Exception
|
||||
{
|
||||
List<WebSocketFrame> send = new ArrayList<>();
|
||||
send.add(new WebSocketFrame((byte)11)); // intentionally bad
|
||||
|
||||
List<WebSocketFrame> expect = new ArrayList<>();
|
||||
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
|
||||
|
||||
Fuzzer fuzzer = new Fuzzer(this);
|
||||
try
|
||||
{
|
||||
fuzzer.connect();
|
||||
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
|
||||
fuzzer.send(send);
|
||||
fuzzer.expect(expect);
|
||||
}
|
||||
finally
|
||||
{
|
||||
fuzzer.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send opcode 12 (reserved)
|
||||
*/
|
||||
@Test
|
||||
public void testCase4_2_2() throws Exception
|
||||
{
|
||||
List<WebSocketFrame> send = new ArrayList<>();
|
||||
send.add(new WebSocketFrame((byte)12).setPayload("bad")); // intentionally bad
|
||||
|
||||
List<WebSocketFrame> expect = new ArrayList<>();
|
||||
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
|
||||
|
||||
Fuzzer fuzzer = new Fuzzer(this);
|
||||
try
|
||||
{
|
||||
fuzzer.connect();
|
||||
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
|
||||
fuzzer.send(send);
|
||||
fuzzer.expect(expect);
|
||||
}
|
||||
finally
|
||||
{
|
||||
fuzzer.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send small text, then frame with opcode 13 (reserved), then ping
|
||||
*/
|
||||
@Test
|
||||
public void testCase4_2_3() throws Exception
|
||||
{
|
||||
List<WebSocketFrame> send = new ArrayList<>();
|
||||
send.add(WebSocketFrame.text("hello"));
|
||||
send.add(new WebSocketFrame((byte)13)); // intentionally bad
|
||||
send.add(WebSocketFrame.ping());
|
||||
|
||||
List<WebSocketFrame> expect = new ArrayList<>();
|
||||
expect.add(WebSocketFrame.text("hello")); // echo
|
||||
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
|
||||
|
||||
Fuzzer fuzzer = new Fuzzer(this);
|
||||
try
|
||||
{
|
||||
fuzzer.connect();
|
||||
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
|
||||
fuzzer.send(send);
|
||||
fuzzer.expect(expect);
|
||||
}
|
||||
finally
|
||||
{
|
||||
fuzzer.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send small text, then frame with opcode 14 (reserved), then ping
|
||||
*/
|
||||
@Test
|
||||
public void testCase4_2_4() throws Exception
|
||||
{
|
||||
List<WebSocketFrame> send = new ArrayList<>();
|
||||
send.add(WebSocketFrame.text("hello"));
|
||||
send.add(new WebSocketFrame((byte)14).setPayload("bad")); // intentionally bad
|
||||
send.add(WebSocketFrame.ping());
|
||||
|
||||
List<WebSocketFrame> expect = new ArrayList<>();
|
||||
expect.add(WebSocketFrame.text("hello")); // echo
|
||||
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
|
||||
|
||||
Fuzzer fuzzer = new Fuzzer(this);
|
||||
try
|
||||
{
|
||||
fuzzer.connect();
|
||||
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
|
||||
fuzzer.send(send);
|
||||
fuzzer.expect(expect);
|
||||
}
|
||||
finally
|
||||
{
|
||||
fuzzer.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send small text, then frame with opcode 15 (reserved), then ping
|
||||
*/
|
||||
@Test
|
||||
public void testCase4_2_5() throws Exception
|
||||
{
|
||||
List<WebSocketFrame> send = new ArrayList<>();
|
||||
send.add(WebSocketFrame.text("hello"));
|
||||
send.add(new WebSocketFrame((byte)15).setPayload("bad")); // intentionally bad
|
||||
send.add(WebSocketFrame.ping());
|
||||
|
||||
List<WebSocketFrame> expect = new ArrayList<>();
|
||||
expect.add(WebSocketFrame.text("hello")); // echo
|
||||
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
|
||||
|
||||
Fuzzer fuzzer = new Fuzzer(this);
|
||||
try
|
||||
{
|
||||
fuzzer.connect();
|
||||
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
|
||||
fuzzer.send(send);
|
||||
fuzzer.expect(expect);
|
||||
}
|
||||
finally
|
||||
{
|
||||
fuzzer.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,846 @@
|
|||
// ========================================================================
|
||||
// Copyright 2011-2012 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.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.eclipse.jetty.toolchain.test.AdvancedRunner;
|
||||
import org.eclipse.jetty.toolchain.test.annotation.Slow;
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
import org.eclipse.jetty.websocket.api.StatusCode;
|
||||
import org.eclipse.jetty.websocket.protocol.CloseInfo;
|
||||
import org.eclipse.jetty.websocket.protocol.OpCode;
|
||||
import org.eclipse.jetty.websocket.protocol.WebSocketFrame;
|
||||
import org.eclipse.jetty.websocket.server.helper.Hex;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
/**
|
||||
* UTF-8 Tests
|
||||
*/
|
||||
@RunWith(AdvancedRunner.class)
|
||||
public class TestABCase6 extends AbstractABCase
|
||||
{
|
||||
/**
|
||||
* text message, 1 frame, 0 length
|
||||
*/
|
||||
@Test
|
||||
public void testCase6_1_1() throws Exception
|
||||
{
|
||||
List<WebSocketFrame> send = new ArrayList<>();
|
||||
send.add(WebSocketFrame.text());
|
||||
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
|
||||
List<WebSocketFrame> expect = new ArrayList<>();
|
||||
expect.add(WebSocketFrame.text());
|
||||
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
|
||||
Fuzzer fuzzer = new Fuzzer(this);
|
||||
try
|
||||
{
|
||||
fuzzer.connect();
|
||||
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
|
||||
fuzzer.send(send);
|
||||
fuzzer.expect(expect);
|
||||
}
|
||||
finally
|
||||
{
|
||||
fuzzer.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* text message, 0 length, 3 fragments
|
||||
*/
|
||||
@Test
|
||||
public void testCase6_1_2() throws Exception
|
||||
{
|
||||
List<WebSocketFrame> send = new ArrayList<>();
|
||||
send.add(new WebSocketFrame(OpCode.TEXT).setFin(false));
|
||||
send.add(new WebSocketFrame(OpCode.CONTINUATION).setFin(false));
|
||||
send.add(new WebSocketFrame(OpCode.CONTINUATION).setFin(true));
|
||||
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
|
||||
List<WebSocketFrame> expect = new ArrayList<>();
|
||||
expect.add(WebSocketFrame.text());
|
||||
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
|
||||
Fuzzer fuzzer = new Fuzzer(this);
|
||||
try
|
||||
{
|
||||
fuzzer.connect();
|
||||
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
|
||||
fuzzer.send(send);
|
||||
fuzzer.expect(expect);
|
||||
}
|
||||
finally
|
||||
{
|
||||
fuzzer.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* text message, small length, 3 fragments (only middle frame has payload)
|
||||
*/
|
||||
@Test
|
||||
public void testCase6_1_3() throws Exception
|
||||
{
|
||||
List<WebSocketFrame> send = new ArrayList<>();
|
||||
send.add(new WebSocketFrame(OpCode.TEXT).setFin(false));
|
||||
send.add(new WebSocketFrame(OpCode.CONTINUATION).setFin(false).setPayload("middle"));
|
||||
send.add(new WebSocketFrame(OpCode.CONTINUATION).setFin(true));
|
||||
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
|
||||
List<WebSocketFrame> expect = new ArrayList<>();
|
||||
expect.add(WebSocketFrame.text("middle"));
|
||||
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
|
||||
Fuzzer fuzzer = new Fuzzer(this);
|
||||
try
|
||||
{
|
||||
fuzzer.connect();
|
||||
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
|
||||
fuzzer.send(send);
|
||||
fuzzer.expect(expect);
|
||||
}
|
||||
finally
|
||||
{
|
||||
fuzzer.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* valid utf8 text message, 1 frame/fragment.
|
||||
*/
|
||||
@Test
|
||||
public void testCase6_2_1() throws Exception
|
||||
{
|
||||
String utf8 = "Hello-\uC2B5@\uC39F\uC3A4\uC3BC\uC3A0\uC3A1-UTF-8!!";
|
||||
byte msg[] = StringUtil.getUtf8Bytes(utf8);
|
||||
|
||||
List<WebSocketFrame> send = new ArrayList<>();
|
||||
send.add(new WebSocketFrame(OpCode.TEXT).setPayload(msg));
|
||||
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
|
||||
List<WebSocketFrame> expect = new ArrayList<>();
|
||||
expect.add(new WebSocketFrame(OpCode.TEXT).setPayload(msg));
|
||||
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
|
||||
Fuzzer fuzzer = new Fuzzer(this);
|
||||
try
|
||||
{
|
||||
fuzzer.connect();
|
||||
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
|
||||
fuzzer.send(send);
|
||||
fuzzer.expect(expect);
|
||||
}
|
||||
finally
|
||||
{
|
||||
fuzzer.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* valid utf8 text message, 2 fragments (on UTF8 code point boundary)
|
||||
*/
|
||||
@Test
|
||||
public void testCase6_2_2() throws Exception
|
||||
{
|
||||
String utf8[] =
|
||||
{ "Hello-\uC2B5@\uC39F\uC3A4", "\uC3BC\uC3A0\uC3A1-UTF-8!!" };
|
||||
|
||||
List<WebSocketFrame> send = new ArrayList<>();
|
||||
send.add(new WebSocketFrame(OpCode.TEXT).setPayload(utf8[0]).setFin(false));
|
||||
send.add(new WebSocketFrame(OpCode.CONTINUATION).setPayload(utf8[1]).setFin(true));
|
||||
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
|
||||
List<WebSocketFrame> expect = new ArrayList<>();
|
||||
expect.add(new WebSocketFrame(OpCode.TEXT).setPayload(utf8[0] + utf8[1]));
|
||||
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
|
||||
Fuzzer fuzzer = new Fuzzer(this);
|
||||
try
|
||||
{
|
||||
fuzzer.connect();
|
||||
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
|
||||
fuzzer.send(send);
|
||||
fuzzer.expect(expect);
|
||||
}
|
||||
finally
|
||||
{
|
||||
fuzzer.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* valid utf8 text message, many fragments (1 byte each)
|
||||
*/
|
||||
@Test
|
||||
public void testCase6_2_3() throws Exception
|
||||
{
|
||||
String utf8 = "Hello-\uC2B5@\uC39F\uC3A4\uC3BC\uC3A0\uC3A1-UTF-8!!";
|
||||
byte msg[] = StringUtil.getUtf8Bytes(utf8);
|
||||
|
||||
List<WebSocketFrame> send = new ArrayList<>();
|
||||
int len = msg.length;
|
||||
byte opcode = OpCode.TEXT;
|
||||
byte mini[];
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
WebSocketFrame frame = new WebSocketFrame(opcode);
|
||||
mini = new byte[1];
|
||||
mini[0] = msg[i];
|
||||
frame.setPayload(mini);
|
||||
frame.setFin(!(i < (len - 1)));
|
||||
send.add(frame);
|
||||
}
|
||||
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
|
||||
List<WebSocketFrame> expect = new ArrayList<>();
|
||||
expect.add(new WebSocketFrame(OpCode.TEXT).setPayload(msg));
|
||||
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
|
||||
Fuzzer fuzzer = new Fuzzer(this);
|
||||
try
|
||||
{
|
||||
fuzzer.connect();
|
||||
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
|
||||
fuzzer.send(send);
|
||||
fuzzer.expect(expect);
|
||||
}
|
||||
finally
|
||||
{
|
||||
fuzzer.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* valid utf8 text message, many fragments (1 byte each)
|
||||
*/
|
||||
@Test
|
||||
public void testCase6_2_4() throws Exception
|
||||
{
|
||||
byte msg[] = Hex.asByteArray("CEBAE1BDB9CF83CEBCCEB5");
|
||||
|
||||
List<WebSocketFrame> send = new ArrayList<>();
|
||||
int len = msg.length;
|
||||
byte opcode = OpCode.TEXT;
|
||||
byte mini[];
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
WebSocketFrame frame = new WebSocketFrame(opcode);
|
||||
mini = new byte[1];
|
||||
mini[0] = msg[i];
|
||||
frame.setPayload(mini);
|
||||
frame.setFin(!(i < (len - 1)));
|
||||
send.add(frame);
|
||||
}
|
||||
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
|
||||
List<WebSocketFrame> expect = new ArrayList<>();
|
||||
expect.add(new WebSocketFrame(OpCode.TEXT).setPayload(msg));
|
||||
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
|
||||
Fuzzer fuzzer = new Fuzzer(this);
|
||||
try
|
||||
{
|
||||
fuzzer.connect();
|
||||
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
|
||||
fuzzer.send(send);
|
||||
fuzzer.expect(expect);
|
||||
}
|
||||
finally
|
||||
{
|
||||
fuzzer.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* invalid utf8 text message, 1 frame/fragments
|
||||
*/
|
||||
@Test
|
||||
public void testCase6_3_1() throws Exception
|
||||
{
|
||||
byte invalid[] = Hex.asByteArray("CEBAE1BDB9CF83CEBCCEB5EDA080656469746564");
|
||||
|
||||
List<WebSocketFrame> send = new ArrayList<>();
|
||||
send.add(new WebSocketFrame(OpCode.TEXT).setPayload(invalid));
|
||||
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
|
||||
List<WebSocketFrame> expect = new ArrayList<>();
|
||||
expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame());
|
||||
|
||||
Fuzzer fuzzer = new Fuzzer(this);
|
||||
try
|
||||
{
|
||||
fuzzer.connect();
|
||||
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
|
||||
fuzzer.send(send);
|
||||
fuzzer.expect(expect);
|
||||
}
|
||||
finally
|
||||
{
|
||||
fuzzer.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* invalid utf8 text message, many fragments (1 byte each)
|
||||
*/
|
||||
@Test
|
||||
public void testCase6_3_2() throws Exception
|
||||
{
|
||||
byte invalid[] = Hex.asByteArray("CEBAE1BDB9CF83CEBCCEB5EDA080656469746564");
|
||||
|
||||
List<WebSocketFrame> send = new ArrayList<>();
|
||||
int len = invalid.length;
|
||||
byte opcode = OpCode.TEXT;
|
||||
byte mini[];
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
WebSocketFrame frame = new WebSocketFrame(opcode);
|
||||
mini = new byte[1];
|
||||
mini[0] = invalid[i];
|
||||
frame.setPayload(mini);
|
||||
frame.setFin(!(i < (len - 1)));
|
||||
send.add(frame);
|
||||
}
|
||||
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
|
||||
List<WebSocketFrame> expect = new ArrayList<>();
|
||||
expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame());
|
||||
|
||||
Fuzzer fuzzer = new Fuzzer(this);
|
||||
try
|
||||
{
|
||||
fuzzer.connect();
|
||||
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
|
||||
fuzzer.send(send);
|
||||
fuzzer.expect(expect);
|
||||
}
|
||||
finally
|
||||
{
|
||||
fuzzer.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* invalid text message, 3 fragments.
|
||||
* <p>
|
||||
* fragment #1 and fragment #3 are both valid in themselves.
|
||||
* <p>
|
||||
* fragment #2 contains the invalid utf8 code point.
|
||||
*/
|
||||
@Test
|
||||
@Slow
|
||||
public void testCase6_4_1() throws Exception
|
||||
{
|
||||
byte part1[] = StringUtil.getUtf8Bytes("\u03BA\u1F79\u03C3\u03BC\u03B5");
|
||||
byte part2[] = Hex.asByteArray("F4908080"); // invalid
|
||||
byte part3[] = StringUtil.getUtf8Bytes("edited");
|
||||
|
||||
List<WebSocketFrame> expect = new ArrayList<>();
|
||||
expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame());
|
||||
|
||||
Fuzzer fuzzer = new Fuzzer(this);
|
||||
try
|
||||
{
|
||||
fuzzer.connect();
|
||||
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
|
||||
|
||||
fuzzer.send(new WebSocketFrame(OpCode.TEXT).setPayload(part1).setFin(false));
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
fuzzer.send(new WebSocketFrame(OpCode.CONTINUATION).setPayload(part2).setFin(false));
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
fuzzer.send(new WebSocketFrame(OpCode.CONTINUATION).setPayload(part3).setFin(true));
|
||||
|
||||
fuzzer.expect(expect);
|
||||
}
|
||||
finally
|
||||
{
|
||||
fuzzer.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* invalid text message, 3 fragments.
|
||||
* <p>
|
||||
* fragment #1 is valid and ends in the middle of an incomplete code point.
|
||||
* <p>
|
||||
* fragment #2 finishes the UTF8 code point but it is invalid
|
||||
* <p>
|
||||
* fragment #3 contains the remainder of the message.
|
||||
*/
|
||||
@Test
|
||||
@Slow
|
||||
public void testCase6_4_2() throws Exception
|
||||
{
|
||||
byte part1[] = Hex.asByteArray("CEBAE1BDB9CF83CEBCCEB5F4"); // split code point
|
||||
byte part2[] = Hex.asByteArray("90"); // continue code point & invalid
|
||||
byte part3[] = Hex.asByteArray("8080656469746564"); // continue code point & finish
|
||||
|
||||
List<WebSocketFrame> expect = new ArrayList<>();
|
||||
expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame());
|
||||
|
||||
Fuzzer fuzzer = new Fuzzer(this);
|
||||
try
|
||||
{
|
||||
fuzzer.connect();
|
||||
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
|
||||
fuzzer.send(new WebSocketFrame(OpCode.TEXT).setPayload(part1).setFin(false));
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
fuzzer.send(new WebSocketFrame(OpCode.CONTINUATION).setPayload(part2).setFin(false));
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
fuzzer.send(new WebSocketFrame(OpCode.CONTINUATION).setPayload(part3).setFin(true));
|
||||
fuzzer.expect(expect);
|
||||
}
|
||||
finally
|
||||
{
|
||||
fuzzer.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* invalid text message, 1 frame/fragment (slowly, and split within code points)
|
||||
*/
|
||||
@Test
|
||||
@Slow
|
||||
public void testCase6_4_3() throws Exception
|
||||
{
|
||||
byte invalid[] = Hex.asByteArray("CEBAE1BDB9CF83CEBCCEB5F49080808080656469746564");
|
||||
|
||||
List<WebSocketFrame> send = new ArrayList<>();
|
||||
send.add(new WebSocketFrame(OpCode.TEXT).setPayload(invalid));
|
||||
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
|
||||
List<WebSocketFrame> expect = new ArrayList<>();
|
||||
expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame());
|
||||
|
||||
Fuzzer fuzzer = new Fuzzer(this);
|
||||
try
|
||||
{
|
||||
fuzzer.connect();
|
||||
|
||||
ByteBuffer net = fuzzer.asNetworkBuffer(send);
|
||||
fuzzer.send(net,6);
|
||||
fuzzer.send(net,11);
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
fuzzer.send(net,4);
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
fuzzer.send(net,100); // the rest
|
||||
|
||||
fuzzer.expect(expect);
|
||||
}
|
||||
finally
|
||||
{
|
||||
fuzzer.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* invalid text message, 1 frame/fragment (slowly, and split within code points)
|
||||
*/
|
||||
@Test
|
||||
@Slow
|
||||
public void testCase6_4_4() throws Exception
|
||||
{
|
||||
byte invalid[] = Hex.asByteArray("CEBAE1BDB9CF83CEBCCEB5F49080808080656469746564");
|
||||
|
||||
List<WebSocketFrame> send = new ArrayList<>();
|
||||
send.add(new WebSocketFrame(OpCode.TEXT).setPayload(invalid));
|
||||
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
|
||||
List<WebSocketFrame> expect = new ArrayList<>();
|
||||
expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame());
|
||||
|
||||
Fuzzer fuzzer = new Fuzzer(this);
|
||||
try
|
||||
{
|
||||
fuzzer.connect();
|
||||
|
||||
ByteBuffer net = fuzzer.asNetworkBuffer(send);
|
||||
fuzzer.send(net,6);
|
||||
fuzzer.send(net,11);
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
fuzzer.send(net,1);
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
fuzzer.send(net,100); // the rest
|
||||
|
||||
fuzzer.expect(expect);
|
||||
}
|
||||
finally
|
||||
{
|
||||
fuzzer.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* valid utf8 text message, 1 frame/fragment.
|
||||
*/
|
||||
@Test
|
||||
public void testCase6_5_1() throws Exception
|
||||
{
|
||||
byte msg[] = Hex.asByteArray("CEBAE1BDB9CF83CEBCCEB5");
|
||||
|
||||
List<WebSocketFrame> send = new ArrayList<>();
|
||||
send.add(new WebSocketFrame(OpCode.TEXT).setPayload(msg));
|
||||
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
|
||||
List<WebSocketFrame> expect = new ArrayList<>();
|
||||
expect.add(new WebSocketFrame(OpCode.TEXT).setPayload(msg));
|
||||
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
|
||||
Fuzzer fuzzer = new Fuzzer(this);
|
||||
try
|
||||
{
|
||||
fuzzer.connect();
|
||||
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
|
||||
fuzzer.send(send);
|
||||
fuzzer.expect(expect);
|
||||
}
|
||||
finally
|
||||
{
|
||||
fuzzer.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* invalid utf8 (incomplete code point) text message, 1 frame/fragment.
|
||||
*/
|
||||
@Test
|
||||
public void testCase6_6_1() throws Exception
|
||||
{
|
||||
byte incomplete[] = Hex.asByteArray("CE");
|
||||
|
||||
List<WebSocketFrame> send = new ArrayList<>();
|
||||
send.add(new WebSocketFrame(OpCode.TEXT).setPayload(incomplete));
|
||||
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
|
||||
List<WebSocketFrame> expect = new ArrayList<>();
|
||||
expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame());
|
||||
|
||||
Fuzzer fuzzer = new Fuzzer(this);
|
||||
try
|
||||
{
|
||||
fuzzer.connect();
|
||||
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
|
||||
fuzzer.send(send);
|
||||
fuzzer.expect(expect);
|
||||
}
|
||||
finally
|
||||
{
|
||||
fuzzer.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* invalid utf8 text message, 1 frame/fragment, 4 valid code points + 1 partial code point
|
||||
*/
|
||||
@Test
|
||||
public void testCase6_6_10() throws Exception
|
||||
{
|
||||
byte invalid[] = Hex.asByteArray("CEBAE1BDB9CF83CEBCCE");
|
||||
|
||||
List<WebSocketFrame> send = new ArrayList<>();
|
||||
send.add(new WebSocketFrame(OpCode.TEXT).setPayload(invalid));
|
||||
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
|
||||
List<WebSocketFrame> expect = new ArrayList<>();
|
||||
expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame());
|
||||
|
||||
Fuzzer fuzzer = new Fuzzer(this);
|
||||
try
|
||||
{
|
||||
fuzzer.connect();
|
||||
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
|
||||
fuzzer.send(send);
|
||||
fuzzer.expect(expect);
|
||||
}
|
||||
finally
|
||||
{
|
||||
fuzzer.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* valid utf8 text message, 1 frame/fragment, 5 valid code points (preserved on echo).
|
||||
*/
|
||||
@Test
|
||||
public void testCase6_6_11() throws Exception
|
||||
{
|
||||
byte msg[] = Hex.asByteArray("CEBAE1BDB9CF83CEBCCEB5");
|
||||
|
||||
List<WebSocketFrame> send = new ArrayList<>();
|
||||
send.add(new WebSocketFrame(OpCode.TEXT).setPayload(msg));
|
||||
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
|
||||
List<WebSocketFrame> expect = new ArrayList<>();
|
||||
expect.add(new WebSocketFrame(OpCode.TEXT).setPayload(msg));
|
||||
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
|
||||
Fuzzer fuzzer = new Fuzzer(this);
|
||||
try
|
||||
{
|
||||
fuzzer.connect();
|
||||
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
|
||||
fuzzer.send(send);
|
||||
fuzzer.expect(expect);
|
||||
}
|
||||
finally
|
||||
{
|
||||
fuzzer.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* valid utf8 text message, 1 frame/fragment, 1 valid code point (preserved on echo).
|
||||
*/
|
||||
@Test
|
||||
public void testCase6_6_2() throws Exception
|
||||
{
|
||||
byte msg[] = Hex.asByteArray("CEBA");
|
||||
|
||||
List<WebSocketFrame> send = new ArrayList<>();
|
||||
send.add(new WebSocketFrame(OpCode.TEXT).setPayload(msg));
|
||||
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
|
||||
List<WebSocketFrame> expect = new ArrayList<>();
|
||||
expect.add(new WebSocketFrame(OpCode.TEXT).setPayload(msg));
|
||||
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
|
||||
Fuzzer fuzzer = new Fuzzer(this);
|
||||
try
|
||||
{
|
||||
fuzzer.connect();
|
||||
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
|
||||
fuzzer.send(send);
|
||||
fuzzer.expect(expect);
|
||||
}
|
||||
finally
|
||||
{
|
||||
fuzzer.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* invalid utf8 text message, 1 frame/fragment, 1 valid code point + 1 partial code point
|
||||
*/
|
||||
@Test
|
||||
public void testCase6_6_3() throws Exception
|
||||
{
|
||||
byte invalid[] = Hex.asByteArray("CEBAE1");
|
||||
|
||||
List<WebSocketFrame> send = new ArrayList<>();
|
||||
send.add(new WebSocketFrame(OpCode.TEXT).setPayload(invalid));
|
||||
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
|
||||
List<WebSocketFrame> expect = new ArrayList<>();
|
||||
expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame());
|
||||
|
||||
Fuzzer fuzzer = new Fuzzer(this);
|
||||
try
|
||||
{
|
||||
fuzzer.connect();
|
||||
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
|
||||
fuzzer.send(send);
|
||||
fuzzer.expect(expect);
|
||||
}
|
||||
finally
|
||||
{
|
||||
fuzzer.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* invalid utf8 text message, 1 frame/fragment, 1 valid code point + 1 invalid code point
|
||||
*/
|
||||
@Test
|
||||
public void testCase6_6_4() throws Exception
|
||||
{
|
||||
byte invalid[] = Hex.asByteArray("CEBAE1BD");
|
||||
|
||||
List<WebSocketFrame> send = new ArrayList<>();
|
||||
send.add(new WebSocketFrame(OpCode.TEXT).setPayload(invalid));
|
||||
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
|
||||
List<WebSocketFrame> expect = new ArrayList<>();
|
||||
expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame());
|
||||
|
||||
Fuzzer fuzzer = new Fuzzer(this);
|
||||
try
|
||||
{
|
||||
fuzzer.connect();
|
||||
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
|
||||
fuzzer.send(send);
|
||||
fuzzer.expect(expect);
|
||||
}
|
||||
finally
|
||||
{
|
||||
fuzzer.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* valid utf8 text message, 1 frame/fragment, 2 valid code points (preserved on echo).
|
||||
*/
|
||||
@Test
|
||||
public void testCase6_6_5() throws Exception
|
||||
{
|
||||
byte msg[] = Hex.asByteArray("CEBAE1BDB9");
|
||||
|
||||
List<WebSocketFrame> send = new ArrayList<>();
|
||||
send.add(new WebSocketFrame(OpCode.TEXT).setPayload(msg));
|
||||
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
|
||||
List<WebSocketFrame> expect = new ArrayList<>();
|
||||
expect.add(new WebSocketFrame(OpCode.TEXT).setPayload(msg));
|
||||
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
|
||||
Fuzzer fuzzer = new Fuzzer(this);
|
||||
try
|
||||
{
|
||||
fuzzer.connect();
|
||||
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
|
||||
fuzzer.send(send);
|
||||
fuzzer.expect(expect);
|
||||
}
|
||||
finally
|
||||
{
|
||||
fuzzer.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* invalid utf8 text message, 1 frame/fragment, 2 valid code points + 1 partial code point
|
||||
*/
|
||||
@Test
|
||||
public void testCase6_6_6() throws Exception
|
||||
{
|
||||
byte invalid[] = Hex.asByteArray("CEBAE1BDB9CF");
|
||||
|
||||
List<WebSocketFrame> send = new ArrayList<>();
|
||||
send.add(new WebSocketFrame(OpCode.TEXT).setPayload(invalid));
|
||||
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
|
||||
List<WebSocketFrame> expect = new ArrayList<>();
|
||||
expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame());
|
||||
|
||||
Fuzzer fuzzer = new Fuzzer(this);
|
||||
try
|
||||
{
|
||||
fuzzer.connect();
|
||||
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
|
||||
fuzzer.send(send);
|
||||
fuzzer.expect(expect);
|
||||
}
|
||||
finally
|
||||
{
|
||||
fuzzer.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* valid utf8 text message, 1 frame/fragment, 3 valid code points (preserved on echo).
|
||||
*/
|
||||
@Test
|
||||
public void testCase6_6_7() throws Exception
|
||||
{
|
||||
byte msg[] = Hex.asByteArray("CEBAE1BDB9CF83");
|
||||
|
||||
List<WebSocketFrame> send = new ArrayList<>();
|
||||
send.add(new WebSocketFrame(OpCode.TEXT).setPayload(msg));
|
||||
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
|
||||
List<WebSocketFrame> expect = new ArrayList<>();
|
||||
expect.add(new WebSocketFrame(OpCode.TEXT).setPayload(msg));
|
||||
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
|
||||
Fuzzer fuzzer = new Fuzzer(this);
|
||||
try
|
||||
{
|
||||
fuzzer.connect();
|
||||
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
|
||||
fuzzer.send(send);
|
||||
fuzzer.expect(expect);
|
||||
}
|
||||
finally
|
||||
{
|
||||
fuzzer.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* invalid utf8 text message, 1 frame/fragment, 3 valid code points + 1 partial code point
|
||||
*/
|
||||
@Test
|
||||
public void testCase6_6_8() throws Exception
|
||||
{
|
||||
byte invalid[] = Hex.asByteArray("CEBAE1BDB9CF83CE");
|
||||
|
||||
List<WebSocketFrame> send = new ArrayList<>();
|
||||
send.add(new WebSocketFrame(OpCode.TEXT).setPayload(invalid));
|
||||
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
|
||||
List<WebSocketFrame> expect = new ArrayList<>();
|
||||
expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame());
|
||||
|
||||
Fuzzer fuzzer = new Fuzzer(this);
|
||||
try
|
||||
{
|
||||
fuzzer.connect();
|
||||
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
|
||||
fuzzer.send(send);
|
||||
fuzzer.expect(expect);
|
||||
}
|
||||
finally
|
||||
{
|
||||
fuzzer.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* valid utf8 text message, 1 frame/fragment, 4 valid code points (preserved on echo).
|
||||
*/
|
||||
@Test
|
||||
public void testCase6_6_9() throws Exception
|
||||
{
|
||||
byte msg[] = Hex.asByteArray("CEBAE1BDB9CF83CEBC");
|
||||
|
||||
List<WebSocketFrame> send = new ArrayList<>();
|
||||
send.add(new WebSocketFrame(OpCode.TEXT).setPayload(msg));
|
||||
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
|
||||
List<WebSocketFrame> expect = new ArrayList<>();
|
||||
expect.add(new WebSocketFrame(OpCode.TEXT).setPayload(msg));
|
||||
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
|
||||
Fuzzer fuzzer = new Fuzzer(this);
|
||||
try
|
||||
{
|
||||
fuzzer.connect();
|
||||
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
|
||||
fuzzer.send(send);
|
||||
fuzzer.expect(expect);
|
||||
}
|
||||
finally
|
||||
{
|
||||
fuzzer.close();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -550,6 +550,14 @@ public class BlockheadClient implements IncomingFrames, OutgoingFrames
|
|||
BufferUtil.writeTo(buf,out);
|
||||
}
|
||||
|
||||
public void writeRaw(ByteBuffer buf, int numBytes) throws IOException
|
||||
{
|
||||
int len = Math.min(numBytes,buf.remaining());
|
||||
byte arr[] = new byte[len];
|
||||
buf.get(arr,0,len);
|
||||
out.write(arr);
|
||||
}
|
||||
|
||||
public void writeRaw(String str) throws IOException
|
||||
{
|
||||
LOG.debug("write((String)[{}]){}{})",str.length(),'\n',str);
|
||||
|
@ -558,20 +566,9 @@ public class BlockheadClient implements IncomingFrames, OutgoingFrames
|
|||
|
||||
public void writeRawSlowly(ByteBuffer buf, int segmentSize) throws IOException
|
||||
{
|
||||
int origLimit = buf.limit();
|
||||
int limit = buf.limit();
|
||||
int len;
|
||||
int pos = buf.position();
|
||||
int overallLeft = buf.remaining();
|
||||
while (overallLeft > 0)
|
||||
while (buf.remaining() > 0)
|
||||
{
|
||||
buf.position(pos);
|
||||
limit = Math.min(origLimit,pos + segmentSize);
|
||||
buf.limit(limit);
|
||||
len = buf.remaining();
|
||||
overallLeft -= len;
|
||||
pos += len;
|
||||
writeRaw(buf);
|
||||
writeRaw(buf,segmentSize);
|
||||
flush();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
//========================================================================
|
||||
//Copyright 2011-2012 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.helper;
|
||||
|
||||
public final class Hex
|
||||
{
|
||||
private static final char[] hexcodes = "0123456789ABCDEF".toCharArray();
|
||||
|
||||
public static byte[] asByteArray(String hstr)
|
||||
{
|
||||
if ((hstr.length() < 0) || ((hstr.length() % 2) != 0))
|
||||
{
|
||||
throw new IllegalArgumentException(String.format("Invalid string length of <%d>",hstr.length()));
|
||||
}
|
||||
|
||||
int size = hstr.length() / 2;
|
||||
byte buf[] = new byte[size];
|
||||
byte hex;
|
||||
int len = hstr.length();
|
||||
|
||||
int idx = (int)Math.floor(((size * 2) - (double)len) / 2);
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
hex = 0;
|
||||
if (i >= 0)
|
||||
{
|
||||
hex = (byte)(Character.digit(hstr.charAt(i),16) << 4);
|
||||
}
|
||||
i++;
|
||||
hex += (byte)(Character.digit(hstr.charAt(i),16));
|
||||
|
||||
buf[idx] = hex;
|
||||
idx++;
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
public static String asHex(byte buf[])
|
||||
{
|
||||
int len = buf.length;
|
||||
char out[] = new char[len * 2];
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
out[i * 2] = hexcodes[(buf[i] & 0xF0) >> 4];
|
||||
out[(i * 2) + 1] = hexcodes[(buf[i] & 0x0F)];
|
||||
}
|
||||
return String.valueOf(out);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue