MockMvcHttpClientConnector support for RequestPostProcessor hook #31298
Description
3rd party frameworks can use RequestPostProcessor to encapsulate request initialization logic for MockMvc
tests which allows extending the fluent API. For example with Spring Security:
mockMvc.perform(get("/messages")
.with(jwt().authorities(new SimpleGrantedAuthority("SCOPE_message:read"))))
.andExpect(status().isOk());
This is currently not possible to use with MockMvcWebTestClient
where a WebTestClient
is configured with a MockMvcHttpClientConnector
, and there is a client separate from the server. The request prepared by WebTestClient
is actually a client request that's passed into the the connector and the client is unaware of any further details. This has led to Spring Security not being able to support MockMvcWebTestClient
in the same way it can support MockMvc
tests or WebTestClient
tests for WebFlux. See spring-projects/spring-security#9257 and also spring-projects/spring-security#11334.
WebTestClient
provides a mutateWith(WebTestClientConfigurer)
which provides access to the underlying ClientHttpConnector
for mutation, but we need to add support for using RequestPostProcessor
s in MockMvcClientHttpConnector
and also allow it to be mutated. Then Spring Security could check the connector type and mutate it accordingly.