Search in sources :

Example 96 with Fuzzer

use of org.eclipse.jetty.websocket.common.test.Fuzzer in project jetty.project by eclipse.

the class TestABCase7_BadStatusCodes method testBadStatusCodeWithReason.

/**
     * the bad close code, with reason
     * @throws Exception on test failure
     */
@Test
public void testBadStatusCodeWithReason() throws Exception {
    ByteBuffer payload = ByteBuffer.allocate(256);
    BufferUtil.clearToFill(payload);
    payload.putChar((char) statusCode);
    payload.put(StringUtil.getBytes("Reason"));
    BufferUtil.flipToFlush(payload, 0);
    List<WebSocketFrame> send = new ArrayList<>();
    send.add(new CloseFrame().setPayload(payload.slice()));
    List<WebSocketFrame> expect = new ArrayList<>();
    expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
    try (Fuzzer fuzzer = new Fuzzer(this)) {
        fuzzer.connect();
        fuzzer.setSendMode(Fuzzer.SendMode.BULK);
        fuzzer.send(send);
        fuzzer.expect(expect);
        fuzzer.expectNoMoreFrames();
    }
}
Also used : Fuzzer(org.eclipse.jetty.websocket.common.test.Fuzzer) ArrayList(java.util.ArrayList) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) CloseFrame(org.eclipse.jetty.websocket.common.frames.CloseFrame) ByteBuffer(java.nio.ByteBuffer) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Example 97 with Fuzzer

use of org.eclipse.jetty.websocket.common.test.Fuzzer in project jetty.project by eclipse.

the class TestABCase1 method testCase1_2_2.

/**
     * Echo 125 byte BINARY message (uses small 7-bit payload length)
     * @throws Exception on test failure
     */
@Test
public void testCase1_2_2() throws Exception {
    byte[] payload = new byte[125];
    Arrays.fill(payload, (byte) 0xFE);
    ByteBuffer buf = ByteBuffer.wrap(payload);
    List<WebSocketFrame> send = new ArrayList<>();
    send.add(new BinaryFrame().setPayload(buf));
    send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    List<WebSocketFrame> expect = new ArrayList<>();
    expect.add(new BinaryFrame().setPayload(clone(buf)));
    expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    try (Fuzzer fuzzer = new Fuzzer(this)) {
        fuzzer.connect();
        fuzzer.setSendMode(SendMode.BULK);
        fuzzer.send(send);
        fuzzer.expect(expect);
    }
}
Also used : Fuzzer(org.eclipse.jetty.websocket.common.test.Fuzzer) BinaryFrame(org.eclipse.jetty.websocket.common.frames.BinaryFrame) ArrayList(java.util.ArrayList) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) ByteBuffer(java.nio.ByteBuffer) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Example 98 with Fuzzer

use of org.eclipse.jetty.websocket.common.test.Fuzzer in project jetty.project by eclipse.

the class TestABCase1 method testCase1_2_8.

/**
     * Echo 65536 byte BINARY message (uses large 8 byte payload length).
     * <p>
     * Only send 1 BINARY frame from client, but in small segments (flushed after each).
     * <p>
     * This is done to test the parsing together of the frame on the server side.
     * @throws Exception on test failure
     */
@Test
public void testCase1_2_8() throws Exception {
    byte[] payload = new byte[65536];
    Arrays.fill(payload, (byte) 0xFE);
    ByteBuffer buf = ByteBuffer.wrap(payload);
    int segmentSize = 997;
    List<WebSocketFrame> send = new ArrayList<>();
    send.add(new BinaryFrame().setPayload(buf));
    send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    List<WebSocketFrame> expect = new ArrayList<>();
    expect.add(new BinaryFrame().setPayload(clone(buf)));
    expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    try (Fuzzer fuzzer = new Fuzzer(this)) {
        fuzzer.connect();
        fuzzer.setSendMode(SendMode.SLOW);
        fuzzer.setSlowSendSegmentSize(segmentSize);
        fuzzer.send(send);
        fuzzer.expect(expect);
    }
}
Also used : Fuzzer(org.eclipse.jetty.websocket.common.test.Fuzzer) BinaryFrame(org.eclipse.jetty.websocket.common.frames.BinaryFrame) ArrayList(java.util.ArrayList) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) ByteBuffer(java.nio.ByteBuffer) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Example 99 with Fuzzer

