use of org.eclipse.jetty.websocket.common.frames.TextFrame 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.frames.TextFrame in project jetty.project by eclipse.
the class DeMaskProcessorTest method testDeMaskTextSliced.
@Test
public void testDeMaskTextSliced() {
final byte msgChar = '*';
final int messageSize = 25;
byte[] message = new byte[messageSize];
Arrays.fill(message, msgChar);
TextFrame frame = new TextFrame();
frame.setPayload(ByteBuffer.wrap(message));
frame.setMask(Hex.asByteArray("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));
LOG.debug("Pre-Processed: {}", Hex.asHex(payload));
DeMaskProcessor demask = new DeMaskProcessor();
demask.reset(frame);
ByteBuffer slice1 = payload.slice();
ByteBuffer slice2 = payload.slice();
// slice at non-multiple of 4, but also where last buffer remaining
// is more than 4.
int slicePoint = 7;
slice1.limit(slicePoint);
slice2.position(slicePoint);
Assert.assertThat("Slices are setup right", slice1.remaining() + slice2.remaining(), is(messageSize));
demask.process(slice1);
demask.process(slice2);
LOG.debug("Post-Processed: {}", Hex.asHex(payload));
Assert.assertThat("Payload.remaining", payload.remaining(), is(messageSize));
for (int i = payload.position(); i < payload.limit(); i++) {
Assert.assertThat("payload[" + i + "]", payload.get(i), is(msgChar));
}
}
use of org.eclipse.jetty.websocket.common.frames.TextFrame in project jetty.project by eclipse.
the class PerMessageDeflateExtensionTest method testDraft21_Hello_UnCompressedBlock_Fragmented.
/**
* Decode payload example as seen in draft-ietf-hybi-permessage-compression-21.
* <p>
* Section 8.2.3.1: A message compressed using 1 compressed DEFLATE block (with fragmentation)
*/
@Test
public void testDraft21_Hello_UnCompressedBlock_Fragmented() {
Tester tester = clientExtensions.newTester("permessage-deflate");
tester.assertNegotiated("permessage-deflate");
// basic, 1 block, compressed with 0 compression level (aka, uncompressed).
tester.parseIncomingHex(// Fragment 1
"0x41 0x03 0xf2 0x48 0xcd", // Fragment 2
"0x80 0x04 0xc9 0xc9 0x07 0x00");
tester.assertHasFrames(new TextFrame().setPayload("He").setFin(false), new ContinuationFrame().setPayload("llo").setFin(true));
}
use of org.eclipse.jetty.websocket.common.frames.TextFrame 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);
}
use of org.eclipse.jetty.websocket.common.frames.TextFrame in project jetty.project by eclipse.
the class TestABCase1_1 method testGenerate127ByteTextCase1_1_4.
@Test
public void testGenerate127ByteTextCase1_1_4() {
int length = 127;
StringBuilder builder = new StringBuilder();
for (int i = 0; i < length; ++i) {
builder.append("*");
}
WebSocketFrame textFrame = new TextFrame().setPayload(builder.toString());
ByteBuffer actual = UnitGenerator.generate(textFrame);
ByteBuffer expected = ByteBuffer.allocate(length + 5);
expected.put(new byte[] { (byte) 0x81 });
// no masking
byte b = 0x00;
b |= length & 0x7E;
expected.put(b);
// expected.put((byte)((length>>8) & 0xFF));
// expected.put((byte)(length & 0xFF));
expected.putShort((short) length);
for (int i = 0; i < length; ++i) {
expected.put("*".getBytes());
}
expected.flip();
ByteBufferAssert.assertEquals("buffers do not match", expected, actual);
}
Aggregations