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"));
}
}
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));
}
}
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);
}
}
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;
}
}
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 "));
}
}
Aggregations