use of org.eclipse.jetty.websocket.common.test.Fuzzer in project jetty.project by eclipse.

the class TestABCase1 method testCase1_1_4.

/**
     * Echo 127 byte TEXT message (uses medium 2 byte payload length)
     * @throws Exception on test failure
     */
@Test
public void testCase1_1_4() throws Exception {
    byte[] payload = new byte[127];
    Arrays.fill(payload, (byte) '*');
    ByteBuffer buf = ByteBuffer.wrap(payload);
    List<WebSocketFrame> send = new ArrayList<>();
    send.add(new TextFrame().setPayload(buf));
    send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    List<WebSocketFrame> expect = new ArrayList<>();
    expect.add(new TextFrame().setPayload(clone(buf)));
    expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    try (Fuzzer fuzzer = new Fuzzer(this)) {
        fuzzer.connect();
        fuzzer.setSendMode(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) ByteBuffer(java.nio.ByteBuffer) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Example 100 with Fuzzer

use of org.eclipse.jetty.websocket.common.test.Fuzzer in project jetty.project by eclipse.

the class TestABCase2 method testCase2_11.

/**
     * 10 pings, sent slowly
     * @throws Exception on test failure
     */
@Test
public void testCase2_11() throws Exception {
    // send 10 pings (slowly) each with unique payload
    // send close
    // expect 10 pongs with OUR payload
    // expect close
    int pingCount = 10;
    List<WebSocketFrame> send = new ArrayList<>();
    List<WebSocketFrame> expect = new ArrayList<>();
    for (int i = 0; i < pingCount; i++) {
        String payload = String.format("ping-%d[%X]", i, i);
        send.add(new PingFrame().setPayload(payload));
        expect.add(new PongFrame().setPayload(payload));
    }
    send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    try (Fuzzer fuzzer = new Fuzzer(this)) {
        fuzzer.connect();
        fuzzer.setSendMode(Fuzzer.SendMode.SLOW);
        fuzzer.setSlowSendSegmentSize(5);
        fuzzer.send(send);
        fuzzer.expect(expect);
    }
}
Also used : PongFrame(org.eclipse.jetty.websocket.common.frames.PongFrame) Fuzzer(org.eclipse.jetty.websocket.common.test.Fuzzer) PingFrame(org.eclipse.jetty.websocket.common.frames.PingFrame) ArrayList(java.util.ArrayList) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Aggregations

WebSocketFrame (org.eclipse.jetty.websocket.common.WebSocketFrame)108 Fuzzer (org.eclipse.jetty.websocket.common.test.Fuzzer)108 ArrayList (java.util.ArrayList)106 Test (org.junit.Test)106 CloseInfo (org.eclipse.jetty.websocket.common.CloseInfo)104 TextFrame (org.eclipse.jetty.websocket.common.frames.TextFrame)59 StacklessLogging (org.eclipse.jetty.util.log.StacklessLogging)45 ByteBuffer (java.nio.ByteBuffer)43 PingFrame (org.eclipse.jetty.websocket.common.frames.PingFrame)27 ContinuationFrame (org.eclipse.jetty.websocket.common.frames.ContinuationFrame)26 PongFrame (org.eclipse.jetty.websocket.common.frames.PongFrame)17 BinaryFrame (org.eclipse.jetty.websocket.common.frames.BinaryFrame)15 Stress (org.eclipse.jetty.toolchain.test.annotation.Stress)6 CloseFrame (org.eclipse.jetty.websocket.common.frames.CloseFrame)6 Slow (org.eclipse.jetty.toolchain.test.annotation.Slow)5