|
18 | 18 |
|
19 | 19 | import java.io.IOException;
|
20 | 20 |
|
| 21 | +import io.micrometer.observation.ObservationRegistry; |
| 22 | +import io.micrometer.observation.ObservationTextPublisher; |
21 | 23 | import jakarta.servlet.ServletException;
|
22 | 24 | import jakarta.servlet.http.HttpServletResponse;
|
23 | 25 | import org.junit.jupiter.api.AfterEach;
|
@@ -104,6 +106,15 @@ public void ignoringMvcMatcher() throws Exception {
|
104 | 106 |
|
105 | 107 | @Test
|
106 | 108 | 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 { |
107 | 118 | loadConfig(RequestRejectedHandlerConfig.class);
|
108 | 119 | this.request.setServletPath("/spring");
|
109 | 120 | this.request.setRequestURI("/spring/\u0019path");
|
@@ -143,6 +154,11 @@ public void loadConfig(Class<?>... configs) {
|
143 | 154 | this.context.getAutowireCapableBeanFactory().autowireBean(this);
|
144 | 155 | }
|
145 | 156 |
|
| 157 | + @EnableWebSecurity |
| 158 | + static class DefaultConfig { |
| 159 | + |
| 160 | + } |
| 161 | + |
146 | 162 | @EnableWebSecurity
|
147 | 163 | @Configuration
|
148 | 164 | @EnableWebMvc
|
@@ -243,4 +259,17 @@ WebSecurityCustomizer webSecurityCustomizer() {
|
243 | 259 |
|
244 | 260 | }
|
245 | 261 |
|
| 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 | + |
246 | 275 | }
|
0 commit comments