Description
Summary
I was asked to open this issue here after Spring REST Docs team investigated my issue why REST Docs did not get configured with formLogin().
SecurityMockMvcRequestBuilders$FormLoginRequestBuilder
does not implementMergeable
so the default configuration that is set up on theMockMvc
instance is not applied. Crucially in the case of Spring REST Docs, this means that theConfigurerApplyingRequestPostProcessor
that applies the REST Docs context to the request is lost.
The original issue can be found here: spring-projects/spring-restdocs#655
The following code causes java.lang.IllegalStateException: REST Docs configuration not found. Did you forget to apply a MockMvcRestDocumentationConfigurer when building the MockMvc instance?
@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
@AutoConfigureRestDocs
public class LoginLogoutTest {
@Autowired
private MockMvc mockMvc;
@Test
public void adminCanLoginLogout() throws Exception {
mockMvc.perform(formLogin().user(TestConfig.ADMIN_USERNAME).password(TestConfig.PASSWORD))
.andExpect(status().isOk())
.andExpect(authenticated().withUsername(TestConfig.ADMIN_USERNAME))
.andDo(document("login"));
mockMvc.perform(logout())
.andExpect(status().isOk())
.andExpect(unauthenticated())
.andDo(document("logout"));
}
}
Actual Behavior
On mvn test
the code causes java.lang.IllegalStateException: REST Docs configuration not found. Did you forget to apply a MockMvcRestDocumentationConfigurer when building the MockMvc instance?
on the line with document("login")
.
Expected Behavior
No errors. The REST Docs should be correctly configured.
Version
All versions
Sample
restdocs-formlogin.zip
This sample causes the same error on mvn test
.