|
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,13 +106,32 @@ 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");
|
110 | 121 | this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
|
111 | 122 | assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_BAD_REQUEST);
|
112 | 123 | }
|
113 | 124 |
|
| 125 | + // gh-12548 |
| 126 | + @Test |
| 127 | + public void requestRejectedHandlerInvokedWhenOperationalObservationRegistry() throws ServletException, IOException { |
| 128 | + loadConfig(ObservationRegistryConfig.class); |
| 129 | + this.request.setServletPath("/spring"); |
| 130 | + this.request.setRequestURI("/spring/\u0019path"); |
| 131 | + this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain); |
| 132 | + assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_BAD_REQUEST); |
| 133 | + } |
| 134 | + |
114 | 135 | @Test
|
115 | 136 | public void ignoringMvcMatcherServletPath() throws Exception {
|
116 | 137 | loadConfig(MvcMatcherServletPathConfig.class, LegacyMvcMatchingConfig.class);
|
@@ -143,6 +164,11 @@ public void loadConfig(Class<?>... configs) {
|
143 | 164 | this.context.getAutowireCapableBeanFactory().autowireBean(this);
|
144 | 165 | }
|
145 | 166 |
|
| 167 | + @EnableWebSecurity |
| 168 | + static class DefaultConfig { |
| 169 | + |
| 170 | + } |
| 171 | + |
146 | 172 | @EnableWebSecurity
|
147 | 173 | @Configuration
|
148 | 174 | @EnableWebMvc
|
@@ -243,4 +269,17 @@ WebSecurityCustomizer webSecurityCustomizer() {
|
243 | 269 |
|
244 | 270 | }
|
245 | 271 |
|
| 272 | + @Configuration |
| 273 | + @EnableWebSecurity |
| 274 | + static class ObservationRegistryConfig { |
| 275 | + |
| 276 | + @Bean |
| 277 | + ObservationRegistry observationRegistry() { |
| 278 | + ObservationRegistry observationRegistry = ObservationRegistry.create(); |
| 279 | + observationRegistry.observationConfig().observationHandler(new ObservationTextPublisher()); |
| 280 | + return observationRegistry; |
| 281 | + } |
| 282 | + |
| 283 | + } |
| 284 | + |
246 | 285 | }
|
0 commit comments