You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When trying to test the file upload form spring boot test, with mock mvc web environment, and having spring security in place, the MultipartGraphQlHttpHandler's method readMultipartFiles throws illegal argument exception.
The assertion is does not allow for wrapped HttpServletRequests to pass.
Assert.isInstanceOf(MultipartHttpServletRequest.class, httpServletRequest,
"Request should be of type MultipartHttpServletRequest");
When having spring security in the filter chain, the httpServletRequest is of instance SecurityContextHolderAwareRequestWrapper. Instead of using this strict assertion, one could use
to obtain the instance of the wrapped MultipartHttpServletRequest.
I'll provide a pull request with a fix. This is just to keep track on the issue.
Below is my unit test, that can be used to reproduce the exception:
@Test
void testWithMockMvc() throws Exception {
// arrange
final var fileName = "fileName.xlsx";
final var fileByteArray = new byte[100];
final var operations = """
{ "query" : "mutation FileUpload($file: Upload!) { uploadFile(file: $file) { fileName size } }" }
""";
final var variables = """
{ "file" : ["variables.file"] }
""";
final var filePart = new MockMultipartFile("file", fileName, "application/octet-stream", fileByteArray);
final var operationsPart = new MockPart("operations", operations.getBytes());
final var variablesPart = new MockPart("map", variables.getBytes());
// act & assert
final var asyncMvcResult = mockMvc.perform(MockMvcRequestBuilders
.multipart("/graphql")
.file(filePart)
.part(operationsPart)
.part(variablesPart)
.accept(MediaType.APPLICATION_GRAPHQL_RESPONSE_VALUE)
.with(SecurityMockMvcRequestPostProcessors.jwt().authorities(new SimpleGrantedAuthority("ADMIN"))))
.andReturn();
mockMvc.perform(asyncDispatch(asyncMvcResult))
.andDo(print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.data.uploadFile.fileName").value(fileName));
}
The text was updated successfully, but these errors were encountered:
assens
added a commit
to assens/multipart-spring-graphql
that referenced
this issue
Feb 21, 2024
When trying to test the file upload form spring boot test, with mock mvc web environment, and having spring security in place, the MultipartGraphQlHttpHandler's method readMultipartFiles throws illegal argument exception.
The assertion is does not allow for wrapped HttpServletRequests to pass.
When having spring security in the filter chain, the httpServletRequest is of instance SecurityContextHolderAwareRequestWrapper. Instead of using this strict assertion, one could use
to obtain the instance of the wrapped MultipartHttpServletRequest.
I'll provide a pull request with a fix. This is just to keep track on the issue.
Below is my unit test, that can be used to reproduce the exception:
The text was updated successfully, but these errors were encountered: