Issue #3012 Compliance modes.

Updated unit tests for messages and reasons

Signed-off-by: Greg Wilkins <gregw@webtide.com>
This commit is contained in:
Greg Wilkins 2019-03-13 11:47:11 +11:00
parent 925d38b9db
commit 0fb17bff76
3 changed files with 20 additions and 11 deletions

View File

@ -15,6 +15,7 @@
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.http;
import java.util.Set;

View File

@ -151,12 +151,14 @@ public class HttpConnectionTest
connector.getConnectionFactory(HttpConnectionFactory.class).getHttpConfiguration().setHttpCompliance(HttpCompliance.RFC2616);
String request = "GET / HTTP/0.9\r\n\r\n";
String response = connector.getResponse(request);
assertThat(response, containsString("400 Bad Version"));
assertThat(response, containsString("400 Bad Request"));
assertThat(response, containsString("reason: Bad Version"));
connector.getConnectionFactory(HttpConnectionFactory.class).getHttpConfiguration().setHttpCompliance(HttpCompliance.RFC7230);
request = "GET / HTTP/0.9\r\n\r\n";
response = connector.getResponse(request);
assertThat(response, containsString("400 Bad Version"));
assertThat(response, containsString("400 Bad Request"));
assertThat(response, containsString("reason: Bad Version"));
}
/**
@ -365,7 +367,8 @@ public class HttpConnectionTest
public void testBadPathDotDotPath() throws Exception
{
String response=connector.getResponse("GET /ooops/../../path HTTP/1.0\r\nHost: localhost:80\r\n\n");
checkContains(response,0,"HTTP/1.1 400 Bad URI");
checkContains(response,0,"HTTP/1.1 400 Bad Request");
checkContains(response,0,"reason: Bad URI");
}
@Test
@ -380,28 +383,32 @@ public class HttpConnectionTest
public void testBadPathEncodedDotDotPath() throws Exception
{
String response=connector.getResponse("GET /ooops/%2e%2e/%2e%2e/path HTTP/1.0\r\nHost: localhost:80\r\n\n");
checkContains(response,0,"HTTP/1.1 400 Bad URI");
checkContains(response,0,"HTTP/1.1 400 Bad Request");
checkContains(response,0,"reason: Bad URI");
}
@Test
public void testBadDotDotPath() throws Exception
{
String response=connector.getResponse("GET ../path HTTP/1.0\r\nHost: localhost:80\r\n\n");
checkContains(response,0,"HTTP/1.1 400 Bad URI");
checkContains(response,0,"HTTP/1.1 400 Bad Request");
checkContains(response,0,"reason: Bad URI");
}
@Test
public void testBadSlashDotDotPath() throws Exception
{
String response=connector.getResponse("GET /../path HTTP/1.0\r\nHost: localhost:80\r\n\n");
checkContains(response,0,"HTTP/1.1 400 Bad URI");
checkContains(response,0,"HTTP/1.1 400 Bad Request");
checkContains(response,0,"reason: Bad URI");
}
@Test
public void testEncodedBadDotDotPath() throws Exception
{
String response=connector.getResponse("GET %2e%2e/path HTTP/1.0\r\nHost: localhost:80\r\n\n");
checkContains(response,0,"HTTP/1.1 400 Bad URI");
checkContains(response,0,"HTTP/1.1 400 Bad Request");
checkContains(response,0,"reason: Bad URI");
}
@Test
@ -538,6 +545,7 @@ public class HttpConnectionTest
public void testChunkNoTrailer() throws Exception
{
// Expect TimeoutException logged
connector.setIdleTimeout(1000);
String response=connector.getResponse("GET /R1 HTTP/1.1\r\n"+
"Host: localhost\r\n"+
"Transfer-Encoding: chunked\r\n"+

View File

@ -18,9 +18,6 @@
package org.eclipse.jetty.servlet;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
@ -48,6 +45,9 @@ import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
public class ComplianceViolations2616Test
{
private static Server server;
@ -183,7 +183,7 @@ public class ComplianceViolations2616Test
String response = connector.getResponse(req1.toString());
assertThat("Response status", response, containsString("HTTP/1.1 200"));
assertThat("Response headers", response, containsString("X-Http-Violation-0: No line Folding"));
assertThat("Response headers", response, containsString("X-Http-Violation-0: Line Folding not supported"));
assertThat("Response body", response, containsString("[Name] = [Some Value]"));
}