use of org.eclipse.jetty.websocket.api.ProtocolException in project jetty.project by eclipse.
the class CloseInfoTest method testFailedTlsHandshake.
/**
* A test of FAILED_TLS_HANDSHAKE (1007)
*/
@Test
public void testFailedTlsHandshake() {
CloseInfo close = new CloseInfo(FAILED_TLS_HANDSHAKE);
assertThat("close.code", close.getStatusCode(), is(FAILED_TLS_HANDSHAKE));
assertThat("close.reason", close.getReason(), nullValue());
try {
@SuppressWarnings("unused") CloseFrame frame = close.asFrame();
fail("Expected " + ProtocolException.class.getName());
} catch (ProtocolException e) {
// expected path
assertThat("ProtocolException message", e.getMessage(), containsString("not allowed (per RFC6455)"));
}
}
use of org.eclipse.jetty.websocket.api.ProtocolException in project jetty.project by eclipse.
the class TestABCase4 method testParserNonControlOpCode4WithPayloadCase4_1_2.
@Test
public void testParserNonControlOpCode4WithPayloadCase4_1_2() throws Exception {
ByteBuffer expected = ByteBuffer.allocate(32);
expected.put(new byte[] { (byte) 0x84, 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: 4"));
}
use of org.eclipse.jetty.websocket.api.ProtocolException in project jetty.project by eclipse.
the class TestABCase7_3 method testCase7_3_2Parse1BytePayloadClose.
@Test
public void testCase7_3_2Parse1BytePayloadClose() {
ByteBuffer expected = Hex.asByteBuffer("880100");
UnitParser parser = new UnitParser(policy);
IncomingFramesCapture capture = new IncomingFramesCapture();
parser.setIncomingFramesHandler(capture);
parser.parseQuietly(expected);
Assert.assertEquals("error on invalid close payload", 1, capture.getErrorCount(ProtocolException.class));
ProtocolException known = (ProtocolException) capture.getErrors().poll();
Assert.assertThat("Payload.message", known.getMessage(), containsString("Invalid close frame payload length"));
}
use of org.eclipse.jetty.websocket.api.ProtocolException in project jetty.project by eclipse.
the class TestABCase7_3 method testCase7_3_6ParseCloseWithInvalidStatusReason.
@Test
public void testCase7_3_6ParseCloseWithInvalidStatusReason() {
byte[] messageBytes = new byte[124];
Arrays.fill(messageBytes, (byte) '*');
ByteBuffer expected = ByteBuffer.allocate(256);
byte b;
// fin + op
b = 0x00;
// fin on
b |= 0x80;
// close
b |= 0x08;
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) (messageBytes.length + 2));
// payload
// status code
expected.putShort((short) 1000);
// reason
expected.put(messageBytes);
expected.flip();
UnitParser parser = new UnitParser(policy);
IncomingFramesCapture capture = new IncomingFramesCapture();
parser.setIncomingFramesHandler(capture);
parser.parseQuietly(expected);
Assert.assertEquals("error on invalid close payload", 1, capture.getErrorCount(ProtocolException.class));
ProtocolException known = (ProtocolException) capture.getErrors().poll();
Assert.assertThat("Payload.message", known.getMessage(), containsString("Invalid control frame payload length"));
}
Aggregations