Search in sources :

Example 6 with CloseFrame

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

the class TestABCase7 method testCase7_3_2.

/**
     * close with invalid payload (payload length 1)
     * @throws Exception on test failure
     */
@Test
public void testCase7_3_2() throws Exception {
    byte[] payload = new byte[] { 0x00 };
    ByteBuffer buf = ByteBuffer.wrap(payload);
    List<WebSocketFrame> send = new ArrayList<>();
    send.add(new CloseFrame().setPayload(buf));
    List<WebSocketFrame> expect = new ArrayList<>();
    expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
    try (Fuzzer fuzzer = new Fuzzer(this);
        StacklessLogging scope = new StacklessLogging(Parser.class)) {
        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) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) ByteBuffer(java.nio.ByteBuffer) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Example 7 with CloseFrame

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

the class TestABCase7_BadStatusCodes method testBadStatusCode.

/**
     * just the close code, no reason
     * @throws Exception on test failure
     */
@Test
public void testBadStatusCode() throws Exception {
    ByteBuffer payload = ByteBuffer.allocate(256);
    BufferUtil.clearToFill(payload);
    payload.putChar((char) statusCode);
    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 8 with CloseFrame

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

the class TestABCase7_GoodStatusCodes method testStatusCode.

/**
     * just the close code, no reason
     * @throws Exception on test failure
     */
@Test
public void testStatusCode() throws Exception {
    ByteBuffer payload = ByteBuffer.allocate(256);
    BufferUtil.clearToFill(payload);
    payload.putChar((char) statusCode);
    BufferUtil.flipToFlush(payload, 0);
    List<WebSocketFrame> send = new ArrayList<>();
    send.add(new CloseFrame().setPayload(payload.slice()));
    List<WebSocketFrame> expect = new ArrayList<>();
    expect.add(new CloseFrame().setPayload(clone(payload)));
    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) Test(org.junit.Test)

Example 9 with CloseFrame

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

the class TestABCase7_3 method testCase7_3_2Generate1BytePayloadClose.

@Test(expected = ProtocolException.class)
public void testCase7_3_2Generate1BytePayloadClose() {
    CloseFrame closeFrame = new CloseFrame();
    closeFrame.setPayload(Hex.asByteBuffer("00"));
    UnitGenerator.generate(closeFrame);
}
Also used : CloseFrame(org.eclipse.jetty.websocket.common.frames.CloseFrame) Test(org.junit.Test)

Example 10 with CloseFrame

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

the class TestABCase7_3 method testCase7_3_6GenerateCloseWithInvalidStatusReason.

@Test(expected = ProtocolException.class)
public void testCase7_3_6GenerateCloseWithInvalidStatusReason() {
    StringBuilder message = new StringBuilder();
    for (int i = 0; i < 124; ++i) {
        message.append("*");
    }
    byte[] messageBytes = message.toString().getBytes();
    CloseFrame closeFrame = new CloseFrame();
    // 126 which is too big for control
    ByteBuffer bb = ByteBuffer.allocate(CloseFrame.MAX_CONTROL_PAYLOAD + 1);
    bb.putChar((char) 1000);
    bb.put(messageBytes);
    BufferUtil.flipToFlush(bb, 0);
    closeFrame.setPayload(bb);
    UnitGenerator.generate(closeFrame);
}
Also used : CloseFrame(org.eclipse.jetty.websocket.common.frames.CloseFrame) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

CloseFrame (org.eclipse.jetty.websocket.common.frames.CloseFrame)20 Test (org.junit.Test)15 ByteBuffer (java.nio.ByteBuffer)10 ArrayList (java.util.ArrayList)6 WebSocketFrame (org.eclipse.jetty.websocket.common.WebSocketFrame)6 Fuzzer (org.eclipse.jetty.websocket.common.test.Fuzzer)6 CloseInfo (org.eclipse.jetty.websocket.common.CloseInfo)4 ProtocolException (org.eclipse.jetty.websocket.api.ProtocolException)3 BinaryFrame (org.eclipse.jetty.websocket.common.frames.BinaryFrame)2 ContinuationFrame (org.eclipse.jetty.websocket.common.frames.ContinuationFrame)2 PingFrame (org.eclipse.jetty.websocket.common.frames.PingFrame)2 PongFrame (org.eclipse.jetty.websocket.common.frames.PongFrame)2 TextFrame (org.eclipse.jetty.websocket.common.frames.TextFrame)2 NotUtf8Exception (org.eclipse.jetty.util.Utf8Appendable.NotUtf8Exception)1 StacklessLogging (org.eclipse.jetty.util.log.StacklessLogging)1 CloseException (org.eclipse.jetty.websocket.api.CloseException)1