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();
}
}
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();
}
}
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();
}
}
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);
}
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);
}
Aggregations