|
52 | 52 | import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
53 | 53 | import static org.mockito.ArgumentMatchers.any;
|
54 | 54 | import static org.mockito.BDDMockito.given;
|
| 55 | +import static org.mockito.BDDMockito.willAnswer; |
55 | 56 | import static org.mockito.BDDMockito.willThrow;
|
56 | 57 | import static org.mockito.Mockito.mock;
|
57 | 58 | import static org.mockito.Mockito.times;
|
@@ -369,4 +370,22 @@ public void doFilterWhenCustomAuthorizationRedirectStrategySetThenCustomAuthoriz
|
369 | 370 | + "redirect_uri=http://localhost/login/oauth2/code/registration-id");
|
370 | 371 | }
|
371 | 372 |
|
| 373 | + // gh-11602 |
| 374 | + |
| 375 | + @Test |
| 376 | + public void doFilterWhenNotAuthorizationRequestAndClientAuthorizationRequiredExceptionThrownThenSaveRequestBeforeCommitted() |
| 377 | + throws Exception { |
| 378 | + String requestUri = "/path"; |
| 379 | + MockHttpServletRequest request = new MockHttpServletRequest("GET", requestUri); |
| 380 | + request.setServletPath(requestUri); |
| 381 | + MockHttpServletResponse response = new MockHttpServletResponse(); |
| 382 | + FilterChain filterChain = mock(FilterChain.class); |
| 383 | + willAnswer((invocation) -> assertThat((invocation.<HttpServletResponse>getArgument(1)).isCommitted()).isFalse()) |
| 384 | + .given(this.requestCache).saveRequest(any(HttpServletRequest.class), any(HttpServletResponse.class)); |
| 385 | + willThrow(new ClientAuthorizationRequiredException(this.registration1.getRegistrationId())).given(filterChain) |
| 386 | + .doFilter(any(ServletRequest.class), any(ServletResponse.class)); |
| 387 | + this.filter.doFilter(request, response, filterChain); |
| 388 | + assertThat(response.isCommitted()).isTrue(); |
| 389 | + } |
| 390 | + |
372 | 391 | }
|
0 commit comments