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

MockMvcHttpClientConnector support for RequestPostProcessor hook #31298

Closed
rstoyanchev opened this issue Sep 22, 2023 · 0 comments
Closed

MockMvcHttpClientConnector support for RequestPostProcessor hook #31298

rstoyanchev opened this issue Sep 22, 2023 · 0 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@rstoyanchev
Copy link
Contributor

rstoyanchev commented Sep 22, 2023

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.

@rstoyanchev rstoyanchev added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement labels Sep 22, 2023
@rstoyanchev rstoyanchev added this to the 6.1.0-RC1 milestone Sep 22, 2023
@rstoyanchev rstoyanchev self-assigned this Sep 22, 2023
@rstoyanchev rstoyanchev changed the title MockMvcHttpClientConnector support RequestPostProcessor hook MockMvcHttpClientConnector support for RequestPostProcessor hook Sep 22, 2023
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) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant