Skip to content

Commit f7657fe

Browse files
committed
Correct Authorization Tests
Issue spring-projectsgh-9289
1 parent 889566d commit f7657fe

9 files changed

+81
-107
lines changed

core/src/test/java/org/springframework/security/authorization/method/Jsr250AuthorizationManagerTests.java

+1-11
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public void checkRequiresUserWhenClassAnnotationsThenApplies() throws Exception
206206
}
207207

208208
@Test
209-
public void checkInheritedAnnotationsWhenDuplicatedThenAnnotationConfigurationException() throws Exception {
209+
public void checkInheritedAnnotationsWhenConflictingThenAnnotationConfigurationException() throws Exception {
210210
Supplier<Authentication> authentication = () -> new TestingAuthenticationToken("user", "password", "ROLE_USER");
211211
MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class,
212212
"inheritedAnnotations");
@@ -215,16 +215,6 @@ public void checkInheritedAnnotationsWhenDuplicatedThenAnnotationConfigurationEx
215215
.isThrownBy(() -> manager.check(authentication, methodInvocation));
216216
}
217217

218-
@Test
219-
public void checkInheritedAnnotationsWhenConflictingThenAnnotationConfigurationException() throws Exception {
220-
Supplier<Authentication> authentication = () -> new TestingAuthenticationToken("user", "password", "ROLE_USER");
221-
MockMethodInvocation methodInvocation = new MockMethodInvocation(new ClassLevelAnnotations(),
222-
ClassLevelAnnotations.class, "inheritedAnnotations");
223-
Jsr250AuthorizationManager manager = new Jsr250AuthorizationManager();
224-
assertThatExceptionOfType(AnnotationConfigurationException.class)
225-
.isThrownBy(() -> manager.check(authentication, methodInvocation));
226-
}
227-
228218
@Test
229219
public void checkRequiresUserWhenMethodsFromInheritThenApplies() throws Exception {
230220
MockMethodInvocation methodInvocation = new MockMethodInvocation(new RolesAllowedClass(),

core/src/test/java/org/springframework/security/authorization/method/PostAuthorizeAuthorizationManagerTests.java

+10-13
Original file line numberDiff line numberDiff line change
@@ -145,22 +145,11 @@ public void checkRequiresUserWhenClassAnnotationsThenApplies() throws Exception
145145
assertThat(decision.isGranted()).isFalse();
146146
}
147147

148-
@Test
149-
public void checkInheritedAnnotationsWhenDuplicatedThenAnnotationConfigurationException() throws Exception {
150-
Supplier<Authentication> authentication = () -> new TestingAuthenticationToken("user", "password", "ROLE_USER");
151-
MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class,
152-
"inheritedAnnotations");
153-
MethodInvocationResult result = new MethodInvocationResult(methodInvocation, null);
154-
PostAuthorizeAuthorizationManager manager = new PostAuthorizeAuthorizationManager();
155-
assertThatExceptionOfType(AnnotationConfigurationException.class)
156-
.isThrownBy(() -> manager.check(authentication, result));
157-
}
158-
159148
@Test
160149
public void checkInheritedAnnotationsWhenConflictingThenAnnotationConfigurationException() throws Exception {
161150
Supplier<Authentication> authentication = () -> new TestingAuthenticationToken("user", "password", "ROLE_USER");
162-
MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class,
163-
"inheritedAnnotations");
151+
MockMethodInvocation methodInvocation = new MockMethodInvocation(new ConflictingAnnotations(),
152+
ConflictingAnnotations.class, "inheritedAnnotations");
164153
MethodInvocationResult result = new MethodInvocationResult(methodInvocation, null);
165154
PostAuthorizeAuthorizationManager manager = new PostAuthorizeAuthorizationManager();
166155
assertThatExceptionOfType(AnnotationConfigurationException.class)
@@ -233,6 +222,14 @@ public void inheritedAnnotations() {
233222

234223
}
235224

225+
public static class ConflictingAnnotations implements InterfaceAnnotationsOne, InterfaceAnnotationsTwo {
226+
227+
@Override
228+
public void inheritedAnnotations() {
229+
}
230+
231+
}
232+
236233
public interface InterfaceAnnotationsOne {
237234

238235
@PostAuthorize("hasRole('ADMIN')")

core/src/test/java/org/springframework/security/authorization/method/PostAuthorizeReactiveAuthorizationManagerTests.java

+10-14
Original file line numberDiff line numberDiff line change
@@ -149,24 +149,12 @@ public void checkRequiresUserWhenClassAnnotationsThenApplies() throws Exception
149149
assertThat(decision.isGranted()).isFalse();
150150
}
151151

