Merge pull request #8547 from eclipse/jetty-12.0.x-disabledTestFixes

re-enabling and fixing some tests for Jetty-12
This commit is contained in:
Lachlan 2022-09-08 10:27:10 +10:00 committed by GitHub
commit 860554b71b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 25 additions and 17 deletions

View File

@ -77,6 +77,22 @@ public class FormFields extends CompletableFuture<Fields> implements Runnable
return futureFormFields;
}
public static CompletableFuture<Fields> from(Request request, int maxFields, int maxLength)
{
Object attr = request.getAttribute(FormFields.class.getName());
if (attr instanceof FormFields futureFormFields)
return futureFormFields;
Charset charset = getFormEncodedCharset(request);
if (charset == null)
return EMPTY;
FormFields futureFormFields = new FormFields(request, charset, maxFields, maxLength);
futureFormFields.run();
request.setAttribute(FormFields.class.getName(), futureFormFields);
return futureFormFields;
}
private static int getRequestAttribute(Request request, String attribute)
{
Object value = request.getAttribute(attribute);
@ -141,7 +157,7 @@ public class FormFields extends CompletableFuture<Fields> implements Runnable
Fields.Field field = parse(chunk);
if (field == null)
break;
if (_maxFields > 0 && _fields.getSize() > _maxFields)
if (_maxFields >= 0 && _fields.getSize() >= _maxFields)
{
chunk.release();
completeExceptionally(new IllegalStateException("form with too many fields"));
@ -245,7 +261,7 @@ public class FormFields extends CompletableFuture<Fields> implements Runnable
private void checkLength(Content.Chunk chunk, String nameOrValue)
{
if (_maxLength > 0)
if (_maxLength >= 0)
{
_length += nameOrValue.length();
if (_length > _maxLength)

View File

@ -1006,7 +1006,9 @@ public class ServletContextRequest extends ContextRequest implements Runnable
{
try
{
_contentParameters = FormFields.from(getRequest()).get();
int maxKeys = getServletRequestState().getContextHandler().getMaxFormKeys();
int maxContentSize = getServletRequestState().getContextHandler().getMaxFormContentSize();
_contentParameters = FormFields.from(getRequest(), maxKeys, maxContentSize).get();
if (_contentParameters == null || _contentParameters.isEmpty())
_contentParameters = NO_PARAMS;
}

View File

@ -1560,8 +1560,6 @@ public class DefaultServletTest
{
Scenarios scenarios = new Scenarios();
// TODO: sendError not working (yet)
/*
scenarios.addScenario(
"GET /context/ - (/index.jsp servlet match, but JSP not supported)",
"""
@ -1573,7 +1571,6 @@ public class DefaultServletTest
HttpStatus.INTERNAL_SERVER_ERROR_500,
(response) -> assertThat(response.getContent(), containsString("JSP support not configured")) // test of SendError response
);
*/
addBasicWelcomeScenarios(scenarios);

View File

@ -34,14 +34,12 @@ import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.util.Fields;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import static org.junit.jupiter.api.Assertions.assertEquals;
@Disabled
public class FormTest
{
private static final int MAX_FORM_CONTENT_SIZE = 128;

View File

@ -37,7 +37,6 @@ import org.eclipse.jetty.toolchain.test.IO;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
@ -147,12 +146,10 @@ public class IncludedServletTest
this.server.stop();
}
@Disabled
@Test
public void testTopWithIncludedHeader() throws IOException
{
URI uri = baseUri.resolve("/top");
System.out.println("GET (String): " + uri.toASCIIString());
InputStream in = null;
InputStreamReader reader = null;

View File

@ -17,6 +17,7 @@ import java.io.IOException;
import java.io.PrintWriter;
import java.net.URLDecoder;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
@ -27,9 +28,9 @@ import org.eclipse.jetty.http.HttpVersion;
import org.eclipse.jetty.server.LocalConnector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.URIUtil;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
@ -56,7 +57,7 @@ public class ResponseHeadersTest
protected void doGet(HttpServletRequest req, HttpServletResponse response) throws ServletException, IOException
{
// The bad use-case
String pathInfo = req.getPathInfo();
String pathInfo = URIUtil.decodePath(req.getPathInfo());
if (pathInfo != null && pathInfo.length() > 1 && pathInfo.startsWith("/"))
{
pathInfo = pathInfo.substring(1);
@ -183,7 +184,6 @@ public class ResponseHeadersTest
assertThat("Response Header Connection", response.get("Connection"), is("Upgrade"));
}
@Disabled
@Test
public void testMultilineResponseHeaderValue() throws Exception
{
@ -205,7 +205,7 @@ public class ResponseHeadersTest
assertThat("Response Header Content-Type", response.get("Content-Type"), is("text/plain;charset=UTF-8"));
String expected = StringUtil.replace(actualPathInfo, "%0A", " "); // replace OBS fold with space
expected = URLDecoder.decode(expected, "utf-8"); // decode the rest
expected = URLDecoder.decode(expected, StandardCharsets.UTF_8); // decode the rest
expected = expected.trim(); // trim whitespace at start/end
assertThat("Response Header X-example", response.get("X-Example"), is(expected));
}

View File

@ -55,7 +55,6 @@ import org.eclipse.jetty.session.SessionDataStoreFactory;
import org.eclipse.jetty.toolchain.test.IO;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@ -295,7 +294,6 @@ public class SessionHandlerTest
}
}
@Disabled
@Test
public void testSimpleSessionCreation() throws Exception
{