Search in sources :

Example 11 with CloseInfo

use of org.eclipse.jetty.websocket.common.CloseInfo 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);
    }
}
Also used : Fuzzer(org.eclipse.jetty.websocket.common.test.Fuzzer) ArrayList(java.util.ArrayList) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) ContinuationFrame(org.eclipse.jetty.websocket.common.frames.ContinuationFrame) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test) Slow(org.eclipse.jetty.toolchain.test.annotation.Slow)

Example 12 with CloseInfo

use of org.eclipse.jetty.websocket.common.CloseInfo in project jetty.project by eclipse.

the class TestABCase6 method testCase6_4_4.

/**
     * invalid text message, 1 frame/fragment (slowly, and split within code points)
     * @throws Exception on test failure
     */
@Test
@Slow
public void testCase6_4_4() throws Exception {
    byte[] invalid = Hex.asByteArray("CEBAE1BDB9CF83CEBCCEB5F49080808080656469746564");
    List<WebSocketFrame> send = new ArrayList<>();
    send.add(new TextFrame().setPayload(ByteBuffer.wrap(invalid)));
    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);
        StacklessLogging scope = new StacklessLogging(Parser.class)) {
        fuzzer.connect();
        ByteBuffer net = fuzzer.asNetworkBuffer(send);
        fuzzer.send(net, 6);
        fuzzer.send(net, 11);
        TimeUnit.SECONDS.sleep(1);
        fuzzer.send(net, 1);
        TimeUnit.SECONDS.sleep(1);
        // the rest
        fuzzer.send(net, 100);
        fuzzer.expect(expect);
    }
}
Also used : Fuzzer(org.eclipse.jetty.websocket.common.test.Fuzzer) ArrayList(java.util.ArrayList) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) Slow(org.eclipse.jetty.toolchain.test.annotation.Slow)

Example 13 with CloseInfo

use of org.eclipse.jetty.websocket.common.CloseInfo in project jetty.project by eclipse.

the class TestABCase6 method testCase6_4_1.

/**
     * invalid text message, 3 fragments.
     * <p>
     * fragment #1 and fragment #3 are both valid in themselves.
     * <p>
     * fragment #2 contains the invalid utf8 code point.
     * @throws Exception on test failure
     */
@Test
@Slow
public void testCase6_4_1() throws Exception {
    byte[] part1 = StringUtil.getUtf8Bytes("κόσμε");
    // invalid
    byte[] part2 = Hex.asByteArray("F4908080");
    byte[] part3 = StringUtil.getUtf8Bytes("edited");
    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);
    }
}
Also used : Fuzzer(org.eclipse.jetty.websocket.common.test.Fuzzer) ArrayList(java.util.ArrayList) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) ContinuationFrame(org.eclipse.jetty.websocket.common.frames.ContinuationFrame) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test) Slow(org.eclipse.jetty.toolchain.test.annotation.Slow)

Example 14 with CloseInfo

use of org.eclipse.jetty.websocket.common.CloseInfo in project jetty.project by eclipse.

the class TestABCase6 method testCase6_1_2.

/**
     * text message, 0 length, 3 fragments
     * @throws Exception on test failure
     */
@Test
public void testCase6_1_2() throws Exception {
    List<WebSocketFrame> send = new ArrayList<>();
    send.add(new TextFrame().setFin(false));
    send.add(new ContinuationFrame().setFin(false));
    send.add(new ContinuationFrame().setFin(true));
    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);
    }
}
Also used : Fuzzer(org.eclipse.jetty.websocket.common.test.Fuzzer) ArrayList(java.util.ArrayList) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) ContinuationFrame(org.eclipse.jetty.websocket.common.frames.ContinuationFrame) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Example 15 with CloseInfo

use of org.eclipse.jetty.websocket.common.CloseInfo in project jetty.project by eclipse.

the class TestABCase6 method testCase6_2_4.

/**
     * valid utf8 text message, many fragments (1 byte each)
     * @throws Exception on test failure
     */
@Test
public void testCase6_2_4() throws Exception {
    byte[] msg = Hex.asByteArray("CEBAE1BDB9CF83CEBCCEB5");
    List<WebSocketFrame> send = new ArrayList<>();
    fragmentText(send, msg);
    send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    List<WebSocketFrame> expect = new ArrayList<>();
    expect.add(new TextFrame().setPayload(ByteBuffer.wrap(msg)));
    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);
    }
}
Also used : Fuzzer(org.eclipse.jetty.websocket.common.test.Fuzzer) ArrayList(java.util.ArrayList) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Aggregations

CloseInfo (org.eclipse.jetty.websocket.common.CloseInfo)151 Test (org.junit.Test)129 WebSocketFrame (org.eclipse.jetty.websocket.common.WebSocketFrame)118 ArrayList (java.util.ArrayList)104 Fuzzer (org.eclipse.jetty.websocket.common.test.Fuzzer)104 TextFrame (org.eclipse.jetty.websocket.common.frames.TextFrame)68 StacklessLogging (org.eclipse.jetty.util.log.StacklessLogging)55 ByteBuffer (java.nio.ByteBuffer)48 PingFrame (org.eclipse.jetty.websocket.common.frames.PingFrame)30 ContinuationFrame (org.eclipse.jetty.websocket.common.frames.ContinuationFrame)27 PongFrame (org.eclipse.jetty.websocket.common.frames.PongFrame)19 BinaryFrame (org.eclipse.jetty.websocket.common.frames.BinaryFrame)17 BlockheadClient (org.eclipse.jetty.websocket.common.test.BlockheadClient)14 IBlockheadClient (org.eclipse.jetty.websocket.common.test.IBlockheadClient)10 CloseableLocalWebSocketSession (org.eclipse.jetty.websocket.common.io.CloseableLocalWebSocketSession)8 LocalWebSocketSession (org.eclipse.jetty.websocket.common.io.LocalWebSocketSession)8 Stress (org.eclipse.jetty.toolchain.test.annotation.Stress)6 Slow (org.eclipse.jetty.toolchain.test.annotation.Slow)5 CloseFrame (org.eclipse.jetty.websocket.common.frames.CloseFrame)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4