|
33 | 33 | import io.micrometer.observation.ObservationRegistry;
|
34 | 34 | import io.micrometer.observation.ObservationTextPublisher;
|
35 | 35 | import jakarta.annotation.security.DenyAll;
|
| 36 | +import jakarta.servlet.RequestDispatcher; |
36 | 37 | import org.aopalliance.aop.Advice;
|
37 | 38 | import org.aopalliance.intercept.MethodInterceptor;
|
38 | 39 | import org.aopalliance.intercept.MethodInvocation;
|
|
138 | 139 | import static org.assertj.core.api.Assertions.assertThat;
|
139 | 140 | import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
140 | 141 | import static org.assertj.core.api.Assertions.assertThatNoException;
|
| 142 | +import static org.hamcrest.Matchers.nullValue; |
141 | 143 | import static org.mockito.ArgumentMatchers.any;
|
142 | 144 | import static org.mockito.Mockito.atLeastOnce;
|
143 | 145 | import static org.mockito.Mockito.clearInvocations;
|
|
149 | 151 | import static org.mockito.Mockito.verifyNoInteractions;
|
150 | 152 | import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user;
|
151 | 153 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
| 154 | +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.request; |
152 | 155 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
153 | 156 |
|
154 | 157 | /**
|
@@ -1279,6 +1282,19 @@ void getWhenPostAuthorizeAuthenticationNameNotMatchThenRespondsWithForbidden() t
|
1279 | 1282 | this.mvc.perform(requestWithUser).andExpect(status().isForbidden());
|
1280 | 1283 | }
|
1281 | 1284 |
|
| 1285 | + // gh-17761 |
| 1286 | + @Test |
| 1287 | + void getWhenPostAuthorizeAuthenticationNameNotMatchThenNoExceptionExposedInRequest() throws Exception { |
| 1288 | + this.spring.register(WebMvcMethodSecurityConfig.class, BasicController.class).autowire(); |
| 1289 | + // @formatter:off |
| 1290 | + MockHttpServletRequestBuilder requestWithUser = get("/authorized-person") |
| 1291 | + .param("name", "john") |
| 1292 | + .with(user("rob")); |
| 1293 | + // @formatter:on |
| 1294 | + this.mvc.perform(requestWithUser) |
| 1295 | + .andExpect(request().attribute(RequestDispatcher.ERROR_EXCEPTION, nullValue())); |
| 1296 | + } |
| 1297 | + |
1282 | 1298 | @Test
|
1283 | 1299 | void getWhenPostAuthorizeWithinServiceAuthenticationNameMatchesThenRespondsWithOk() throws Exception {
|
1284 | 1300 | this.spring.register(WebMvcMethodSecurityConfig.class, BasicController.class, BasicService.class).autowire();
|
|
0 commit comments