use of org.eclipse.jetty.websocket.common.test.UnitParser in project jetty.project by eclipse.
the class TestABCase2 method testParseHelloPingCase2_2.
@Test
public void testParseHelloPingCase2_2() {
String message = "Hello, world!";
byte[] messageBytes = message.getBytes();
ByteBuffer expected = ByteBuffer.allocate(32);
expected.put(new byte[] { (byte) 0x89 });
// no masking
byte b = 0x00;
b |= messageBytes.length & 0x7F;
expected.put(b);
expected.put(messageBytes);
expected.flip();
Parser parser = new UnitParser(policy);
IncomingFramesCapture capture = new IncomingFramesCapture();
parser.setIncomingFramesHandler(capture);
parser.parse(expected);
capture.assertNoErrors();
capture.assertHasFrame(OpCode.PING, 1);
Frame pActual = capture.getFrames().poll();
Assert.assertThat("PingFrame.payloadLength", pActual.getPayloadLength(), is(message.length()));
Assert.assertEquals("PingFrame.payload", message.length(), pActual.getPayloadLength());
}
use of org.eclipse.jetty.websocket.common.test.UnitParser in project jetty.project by eclipse.
the class TestABCase2 method testParseBinaryPingCase2_3.
@Test
public void testParseBinaryPingCase2_3() {
byte[] bytes = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
ByteBuffer expected = ByteBuffer.allocate(32);
expected.put(new byte[] { (byte) 0x89 });
// no masking
byte b = 0x00;
b |= bytes.length & 0x7F;
expected.put(b);
expected.put(bytes);
expected.flip();
Parser parser = new UnitParser(policy);
IncomingFramesCapture capture = new IncomingFramesCapture();
parser.setIncomingFramesHandler(capture);
parser.parse(expected);
capture.assertNoErrors();
capture.assertHasFrame(OpCode.PING, 1);
Frame pActual = capture.getFrames().poll();
Assert.assertThat("PingFrame.payloadLength", pActual.getPayloadLength(), is(bytes.length));
Assert.assertEquals("PingFrame.payload", bytes.length, pActual.getPayloadLength());
}
use of org.eclipse.jetty.websocket.common.test.UnitParser in project jetty.project by eclipse.
the class TestABCase2 method testParseOversizedBinaryPingCase2_5.
@Test
public void testParseOversizedBinaryPingCase2_5() {
byte[] bytes = new byte[126];
Arrays.fill(bytes, (byte) 0x00);
ByteBuffer expected = ByteBuffer.allocate(bytes.length + Generator.MAX_HEADER_LENGTH);
byte b;
// fin + op
b = 0x00;
// fin on
b |= 0x80;
// ping
b |= 0x09;
expected.put(b);
// mask + len
b = 0x00;
// no masking
b |= 0x00;
// 2 byte len
b |= 0x7E;
expected.put(b);
// 2 byte len
expected.putChar((char) bytes.length);
// payload
expected.put(bytes);
expected.flip();
UnitParser parser = new UnitParser(policy);
IncomingFramesCapture capture = new IncomingFramesCapture();
parser.setIncomingFramesHandler(capture);
parser.parseQuietly(expected);
Assert.assertEquals("error should be returned for too large of ping payload", 1, capture.getErrorCount(ProtocolException.class));
}
use of org.eclipse.jetty.websocket.common.test.UnitParser in project jetty.project by eclipse.
the class TestABCase4 method testParserNonControlOpCode3Case4_1_1.
@Test
public void testParserNonControlOpCode3Case4_1_1() throws Exception {
ByteBuffer expected = ByteBuffer.allocate(32);
expected.put(new byte[] { (byte) 0x83, 0x00 });
expected.flip();
IncomingFramesCapture capture = new IncomingFramesCapture();
try (StacklessLogging logging = new StacklessLogging(Parser.class)) {
Parser parser = new UnitParser(policy);
parser.setIncomingFramesHandler(capture);
try {
parser.parse(expected);
} catch (ProtocolException ignore) {
// ignore
}
}
Assert.assertEquals("error on undefined opcode", 1, capture.getErrorCount(WebSocketException.class));
Throwable known = capture.getErrors().poll();
Assert.assertTrue("undefined option should be in message", known.getMessage().contains("Unknown opcode: 3"));
}
use of org.eclipse.jetty.websocket.common.test.UnitParser in project jetty.project by eclipse.
the class TestABCase4 method testParserControlOpCode12WithPayloadCase4_2_2.
@Test
public void testParserControlOpCode12WithPayloadCase4_2_2() throws Exception {
ByteBuffer expected = ByteBuffer.allocate(32);
expected.put(new byte[] { (byte) 0x8c, 0x01, 0x00 });
expected.flip();
IncomingFramesCapture capture = new IncomingFramesCapture();
try (StacklessLogging logging = new StacklessLogging(Parser.class)) {
Parser parser = new UnitParser(policy);
parser.setIncomingFramesHandler(capture);
try {
parser.parse(expected);
} catch (ProtocolException ignore) {
// ignore
}
}
Assert.assertEquals("error on undefined opcode", 1, capture.getErrorCount(WebSocketException.class));
Throwable known = capture.getErrors().poll();
Assert.assertTrue("undefined option should be in message", known.getMessage().contains("Unknown opcode: 12"));
}
Aggregations