Search in sources :

Example 36 with StacklessLogging

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);
        }
    }
}
Also used : Fuzzer(org.eclipse.jetty.websocket.common.test.Fuzzer) ArrayList(java.util.ArrayList) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) ByteBuffer(java.nio.ByteBuffer) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test) Slow(org.eclipse.jetty.toolchain.test.annotation.Slow)

Example 37 with StacklessLogging

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);
    }
}
Also used : Fuzzer(org.eclipse.jetty.websocket.common.test.Fuzzer) ArrayList(java.util.ArrayList) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) Slow(org.eclipse.jetty.toolchain.test.annotation.Slow)

Example 38 with StacklessLogging

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));
    }
}
Also used : IBlockheadClient(org.eclipse.jetty.websocket.common.test.IBlockheadClient) BlockheadClient(org.eclipse.jetty.websocket.common.test.BlockheadClient) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) IBlockheadClient(org.eclipse.jetty.websocket.common.test.IBlockheadClient) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Example 39 with StacklessLogging

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();
    }
}
Also used : Fuzzer(org.eclipse.jetty.websocket.common.test.Fuzzer) ArrayList(java.util.ArrayList) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Example 40 with StacklessLogging

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

Aggregations

StacklessLogging (org.eclipse.jetty.util.log.StacklessLogging)143 Test (org.junit.Test)134 CloseInfo (org.eclipse.jetty.websocket.common.CloseInfo)55 WebSocketFrame (org.eclipse.jetty.websocket.common.WebSocketFrame)51 ArrayList (java.util.ArrayList)46 Fuzzer (org.eclipse.jetty.websocket.common.test.Fuzzer)45 TextFrame (org.eclipse.jetty.websocket.common.frames.TextFrame)35 ByteBuffer (java.nio.ByteBuffer)29 IOException (java.io.IOException)26 HttpServletRequest (javax.servlet.http.HttpServletRequest)24 HttpServletResponse (javax.servlet.http.HttpServletResponse)22 ContinuationFrame (org.eclipse.jetty.websocket.common.frames.ContinuationFrame)21 ServletException (javax.servlet.ServletException)20 CountDownLatch (java.util.concurrent.CountDownLatch)17 PingFrame (org.eclipse.jetty.websocket.common.frames.PingFrame)17 Matchers.containsString (org.hamcrest.Matchers.containsString)17 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)14 AbstractHandler (org.eclipse.jetty.server.handler.AbstractHandler)13 OutputStream (java.io.OutputStream)12 Socket (java.net.Socket)12