Skip to content

Commit 66711f2

Browse files
committed
Add RequestRejectedHandler Test
Issue gh-12548
1 parent 9603a68 commit 66711f2

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

config/src/test/java/org/springframework/security/config/annotation/web/builders/WebSecurityTests.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import java.io.IOException;
2020

21+
import io.micrometer.observation.ObservationRegistry;
22+
import io.micrometer.observation.ObservationTextPublisher;
2123
import jakarta.servlet.ServletException;
2224
import jakarta.servlet.http.HttpServletResponse;
2325
import org.junit.jupiter.api.AfterEach;
@@ -104,6 +106,15 @@ public void ignoringMvcMatcher() throws Exception {
104106

105107
@Test
106108
public void requestRejectedHandlerInvoked() throws ServletException, IOException {
109+
loadConfig(DefaultConfig.class);
110+
this.request.setServletPath("/spring");
111+
this.request.setRequestURI("/spring/\u0019path");
112+
this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
113+
assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_BAD_REQUEST);
114+
}
115+
116+
@Test
117+
public void customRequestRejectedHandlerInvoked() throws ServletException, IOException {
107118
loadConfig(RequestRejectedHandlerConfig.class);
108119
this.request.setServletPath("/spring");
109120
this.request.setRequestURI("/spring/\u0019path");
@@ -143,6 +154,11 @@ public void loadConfig(Class<?>... configs) {
143154
this.context.getAutowireCapableBeanFactory().autowireBean(this);
144155
}
145156

157+
@EnableWebSecurity
158+
static class DefaultConfig {
159+
160+
}
161+
146162
@EnableWebSecurity
147163
@Configuration
148164
@EnableWebMvc
@@ -243,4 +259,17 @@ WebSecurityCustomizer webSecurityCustomizer() {
243259

244260
}
245261

262+
@Configuration
263+
@EnableWebSecurity
264+
static class ObservationRegistryConfig {
265+
266+
@Bean
267+
ObservationRegistry observationRegistry() {
268+
ObservationRegistry observationRegistry = ObservationRegistry.create();
269+
observationRegistry.observationConfig().observationHandler(new ObservationTextPublisher());
270+
return observationRegistry;
271+
}
272+
273+
}
274+
246275
}

0 commit comments

Comments
 (0)