152-
@Test
153-
public void checkInheritedAnnotationsWhenDuplicatedThenAnnotationConfigurationException() throws Exception {
154-
Mono<Authentication> authentication = Mono
155-
.just(new TestingAuthenticationToken("user", "password", "ROLE_USER"));
156-
MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class,
157-
"inheritedAnnotations");
158-
MethodInvocationResult result = new MethodInvocationResult(methodInvocation, null);
159-
PostAuthorizeReactiveAuthorizationManager manager = new PostAuthorizeReactiveAuthorizationManager();
160-
assertThatExceptionOfType(AnnotationConfigurationException.class)
161-
.isThrownBy(() -> manager.check(authentication, result));
162-
}
163-
164152
@Test
165153
public void checkInheritedAnnotationsWhenConflictingThenAnnotationConfigurationException() throws Exception {
166154
Mono<Authentication> authentication = Mono
167155
.just(new TestingAuthenticationToken("user", "password", "ROLE_USER"));
168-
MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class,
169-
"inheritedAnnotations");
156+
MockMethodInvocation methodInvocation = new MockMethodInvocation(new ConflictingAnnotations(),
157+
ConflictingAnnotations.class, "inheritedAnnotations");
170158
MethodInvocationResult result = new MethodInvocationResult(methodInvocation, null);
171159
PostAuthorizeReactiveAuthorizationManager manager = new PostAuthorizeReactiveAuthorizationManager();
172160
assertThatExceptionOfType(AnnotationConfigurationException.class)
@@ -216,6 +204,14 @@ public void inheritedAnnotations() {
216204

217205
}
218206

207+
public static class ConflictingAnnotations implements InterfaceAnnotationsOne, InterfaceAnnotationsTwo {
208+
209+
@Override
210+
public void inheritedAnnotations() {
211+
}
212+
213+
}
214+
219215
public interface InterfaceAnnotationsOne {
220216

221217
@PostAuthorize("hasRole('ADMIN')")

core/src/test/java/org/springframework/security/authorization/method/PostFilterAuthorizationMethodInterceptorTests.java

+10-11
Original file line numberDiff line numberDiff line change
@@ -109,19 +109,10 @@ public Object proceed() {
109109
assertThat(result).asInstanceOf(InstanceOfAssertFactories.array(String[].class)).containsOnly("john");
110110
}
111111

112-
@Test
113-
public void checkInheritedAnnotationsWhenDuplicatedThenAnnotationConfigurationException() throws Exception {
114-
MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class,
115-
"inheritedAnnotations");
116-
PostFilterAuthorizationMethodInterceptor advice = new PostFilterAuthorizationMethodInterceptor();
117-
assertThatExceptionOfType(AnnotationConfigurationException.class)
118-
.isThrownBy(() -> advice.invoke(methodInvocation));
119-
}
120-
121112
@Test
122113
public void checkInheritedAnnotationsWhenConflictingThenAnnotationConfigurationException() throws Exception {
123-
MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class,
124-
"inheritedAnnotations");
114+
MockMethodInvocation methodInvocation = new MockMethodInvocation(new ConflictingAnnotations(),
115+
ConflictingAnnotations.class, "inheritedAnnotations");
125116
PostFilterAuthorizationMethodInterceptor advice = new PostFilterAuthorizationMethodInterceptor();
126117
assertThatExceptionOfType(AnnotationConfigurationException.class)
127118
.isThrownBy(() -> advice.invoke(methodInvocation));
@@ -230,6 +221,14 @@ public void doSomething() {
230221

231222
}
232223

224+
public static class ConflictingAnnotations implements InterfaceAnnotationsOne, InterfaceAnnotationsTwo {
225+
226+
@Override
227+
public void inheritedAnnotations() {
228+
}
229+
230+
}
231+
233232
public interface InterfaceAnnotationsOne {
234233

235234
@PostFilter("filterObject == 'jim'")

core/src/test/java/org/springframework/security/authorization/method/PostFilterAuthorizationReactiveMethodInterceptorTests.java

+10-11
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,10 @@ public Object proceed() {
105105
.containsOnly("john");
106106
}
107107

108-
@Test
109-
public void checkInheritedAnnotationsWhenDuplicatedThenAnnotationConfigurationException() throws Exception {
110-
MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class,
111-
"inheritedAnnotations");
112-
PostFilterAuthorizationReactiveMethodInterceptor interceptor = new PostFilterAuthorizationReactiveMethodInterceptor();
113-
assertThatExceptionOfType(AnnotationConfigurationException.class)
114-
.isThrownBy(() -> interceptor.invoke(methodInvocation));
115-
}
116-
117108
@Test
118109
public void checkInheritedAnnotationsWhenConflictingThenAnnotationConfigurationException() throws Exception {
119-
MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class,
120-
"inheritedAnnotations");
110+
MockMethodInvocation methodInvocation = new MockMethodInvocation(new ConflictingAnnotations(),
111+
ConflictingAnnotations.class, "inheritedAnnotations");
121112
PostFilterAuthorizationReactiveMethodInterceptor interceptor = new PostFilterAuthorizationReactiveMethodInterceptor();
122113
assertThatExceptionOfType(AnnotationConfigurationException.class)
123114
.isThrownBy(() -> interceptor.invoke(methodInvocation));
@@ -155,6 +146,14 @@ public void doSomething() {
155146

156147
}
157148

