mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-10-03 13:39:34 +00:00
Detect all common size exceptions from Tomcat and Commons FileUpload 2.x
Closes gh-36317
This commit is contained in:
+68
@@ -123,6 +123,47 @@ class StandardMultipartHttpServletRequestTests {
|
||||
.isThrownBy(() -> requestWithException(ex)).withCause(ex);
|
||||
}
|
||||
|
||||
@Test // gh-32549
|
||||
void undertowRequestTooBigException() {
|
||||
IOException ex = new IOException("Connection terminated as request was larger than 10000");
|
||||
|
||||
assertThatExceptionOfType(MaxUploadSizeExceededException.class)
|
||||
.isThrownBy(() -> requestWithException(ex)).withCause(ex);
|
||||
}
|
||||
|
||||
@Test // gh-36317: Tomcat's Commons FileUpload
|
||||
void commonsFileSizeLimitExceededException() {
|
||||
IOException ex = new FileSizeLimitExceededException();
|
||||
|
||||
assertThatExceptionOfType(MaxUploadSizeExceededException.class)
|
||||
.isThrownBy(() -> requestWithException(ex)).withCause(ex);
|
||||
}
|
||||
|
||||
@Test // gh-36317: Tomcat's Commons FileUpload
|
||||
void commonsFileCountLimitExceededException() {
|
||||
IOException ex = new FileCountLimitExceededException();
|
||||
|
||||
assertThatExceptionOfType(MaxUploadSizeExceededException.class)
|
||||
.isThrownBy(() -> requestWithException(ex)).withCause(ex);
|
||||
}
|
||||
|
||||
@Test // gh-36317: Commons FileUpload 2.x
|
||||
void commonsFileUploadByteCountLimitException() {
|
||||
IOException ex = new FileUploadByteCountLimitException();
|
||||
|
||||
assertThatExceptionOfType(MaxUploadSizeExceededException.class)
|
||||
.isThrownBy(() -> requestWithException(ex)).withCause(ex);
|
||||
}
|
||||
|
||||
@Test // gh-36317: Commons FileUpload 2.x
|
||||
void commonsFileUploadFileCountLimitException() {
|
||||
IOException ex = new FileUploadFileCountLimitException();
|
||||
|
||||
assertThatExceptionOfType(MaxUploadSizeExceededException.class)
|
||||
.isThrownBy(() -> requestWithException(ex)).withCause(ex);
|
||||
}
|
||||
|
||||
|
||||
private static StandardMultipartHttpServletRequest requestWithPart(String name, String disposition, String content) {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
MockPart part = new MockPart(name, null, content.getBytes(StandardCharsets.UTF_8));
|
||||
@@ -141,4 +182,31 @@ class StandardMultipartHttpServletRequestTests {
|
||||
return new StandardMultipartHttpServletRequest(request);
|
||||
}
|
||||
|
||||
private static StandardMultipartHttpServletRequest requestWithException(IOException ex) {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest() {
|
||||
@Override
|
||||
public Collection<Part> getParts() throws IOException {
|
||||
throw ex;
|
||||
}
|
||||
};
|
||||
return new StandardMultipartHttpServletRequest(request);
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private static class FileSizeLimitExceededException extends IOException {
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private static class FileCountLimitExceededException extends IOException {
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private static class FileUploadByteCountLimitException extends IOException {
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private static class FileUploadFileCountLimitException extends IOException {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user