|
48 | 48 | import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
49 | 49 | import static org.mockito.ArgumentMatchers.any;
|
50 | 50 | import static org.mockito.BDDMockito.given;
|
| 51 | +import static org.mockito.BDDMockito.willAnswer; |
51 | 52 | import static org.mockito.BDDMockito.willThrow;
|
52 | 53 | import static org.mockito.Mockito.mock;
|
53 | 54 | import static org.mockito.Mockito.times;
|
@@ -333,4 +334,22 @@ public void doFilterWhenAuthorizationRequestAndCustomAuthorizationRequestUriSetT
|
333 | 334 | + "login_hint=user@provider\\.com");
|
334 | 335 | }
|
335 | 336 |
|
| 337 | + // gh-11602 |
| 338 | + |
| 339 | + @Test |
| 340 | + public void doFilterWhenNotAuthorizationRequestAndClientAuthorizationRequiredExceptionThrownThenSaveRequestBeforeCommitted() |
| 341 | + throws Exception { |
| 342 | + String requestUri = "/path"; |
| 343 | + MockHttpServletRequest request = new MockHttpServletRequest("GET", requestUri); |
| 344 | + request.setServletPath(requestUri); |
| 345 | + MockHttpServletResponse response = new MockHttpServletResponse(); |
| 346 | + FilterChain filterChain = mock(FilterChain.class); |
| 347 | + willAnswer((invocation) -> assertThat((invocation.<HttpServletResponse>getArgument(1)).isCommitted()).isFalse()) |
| 348 | + .given(this.requestCache).saveRequest(any(HttpServletRequest.class), any(HttpServletResponse.class)); |
| 349 | + willThrow(new ClientAuthorizationRequiredException(this.registration1.getRegistrationId())).given(filterChain) |
| 350 | + .doFilter(any(ServletRequest.class), any(ServletResponse.class)); |
| 351 | + this.filter.doFilter(request, response, filterChain); |
| 352 | + assertThat(response.isCommitted()).isTrue(); |
| 353 | + } |
| 354 | + |
336 | 355 | }
|
0 commit comments