149+
public static class ConflictingAnnotations implements InterfaceAnnotationsOne, InterfaceAnnotationsTwo {
150+
151+
@Override
152+
public void inheritedAnnotations() {
153+
}
154+
155+
}
156+
158157
public interface InterfaceAnnotationsOne {
159158

160159
@PostFilter("filterObject == 'jim'")

core/src/test/java/org/springframework/security/authorization/method/PreAuthorizeAuthorizationManagerTests.java

+10-12
Original file line numberDiff line numberDiff line change
@@ -114,21 +114,11 @@ public void checkRequiresUserWhenClassAnnotationsThenApplies() throws Exception
114114
assertThat(decision.isGranted()).isFalse();
115115
}
116116

117-
@Test
118-
public void checkInheritedAnnotationsWhenDuplicatedThenAnnotationConfigurationException() throws Exception {
119-
Supplier<Authentication> authentication = () -> new TestingAuthenticationToken("user", "password", "ROLE_USER");
120-
MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class,
121-
"inheritedAnnotations");
122-
PreAuthorizeAuthorizationManager manager = new PreAuthorizeAuthorizationManager();
123-
assertThatExceptionOfType(AnnotationConfigurationException.class)
124-
.isThrownBy(() -> manager.check(authentication, methodInvocation));
125-
}
126-
127117
@Test
128118
public void checkInheritedAnnotationsWhenConflictingThenAnnotationConfigurationException() throws Exception {
129119
Supplier<Authentication> authentication = () -> new TestingAuthenticationToken("user", "password", "ROLE_USER");
130-
MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class,
131-
"inheritedAnnotations");
120+
MockMethodInvocation methodInvocation = new MockMethodInvocation(new ConflictingAnnotations(),
121+
ConflictingAnnotations.class, "inheritedAnnotations");
132122
PreAuthorizeAuthorizationManager manager = new PreAuthorizeAuthorizationManager();
133123
assertThatExceptionOfType(AnnotationConfigurationException.class)
134124
.isThrownBy(() -> manager.check(authentication, methodInvocation));
@@ -207,6 +197,14 @@ public void inheritedAnnotations() {
207197

208198
}
209199

200+
public static class ConflictingAnnotations implements InterfaceAnnotationsOne, InterfaceAnnotationsTwo {
201+
202+
@Override
203+
public void inheritedAnnotations() {
204+
}
205+
206+
}
207+
210208
public interface InterfaceAnnotationsOne {
211209

212210
@PreAuthorize("hasRole('ADMIN')")

core/src/test/java/org/springframework/security/authorization/method/PreAuthorizeReactiveAuthorizationManagerTests.java

+10-13
Original file line numberDiff line numberDiff line change
@@ -123,23 +123,12 @@ public void checkRequiresUserWhenClassAnnotationsThenApplies() throws Exception
123123
assertThat(decision.isGranted()).isFalse();
124124
}
125125

126-
@Test
127-
public void checkInheritedAnnotationsWhenDuplicatedThenAnnotationConfigurationException() throws Exception {
128-
Mono<Authentication> authentication = Mono
129-
.just(new TestingAuthenticationToken("user", "password", "ROLE_USER"));
130-
MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class,
131-
"inheritedAnnotations");
132-
PreAuthorizeReactiveAuthorizationManager manager = new PreAuthorizeReactiveAuthorizationManager();
133-
assertThatExceptionOfType(AnnotationConfigurationException.class)
134-
.isThrownBy(() -> manager.check(authentication, methodInvocation));
135-
}
136-
137126
@Test
138127
public void checkInheritedAnnotationsWhenConflictingThenAnnotationConfigurationException() throws Exception {
139128
Mono<Authentication> authentication = Mono
140129
.just(new TestingAuthenticationToken("user", "password", "ROLE_USER"));
141-
MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class,
142-
"inheritedAnnotations");
130+
MockMethodInvocation methodInvocation = new MockMethodInvocation(new ConflictingAnnotations(),
131+
ConflictingAnnotations.class, "inheritedAnnotations");
143132
PreAuthorizeReactiveAuthorizationManager manager = new PreAuthorizeReactiveAuthorizationManager();
144133
assertThatExceptionOfType(AnnotationConfigurationException.class)
145134
.isThrownBy(() -> manager.check(authentication, methodInvocation));
@@ -183,6 +172,14 @@ public void inheritedAnnotations() {
183172

184173
}
185174

