use of org.eclipse.jetty.websocket.common.WebSocketFrame in project jetty.project by eclipse.
the class DeMaskProcessorTest method testDeMaskText.
@Test
public void testDeMaskText() {
// Use a string that is not multiple of 4 in length to test if/else branches in DeMaskProcessor
String message = "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF01";
WebSocketFrame frame = new TextFrame().setPayload(message);
frame.setMask(TypeUtil.fromHexString("11223344"));
ByteBuffer buf = UnitGenerator.generate(frame);
LOG.debug("Buf: {}", BufferUtil.toDetailString(buf));
ByteBuffer payload = buf.slice();
// where payload starts
payload.position(6);
LOG.debug("Payload: {}", BufferUtil.toDetailString(payload));
DeMaskProcessor demask = new DeMaskProcessor();
demask.reset(frame);
demask.process(payload);
ByteBufferAssert.assertEquals("DeMasked Text Payload", message, payload);
}
use of org.eclipse.jetty.websocket.common.WebSocketFrame in project jetty.project by eclipse.
the class TestABCase2 method testGenerate125OctetPingCase2_4.
@Test
public void testGenerate125OctetPingCase2_4() {
byte[] bytes = new byte[125];
for (int i = 0; i < bytes.length; ++i) {
bytes[i] = Integer.valueOf(Integer.toOctalString(i)).byteValue();
}
WebSocketFrame pingFrame = new PingFrame().setPayload(bytes);
ByteBuffer actual = UnitGenerator.generate(pingFrame);
ByteBuffer expected = ByteBuffer.allocate(bytes.length + 32);
expected.put(new byte[] { (byte) 0x89 });
// no masking
byte b = 0x00;
b |= bytes.length & 0x7F;
expected.put(b);
expected.put(bytes);
expected.flip();
ByteBufferAssert.assertEquals("buffers do not match", expected, actual);
}
use of org.eclipse.jetty.websocket.common.WebSocketFrame in project jetty.project by eclipse.
the class PerMessageDeflateExtensionTest method testOutgoingPing.
/**
* Outgoing PING (Control Frame) should pass through extension unmodified
* @throws IOException on test failure
*/
@Test
public void testOutgoingPing() throws IOException {
PerMessageDeflateExtension ext = new PerMessageDeflateExtension();
ext.setBufferPool(bufferPool);
ext.setPolicy(WebSocketPolicy.newServerPolicy());
ExtensionConfig config = ExtensionConfig.parse("permessage-deflate");
ext.setConfig(config);
// Setup capture of outgoing frames
OutgoingFramesCapture capture = new OutgoingFramesCapture();
// Wire up stack
ext.setNextOutgoingFrames(capture);
String payload = "Are you there?";
Frame ping = new PingFrame().setPayload(payload);
ext.outgoingFrame(ping, null, BatchMode.OFF);
capture.assertFrameCount(1);
capture.assertHasFrame(OpCode.PING, 1);
WebSocketFrame actual = capture.getFrames().getFirst();
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.WebSocketFrame 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.WebSocketFrame in project jetty.project by eclipse.
the class TestABCase1_1 method testGenerateEmptyTextCase1_1_1.
@Test
public void testGenerateEmptyTextCase1_1_1() {
WebSocketFrame textFrame = new TextFrame().setPayload("");
ByteBuffer actual = UnitGenerator.generate(textFrame);
ByteBuffer expected = ByteBuffer.allocate(5);
expected.put(new byte[] { (byte) 0x81, (byte) 0x00 });
expected.flip();
ByteBufferAssert.assertEquals("buffers do not match", expected, actual);
}
Aggregations