mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-12-12 19:13:37 +00:00
Add RequestRejectedHandler Test
Issue gh-12548
This commit is contained in:
parent
9603a68e8f
commit
66711f2365
@ -18,6 +18,8 @@ package org.springframework.security.config.annotation.web.builders;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import io.micrometer.observation.ObservationRegistry;
|
||||||
|
import io.micrometer.observation.ObservationTextPublisher;
|
||||||
import jakarta.servlet.ServletException;
|
import jakarta.servlet.ServletException;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
@ -104,6 +106,15 @@ public class WebSecurityTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void requestRejectedHandlerInvoked() throws ServletException, IOException {
|
public void requestRejectedHandlerInvoked() throws ServletException, IOException {
|
||||||
|
loadConfig(DefaultConfig.class);
|
||||||
|
this.request.setServletPath("/spring");
|
||||||
|
this.request.setRequestURI("/spring/\u0019path");
|
||||||
|
this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
|
||||||
|
assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void customRequestRejectedHandlerInvoked() throws ServletException, IOException {
|
||||||
loadConfig(RequestRejectedHandlerConfig.class);
|
loadConfig(RequestRejectedHandlerConfig.class);
|
||||||
this.request.setServletPath("/spring");
|
this.request.setServletPath("/spring");
|
||||||
this.request.setRequestURI("/spring/\u0019path");
|
this.request.setRequestURI("/spring/\u0019path");
|
||||||
@ -143,6 +154,11 @@ public class WebSecurityTests {
|
|||||||
this.context.getAutowireCapableBeanFactory().autowireBean(this);
|
this.context.getAutowireCapableBeanFactory().autowireBean(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EnableWebSecurity
|
||||||
|
static class DefaultConfig {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@EnableWebSecurity
|
@EnableWebSecurity
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableWebMvc
|
@EnableWebMvc
|
||||||
@ -243,4 +259,17 @@ public class WebSecurityTests {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableWebSecurity
|
||||||
|
static class ObservationRegistryConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
ObservationRegistry observationRegistry() {
|
||||||
|
ObservationRegistry observationRegistry = ObservationRegistry.create();
|
||||||
|
observationRegistry.observationConfig().observationHandler(new ObservationTextPublisher());
|
||||||
|
return observationRegistry;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user