Potentially fixes related issues like https://github.com/spring-projects/spring-security/issues/9257 and https://github.com/spring-projects/spring-security/issues/11334

This PR is unpolished and is just to illustrate the idea of allowing mutateWith on MockMvc RequestPostProcessors as I'm not even sure if this design approach would be acceptable.

The basic design idea is to have the MockMvcWebTestClient interface extend WebTestClient with some MockMvc specific methods.

package com.example;

import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.oidcLogin;
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.web.servlet.client.MockMvcWebTestClient;
import org.springframework.web.context.WebApplicationContext;

@SpringBootTest
@AutoConfigureMockMvc
@TestInstance(Lifecycle.PER_CLASS)
@ActiveProfiles("test")
class MockMvcTest {
    MockMvcWebTestClient client;

    @Autowired
    void setupClient(WebApplicationContext context) {
        client = MockMvcWebTestClient.bindToApplicationContext(context).apply(springSecurity()).build();
    }

    @Test
    void givenOidcLoginShouldReturnOk() {
        client.mutateWith(oidcLogin()).get().uri("/login-user").exchange().expectStatus()
                .isOk();
    }
}

Comment From: pivotal-cla

@justin-tay Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

Comment From: pivotal-cla

@justin-tay Thank you for signing the Contributor License Agreement!

Comment From: justin-tay

I see your point about the design. I tried to pick this up again but I don't really know how to do this without making breaking changes, plus I think my initial design was pretty off track. I think it might be best for you to make the changes instead.

Comment From: rstoyanchev

Thanks @justin-tay for inserting some momentum into this. I've created #31298.