Search in sources :

Example 6 with TextFrame

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));
    }
}
Also used : TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 7 with TextFrame

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));
}
Also used : Tester(org.eclipse.jetty.websocket.common.extensions.ExtensionTool.Tester) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) ContinuationFrame(org.eclipse.jetty.websocket.common.frames.ContinuationFrame) AbstractExtensionTest(org.eclipse.jetty.websocket.common.extensions.AbstractExtensionTest) Test(org.junit.Test)

Example 8 with TextFrame

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);
}
Also used : TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 9 with TextFrame

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);
}
Also used : TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 10 with TextFrame

use of org.eclipse.jetty.websocket.common.frames.TextFrame in project jetty.project by eclipse.

the class TestABCase1_1 method testGenerate126ByteTextCase1_1_3.

@Test
public void testGenerate126ByteTextCase1_1_3() {
    int length = 126;
    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);
}
Also used : TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

TextFrame (org.eclipse.jetty.websocket.common.frames.TextFrame)142 Test (org.junit.Test)130 WebSocketFrame (org.eclipse.jetty.websocket.common.WebSocketFrame)109 ArrayList (java.util.ArrayList)69 CloseInfo (org.eclipse.jetty.websocket.common.CloseInfo)68 Fuzzer (org.eclipse.jetty.websocket.common.test.Fuzzer)59 ByteBuffer (java.nio.ByteBuffer)54 ContinuationFrame (org.eclipse.jetty.websocket.common.frames.ContinuationFrame)38 StacklessLogging (org.eclipse.jetty.util.log.StacklessLogging)35 BlockheadClient (org.eclipse.jetty.websocket.common.test.BlockheadClient)33 PingFrame (org.eclipse.jetty.websocket.common.frames.PingFrame)23 IBlockheadClient (org.eclipse.jetty.websocket.common.test.IBlockheadClient)14 URI (java.net.URI)13 IncomingFramesCapture (org.eclipse.jetty.websocket.common.test.IncomingFramesCapture)12 Matchers.containsString (org.hamcrest.Matchers.containsString)10 PongFrame (org.eclipse.jetty.websocket.common.frames.PongFrame)9 Frame (org.eclipse.jetty.websocket.api.extensions.Frame)8 ExtensionConfig (org.eclipse.jetty.websocket.api.extensions.ExtensionConfig)6 UnitParser (org.eclipse.jetty.websocket.common.test.UnitParser)6 Slow (org.eclipse.jetty.toolchain.test.annotation.Slow)5