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

Closed
spring-projects-issues opened this issue Jan 7, 2019 · 3 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: superseded An issue that has been superseded by another type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link
Collaborator

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-projects-issues
Copy link
Collaborator Author

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-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues added type: enhancement A general enhancement in: web Issues in web modules (web, webmvc, webflux, websocket) labels Jan 11, 2019
@rstoyanchev rstoyanchev self-assigned this Dec 13, 2019
@rstoyanchev rstoyanchev removed this from the General Backlog milestone Dec 13, 2019
@rstoyanchev
Copy link
Contributor

This is now superseded by #2079.

@rstoyanchev rstoyanchev added the status: superseded An issue that has been superseded by another label Dec 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: superseded An issue that has been superseded by another type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants