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