Polish
This commit is contained in:
parent
84438183e1
commit
4a1bea1fed
|
@ -78,7 +78,7 @@ public class SecurityAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWebConfiguration() {
|
public void testWebConfiguration() {
|
||||||
this.contextRunner.run(context -> {
|
this.contextRunner.run((context) -> {
|
||||||
assertThat(context.getBean(AuthenticationManagerBuilder.class)).isNotNull();
|
assertThat(context.getBean(AuthenticationManagerBuilder.class)).isNotNull();
|
||||||
assertThat(context.getBean(FilterChainProxy.class).getFilterChains())
|
assertThat(context.getBean(FilterChainProxy.class).getFilterChains())
|
||||||
.hasSize(1);
|
.hasSize(1);
|
||||||
|
@ -89,7 +89,7 @@ public class SecurityAutoConfigurationTests {
|
||||||
public void testDefaultFilterOrderWithSecurityAdapter() {
|
public void testDefaultFilterOrderWithSecurityAdapter() {
|
||||||
this.contextRunner.withConfiguration(AutoConfigurations.of(WebSecurity.class,
|
this.contextRunner.withConfiguration(AutoConfigurations.of(WebSecurity.class,
|
||||||
SecurityFilterAutoConfiguration.class)).run(
|
SecurityFilterAutoConfiguration.class)).run(
|
||||||
context -> assertThat(context
|
(context) -> assertThat(context
|
||||||
.getBean("securityFilterChainRegistration",
|
.getBean("securityFilterChainRegistration",
|
||||||
DelegatingFilterProxyRegistrationBean.class)
|
DelegatingFilterProxyRegistrationBean.class)
|
||||||
.getOrder()).isEqualTo(
|
.getOrder()).isEqualTo(
|
||||||
|
@ -111,36 +111,30 @@ public class SecurityAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultAuthenticationEventPublisherRegistered() {
|
public void defaultAuthenticationEventPublisherRegistered() {
|
||||||
this.contextRunner.run(context -> {
|
this.contextRunner.run((context) -> assertThat(
|
||||||
assertThat(context.getBean(AuthenticationEventPublisher.class))
|
context.getBean(AuthenticationEventPublisher.class))
|
||||||
.isInstanceOf(DefaultAuthenticationEventPublisher.class);
|
.isInstanceOf(DefaultAuthenticationEventPublisher.class));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultAuthenticationEventPublisherIsConditionalOnMissingBean() {
|
public void defaultAuthenticationEventPublisherIsConditionalOnMissingBean() {
|
||||||
this.contextRunner
|
this.contextRunner
|
||||||
.withUserConfiguration(AuthenticationEventPublisherConfiguration.class)
|
.withUserConfiguration(AuthenticationEventPublisherConfiguration.class)
|
||||||
.run(context -> {
|
.run((context) -> assertThat(
|
||||||
assertThat(context.getBean(AuthenticationEventPublisher.class))
|
context.getBean(AuthenticationEventPublisher.class)).isInstanceOf(
|
||||||
.isInstanceOf(
|
AuthenticationEventPublisherConfiguration.TestAuthenticationEventPublisher.class));
|
||||||
AuthenticationEventPublisherConfiguration.TestAuthenticationEventPublisher.class);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDefaultFilterOrder() {
|
public void testDefaultFilterOrder() {
|
||||||
this.contextRunner
|
this.contextRunner.withConfiguration(
|
||||||
.withConfiguration(
|
AutoConfigurations.of(SecurityFilterAutoConfiguration.class)).run(
|
||||||
AutoConfigurations.of(SecurityFilterAutoConfiguration.class))
|
(context) -> assertThat(context
|
||||||
.run(context -> {
|
|
||||||
assertThat(context
|
|
||||||
.getBean("securityFilterChainRegistration",
|
.getBean("securityFilterChainRegistration",
|
||||||
DelegatingFilterProxyRegistrationBean.class)
|
DelegatingFilterProxyRegistrationBean.class)
|
||||||
.getOrder()).isEqualTo(
|
.getOrder()).isEqualTo(
|
||||||
FilterRegistrationBean.REQUEST_WRAPPER_FILTER_MAX_ORDER
|
FilterRegistrationBean.REQUEST_WRAPPER_FILTER_MAX_ORDER
|
||||||
- 100);
|
- 100));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -148,17 +142,16 @@ public class SecurityAutoConfigurationTests {
|
||||||
this.contextRunner
|
this.contextRunner
|
||||||
.withConfiguration(
|
.withConfiguration(
|
||||||
AutoConfigurations.of(SecurityFilterAutoConfiguration.class))
|
AutoConfigurations.of(SecurityFilterAutoConfiguration.class))
|
||||||
.withPropertyValues("spring.security.filter.order:12345").run(context -> {
|
.withPropertyValues("spring.security.filter.order:12345").run(
|
||||||
assertThat(context
|
(context) -> assertThat(context
|
||||||
.getBean("securityFilterChainRegistration",
|
.getBean("securityFilterChainRegistration",
|
||||||
DelegatingFilterProxyRegistrationBean.class)
|
DelegatingFilterProxyRegistrationBean.class)
|
||||||
.getOrder()).isEqualTo(12345);
|
.getOrder()).isEqualTo(12345));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDefaultUsernamePassword() {
|
public void testDefaultUsernamePassword() {
|
||||||
this.contextRunner.run(context -> {
|
this.contextRunner.run((context) -> {
|
||||||
UserDetailsService manager = context.getBean(UserDetailsService.class);
|
UserDetailsService manager = context.getBean(UserDetailsService.class);
|
||||||
assertThat(this.outputCapture.toString())
|
assertThat(this.outputCapture.toString())
|
||||||
.contains("Using generated security password:");
|
.contains("Using generated security password:");
|
||||||
|
@ -170,7 +163,7 @@ public class SecurityAutoConfigurationTests {
|
||||||
public void defaultUserNotCreatedIfAuthenticationManagerBeanPresent() {
|
public void defaultUserNotCreatedIfAuthenticationManagerBeanPresent() {
|
||||||
this.contextRunner
|
this.contextRunner
|
||||||
.withUserConfiguration(TestAuthenticationManagerConfiguration.class)
|
.withUserConfiguration(TestAuthenticationManagerConfiguration.class)
|
||||||
.run(context -> {
|
.run((context) -> {
|
||||||
AuthenticationManager manager = context
|
AuthenticationManager manager = context
|
||||||
.getBean(AuthenticationManager.class);
|
.getBean(AuthenticationManager.class);
|
||||||
assertThat(manager).isEqualTo(context.getBean(
|
assertThat(manager).isEqualTo(context.getBean(
|
||||||
|
@ -187,7 +180,7 @@ public class SecurityAutoConfigurationTests {
|
||||||
public void defaultUserNotCreatedIfUserDetailsServiceBeanPresent() {
|
public void defaultUserNotCreatedIfUserDetailsServiceBeanPresent() {
|
||||||
this.contextRunner
|
this.contextRunner
|
||||||
.withUserConfiguration(TestUserDetailsServiceConfiguration.class)
|
.withUserConfiguration(TestUserDetailsServiceConfiguration.class)
|
||||||
.run(context -> {
|
.run((context) -> {
|
||||||
UserDetailsService userDetailsService = context
|
UserDetailsService userDetailsService = context
|
||||||
.getBean(UserDetailsService.class);
|
.getBean(UserDetailsService.class);
|
||||||
assertThat(this.outputCapture.toString())
|
assertThat(this.outputCapture.toString())
|
||||||
|
@ -200,7 +193,7 @@ public class SecurityAutoConfigurationTests {
|
||||||
public void defaultUserNotCreatedIfAuthenticationProviderBeanPresent() {
|
public void defaultUserNotCreatedIfAuthenticationProviderBeanPresent() {
|
||||||
this.contextRunner
|
this.contextRunner
|
||||||
.withUserConfiguration(TestAuthenticationProviderConfiguration.class)
|
.withUserConfiguration(TestAuthenticationProviderConfiguration.class)
|
||||||
.run(context -> {
|
.run((context) -> {
|
||||||
AuthenticationProvider provider = context
|
AuthenticationProvider provider = context
|
||||||
.getBean(AuthenticationProvider.class);
|
.getBean(AuthenticationProvider.class);
|
||||||
assertThat(this.outputCapture.toString())
|
assertThat(this.outputCapture.toString())
|
||||||
|
@ -220,7 +213,7 @@ public class SecurityAutoConfigurationTests {
|
||||||
.withConfiguration(
|
.withConfiguration(
|
||||||
AutoConfigurations.of(HibernateJpaAutoConfiguration.class,
|
AutoConfigurations.of(HibernateJpaAutoConfiguration.class,
|
||||||
DataSourceAutoConfiguration.class))
|
DataSourceAutoConfiguration.class))
|
||||||
.run(context -> assertThat(context.getBean(JpaTransactionManager.class))
|
.run((context) -> assertThat(context.getBean(JpaTransactionManager.class))
|
||||||
.isNotNull());
|
.isNotNull());
|
||||||
// This can fail if security @Conditionals force early instantiation of the
|
// This can fail if security @Conditionals force early instantiation of the
|
||||||
// HibernateJpaAutoConfiguration (e.g. the EntityManagerFactory is not found)
|
// HibernateJpaAutoConfiguration (e.g. the EntityManagerFactory is not found)
|
||||||
|
@ -228,7 +221,7 @@ public class SecurityAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSecurityEvaluationContextExtensionSupport() {
|
public void testSecurityEvaluationContextExtensionSupport() {
|
||||||
this.contextRunner.run(context -> assertThat(context)
|
this.contextRunner.run((context) -> assertThat(context)
|
||||||
.getBean(SecurityEvaluationContextExtension.class).isNotNull());
|
.getBean(SecurityEvaluationContextExtension.class).isNotNull());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,7 +230,7 @@ public class SecurityAutoConfigurationTests {
|
||||||
this.contextRunner
|
this.contextRunner
|
||||||
.withConfiguration(
|
.withConfiguration(
|
||||||
AutoConfigurations.of(SecurityFilterAutoConfiguration.class))
|
AutoConfigurations.of(SecurityFilterAutoConfiguration.class))
|
||||||
.run(context -> {
|
.run((context) -> {
|
||||||
DelegatingFilterProxyRegistrationBean bean = context.getBean(
|
DelegatingFilterProxyRegistrationBean bean = context.getBean(
|
||||||
"securityFilterChainRegistration",
|
"securityFilterChainRegistration",
|
||||||
DelegatingFilterProxyRegistrationBean.class);
|
DelegatingFilterProxyRegistrationBean.class);
|
||||||
|
@ -256,7 +249,7 @@ public class SecurityAutoConfigurationTests {
|
||||||
"spring.security.filter.dispatcher-types:INCLUDE,ERROR")
|
"spring.security.filter.dispatcher-types:INCLUDE,ERROR")
|
||||||
.withConfiguration(
|
.withConfiguration(
|
||||||
AutoConfigurations.of(SecurityFilterAutoConfiguration.class))
|
AutoConfigurations.of(SecurityFilterAutoConfiguration.class))
|
||||||
.run(context -> {
|
.run((context) -> {
|
||||||
DelegatingFilterProxyRegistrationBean bean = context.getBean(
|
DelegatingFilterProxyRegistrationBean bean = context.getBean(
|
||||||
"securityFilterChainRegistration",
|
"securityFilterChainRegistration",
|
||||||
DelegatingFilterProxyRegistrationBean.class);
|
DelegatingFilterProxyRegistrationBean.class);
|
||||||
|
|
|
@ -104,9 +104,8 @@ public class LambdaSafeTests {
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void callbackInvokeWhenLambdaMismatchShouldSwallowException() {
|
public void callbackInvokeWhenLambdaMismatchShouldSwallowException() {
|
||||||
GenericCallback<StringBuilder> callbackInstance = (s) -> {
|
GenericCallback<StringBuilder> callbackInstance = (s) -> fail(
|
||||||
fail("Should not get here");
|
"Should not get here");
|
||||||
};
|
|
||||||
String argument = "foo";
|
String argument = "foo";
|
||||||
LambdaSafe.callback(GenericCallback.class, callbackInstance, argument)
|
LambdaSafe.callback(GenericCallback.class, callbackInstance, argument)
|
||||||
.invoke((c) -> c.handle(argument));
|
.invoke((c) -> c.handle(argument));
|
||||||
|
@ -115,9 +114,8 @@ public class LambdaSafeTests {
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void callbackInvokeWhenLambdaMismatchOnDifferentArgumentShouldSwallowException() {
|
public void callbackInvokeWhenLambdaMismatchOnDifferentArgumentShouldSwallowException() {
|
||||||
GenericMultiArgCallback<StringBuilder> callbackInstance = (n, s, b) -> {
|
GenericMultiArgCallback<StringBuilder> callbackInstance = (n, s,
|
||||||
fail("Should not get here");
|
b) -> fail("Should not get here");
|
||||||
};
|
|
||||||
String argument = "foo";
|
String argument = "foo";
|
||||||
LambdaSafe.callback(GenericMultiArgCallback.class, callbackInstance, argument)
|
LambdaSafe.callback(GenericMultiArgCallback.class, callbackInstance, argument)
|
||||||
.invoke((c) -> c.handle(1, argument, false));
|
.invoke((c) -> c.handle(1, argument, false));
|
||||||
|
@ -262,9 +260,8 @@ public class LambdaSafeTests {
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void callbacksInvokeWhenLambdaMismatchShouldSwallowException() {
|
public void callbacksInvokeWhenLambdaMismatchShouldSwallowException() {
|
||||||
GenericCallback<StringBuilder> callbackInstance = (s) -> {
|
GenericCallback<StringBuilder> callbackInstance = (s) -> fail(
|
||||||
fail("Should not get here");
|
"Should not get here");
|
||||||
};
|
|
||||||
String argument = "foo";
|
String argument = "foo";
|
||||||
LambdaSafe.callbacks(GenericCallback.class,
|
LambdaSafe.callbacks(GenericCallback.class,
|
||||||
Collections.singleton(callbackInstance), argument)
|
Collections.singleton(callbackInstance), argument)
|
||||||
|
@ -274,9 +271,8 @@ public class LambdaSafeTests {
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void callbacksInvokeWhenLambdaMismatchOnDifferentArgumentShouldSwallowException() {
|
public void callbacksInvokeWhenLambdaMismatchOnDifferentArgumentShouldSwallowException() {
|
||||||
GenericMultiArgCallback<StringBuilder> callbackInstance = (n, s, b) -> {
|
GenericMultiArgCallback<StringBuilder> callbackInstance = (n, s,
|
||||||
fail("Should not get here");
|
b) -> fail("Should not get here");
|
||||||
};
|
|
||||||
String argument = "foo";
|
String argument = "foo";
|
||||||
LambdaSafe
|
LambdaSafe
|
||||||
.callbacks(GenericMultiArgCallback.class,
|
.callbacks(GenericMultiArgCallback.class,
|
||||||
|
@ -410,9 +406,8 @@ public class LambdaSafeTests {
|
||||||
public void callbackWithLoggerShouldUseLogger() {
|
public void callbackWithLoggerShouldUseLogger() {
|
||||||
Log logger = mock(Log.class);
|
Log logger = mock(Log.class);
|
||||||
given(logger.isDebugEnabled()).willReturn(true);
|
given(logger.isDebugEnabled()).willReturn(true);
|
||||||
GenericCallback<StringBuilder> callbackInstance = (s) -> {
|
GenericCallback<StringBuilder> callbackInstance = (s) -> fail(
|
||||||
fail("Should not get here");
|
"Should not get here");
|
||||||
};
|
|
||||||
String argument = "foo";
|
String argument = "foo";
|
||||||
LambdaSafe.callback(GenericCallback.class, callbackInstance, argument)
|
LambdaSafe.callback(GenericCallback.class, callbackInstance, argument)
|
||||||
.withLogger(logger).invoke((c) -> c.handle(argument));
|
.withLogger(logger).invoke((c) -> c.handle(argument));
|
||||||
|
|
|
@ -24,7 +24,6 @@ import org.junit.runner.RunWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.actuate.autoconfigure.security.reactive.EndpointRequest;
|
import org.springframework.boot.actuate.autoconfigure.security.reactive.EndpointRequest;
|
||||||
import org.springframework.boot.autoconfigure.security.reactive.PathRequest;
|
import org.springframework.boot.autoconfigure.security.reactive.PathRequest;
|
||||||
import org.springframework.boot.autoconfigure.security.reactive.StaticResourceRequest;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
@ -102,9 +101,9 @@ public class SampleSecureWebFluxCustomSecurityTests {
|
||||||
http.authorizeExchange().matchers(EndpointRequest.to("health", "info"))
|
http.authorizeExchange().matchers(EndpointRequest.to("health", "info"))
|
||||||
.permitAll().matchers(EndpointRequest.toAnyEndpoint())
|
.permitAll().matchers(EndpointRequest.toAnyEndpoint())
|
||||||
.hasRole("ACTUATOR")
|
.hasRole("ACTUATOR")
|
||||||
.matchers(PathRequest.toStaticResources().atCommonLocations()).permitAll()
|
.matchers(PathRequest.toStaticResources().atCommonLocations())
|
||||||
.pathMatchers("/login").permitAll().anyExchange().authenticated()
|
.permitAll().pathMatchers("/login").permitAll().anyExchange()
|
||||||
.and().httpBasic();
|
.authenticated().and().httpBasic();
|
||||||
return http.build();
|
return http.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue