|
|
|
@ -18,23 +18,29 @@ package org.springframework.web.multipart.support; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
|
|
|
|
import java.util.Collection; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import jakarta.servlet.ServletException; |
|
|
|
|
|
|
|
import jakarta.servlet.http.Part; |
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.http.converter.FormHttpMessageConverter; |
|
|
|
import org.springframework.http.converter.FormHttpMessageConverter; |
|
|
|
import org.springframework.util.LinkedMultiValueMap; |
|
|
|
import org.springframework.util.LinkedMultiValueMap; |
|
|
|
import org.springframework.util.MultiValueMap; |
|
|
|
import org.springframework.util.MultiValueMap; |
|
|
|
|
|
|
|
import org.springframework.web.multipart.MaxUploadSizeExceededException; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
import org.springframework.web.testfixture.http.MockHttpOutputMessage; |
|
|
|
import org.springframework.web.testfixture.http.MockHttpOutputMessage; |
|
|
|
import org.springframework.web.testfixture.servlet.MockHttpServletRequest; |
|
|
|
import org.springframework.web.testfixture.servlet.MockHttpServletRequest; |
|
|
|
import org.springframework.web.testfixture.servlet.MockPart; |
|
|
|
import org.springframework.web.testfixture.servlet.MockPart; |
|
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Unit tests for {@link StandardMultipartHttpServletRequest}. |
|
|
|
* Unit tests for {@link StandardMultipartHttpServletRequest}. |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Rossen Stoyanchev |
|
|
|
* @author Rossen Stoyanchev |
|
|
|
|
|
|
|
* @author Juergen Hoeller |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
class StandardMultipartHttpServletRequestTests { |
|
|
|
class StandardMultipartHttpServletRequestTests { |
|
|
|
|
|
|
|
|
|
|
|
@ -92,6 +98,31 @@ class StandardMultipartHttpServletRequestTests { |
|
|
|
""".replace("\n", "\r\n")); |
|
|
|
""".replace("\n", "\r\n")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void plainSizeExceededServletException() { |
|
|
|
|
|
|
|
ServletException ex = new ServletException("Request size exceeded"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThatExceptionOfType(MaxUploadSizeExceededException.class) |
|
|
|
|
|
|
|
.isThrownBy(() -> requestWithException(ex)).withCause(ex); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test // gh-28759
|
|
|
|
|
|
|
|
void jetty94MaxRequestSizeException() { |
|
|
|
|
|
|
|
ServletException ex = new ServletException(new IllegalStateException("Request exceeds maxRequestSize")); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThatExceptionOfType(MaxUploadSizeExceededException.class) |
|
|
|
|
|
|
|
.isThrownBy(() -> requestWithException(ex)).withCause(ex); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test // gh-31850
|
|
|
|
|
|
|
|
void jetty12MaxLengthExceededException() { |
|
|
|
|
|
|
|
ServletException ex = new ServletException(new RuntimeException("400: bad multipart", |
|
|
|
|
|
|
|
new IllegalStateException("max length exceeded"))); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThatExceptionOfType(MaxUploadSizeExceededException.class) |
|
|
|
|
|
|
|
.isThrownBy(() -> requestWithException(ex)).withCause(ex); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static StandardMultipartHttpServletRequest requestWithPart(String name, String disposition, String content) { |
|
|
|
private static StandardMultipartHttpServletRequest requestWithPart(String name, String disposition, String content) { |
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest(); |
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest(); |
|
|
|
@ -101,4 +132,14 @@ class StandardMultipartHttpServletRequestTests { |
|
|
|
return new StandardMultipartHttpServletRequest(request); |
|
|
|
return new StandardMultipartHttpServletRequest(request); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static StandardMultipartHttpServletRequest requestWithException(ServletException ex) { |
|
|
|
|
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public Collection<Part> getParts() throws ServletException { |
|
|
|
|
|
|
|
throw ex; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
return new StandardMultipartHttpServletRequest(request); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|