Signed-off-by: Tran Ngoc Nhan <ngocnhan.tran1996@gmail.com>
This commit is contained in:
Tran Ngoc Nhan 2025-06-21 02:11:04 +07:00
parent b6182eb29a
commit 3de359c580
3 changed files with 0 additions and 11 deletions

View File

@ -85,7 +85,6 @@ class AuthorizationManagerWebInvocationPrivilegeEvaluatorTests {
@Test @Test
void isAllowedWhenServletContextExistsThenFilterInvocationHasServletContext() { void isAllowedWhenServletContextExistsThenFilterInvocationHasServletContext() {
ServletContext servletContext = new MockServletContext(); ServletContext servletContext = new MockServletContext();
given(this.authorizationManager.authorize(any(), any())).willCallRealMethod();
this.privilegeEvaluator.setServletContext(servletContext); this.privilegeEvaluator.setServletContext(servletContext);
this.privilegeEvaluator.isAllowed("/test", TestAuthentication.authenticatedUser()); this.privilegeEvaluator.isAllowed("/test", TestAuthentication.authenticatedUser());
ArgumentCaptor<HttpServletRequest> captor = ArgumentCaptor.forClass(HttpServletRequest.class); ArgumentCaptor<HttpServletRequest> captor = ArgumentCaptor.forClass(HttpServletRequest.class);
@ -102,7 +101,6 @@ class AuthorizationManagerWebInvocationPrivilegeEvaluatorTests {
void isAllowedWhenRequestTransformerThenUsesRequestTransformerResult() { void isAllowedWhenRequestTransformerThenUsesRequestTransformerResult() {
HttpServletRequest request = new MockHttpServletRequest(); HttpServletRequest request = new MockHttpServletRequest();
given(this.requestTransformer.transform(any())).willReturn(request); given(this.requestTransformer.transform(any())).willReturn(request);
given(this.authorizationManager.authorize(any(), any())).willCallRealMethod();
this.privilegeEvaluator.setRequestTransformer(this.requestTransformer); this.privilegeEvaluator.setRequestTransformer(this.requestTransformer);
this.privilegeEvaluator.isAllowed("/test", TestAuthentication.authenticatedUser()); this.privilegeEvaluator.isAllowed("/test", TestAuthentication.authenticatedUser());

View File

@ -118,7 +118,6 @@ public class AuthorizationFilterTests {
@Test @Test
public void filterWhenAuthorizationManagerVerifyThrowsAccessDeniedExceptionThenStopFilterChain() { public void filterWhenAuthorizationManagerVerifyThrowsAccessDeniedExceptionThenStopFilterChain() {
AuthorizationManager<HttpServletRequest> mockAuthorizationManager = mock(AuthorizationManager.class); AuthorizationManager<HttpServletRequest> mockAuthorizationManager = mock(AuthorizationManager.class);
given(mockAuthorizationManager.authorize(any(), any())).willCallRealMethod();
AuthorizationFilter filter = new AuthorizationFilter(mockAuthorizationManager); AuthorizationFilter filter = new AuthorizationFilter(mockAuthorizationManager);
TestingAuthenticationToken authenticationToken = new TestingAuthenticationToken("user", "password"); TestingAuthenticationToken authenticationToken = new TestingAuthenticationToken("user", "password");
@ -196,7 +195,6 @@ public class AuthorizationFilterTests {
@Test @Test
public void doFilterWhenErrorThenDoFilter() throws Exception { public void doFilterWhenErrorThenDoFilter() throws Exception {
AuthorizationManager<HttpServletRequest> authorizationManager = mock(AuthorizationManager.class); AuthorizationManager<HttpServletRequest> authorizationManager = mock(AuthorizationManager.class);
given(authorizationManager.authorize(any(), any())).willCallRealMethod();
AuthorizationFilter authorizationFilter = new AuthorizationFilter(authorizationManager); AuthorizationFilter authorizationFilter = new AuthorizationFilter(authorizationManager);
MockHttpServletRequest mockRequest = new MockHttpServletRequest(null, "/path"); MockHttpServletRequest mockRequest = new MockHttpServletRequest(null, "/path");
mockRequest.setDispatcherType(DispatcherType.ERROR); mockRequest.setDispatcherType(DispatcherType.ERROR);
@ -233,7 +231,6 @@ public class AuthorizationFilterTests {
@Test @Test
public void doFilterWhenObserveOncePerRequestTrueAndNotAppliedThenInvoked() throws ServletException, IOException { public void doFilterWhenObserveOncePerRequestTrueAndNotAppliedThenInvoked() throws ServletException, IOException {
given(this.authorizationManager.authorize(any(), any())).willCallRealMethod();
this.filter.setObserveOncePerRequest(true); this.filter.setObserveOncePerRequest(true);
this.filter.doFilter(this.request, this.response, this.chain); this.filter.doFilter(this.request, this.response, this.chain);
verify(this.authorizationManager).authorize(any(), any()); verify(this.authorizationManager).authorize(any(), any());
@ -242,7 +239,6 @@ public class AuthorizationFilterTests {
@Test @Test
public void doFilterWhenObserveOncePerRequestFalseAndIsAppliedThenInvoked() throws ServletException, IOException { public void doFilterWhenObserveOncePerRequestFalseAndIsAppliedThenInvoked() throws ServletException, IOException {
setIsAppliedTrue(); setIsAppliedTrue();
given(this.authorizationManager.authorize(any(), any())).willCallRealMethod();
this.filter.setObserveOncePerRequest(false); this.filter.setObserveOncePerRequest(false);
this.filter.doFilter(this.request, this.response, this.chain); this.filter.doFilter(this.request, this.response, this.chain);
verify(this.authorizationManager).authorize(any(), any()); verify(this.authorizationManager).authorize(any(), any());
@ -250,7 +246,6 @@ public class AuthorizationFilterTests {
@Test @Test
public void doFilterWhenObserveOncePerRequestFalseAndNotAppliedThenInvoked() throws ServletException, IOException { public void doFilterWhenObserveOncePerRequestFalseAndNotAppliedThenInvoked() throws ServletException, IOException {
given(this.authorizationManager.authorize(any(), any())).willCallRealMethod();
this.filter.setObserveOncePerRequest(false); this.filter.setObserveOncePerRequest(false);
this.filter.doFilter(this.request, this.response, this.chain); this.filter.doFilter(this.request, this.response, this.chain);
verify(this.authorizationManager).authorize(any(), any()); verify(this.authorizationManager).authorize(any(), any());
@ -266,7 +261,6 @@ public class AuthorizationFilterTests {
@Test @Test
public void doFilterWhenFilterErrorDispatchTrueAndIsErrorThenInvoked() throws ServletException, IOException { public void doFilterWhenFilterErrorDispatchTrueAndIsErrorThenInvoked() throws ServletException, IOException {
given(this.authorizationManager.authorize(any(), any())).willCallRealMethod();
this.request.setDispatcherType(DispatcherType.ERROR); this.request.setDispatcherType(DispatcherType.ERROR);
this.filter.setFilterErrorDispatch(true); this.filter.setFilterErrorDispatch(true);
this.filter.doFilter(this.request, this.response, this.chain); this.filter.doFilter(this.request, this.response, this.chain);
@ -290,7 +284,6 @@ public class AuthorizationFilterTests {
@Test @Test
public void doFilterWhenFilterAsyncDispatchTrueAndIsAsyncThenInvoked() throws ServletException, IOException { public void doFilterWhenFilterAsyncDispatchTrueAndIsAsyncThenInvoked() throws ServletException, IOException {
given(this.authorizationManager.authorize(any(), any())).willCallRealMethod();
this.request.setDispatcherType(DispatcherType.ASYNC); this.request.setDispatcherType(DispatcherType.ASYNC);
this.filter.setFilterAsyncDispatch(true); this.filter.setFilterAsyncDispatch(true);
this.filter.doFilter(this.request, this.response, this.chain); this.filter.doFilter(this.request, this.response, this.chain);

View File

@ -81,7 +81,6 @@ public class DelegatingReactiveAuthorizationManagerTests {
given(this.match1.matches(any())).willReturn(ServerWebExchangeMatcher.MatchResult.match()); given(this.match1.matches(any())).willReturn(ServerWebExchangeMatcher.MatchResult.match());
given(this.delegate1.authorize(eq(this.authentication), any(AuthorizationContext.class))) given(this.delegate1.authorize(eq(this.authentication), any(AuthorizationContext.class)))
.willReturn(Mono.just(this.decision)); .willReturn(Mono.just(this.decision));
given(this.delegate1.authorize(eq(this.authentication), any(AuthorizationContext.class))).willCallRealMethod();
assertThat(this.manager.authorize(this.authentication, this.exchange).block()).isEqualTo(this.decision); assertThat(this.manager.authorize(this.authentication, this.exchange).block()).isEqualTo(this.decision);
verifyNoMoreInteractions(this.match2, this.delegate2); verifyNoMoreInteractions(this.match2, this.delegate2);
} }
@ -92,7 +91,6 @@ public class DelegatingReactiveAuthorizationManagerTests {
given(this.match2.matches(any())).willReturn(ServerWebExchangeMatcher.MatchResult.match()); given(this.match2.matches(any())).willReturn(ServerWebExchangeMatcher.MatchResult.match());
given(this.delegate2.authorize(eq(this.authentication), any(AuthorizationContext.class))) given(this.delegate2.authorize(eq(this.authentication), any(AuthorizationContext.class)))
.willReturn(Mono.just(this.decision)); .willReturn(Mono.just(this.decision));
given(this.delegate2.authorize(eq(this.authentication), any(AuthorizationContext.class))).willCallRealMethod();
assertThat(this.manager.authorize(this.authentication, this.exchange).block()).isEqualTo(this.decision); assertThat(this.manager.authorize(this.authentication, this.exchange).block()).isEqualTo(this.decision);
verifyNoMoreInteractions(this.delegate1); verifyNoMoreInteractions(this.delegate1);
} }