From ec7c1137ff090f72c84d25616b556a54f9eb82e4 Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Thu, 1 Sep 2022 10:13:09 +1000 Subject: [PATCH 1/7] uncomment testWelcomeExactServlet test Signed-off-by: Lachlan Roberts --- .../org/eclipse/jetty/ee10/servlet/DefaultServletTest.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/DefaultServletTest.java b/jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/DefaultServletTest.java index fd2649e69bd..bed67553565 100644 --- a/jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/DefaultServletTest.java +++ b/jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/DefaultServletTest.java @@ -1561,8 +1561,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)", """ @@ -1574,7 +1572,6 @@ public class DefaultServletTest HttpStatus.INTERNAL_SERVER_ERROR_500, (response) -> assertThat(response.getContent(), containsString("JSP support not configured")) // test of SendError response ); - */ addBasicWelcomeScenarios(scenarios); From 81d695c501ff0c35ebf699feb40892fda3c3e991 Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Thu, 1 Sep 2022 15:24:03 +1000 Subject: [PATCH 2/7] uncomment IncludedServletTest Signed-off-by: Lachlan Roberts --- .../org/eclipse/jetty/ee10/servlet/IncludedServletTest.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/IncludedServletTest.java b/jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/IncludedServletTest.java index e67dcc111db..c8ac8d23d05 100644 --- a/jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/IncludedServletTest.java +++ b/jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/IncludedServletTest.java @@ -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; From 984f50bd22b24599876a6fc77846da9415eaa36f Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Thu, 1 Sep 2022 15:51:12 +1000 Subject: [PATCH 3/7] Fix failures in FormTest by fixing bugs in FormFields Signed-off-by: Lachlan Roberts --- .../org/eclipse/jetty/server/FormFields.java | 20 +++++++++++++++++-- .../ee10/servlet/ServletContextRequest.java | 4 +++- .../eclipse/jetty/ee10/servlet/FormTest.java | 3 --- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/FormFields.java b/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/FormFields.java index 42f078ee468..64456f03801 100644 --- a/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/FormFields.java +++ b/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/FormFields.java @@ -77,6 +77,22 @@ public class FormFields extends CompletableFuture implements Runnable return futureFormFields; } + public static CompletableFuture 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 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 implements Runnable private void checkLength(Content.Chunk chunk, String nameOrValue) { - if (_maxLength > 0) + if (_maxLength >= 0) { _length += nameOrValue.length(); if (_length > _maxLength) diff --git a/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/ServletContextRequest.java b/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/ServletContextRequest.java index b1c705ae041..d2384f513f9 100644 --- a/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/ServletContextRequest.java +++ b/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/ServletContextRequest.java @@ -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; } diff --git a/jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/FormTest.java b/jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/FormTest.java index 08d763d8da5..01a3e7c42d5 100644 --- a/jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/FormTest.java +++ b/jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/FormTest.java @@ -34,14 +34,11 @@ 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; From 89bb2a9593619d687312324b4390e204aa0efe43 Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Tue, 6 Sep 2022 17:48:18 +1000 Subject: [PATCH 4/7] re-enable and fix ResponseHeadersTest.testMultilineResponseHeaderValue Signed-off-by: Lachlan Roberts --- .../eclipse/jetty/ee10/servlet/ResponseHeadersTest.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/ResponseHeadersTest.java b/jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/ResponseHeadersTest.java index 14efd2f3d3c..43395fe78db 100644 --- a/jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/ResponseHeadersTest.java +++ b/jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/ResponseHeadersTest.java @@ -15,7 +15,6 @@ package org.eclipse.jetty.ee10.servlet; import java.io.IOException; import java.io.PrintWriter; -import java.net.URLDecoder; import java.nio.ByteBuffer; import jakarta.servlet.ServletException; @@ -26,10 +25,9 @@ import org.eclipse.jetty.http.HttpTester; 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; @@ -183,7 +181,6 @@ public class ResponseHeadersTest assertThat("Response Header Connection", response.get("Connection"), is("Upgrade")); } - @Disabled @Test public void testMultilineResponseHeaderValue() throws Exception { @@ -204,9 +201,7 @@ public class ResponseHeadersTest assertThat("Response Code", response.getStatus(), is(200)); 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 = expected.trim(); // trim whitespace at start/end + String expected = URIUtil.canonicalPath(actualPathInfo); assertThat("Response Header X-example", response.get("X-Example"), is(expected)); } From a4b761990671cd4034289a716499c5cc67425361 Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Tue, 6 Sep 2022 17:49:22 +1000 Subject: [PATCH 5/7] re-enable SessionHandlerTest Signed-off-by: Lachlan Roberts --- .../java/org/eclipse/jetty/ee10/servlet/SessionHandlerTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/SessionHandlerTest.java b/jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/SessionHandlerTest.java index 6eac739d3ae..7a03e83155f 100644 --- a/jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/SessionHandlerTest.java +++ b/jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/SessionHandlerTest.java @@ -56,7 +56,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; @@ -296,7 +295,6 @@ public class SessionHandlerTest } } - @Disabled @Test public void testSimpleSessionCreation() throws Exception { From 13032a2cd2b3e0852978ded9841876b1017040e3 Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Tue, 6 Sep 2022 18:50:41 +1000 Subject: [PATCH 6/7] fix checkstyle issues Signed-off-by: Lachlan Roberts --- .../src/test/java/org/eclipse/jetty/ee10/servlet/FormTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/FormTest.java b/jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/FormTest.java index 01a3e7c42d5..ce9a525aa02 100644 --- a/jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/FormTest.java +++ b/jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/FormTest.java @@ -39,6 +39,7 @@ import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import static org.junit.jupiter.api.Assertions.assertEquals; + public class FormTest { private static final int MAX_FORM_CONTENT_SIZE = 128; From 6eb96b70a516132e0783a0c78281de54a58cc63c Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Tue, 6 Sep 2022 23:44:31 +1000 Subject: [PATCH 7/7] fully decode pathInfo in ResponseHeadersTest.MultilineResponseValueServlet Signed-off-by: Lachlan Roberts --- .../eclipse/jetty/ee10/servlet/ResponseHeadersTest.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/ResponseHeadersTest.java b/jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/ResponseHeadersTest.java index 43395fe78db..a313d817b9c 100644 --- a/jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/ResponseHeadersTest.java +++ b/jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/ResponseHeadersTest.java @@ -15,7 +15,9 @@ package org.eclipse.jetty.ee10.servlet; 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; @@ -25,6 +27,7 @@ import org.eclipse.jetty.http.HttpTester; 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; @@ -54,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); @@ -201,7 +204,9 @@ public class ResponseHeadersTest assertThat("Response Code", response.getStatus(), is(200)); assertThat("Response Header Content-Type", response.get("Content-Type"), is("text/plain;charset=UTF-8")); - String expected = URIUtil.canonicalPath(actualPathInfo); + String expected = StringUtil.replace(actualPathInfo, "%0A", " "); // replace OBS fold with space + 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)); }