Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MockHttpServletRequestBuilder does not allow invalid content type for testing [SPR-17643] #22172

Open
spring-issuemaster opened this issue Jan 7, 2019 · 2 comments

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Jan 7, 2019

dmitry87 opened SPR-17643 and commented

 

Invalid mime type "yaml": does not contain '/'
org.springframework.http.InvalidMediaTypeException: Invalid mime type "yaml": does not contain '/'
 at org.springframework.http.MediaType.parseMediaType(MediaType.java:512)
 at org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder.contentType(MockHttpServletRequestBuilder.java:277)

One of the app in stack sends invalid content type. Currently it is impossible to cover this in Unit test because MockHttpServletRequestBuilder uses MediaType.parse(contentType: String).toString() to get the value and it fails to get to ExceptionHandler

I propose that MockHttpServletRequestBuilder could accept any string for contentType. In this case when we send payload with invalid(unparsable) contentType to our controller we will handle InvalidMediaTypeException with our exception handler in Unit tests

 


Affects: 5.1.3

Referenced from: pull request #2077

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jan 7, 2019

Juergen Hoeller commented

I suppose you can set the Content-Type header directly for the time being? Otherwise you could also modify the content type on the MockHttpServletRequest instance itself where no such parsing is in place.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jan 8, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.