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
Introduce method in MockHttpServletRequestBuilder
to set remote address
#30484
Comments
remoteAddr()
in MockHttpServletRequestBuilder
to set remote address
Hi @leewin12, Thanks for the proposal. It would not be much work to introduce Also, there are several additional properties of @rstoyanchev, WDYT? |
Have you considered extracting the boilerplate code into a static utility like the following? public static RequestPostProcessor remoteAddress(String address) {
return request -> {
request.setRemoteAddr(address);
return request;
};
} You could then use that like this: mockMvc.perform(post("/example")
.with(remoteAddress("192.168.0.100"))
.content(json)); |
Indeed, we frequently use the static utility method in our projects. PS: This change could also benefit companies that provide dynamic IP address restrictions, like B2B API providers. |
remoteAddr()
in MockHttpServletRequestBuilder
to set remote addressMockHttpServletRequestBuilder
to set remote address
I think it makes sense to make this more of a first-class option. |
@sbrannen @rstoyanchev Please feel free to review and provide any feedback. |
I'd like to propose the addition of a method to set the remote address directly in the MockHttpServletRequestBuilder. Currently, this can be achieved using with(RequestPostProcessor), but it introduces some boilerplate code that could be streamlined.
Setting restrictions on remote addresses is a common practice in Spring applications. As such, it's important to be able to easily verify these restrictions through unit tests.
Given the nature of IP restrictions (e.g., CIDR input), this often results in multiple lines of repetitive code.
I'm happy to implement this feature if the proposal is accepted. Feel free to leave any comments or suggestions.
I deeply appreciate the work and dedication of all spring framework contributors.
Current Method (Java > 1.8):
Proposed Method:
The text was updated successfully, but these errors were encountered: