mirror of
				https://github.com/spring-projects/spring-security.git
				synced 2025-10-31 06:38:42 +00:00 
			
		
		
		
	Correct Authorization Tests
Issue gh-9289
This commit is contained in:
		
							parent
							
								
									56c93afc66
								
							
						
					
					
						commit
						03bcc6776a
					
				| @ -206,7 +206,7 @@ public class Jsr250AuthorizationManagerTests { | ||||
| 	} | ||||
| 
 | ||||
| 	@Test | ||||
| 	public void checkInheritedAnnotationsWhenDuplicatedThenAnnotationConfigurationException() throws Exception { | ||||
| 	public void checkInheritedAnnotationsWhenConflictingThenAnnotationConfigurationException() throws Exception { | ||||
| 		Supplier<Authentication> authentication = () -> new TestingAuthenticationToken("user", "password", "ROLE_USER"); | ||||
| 		MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class, | ||||
| 				"inheritedAnnotations"); | ||||
| @ -215,16 +215,6 @@ public class Jsr250AuthorizationManagerTests { | ||||
| 			.isThrownBy(() -> manager.check(authentication, methodInvocation)); | ||||
| 	} | ||||
| 
 | ||||
| 	@Test | ||||
| 	public void checkInheritedAnnotationsWhenConflictingThenAnnotationConfigurationException() throws Exception { | ||||
| 		Supplier<Authentication> authentication = () -> new TestingAuthenticationToken("user", "password", "ROLE_USER"); | ||||
| 		MockMethodInvocation methodInvocation = new MockMethodInvocation(new ClassLevelAnnotations(), | ||||
| 				ClassLevelAnnotations.class, "inheritedAnnotations"); | ||||
| 		Jsr250AuthorizationManager manager = new Jsr250AuthorizationManager(); | ||||
| 		assertThatExceptionOfType(AnnotationConfigurationException.class) | ||||
| 			.isThrownBy(() -> manager.check(authentication, methodInvocation)); | ||||
| 	} | ||||
| 
 | ||||
| 	@Test | ||||
| 	public void checkRequiresUserWhenMethodsFromInheritThenApplies() throws Exception { | ||||
| 		MockMethodInvocation methodInvocation = new MockMethodInvocation(new RolesAllowedClass(), | ||||
|  | ||||
| @ -145,22 +145,11 @@ public class PostAuthorizeAuthorizationManagerTests { | ||||
| 		assertThat(decision.isGranted()).isFalse(); | ||||
| 	} | ||||
| 
 | ||||
| 	@Test | ||||
| 	public void checkInheritedAnnotationsWhenDuplicatedThenAnnotationConfigurationException() throws Exception { | ||||
| 		Supplier<Authentication> authentication = () -> new TestingAuthenticationToken("user", "password", "ROLE_USER"); | ||||
| 		MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class, | ||||
| 				"inheritedAnnotations"); | ||||
| 		MethodInvocationResult result = new MethodInvocationResult(methodInvocation, null); | ||||
| 		PostAuthorizeAuthorizationManager manager = new PostAuthorizeAuthorizationManager(); | ||||
| 		assertThatExceptionOfType(AnnotationConfigurationException.class) | ||||
| 			.isThrownBy(() -> manager.check(authentication, result)); | ||||
| 	} | ||||
| 
 | ||||
| 	@Test | ||||
| 	public void checkInheritedAnnotationsWhenConflictingThenAnnotationConfigurationException() throws Exception { | ||||
| 		Supplier<Authentication> authentication = () -> new TestingAuthenticationToken("user", "password", "ROLE_USER"); | ||||
| 		MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class, | ||||
| 				"inheritedAnnotations"); | ||||
| 		MockMethodInvocation methodInvocation = new MockMethodInvocation(new ConflictingAnnotations(), | ||||
| 				ConflictingAnnotations.class, "inheritedAnnotations"); | ||||
| 		MethodInvocationResult result = new MethodInvocationResult(methodInvocation, null); | ||||
| 		PostAuthorizeAuthorizationManager manager = new PostAuthorizeAuthorizationManager(); | ||||
| 		assertThatExceptionOfType(AnnotationConfigurationException.class) | ||||
| @ -233,6 +222,14 @@ public class PostAuthorizeAuthorizationManagerTests { | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| 	public static class ConflictingAnnotations implements InterfaceAnnotationsOne, InterfaceAnnotationsTwo { | ||||
| 
 | ||||
| 		@Override | ||||
| 		public void inheritedAnnotations() { | ||||
| 		} | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| 	public interface InterfaceAnnotationsOne { | ||||
| 
 | ||||
| 		@PostAuthorize("hasRole('ADMIN')") | ||||
|  | ||||
| @ -149,24 +149,12 @@ public class PostAuthorizeReactiveAuthorizationManagerTests { | ||||
| 		assertThat(decision.isGranted()).isFalse(); | ||||
| 	} | ||||
| 
 | ||||
| 	@Test | ||||
| 	public void checkInheritedAnnotationsWhenDuplicatedThenAnnotationConfigurationException() throws Exception { | ||||
| 		Mono<Authentication> authentication = Mono | ||||
| 			.just(new TestingAuthenticationToken("user", "password", "ROLE_USER")); | ||||
| 		MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class, | ||||
| 				"inheritedAnnotations"); | ||||
| 		MethodInvocationResult result = new MethodInvocationResult(methodInvocation, null); | ||||
| 		PostAuthorizeReactiveAuthorizationManager manager = new PostAuthorizeReactiveAuthorizationManager(); | ||||
| 		assertThatExceptionOfType(AnnotationConfigurationException.class) | ||||
| 			.isThrownBy(() -> manager.check(authentication, result)); | ||||
| 	} | ||||
| 
 | ||||
| 	@Test | ||||
| 	public void checkInheritedAnnotationsWhenConflictingThenAnnotationConfigurationException() throws Exception { | ||||
| 		Mono<Authentication> authentication = Mono | ||||
| 			.just(new TestingAuthenticationToken("user", "password", "ROLE_USER")); | ||||
| 		MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class, | ||||
| 				"inheritedAnnotations"); | ||||
| 		MockMethodInvocation methodInvocation = new MockMethodInvocation(new ConflictingAnnotations(), | ||||
| 				ConflictingAnnotations.class, "inheritedAnnotations"); | ||||
| 		MethodInvocationResult result = new MethodInvocationResult(methodInvocation, null); | ||||
| 		PostAuthorizeReactiveAuthorizationManager manager = new PostAuthorizeReactiveAuthorizationManager(); | ||||
| 		assertThatExceptionOfType(AnnotationConfigurationException.class) | ||||
| @ -216,6 +204,14 @@ public class PostAuthorizeReactiveAuthorizationManagerTests { | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| 	public static class ConflictingAnnotations implements InterfaceAnnotationsOne, InterfaceAnnotationsTwo { | ||||
| 
 | ||||
| 		@Override | ||||
| 		public void inheritedAnnotations() { | ||||
| 		} | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| 	public interface InterfaceAnnotationsOne { | ||||
| 
 | ||||
| 		@PostAuthorize("hasRole('ADMIN')") | ||||
|  | ||||
| @ -109,19 +109,10 @@ public class PostFilterAuthorizationMethodInterceptorTests { | ||||
| 		assertThat(result).asInstanceOf(InstanceOfAssertFactories.array(String[].class)).containsOnly("john"); | ||||
| 	} | ||||
| 
 | ||||
| 	@Test | ||||
| 	public void checkInheritedAnnotationsWhenDuplicatedThenAnnotationConfigurationException() throws Exception { | ||||
| 		MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class, | ||||
| 				"inheritedAnnotations"); | ||||
| 		PostFilterAuthorizationMethodInterceptor advice = new PostFilterAuthorizationMethodInterceptor(); | ||||
| 		assertThatExceptionOfType(AnnotationConfigurationException.class) | ||||
| 			.isThrownBy(() -> advice.invoke(methodInvocation)); | ||||
| 	} | ||||
| 
 | ||||
| 	@Test | ||||
| 	public void checkInheritedAnnotationsWhenConflictingThenAnnotationConfigurationException() throws Exception { | ||||
| 		MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class, | ||||
| 				"inheritedAnnotations"); | ||||
| 		MockMethodInvocation methodInvocation = new MockMethodInvocation(new ConflictingAnnotations(), | ||||
| 				ConflictingAnnotations.class, "inheritedAnnotations"); | ||||
| 		PostFilterAuthorizationMethodInterceptor advice = new PostFilterAuthorizationMethodInterceptor(); | ||||
| 		assertThatExceptionOfType(AnnotationConfigurationException.class) | ||||
| 			.isThrownBy(() -> advice.invoke(methodInvocation)); | ||||
| @ -230,6 +221,14 @@ public class PostFilterAuthorizationMethodInterceptorTests { | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| 	public static class ConflictingAnnotations implements InterfaceAnnotationsOne, InterfaceAnnotationsTwo { | ||||
| 
 | ||||
| 		@Override | ||||
| 		public void inheritedAnnotations() { | ||||
| 		} | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| 	public interface InterfaceAnnotationsOne { | ||||
| 
 | ||||
| 		@PostFilter("filterObject == 'jim'") | ||||
|  | ||||
| @ -105,19 +105,10 @@ public class PostFilterAuthorizationReactiveMethodInterceptorTests { | ||||
| 			.containsOnly("john"); | ||||
| 	} | ||||
| 
 | ||||
| 	@Test | ||||
| 	public void checkInheritedAnnotationsWhenDuplicatedThenAnnotationConfigurationException() throws Exception { | ||||
| 		MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class, | ||||
| 				"inheritedAnnotations"); | ||||
| 		PostFilterAuthorizationReactiveMethodInterceptor interceptor = new PostFilterAuthorizationReactiveMethodInterceptor(); | ||||
| 		assertThatExceptionOfType(AnnotationConfigurationException.class) | ||||
| 			.isThrownBy(() -> interceptor.invoke(methodInvocation)); | ||||
| 	} | ||||
| 
 | ||||
| 	@Test | ||||
| 	public void checkInheritedAnnotationsWhenConflictingThenAnnotationConfigurationException() throws Exception { | ||||
| 		MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class, | ||||
| 				"inheritedAnnotations"); | ||||
| 		MockMethodInvocation methodInvocation = new MockMethodInvocation(new ConflictingAnnotations(), | ||||
| 				ConflictingAnnotations.class, "inheritedAnnotations"); | ||||
| 		PostFilterAuthorizationReactiveMethodInterceptor interceptor = new PostFilterAuthorizationReactiveMethodInterceptor(); | ||||
| 		assertThatExceptionOfType(AnnotationConfigurationException.class) | ||||
| 			.isThrownBy(() -> interceptor.invoke(methodInvocation)); | ||||
| @ -155,6 +146,14 @@ public class PostFilterAuthorizationReactiveMethodInterceptorTests { | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| 	public static class ConflictingAnnotations implements InterfaceAnnotationsOne, InterfaceAnnotationsTwo { | ||||
| 
 | ||||
| 		@Override | ||||
| 		public void inheritedAnnotations() { | ||||
| 		} | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| 	public interface InterfaceAnnotationsOne { | ||||
| 
 | ||||
| 		@PostFilter("filterObject == 'jim'") | ||||
|  | ||||
| @ -114,21 +114,11 @@ public class PreAuthorizeAuthorizationManagerTests { | ||||
| 		assertThat(decision.isGranted()).isFalse(); | ||||
| 	} | ||||
| 
 | ||||
| 	@Test | ||||
| 	public void checkInheritedAnnotationsWhenDuplicatedThenAnnotationConfigurationException() throws Exception { | ||||
| 		Supplier<Authentication> authentication = () -> new TestingAuthenticationToken("user", "password", "ROLE_USER"); | ||||
| 		MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class, | ||||
| 				"inheritedAnnotations"); | ||||
| 		PreAuthorizeAuthorizationManager manager = new PreAuthorizeAuthorizationManager(); | ||||
| 		assertThatExceptionOfType(AnnotationConfigurationException.class) | ||||
| 			.isThrownBy(() -> manager.check(authentication, methodInvocation)); | ||||
| 	} | ||||
| 
 | ||||
| 	@Test | ||||
| 	public void checkInheritedAnnotationsWhenConflictingThenAnnotationConfigurationException() throws Exception { | ||||
| 		Supplier<Authentication> authentication = () -> new TestingAuthenticationToken("user", "password", "ROLE_USER"); | ||||
| 		MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class, | ||||
| 				"inheritedAnnotations"); | ||||
| 		MockMethodInvocation methodInvocation = new MockMethodInvocation(new ConflictingAnnotations(), | ||||
| 				ConflictingAnnotations.class, "inheritedAnnotations"); | ||||
| 		PreAuthorizeAuthorizationManager manager = new PreAuthorizeAuthorizationManager(); | ||||
| 		assertThatExceptionOfType(AnnotationConfigurationException.class) | ||||
| 			.isThrownBy(() -> manager.check(authentication, methodInvocation)); | ||||
| @ -207,6 +197,14 @@ public class PreAuthorizeAuthorizationManagerTests { | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| 	public static class ConflictingAnnotations implements InterfaceAnnotationsOne, InterfaceAnnotationsTwo { | ||||
| 
 | ||||
| 		@Override | ||||
| 		public void inheritedAnnotations() { | ||||
| 		} | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| 	public interface InterfaceAnnotationsOne { | ||||
| 
 | ||||
| 		@PreAuthorize("hasRole('ADMIN')") | ||||
|  | ||||
| @ -123,23 +123,12 @@ public class PreAuthorizeReactiveAuthorizationManagerTests { | ||||
| 		assertThat(decision.isGranted()).isFalse(); | ||||
| 	} | ||||
| 
 | ||||
| 	@Test | ||||
| 	public void checkInheritedAnnotationsWhenDuplicatedThenAnnotationConfigurationException() throws Exception { | ||||
| 		Mono<Authentication> authentication = Mono | ||||
| 			.just(new TestingAuthenticationToken("user", "password", "ROLE_USER")); | ||||
| 		MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class, | ||||
| 				"inheritedAnnotations"); | ||||
| 		PreAuthorizeReactiveAuthorizationManager manager = new PreAuthorizeReactiveAuthorizationManager(); | ||||
| 		assertThatExceptionOfType(AnnotationConfigurationException.class) | ||||
| 			.isThrownBy(() -> manager.check(authentication, methodInvocation)); | ||||
| 	} | ||||
| 
 | ||||
| 	@Test | ||||
| 	public void checkInheritedAnnotationsWhenConflictingThenAnnotationConfigurationException() throws Exception { | ||||
| 		Mono<Authentication> authentication = Mono | ||||
| 			.just(new TestingAuthenticationToken("user", "password", "ROLE_USER")); | ||||
| 		MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class, | ||||
| 				"inheritedAnnotations"); | ||||
| 		MockMethodInvocation methodInvocation = new MockMethodInvocation(new ConflictingAnnotations(), | ||||
| 				ConflictingAnnotations.class, "inheritedAnnotations"); | ||||
| 		PreAuthorizeReactiveAuthorizationManager manager = new PreAuthorizeReactiveAuthorizationManager(); | ||||
| 		assertThatExceptionOfType(AnnotationConfigurationException.class) | ||||
| 			.isThrownBy(() -> manager.check(authentication, methodInvocation)); | ||||
| @ -183,6 +172,14 @@ public class PreAuthorizeReactiveAuthorizationManagerTests { | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| 	public static class ConflictingAnnotations implements InterfaceAnnotationsOne, InterfaceAnnotationsTwo { | ||||
| 
 | ||||
| 		@Override | ||||
| 		public void inheritedAnnotations() { | ||||
| 		} | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| 	public interface InterfaceAnnotationsOne { | ||||
| 
 | ||||
| 		@PreAuthorize("hasRole('ADMIN')") | ||||
|  | ||||
| @ -169,19 +169,10 @@ public class PreFilterAuthorizationMethodInterceptorTests { | ||||
| 			.withMessage("Unable to determine the method argument for filtering. Specify the filter target."); | ||||
| 	} | ||||
| 
 | ||||
| 	@Test | ||||
| 	public void checkInheritedAnnotationsWhenDuplicatedThenAnnotationConfigurationException() throws Exception { | ||||
| 		MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class, | ||||
| 				"inheritedAnnotations"); | ||||
| 		PreFilterAuthorizationMethodInterceptor advice = new PreFilterAuthorizationMethodInterceptor(); | ||||
| 		assertThatExceptionOfType(AnnotationConfigurationException.class) | ||||
| 			.isThrownBy(() -> advice.invoke(methodInvocation)); | ||||
| 	} | ||||
| 
 | ||||
| 	@Test | ||||
| 	public void checkInheritedAnnotationsWhenConflictingThenAnnotationConfigurationException() throws Exception { | ||||
| 		MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class, | ||||
| 				"inheritedAnnotations"); | ||||
| 		MockMethodInvocation methodInvocation = new MockMethodInvocation(new ConflictingAnnotations(), | ||||
| 				ConflictingAnnotations.class, "inheritedAnnotations"); | ||||
| 		PreFilterAuthorizationMethodInterceptor advice = new PreFilterAuthorizationMethodInterceptor(); | ||||
| 		assertThatExceptionOfType(AnnotationConfigurationException.class) | ||||
| 			.isThrownBy(() -> advice.invoke(methodInvocation)); | ||||
| @ -297,6 +288,14 @@ public class PreFilterAuthorizationMethodInterceptorTests { | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| 	public static class ConflictingAnnotations implements InterfaceAnnotationsOne, InterfaceAnnotationsTwo { | ||||
| 
 | ||||
| 		@Override | ||||
| 		public void inheritedAnnotations() { | ||||
| 		} | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| 	public interface InterfaceAnnotationsOne { | ||||
| 
 | ||||
| 		@PreFilter("filterObject == 'jim'") | ||||
|  | ||||
| @ -140,19 +140,10 @@ public class PreFilterAuthorizationReactiveMethodInterceptorTests { | ||||
| 			.containsOnly("john"); | ||||
| 	} | ||||
| 
 | ||||
| 	@Test | ||||
| 	public void checkInheritedAnnotationsWhenDuplicatedThenAnnotationConfigurationException() throws Exception { | ||||
| 		MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class, | ||||
| 				"inheritedAnnotations"); | ||||
| 		PreFilterAuthorizationReactiveMethodInterceptor interceptor = new PreFilterAuthorizationReactiveMethodInterceptor(); | ||||
| 		assertThatExceptionOfType(AnnotationConfigurationException.class) | ||||
| 			.isThrownBy(() -> interceptor.invoke(methodInvocation)); | ||||
| 	} | ||||
| 
 | ||||
| 	@Test | ||||
| 	public void checkInheritedAnnotationsWhenConflictingThenAnnotationConfigurationException() throws Exception { | ||||
| 		MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class, | ||||
| 				"inheritedAnnotations"); | ||||
| 		MockMethodInvocation methodInvocation = new MockMethodInvocation(new ConflictingAnnotations(), | ||||
| 				ConflictingAnnotations.class, "inheritedAnnotations"); | ||||
| 		PreFilterAuthorizationReactiveMethodInterceptor interceptor = new PreFilterAuthorizationReactiveMethodInterceptor(); | ||||
| 		assertThatExceptionOfType(AnnotationConfigurationException.class) | ||||
| 			.isThrownBy(() -> interceptor.invoke(methodInvocation)); | ||||
| @ -200,6 +191,14 @@ public class PreFilterAuthorizationReactiveMethodInterceptorTests { | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| 	public static class ConflictingAnnotations implements InterfaceAnnotationsOne, InterfaceAnnotationsTwo { | ||||
| 
 | ||||
| 		@Override | ||||
| 		public void inheritedAnnotations() { | ||||
| 		} | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| 	public interface InterfaceAnnotationsOne { | ||||
| 
 | ||||
| 		@PreFilter("filterObject == 'jim'") | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user