From 924b9e95a1a2c9d5bd05528d6986e29ee921c930 Mon Sep 17 00:00:00 2001 From: Eleftheria Stein Date: Fri, 3 Jan 2020 20:08:52 -0500 Subject: [PATCH] Polish MethodSecurityEvaluationContext Issue: gh-6224 --- ...activeMethodSecurityConfigurationTests.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/config/src/test/java/org/springframework/security/config/annotation/method/configuration/ReactiveMethodSecurityConfigurationTests.java b/config/src/test/java/org/springframework/security/config/annotation/method/configuration/ReactiveMethodSecurityConfigurationTests.java index 3a27f322e6..9df29cd18f 100644 --- a/config/src/test/java/org/springframework/security/config/annotation/method/configuration/ReactiveMethodSecurityConfigurationTests.java +++ b/config/src/test/java/org/springframework/security/config/annotation/method/configuration/ReactiveMethodSecurityConfigurationTests.java @@ -17,7 +17,6 @@ package org.springframework.security.config.annotation.method.configuration; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; import org.junit.Rule; import org.junit.Test; @@ -44,12 +43,12 @@ public class ReactiveMethodSecurityConfigurationTests { DefaultMethodSecurityExpressionHandler methodSecurityExpressionHandler; @Test - public void rolePrefixWithGrantedAuthorityDefaults() { + public void rolePrefixWithGrantedAuthorityDefaults() throws NoSuchMethodException { this.spring.register(WithRolePrefixConfiguration.class).autowire(); TestingAuthenticationToken authentication = new TestingAuthenticationToken( "principal", "credential", "CUSTOM_ABC"); - MockMethodInvocation methodInvocation = mock(MockMethodInvocation.class); + MockMethodInvocation methodInvocation = new MockMethodInvocation(new Foo(), Foo.class, "bar", String.class); EvaluationContext context = this.methodSecurityExpressionHandler .createEvaluationContext(authentication, methodInvocation); @@ -63,12 +62,12 @@ public class ReactiveMethodSecurityConfigurationTests { } @Test - public void rolePrefixWithDefaultConfig() { + public void rolePrefixWithDefaultConfig() throws NoSuchMethodException { this.spring.register(ReactiveMethodSecurityConfiguration.class).autowire(); TestingAuthenticationToken authentication = new TestingAuthenticationToken( "principal", "credential", "ROLE_ABC"); - MockMethodInvocation methodInvocation = mock(MockMethodInvocation.class); + MockMethodInvocation methodInvocation = new MockMethodInvocation(new Foo(), Foo.class, "bar", String.class); EvaluationContext context = this.methodSecurityExpressionHandler .createEvaluationContext(authentication, methodInvocation); @@ -89,12 +88,12 @@ public class ReactiveMethodSecurityConfigurationTests { } @Test - public void rolePrefixWithGrantedAuthorityDefaultsAndSubclassWithProxyingEnabled() { + public void rolePrefixWithGrantedAuthorityDefaultsAndSubclassWithProxyingEnabled() throws NoSuchMethodException { this.spring.register(SubclassConfig.class).autowire(); TestingAuthenticationToken authentication = new TestingAuthenticationToken( "principal", "credential", "ROLE_ABC"); - MockMethodInvocation methodInvocation = mock(MockMethodInvocation.class); + MockMethodInvocation methodInvocation = new MockMethodInvocation(new Foo(), Foo.class, "bar", String.class); EvaluationContext context = this.methodSecurityExpressionHandler .createEvaluationContext(authentication, methodInvocation); @@ -108,4 +107,9 @@ public class ReactiveMethodSecurityConfigurationTests { @Configuration static class SubclassConfig extends ReactiveMethodSecurityConfiguration { } + + private static class Foo { + public void bar(String param){ + } + } }