use of org.eclipse.jetty.websocket.common.frames.TextFrame in project jetty.project by eclipse.
the class TestABCase6 method testCase6_4_3.
/**
* invalid text message, 1 frame/fragment (slowly, and split within code points)
* @throws Exception on test failure
*/
@Test
@Slow
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)) {
ByteBuffer payload = ByteBuffer.allocate(64);
BufferUtil.clearToFill(payload);
// good
payload.put(TypeUtil.fromHexString("cebae1bdb9cf83cebcceb5"));
// INVALID
payload.put(TypeUtil.fromHexString("f4908080"));
// good
payload.put(TypeUtil.fromHexString("656469746564"));
BufferUtil.flipToFlush(payload, 0);
List<WebSocketFrame> send = new ArrayList<>();
send.add(new TextFrame().setPayload(payload));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) {
fuzzer.connect();
ByteBuffer net = fuzzer.asNetworkBuffer(send);
int[] splits = { 17, 21, net.limit() };
// Header + good UTF
ByteBuffer part1 = net.slice();
part1.limit(splits[0]);
// invalid UTF
ByteBuffer part2 = net.slice();
part2.position(splits[0]);
part2.limit(splits[1]);
// good UTF
ByteBuffer part3 = net.slice();
part3.position(splits[1]);
part3.limit(splits[2]);
// the header + good utf
fuzzer.send(part1);
TimeUnit.MILLISECONDS.sleep(500);
// the bad UTF
fuzzer.send(part2);
TimeUnit.MILLISECONDS.sleep(500);
// the rest (shouldn't work)
fuzzer.send(part3);
fuzzer.expect(expect);
}
}
}
use of org.eclipse.jetty.websocket.common.frames.TextFrame in project jetty.project by eclipse.
the class TestABCase6 method testCase6_1_1.
/**
* text message, 1 frame, 0 length
* @throws Exception on test failure
*/
@Test
public void testCase6_1_1() throws Exception {
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)) {
fuzzer.connect();
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
fuzzer.send(send);
fuzzer.expect(expect);
}
}
use of org.eclipse.jetty.websocket.common.frames.TextFrame in project jetty.project by eclipse.
the class TestABCase6 method testCase6_1_3.
/**
* text message, small length, 3 fragments (only middle frame has payload)
* @throws Exception on test failure
*/
@Test
public void testCase6_1_3() throws Exception {
List<WebSocketFrame> send = new ArrayList<>();
send.add(new TextFrame().setFin(false));
send.add(new ContinuationFrame().setPayload("middle").setFin(false));
send.add(new ContinuationFrame().setFin(true));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new TextFrame().setPayload("middle"));
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);
}
}
use of org.eclipse.jetty.websocket.common.frames.TextFrame in project jetty.project by eclipse.
the class TestABCase6 method testCase6_4_2.
/**
* 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.
* @throws Exception on test failure
*/
@Test
@Slow
public void testCase6_4_2() throws Exception {
// split code point
byte[] part1 = Hex.asByteArray("CEBAE1BDB9CF83CEBCCEB5F4");
// continue code point & invalid
byte[] part2 = Hex.asByteArray("90");
// continue code point & finish
byte[] part3 = Hex.asByteArray("8080656469746564");
List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) {
fuzzer.connect();
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
fuzzer.send(new TextFrame().setPayload(ByteBuffer.wrap(part1)).setFin(false));
TimeUnit.SECONDS.sleep(1);
fuzzer.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);
}
}
use of org.eclipse.jetty.websocket.common.frames.TextFrame in project jetty.project by eclipse.
the class TestABCase6 method fragmentText.
/**
* Split a message byte array into a series of fragments (frames + continuations) of 1 byte message contents each.
* @param frames the frames
* @param msg the message
*/
protected void fragmentText(List<WebSocketFrame> frames, byte[] msg) {
int len = msg.length;
boolean continuation = false;
byte[] mini;
for (int i = 0; i < len; i++) {
DataFrame frame = null;
if (continuation) {
frame = new ContinuationFrame();
} else {
frame = new TextFrame();
}
mini = new byte[1];
mini[0] = msg[i];
frame.setPayload(ByteBuffer.wrap(mini));
boolean isLast = (i >= (len - 1));
frame.setFin(isLast);
frames.add(frame);
continuation = true;
}
}
Aggregations