175+
public static class ConflictingAnnotations implements InterfaceAnnotationsOne, InterfaceAnnotationsTwo {
176+
177+
@Override
178+
public void inheritedAnnotations() {
179+
}
180+
181+
}
182+
186183
public interface InterfaceAnnotationsOne {
187184

188185
@PreAuthorize("hasRole('ADMIN')")

core/src/test/java/org/springframework/security/authorization/method/PreFilterAuthorizationMethodInterceptorTests.java

+10-11
Original file line numberDiff line numberDiff line change
@@ -169,19 +169,10 @@ public void findFilterTargetWhenNameNotProvidedAndNotSingleArgThenException() th
169169
.withMessage("Unable to determine the method argument for filtering. Specify the filter target.");
170170
}
171171

172-
@Test
173-
public void checkInheritedAnnotationsWhenDuplicatedThenAnnotationConfigurationException() throws Exception {
174-
MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class,
175-
"inheritedAnnotations");
176-
PreFilterAuthorizationMethodInterceptor advice = new PreFilterAuthorizationMethodInterceptor();
177-
assertThatExceptionOfType(AnnotationConfigurationException.class)
178-
.isThrownBy(() -> advice.invoke(methodInvocation));
179-
}
180-
181172
@Test
182173
public void checkInheritedAnnotationsWhenConflictingThenAnnotationConfigurationException() throws Exception {
183-
MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class,
184-
"inheritedAnnotations");
174+
MockMethodInvocation methodInvocation = new MockMethodInvocation(new ConflictingAnnotations(),
175+
ConflictingAnnotations.class, "inheritedAnnotations");
185176
PreFilterAuthorizationMethodInterceptor advice = new PreFilterAuthorizationMethodInterceptor();
186177
assertThatExceptionOfType(AnnotationConfigurationException.class)
187178
.isThrownBy(() -> advice.invoke(methodInvocation));
@@ -297,6 +288,14 @@ public void doSomething() {
297288

298289
}
299290

291+
public static class ConflictingAnnotations implements InterfaceAnnotationsOne, InterfaceAnnotationsTwo {
292+
293+
@Override
294+
public void inheritedAnnotations() {
295+
}
296+
297+
}
298+
300299
public interface InterfaceAnnotationsOne {
301300

302301
@PreFilter("filterObject == 'jim'")

core/src/test/java/org/springframework/security/authorization/method/PreFilterAuthorizationReactiveMethodInterceptorTests.java

+10-11
Original file line numberDiff line numberDiff line change
@@ -140,19 +140,10 @@ public Object proceed() {
140140
.containsOnly("john");
141141
}
142142

143-
@Test
144-
public void checkInheritedAnnotationsWhenDuplicatedThenAnnotationConfigurationException() throws Exception {
145-
MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class,
146-
"inheritedAnnotations");
147-
PreFilterAuthorizationReactiveMethodInterceptor interceptor = new PreFilterAuthorizationReactiveMethodInterceptor();
148-
assertThatExceptionOfType(AnnotationConfigurationException.class)
149-
.isThrownBy(() -> interceptor.invoke(methodInvocation));
150-
}
151-
152143
@Test
153144
public void checkInheritedAnnotationsWhenConflictingThenAnnotationConfigurationException() throws Exception {
154-
MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class,
155-
"inheritedAnnotations");
145+
MockMethodInvocation methodInvocation = new MockMethodInvocation(new ConflictingAnnotations(),
146+
ConflictingAnnotations.class, "inheritedAnnotations");
156147
PreFilterAuthorizationReactiveMethodInterceptor interceptor = new PreFilterAuthorizationReactiveMethodInterceptor();
157148
assertThatExceptionOfType(AnnotationConfigurationException.class)
158149
.isThrownBy(() -> interceptor.invoke(methodInvocation));
@@ -200,6 +191,14 @@ public void doSomething() {
200191

201192
}
202193

194+
public static class ConflictingAnnotations implements InterfaceAnnotationsOne, InterfaceAnnotationsTwo {
195+
196+
@Override
197+
public void inheritedAnnotations() {
198+
}
199+
200+
}
201+
203202
public interface InterfaceAnnotationsOne {
204203

205204
@PreFilter("filterObject == 'jim'")

0 commit comments

Comments
 (0)