|
50 | 50 | import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
51 | 51 | import static org.mockito.ArgumentMatchers.any;
|
52 | 52 | import static org.mockito.BDDMockito.given;
|
| 53 | +import static org.mockito.BDDMockito.willAnswer; |
53 | 54 | import static org.mockito.BDDMockito.willThrow;
|
54 | 55 | import static org.mockito.Mockito.mock;
|
55 | 56 | import static org.mockito.Mockito.verify;
|
@@ -325,4 +326,22 @@ public void doFilterWhenCustomAuthorizationRedirectStrategySetThenCustomAuthoriz
|
325 | 326 | + "redirect_uri=http://localhost/login/oauth2/code/registration-id");
|
326 | 327 | }
|
327 | 328 |
|
| 329 | + // gh-11602 |
| 330 | + |
| 331 | + @Test |
| 332 | + public void doFilterWhenNotAuthorizationRequestAndClientAuthorizationRequiredExceptionThrownThenSaveRequestBeforeCommitted() |
| 333 | + throws Exception { |
| 334 | + String requestUri = "/path"; |
| 335 | + MockHttpServletRequest request = new MockHttpServletRequest("GET", requestUri); |
| 336 | + request.setServletPath(requestUri); |
| 337 | + MockHttpServletResponse response = new MockHttpServletResponse(); |
| 338 | + FilterChain filterChain = mock(FilterChain.class); |
| 339 | + willAnswer((invocation) -> assertThat((invocation.<HttpServletResponse>getArgument(1)).isCommitted()).isFalse()) |
| 340 | + .given(this.requestCache).saveRequest(any(HttpServletRequest.class), any(HttpServletResponse.class)); |
| 341 | + willThrow(new ClientAuthorizationRequiredException(this.registration1.getRegistrationId())).given(filterChain) |
| 342 | + .doFilter(any(ServletRequest.class), any(ServletResponse.class)); |
| 343 | + this.filter.doFilter(request, response, filterChain); |
| 344 | + assertThat(response.isCommitted()).isTrue(); |
| 345 | + } |
| 346 | + |
328 | 347 | }
|
0 commit comments