use of org.eclipse.jetty.util.log.StacklessLogging in project jetty.project by eclipse.
the class TestABCase6 method testCase6_4_3.
/**
* invalid text message, 1 frame/fragment (slowly, and split within code points)
* @throws Exception on test failure
*/
@Test
@Slow
public void testCase6_4_3() throws Exception {
// Disable Long Stacks from Parser (we know this test will throw an exception)
try (StacklessLogging scope = new StacklessLogging(Parser.class)) {
ByteBuffer payload = ByteBuffer.allocate(64);
BufferUtil.clearToFill(payload);
// good
payload.put(TypeUtil.fromHexString("cebae1bdb9cf83cebcceb5"));
// INVALID
payload.put(TypeUtil.fromHexString("f4908080"));
// good
payload.put(TypeUtil.fromHexString("656469746564"));
BufferUtil.flipToFlush(payload, 0);
List<WebSocketFrame> send = new ArrayList<>();
send.add(new TextFrame().setPayload(payload));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) {
fuzzer.connect();
ByteBuffer net = fuzzer.asNetworkBuffer(send);
int[] splits = { 17, 21, net.limit() };
// Header + good UTF
ByteBuffer part1 = net.slice();
part1.limit(splits[0]);
// invalid UTF
ByteBuffer part2 = net.slice();
part2.position(splits[0]);
part2.limit(splits[1]);
// good UTF
ByteBuffer part3 = net.slice();
part3.position(splits[1]);
part3.limit(splits[2]);
// the header + good utf
fuzzer.send(part1);
TimeUnit.MILLISECONDS.sleep(500);
// the bad UTF
fuzzer.send(part2);
TimeUnit.MILLISECONDS.sleep(500);
// the rest (shouldn't work)
fuzzer.send(part3);
fuzzer.expect(expect);
}
}
}
use of org.eclipse.jetty.util.log.StacklessLogging in project jetty.project by eclipse.
the class TestABCase6 method testCase6_4_4.
/**
* invalid text message, 1 frame/fragment (slowly, and split within code points)
* @throws Exception on test failure
*/
@Test
@Slow
public void testCase6_4_4() throws Exception {
byte[] invalid = Hex.asByteArray("CEBAE1BDB9CF83CEBCCEB5F49080808080656469746564");
List<WebSocketFrame> send = new ArrayList<>();
send.add(new TextFrame().setPayload(ByteBuffer.wrap(invalid)));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this);
StacklessLogging scope = new StacklessLogging(Parser.class)) {
fuzzer.connect();
ByteBuffer net = fuzzer.asNetworkBuffer(send);
fuzzer.send(net, 6);
fuzzer.send(net, 11);
TimeUnit.SECONDS.sleep(1);
fuzzer.send(net, 1);
TimeUnit.SECONDS.sleep(1);
// the rest
fuzzer.send(net, 100);
fuzzer.expect(expect);
}
}
use of org.eclipse.jetty.util.log.StacklessLogging in project jetty.project by eclipse.
the class MisbehavingClassTest method testListenerRuntimeOnConnect.
@Test
public void testListenerRuntimeOnConnect() throws Exception {
try (IBlockheadClient client = new BlockheadClient(server.getServerUri());
StacklessLogging scope = new StacklessLogging(ListenerRuntimeOnConnectSocket.class, WebSocketSession.class)) {
client.setProtocols("listener-runtime-connect");
client.setTimeout(1, TimeUnit.SECONDS);
ListenerRuntimeOnConnectSocket socket = badSocketsServlet.listenerRuntimeConnect;
socket.reset();
client.connect();
client.sendStandardRequest();
client.expectUpgradeResponse();
EventQueue<WebSocketFrame> frames = client.readFrames(1, 1, TimeUnit.SECONDS);
WebSocketFrame frame = frames.poll();
assertThat("frames[0].opcode", frame.getOpCode(), is(OpCode.CLOSE));
CloseInfo close = new CloseInfo(frame);
assertThat("Close Status Code", close.getStatusCode(), is(StatusCode.SERVER_ERROR));
// respond with close
client.write(close.asFrame());
// ensure server socket got close event
assertThat("Close Latch", socket.closeLatch.await(1, TimeUnit.SECONDS), is(true));
assertThat("closeStatusCode", socket.closeStatusCode, is(StatusCode.SERVER_ERROR));
// Validate errors
assertThat("socket.onErrors", socket.errors.size(), is(1));
Throwable cause = socket.errors.pop();
assertThat("Error type", cause, instanceOf(RuntimeException.class));
}
}
use of org.eclipse.jetty.util.log.StacklessLogging in project jetty.project by eclipse.
the class TestABCase7 method testCase7_3_5.
/**
* close with valid payload (with 123 byte reason)
* @throws Exception on test failure
*/
@Test
public void testCase7_3_5() throws Exception {
byte[] utf = new byte[123];
Arrays.fill(utf, (byte) '!');
String reason = StringUtil.toUTF8String(utf, 0, utf.length);
List<WebSocketFrame> send = new ArrayList<>();
send.add(new CloseInfo(StatusCode.NORMAL, reason).asFrame());
List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.NORMAL, reason).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this);
StacklessLogging logging = new StacklessLogging(AbstractWebSocketConnection.class)) {
fuzzer.connect();
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
fuzzer.send(send);
fuzzer.expect(expect);
fuzzer.expectNoMoreFrames();
}
}
use of org.eclipse.jetty.util.log.StacklessLogging 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();
}
}
Aggregations