Simplify mockmvc security in tests following upstream changes

SecurityMockMvcConfigurer now honors filter order so we can use that instead
of manually adding the filter.
pull/17875/head
Madhura Bhave 5 years ago
parent a785a5b58a
commit dab815af40

@ -181,6 +181,11 @@
<artifactId>postgresql</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>

@ -52,6 +52,7 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.mockito.Mockito.mock;
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
/**
@ -151,9 +152,8 @@ class RemoteDevToolsAutoConfigurationTests {
void securityConfigurationShouldAllowAccess() throws Exception {
this.context = getContext(() -> loadContext("spring.devtools.remote.secret:supersecret"));
DispatcherFilter filter = this.context.getBean(DispatcherFilter.class);
Filter securityFilterChain = this.context.getBean(BeanIds.SPRING_SECURITY_FILTER_CHAIN, Filter.class);
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context).addFilter(securityFilterChain)
.addFilter(filter).build();
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context).apply(springSecurity()).addFilter(filter)
.build();
mockMvc.perform(MockMvcRequestBuilders.get(DEFAULT_CONTEXT_PATH + "/restart").header(DEFAULT_SECRET_HEADER_NAME,
"supersecret")).andExpect(status().isOk());
assertRestartInvoked(true);
@ -164,9 +164,8 @@ class RemoteDevToolsAutoConfigurationTests {
this.context = getContext(() -> loadContext("spring.devtools.remote.secret:supersecret",
"server.servlet.context-path:/test", "spring.devtools.remote.context-path:/custom"));
DispatcherFilter filter = this.context.getBean(DispatcherFilter.class);
Filter securityFilterChain = this.context.getBean(BeanIds.SPRING_SECURITY_FILTER_CHAIN, Filter.class);
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context).addFilter(securityFilterChain)
.addFilter(filter).build();
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context).apply(springSecurity()).addFilter(filter)
.build();
mockMvc.perform(
MockMvcRequestBuilders.get("/test/custom/restart").header(DEFAULT_SECRET_HEADER_NAME, "supersecret"))
.andExpect(status().isOk());

Loading…
Cancel
Save