Skip to content

MockMvcHttpClientConnector support for RequestPostProcessor hook #31298

Closed
@rstoyanchev

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 RequestPostProcessors in MockMvcClientHttpConnector and also allow it to be mutated. Then Spring Security could check the connector type and mutate it accordingly.

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions