Search in sources :

Example 1 with DispatcherFilter

use of org.springframework.boot.devtools.remote.server.DispatcherFilter in project spring-boot by spring-projects.

the class RemoteDevToolsAutoConfigurationTests method invokeTunnelWithCustomHeaderName.

@Test
public void invokeTunnelWithCustomHeaderName() throws Exception {
    loadContext("spring.devtools.remote.secret:supersecret", "spring.devtools.remote.secretHeaderName:customheader");
    DispatcherFilter filter = this.context.getBean(DispatcherFilter.class);
    this.request.setRequestURI(DEFAULT_CONTEXT_PATH + "/debug");
    this.request.addHeader("customheader", "supersecret");
    filter.doFilter(this.request, this.response, this.chain);
    assertTunnelInvoked(true);
}
Also used : DispatcherFilter(org.springframework.boot.devtools.remote.server.DispatcherFilter) Test(org.junit.Test)

Example 2 with DispatcherFilter

use of org.springframework.boot.devtools.remote.server.DispatcherFilter in project spring-boot by spring-projects.

the class RemoteDevToolsAutoConfigurationTests method invokeTunnelWithCustomServerContextPath.

@Test
public void invokeTunnelWithCustomServerContextPath() throws Exception {
    loadContext("spring.devtools.remote.secret:supersecret", "server.servlet.context-path:/test");
    DispatcherFilter filter = this.context.getBean(DispatcherFilter.class);
    this.request.setRequestURI("/test" + DEFAULT_CONTEXT_PATH + "/debug");
    this.request.addHeader(DEFAULT_SECRET_HEADER_NAME, "supersecret");
    filter.doFilter(this.request, this.response, this.chain);
    assertTunnelInvoked(true);
}
Also used : DispatcherFilter(org.springframework.boot.devtools.remote.server.DispatcherFilter) Test(org.junit.Test)

Example 3 with DispatcherFilter

use of org.springframework.boot.devtools.remote.server.DispatcherFilter in project spring-boot by spring-projects.

the class RemoteDevToolsAutoConfigurationTests method securityConfigurationShouldAllowAccess.

@Test
void securityConfigurationShouldAllowAccess() throws Exception {
    this.context = getContext(() -> loadContext("spring.devtools.remote.secret:supersecret"));
    DispatcherFilter filter = this.context.getBean(DispatcherFilter.class);
    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);
    assertThat(this.context.containsBean("devtoolsSecurityFilterChain")).isTrue();
}
Also used : DispatcherFilter(org.springframework.boot.devtools.remote.server.DispatcherFilter) MockMvc(org.springframework.test.web.servlet.MockMvc) Test(org.junit.jupiter.api.Test)

Example 4 with DispatcherFilter

use of org.springframework.boot.devtools.remote.server.DispatcherFilter in project spring-boot by spring-projects.

the class RemoteDevToolsAutoConfigurationTests method ignoresInvalidSecretInRequest.

@Test
void ignoresInvalidSecretInRequest() throws Exception {
    this.context = getContext(() -> loadContext("spring.devtools.remote.secret:supersecret"));
    DispatcherFilter filter = this.context.getBean(DispatcherFilter.class);
    this.request.setRequestURI(DEFAULT_CONTEXT_PATH + "/restart");
    this.request.addHeader(DEFAULT_SECRET_HEADER_NAME, "invalid");
    filter.doFilter(this.request, this.response, this.chain);
    assertRestartInvoked(false);
}
Also used : DispatcherFilter(org.springframework.boot.devtools.remote.server.DispatcherFilter) Test(org.junit.jupiter.api.Test)

Example 5 with DispatcherFilter

use of org.springframework.boot.devtools.remote.server.DispatcherFilter in project spring-boot by spring-projects.

the class RemoteDevToolsAutoConfigurationTests method securityConfigurationDoesNotAffectOtherPaths.

@Test
void securityConfigurationDoesNotAffectOtherPaths() 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.perform(MockMvcRequestBuilders.get("/my-path")).andExpect(status().isUnauthorized());
}
Also used : DispatcherFilter(org.springframework.boot.devtools.remote.server.DispatcherFilter) Filter(jakarta.servlet.Filter) SourceDirectoryUrlFilter(org.springframework.boot.devtools.restart.server.SourceDirectoryUrlFilter) DispatcherFilter(org.springframework.boot.devtools.remote.server.DispatcherFilter) MockMvc(org.springframework.test.web.servlet.MockMvc) Test(org.junit.jupiter.api.Test)

Aggregations

DispatcherFilter (org.springframework.boot.devtools.remote.server.DispatcherFilter)14 Test (org.junit.jupiter.api.Test)11 MockMvc (org.springframework.test.web.servlet.MockMvc)4 Test (org.junit.Test)3 Filter (jakarta.servlet.Filter)1 PropertyPlaceholderAutoConfiguration (org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration)1 SourceDirectoryUrlFilter (org.springframework.boot.devtools.restart.server.SourceDirectoryUrlFilter)1 AnnotationConfigServletWebApplicationContext (org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext)1 MockServletContext (org.springframework.mock.web.MockServletContext)1