use of org.junit.Test 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.junit.Test in project jetty.project by eclipse.
the class HttpParserTest method testIPv6Host.
@Test
public void testIPv6Host() throws Exception {
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.assertEquals("[::1]", _host);
Assert.assertEquals(0, _port);
}
use of org.junit.Test in project jetty.project by eclipse.
the class HttpParserTest method testResponseParse3.
@Test
public void testResponseParse3() throws Exception {
ByteBuffer buffer = BufferUtil.toBuffer("HTTP/1.1 200\r\n" + "Content-Length: 10\r\n" + "Content-Type: text/plain\r\n" + "\r\n" + "0123456789\r\n");
HttpParser.ResponseHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
parser.parseNext(buffer);
Assert.assertEquals("HTTP/1.1", _methodOrVersion);
Assert.assertEquals("200", _uriOrStatus);
Assert.assertEquals(null, _versionOrReason);
Assert.assertEquals(_content.length(), 10);
Assert.assertTrue(_headerCompleted);
Assert.assertTrue(_messageCompleted);
}
use of org.junit.Test in project jetty.project by eclipse.
the class HttpParserTest method testChunkEarlyEOF.
@Test
public void testChunkEarlyEOF() throws Exception {
ByteBuffer buffer = BufferUtil.toBuffer("GET /chunk HTTP/1.0\r\n" + "Header1: value1\r\n" + "Transfer-Encoding: chunked\r\n" + "\r\n" + "a;\r\n" + "0123456789\r\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
parser.atEOF();
parseAll(parser, buffer);
Assert.assertEquals("GET", _methodOrVersion);
Assert.assertEquals("/chunk", _uriOrStatus);
Assert.assertEquals("HTTP/1.0", _versionOrReason);
Assert.assertEquals(1, _headers);
Assert.assertEquals("Header1", _hdr[0]);
Assert.assertEquals("value1", _val[0]);
Assert.assertEquals("0123456789", _content);
Assert.assertTrue(_early);
}
use of org.junit.Test in project jetty.project by eclipse.
the class HttpParserTest method testCaseSensitiveLegacy.
@Test
public void testCaseSensitiveLegacy() throws Exception {
ByteBuffer buffer = BufferUtil.toBuffer("gEt / http/1.0\r\n" + "HOST: localhost\r\n" + "cOnNeCtIoN: ClOsE\r\n" + "\r\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler, -1, HttpCompliance.LEGACY);
parseAll(parser, buffer);
Assert.assertNull(_bad);
Assert.assertEquals("gEt", _methodOrVersion);
Assert.assertEquals("/", _uriOrStatus);
Assert.assertEquals("HTTP/1.0", _versionOrReason);
Assert.assertEquals("HOST", _hdr[0]);
Assert.assertEquals("localhost", _val[0]);
Assert.assertEquals("cOnNeCtIoN", _hdr[1]);
Assert.assertEquals("ClOsE", _val[1]);
Assert.assertEquals(1, _headers);
Assert.assertThat(_complianceViolation, Matchers.containsString("case sensitive"));
}
Aggregations