use of org.eclipse.jetty.websocket.common.test.IncomingFramesCapture in project jetty.project by eclipse.
the class PerMessageDeflateExtensionTest method testIncomingPing.
/**
* Incoming PING (Control Frame) should pass through extension unmodified
*/
@Test
public void testIncomingPing() {
PerMessageDeflateExtension ext = new PerMessageDeflateExtension();
ext.setBufferPool(bufferPool);
ext.setPolicy(WebSocketPolicy.newServerPolicy());
ExtensionConfig config = ExtensionConfig.parse("permessage-deflate");
ext.setConfig(config);
// Setup capture of incoming frames
IncomingFramesCapture capture = new IncomingFramesCapture();
// Wire up stack
ext.setNextIncomingFrames(capture);
String payload = "Are you there?";
Frame ping = new PingFrame().setPayload(payload);
ext.incomingFrame(ping);
capture.assertFrameCount(1);
capture.assertHasFrame(OpCode.PING, 1);
WebSocketFrame actual = capture.getFrames().poll();
Assert.assertThat("Frame.opcode", actual.getOpCode(), is(OpCode.PING));
Assert.assertThat("Frame.fin", actual.isFin(), is(true));
Assert.assertThat("Frame.rsv1", actual.isRsv1(), is(false));
Assert.assertThat("Frame.rsv2", actual.isRsv2(), is(false));
Assert.assertThat("Frame.rsv3", actual.isRsv3(), is(false));
ByteBuffer expected = BufferUtil.toBuffer(payload, StandardCharsets.UTF_8);
Assert.assertThat("Frame.payloadLength", actual.getPayloadLength(), is(expected.remaining()));
ByteBufferAssert.assertEquals("Frame.payload", expected, actual.getPayload().slice());
}
use of org.eclipse.jetty.websocket.common.test.IncomingFramesCapture in project jetty.project by eclipse.
the class TestABCase7_3 method testCase7_3_5ParseCloseWithStatusMaxReason.
@Test
public void testCase7_3_5ParseCloseWithStatusMaxReason() {
StringBuilder message = new StringBuilder();
for (int i = 0; i < 123; ++i) {
message.append("*");
}
byte[] messageBytes = message.toString().getBytes(StandardCharsets.UTF_8);
ByteBuffer expected = ByteBuffer.allocate(132);
expected.put(new byte[] { (byte) 0x88 });
// no masking
byte b = 0x00;
b |= (messageBytes.length + 2) & 0x7F;
expected.put(b);
expected.putShort((short) 1000);
expected.put(messageBytes);
expected.flip();
Parser parser = new UnitParser(policy);
IncomingFramesCapture capture = new IncomingFramesCapture();
parser.setIncomingFramesHandler(capture);
parser.parse(expected);
capture.assertNoErrors();
capture.assertHasFrame(OpCode.CLOSE, 1);
Frame pActual = capture.getFrames().poll();
Assert.assertThat("CloseFrame.payloadLength", pActual.getPayloadLength(), is(125));
}
use of org.eclipse.jetty.websocket.common.test.IncomingFramesCapture in project jetty.project by eclipse.
the class TestABCase1_1 method testParse65536ByteTextCase1_1_7.
@Test
public void testParse65536ByteTextCase1_1_7() {
int length = 65536;
ByteBuffer expected = ByteBuffer.allocate(length + 11);
expected.put(new byte[] { (byte) 0x81 });
// no masking
byte b = 0x00;
b |= 0x7F;
expected.put(b);
expected.put(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00 });
for (int i = 0; i < length; ++i) {
expected.put("*".getBytes());
}
expected.flip();
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.CLIENT);
policy.setMaxTextMessageSize(length);
Parser parser = new UnitParser(policy);
IncomingFramesCapture capture = new IncomingFramesCapture();
parser.setIncomingFramesHandler(capture);
parser.parse(expected);
capture.assertNoErrors();
capture.assertHasFrame(OpCode.TEXT, 1);
Frame pActual = capture.getFrames().poll();
Assert.assertThat("TextFrame.payloadLength", pActual.getPayloadLength(), is(length));
// Assert.assertEquals("TextFrame.payload",length,pActual.getPayloadData().length);
}
use of org.eclipse.jetty.websocket.common.test.IncomingFramesCapture in project jetty.project by eclipse.
the class TestABCase1_1 method testParse65535ByteTextCase1_1_6.
@Test
public void testParse65535ByteTextCase1_1_6() {
int length = 65535;
ByteBuffer expected = ByteBuffer.allocate(length + 5);
expected.put(new byte[] { (byte) 0x81 });
// no masking
byte b = 0x00;
b |= 0x7E;
expected.put(b);
expected.put(new byte[] { (byte) 0xff, (byte) 0xff });
for (int i = 0; i < length; ++i) {
expected.put("*".getBytes());
}
expected.flip();
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.CLIENT);
policy.setMaxTextMessageSize(length);
Parser parser = new UnitParser(policy);
IncomingFramesCapture capture = new IncomingFramesCapture();
parser.setIncomingFramesHandler(capture);
parser.parse(expected);
capture.assertNoErrors();
capture.assertHasFrame(OpCode.TEXT, 1);
Frame pActual = capture.getFrames().poll();
Assert.assertThat("TextFrame.payloadLength", pActual.getPayloadLength(), is(length));
// Assert.assertEquals("TextFrame.payload",length,pActual.getPayloadData().length);
}
use of org.eclipse.jetty.websocket.common.test.IncomingFramesCapture in project jetty.project by eclipse.
the class TestABCase1_1 method testParse125ByteTextCase1_1_2.
@Test
public void testParse125ByteTextCase1_1_2() {
int length = 125;
ByteBuffer expected = ByteBuffer.allocate(length + 5);
expected.put(new byte[] { (byte) 0x81 });
// no masking
byte b = 0x00;
b |= length & 0x7F;
expected.put(b);
for (int i = 0; i < length; ++i) {
expected.put("*".getBytes());
}
expected.flip();
Parser parser = new UnitParser(policy);
IncomingFramesCapture capture = new IncomingFramesCapture();
parser.setIncomingFramesHandler(capture);
parser.parse(expected);
capture.assertNoErrors();
capture.assertHasFrame(OpCode.TEXT, 1);
Frame pActual = capture.getFrames().poll();
Assert.assertThat("TextFrame.payloadLength", pActual.getPayloadLength(), is(length));
// Assert.assertEquals("TextFrame.payload",length,pActual.getPayloadData().length);
}
Aggregations