From 820fbb7331a7cef4f5e823c7717f7e916bd76f77 Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Thu, 9 Feb 2023 15:57:50 +1100 Subject: [PATCH] #9287 - catch error in ee9 maxRequestSize MultiPart test Signed-off-by: Lachlan Roberts --- .../ee9/servlet/MultiPartServletTest.java | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/jetty-ee9/jetty-ee9-servlet/src/test/java/org/eclipse/jetty/ee9/servlet/MultiPartServletTest.java b/jetty-ee9/jetty-ee9-servlet/src/test/java/org/eclipse/jetty/ee9/servlet/MultiPartServletTest.java index 6cc9a3993e4..5f988e44ebf 100644 --- a/jetty-ee9/jetty-ee9-servlet/src/test/java/org/eclipse/jetty/ee9/servlet/MultiPartServletTest.java +++ b/jetty-ee9/jetty-ee9-servlet/src/test/java/org/eclipse/jetty/ee9/servlet/MultiPartServletTest.java @@ -46,6 +46,7 @@ import org.eclipse.jetty.http.HttpScheme; import org.eclipse.jetty.http.HttpStatus; import org.eclipse.jetty.http.MimeTypes; import org.eclipse.jetty.http.MultiPart; +import org.eclipse.jetty.io.EofException; import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; @@ -58,10 +59,12 @@ import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.startsWith; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; public class MultiPartServletTest { @@ -251,20 +254,28 @@ public class MultiPartServletTest .body(multiPart) .send(listener); - // Write large amount of content to the part. - byte[] byteArray = new byte[1024 * 1024]; - Arrays.fill(byteArray, (byte)1); - for (int i = 0; i < 1024 * 2; i++) + Throwable writeError = null; + try { - content.getOutputStream().write(byteArray); + // Write large amount of content to the part. + byte[] byteArray = new byte[1024 * 1024]; + Arrays.fill(byteArray, (byte)1); + for (int i = 0; i < 1024 * 1024; i++) + { + content.getOutputStream().write(byteArray); + } + fail("We should never be able to write all the content."); + } + catch (Exception e) + { + writeError = e; } - content.close(); + assertThat(writeError, instanceOf(EofException.class)); + + // We should get 400 response, for some reason reading the content throws EofException. Response response = listener.get(30, TimeUnit.SECONDS); assertThat(response.getStatus(), equalTo(HttpStatus.BAD_REQUEST_400)); - String responseContent = IO.toString(listener.getInputStream()); - assertThat(responseContent, containsString("Unable to parse form content")); - assertThat(responseContent, containsString("Request exceeds maxRequestSize")); } @Test