Search in sources :

Example 1 with StacklessLogging

use of org.eclipse.jetty.util.log.StacklessLogging in project jetty.project by eclipse.

the class HttpParserTest method testBadIPv6Host.

@Test
public void testBadIPv6Host() throws Exception {
    try (StacklessLogging s = new StacklessLogging(HttpParser.class)) {
        ByteBuffer buffer = BufferUtil.toBuffer("GET / HTTP/1.1\r\n" + "Host: [::1\r\n" + "Connection: close\r\n" + "\r\n");
        HttpParser.RequestHandler handler = new Handler();
        HttpParser parser = new HttpParser(handler);
        parser.parseNext(buffer);
        Assert.assertThat(_bad, Matchers.containsString("Bad"));
    }
}
Also used : StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 2 with StacklessLogging

use of org.eclipse.jetty.util.log.StacklessLogging in project jetty.project by eclipse.

the class AsyncMiddleManServletTest method testClientRequestReadFailsOnSecondRead.

@Test
public void testClientRequestReadFailsOnSecondRead() throws Exception {
    try (StacklessLogging scope = new StacklessLogging(HttpChannel.class)) {
        startServer(new EchoHttpServlet());
        startProxy(new AsyncMiddleManServlet() {

            private int count;

            @Override
            protected int readClientRequestContent(ServletInputStream input, byte[] buffer) throws IOException {
                if (++count < 2)
                    return super.readClientRequestContent(input, buffer);
                else
                    throw new IOException("explicitly_thrown_by_test");
            }
        });
        startClient();
        final CountDownLatch latch = new CountDownLatch(1);
        DeferredContentProvider content = new DeferredContentProvider();
        client.newRequest("localhost", serverConnector.getLocalPort()).content(content).send(new Response.CompleteListener() {

            @Override
            public void onComplete(Result result) {
                if (result.getResponse().getStatus() == 502)
                    latch.countDown();
            }
        });
        content.offer(ByteBuffer.allocate(512));
        sleep(1000);
        content.offer(ByteBuffer.allocate(512));
        content.close();
        Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
    }
}
Also used : RuntimeIOException(org.eclipse.jetty.io.RuntimeIOException) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) Result(org.eclipse.jetty.client.api.Result) ContentResponse(org.eclipse.jetty.client.api.ContentResponse) Response(org.eclipse.jetty.client.api.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletInputStream(javax.servlet.ServletInputStream) DeferredContentProvider(org.eclipse.jetty.client.util.DeferredContentProvider) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) Test(org.junit.Test)

Example 3 with StacklessLogging

use of org.eclipse.jetty.util.log.StacklessLogging in project jetty.project by eclipse.

the class RequestTest method testHashDOSKeys.

@Test
public void testHashDOSKeys() throws Exception {
    try (StacklessLogging stackless = new StacklessLogging(HttpChannel.class)) {
        LOG.info("Expecting maxFormKeys limit and Closing HttpParser exceptions...");
        _server.setAttribute("org.eclipse.jetty.server.Request.maxFormContentSize", -1);
        _server.setAttribute("org.eclipse.jetty.server.Request.maxFormKeys", 1000);
        StringBuilder buf = new StringBuilder(4000000);
        buf.append("a=b");
        // The evil keys file is not distributed - as it is dangerous
        File evil_keys = new File("/tmp/keys_mapping_to_zero_2m");
        if (evil_keys.exists()) {
            LOG.info("Using real evil keys!");
            try (BufferedReader in = new BufferedReader(new FileReader(evil_keys))) {
                String key = null;
                while ((key = in.readLine()) != null) buf.append("&").append(key).append("=").append("x");
            }
        } else {
            // we will just create a lot of keys and make sure the limit is applied
            for (int i = 0; i < 2000; i++) buf.append("&").append("K").append(i).append("=").append("x");
        }
        buf.append("&c=d");
        _handler._checker = new RequestTester() {

            @Override
            public boolean check(HttpServletRequest request, HttpServletResponse response) {
                return "b".equals(request.getParameter("a")) && request.getParameter("c") == null;
            }
        };
        String request = "POST / HTTP/1.1\r\n" + "Host: whatever\r\n" + "Content-Type: " + MimeTypes.Type.FORM_ENCODED.asString() + "\r\n" + "Content-Length: " + buf.length() + "\r\n" + "Connection: close\r\n" + "\r\n" + buf;
        long start = System.currentTimeMillis();
        String response = _connector.getResponse(request);
        assertThat(response, Matchers.containsString("IllegalStateException"));
        long now = System.currentTimeMillis();
        assertTrue((now - start) < 5000);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) BufferedReader(java.io.BufferedReader) HttpServletResponse(javax.servlet.http.HttpServletResponse) FileReader(java.io.FileReader) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) File(java.io.File) LocalEndPoint(org.eclipse.jetty.server.LocalConnector.LocalEndPoint) Test(org.junit.Test)

Example 4 with StacklessLogging

use of org.eclipse.jetty.util.log.StacklessLogging in project jetty.project by eclipse.

the class PartialRFC2616Test method test14_23.

@Test
public void test14_23() throws Exception {
    try (StacklessLogging stackless = new StacklessLogging(HttpParser.class)) {
        int offset = 0;
        String response = connector.getResponse("GET /R1 HTTP/1.0\n" + "Connection: close\n" + "\n");
        offset = checkContains(response, offset, "HTTP/1.1 200", "200") + 1;
        offset = 0;
        response = connector.getResponse("GET /R1 HTTP/1.1\n" + "Connection: close\n" + "\n");
        offset = checkContains(response, offset, "HTTP/1.1 400", "400") + 1;
        offset = 0;
        response = connector.getResponse("GET /R1 HTTP/1.1\n" + "Host: localhost\n" + "Connection: close\n" + "\n");
        offset = checkContains(response, offset, "HTTP/1.1 200", "200") + 1;
        offset = 0;
        response = connector.getResponse("GET /R1 HTTP/1.1\n" + "Host:\n" + "Connection: close\n" + "\n");
        offset = checkContains(response, offset, "HTTP/1.1 200", "200") + 1;
    }
}
Also used : StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) Matchers.containsString(org.hamcrest.Matchers.containsString) LocalEndPoint(org.eclipse.jetty.server.LocalConnector.LocalEndPoint) Test(org.junit.Test)

Example 5 with StacklessLogging

use of org.eclipse.jetty.util.log.StacklessLogging in project jetty.project by eclipse.

the class HttpServerTestBase method testFullURI.

/*
    * Feed a full header method
    */
@Test
public void testFullURI() throws Exception {
    configureServer(new HelloWorldHandler());
    try (Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort());
        StacklessLogging stackless = new StacklessLogging(HttpConnection.class)) {
        ((AbstractLogger) Log.getLogger(HttpConnection.class)).info("expect URI is too large, then ISE extra data ...");
        OutputStream os = client.getOutputStream();
        byte[] buffer = new byte[64 * 1024];
        buffer[0] = 'G';
        buffer[1] = 'E';
        buffer[2] = 'T';
        buffer[3] = ' ';
        buffer[4] = '/';
        Arrays.fill(buffer, 5, buffer.length - 1, (byte) 'A');
        os.write(buffer);
        os.flush();
        // Read the response.
        String response = readResponse(client);
        Assert.assertThat(response, Matchers.containsString("HTTP/1.1 414 "));
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) ServletOutputStream(javax.servlet.ServletOutputStream) OutputStream(java.io.OutputStream) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) Matchers.containsString(org.hamcrest.Matchers.containsString) Socket(java.net.Socket) AbstractLogger(org.eclipse.jetty.util.log.AbstractLogger) 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