Search in sources :

Example 11 with DispatcherFilter

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

the class RemoteDevToolsAutoConfigurationTests method securityConfigurationWhenWebSecurityConfigurerAdapterIsFound2.

@Test
void securityConfigurationWhenWebSecurityConfigurerAdapterIsFound2() throws Exception {
    this.context = getContext(() -> {
        AnnotationConfigServletWebApplicationContext context = new AnnotationConfigServletWebApplicationContext();
        context.setServletContext(new MockServletContext());
        context.register(Config.class, PropertyPlaceholderAutoConfiguration.class, TestWebSecurityConfigurerAdapter.class);
        TestPropertyValues.of("spring.devtools.remote.secret:supersecret").applyTo(context);
        context.refresh();
        return context;
    });
    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);
}
Also used : AnnotationConfigServletWebApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext) PropertyPlaceholderAutoConfiguration(org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration) MockServletContext(org.springframework.mock.web.MockServletContext) DispatcherFilter(org.springframework.boot.devtools.remote.server.DispatcherFilter) MockMvc(org.springframework.test.web.servlet.MockMvc) Test(org.junit.jupiter.api.Test)

Example 12 with DispatcherFilter

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

the class RemoteDevToolsAutoConfigurationTests method ignoresIfMissingSecretFromRequest.

@Test
void ignoresIfMissingSecretFromRequest() 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");
    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 13 with DispatcherFilter

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

the class RemoteDevToolsAutoConfigurationTests method securityConfigurationShouldAllowAccessToCustomPath.

@Test
void securityConfigurationShouldAllowAccessToCustomPath() throws Exception {
    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);
    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());
    assertRestartInvoked(true);
}
Also used : DispatcherFilter(org.springframework.boot.devtools.remote.server.DispatcherFilter) MockMvc(org.springframework.test.web.servlet.MockMvc) Test(org.junit.jupiter.api.Test)

Example 14 with DispatcherFilter

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

the class RemoteDevToolsAutoConfigurationTests method invokeRestartWithCustomServerContextPath.

@Test
void invokeRestartWithCustomServerContextPath() throws Exception {
    this.context = getContext(() -> 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 + "/restart");
    this.request.addHeader(DEFAULT_SECRET_HEADER_NAME, "supersecret");
    filter.doFilter(this.request, this.response, this.chain);
    assertRestartInvoked(true);
}
Also used : DispatcherFilter(org.springframework.boot.devtools.remote.server.DispatcherFilter) 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