Polish
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -95,8 +95,8 @@ public class FlywayAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void createDataSource() throws Exception {
|
||||
TestPropertyValues.of("spring.flyway.url:jdbc:hsqldb:mem:flywaytest", "spring.flyway.user:sa")
|
||||
.applyTo(this.context);
|
||||
TestPropertyValues.of("spring.flyway.url:jdbc:hsqldb:mem:flywaytest",
|
||||
"spring.flyway.user:sa").applyTo(this.context);
|
||||
registerAndRefresh(EmbeddedDataSourceConfiguration.class,
|
||||
FlywayAutoConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
@@ -162,7 +162,8 @@ public class FlywayAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void changeLogDoesNotExist() throws Exception {
|
||||
TestPropertyValues.of("spring.flyway.locations:file:no-such-dir").applyTo(this.context);
|
||||
TestPropertyValues.of("spring.flyway.locations:file:no-such-dir")
|
||||
.applyTo(this.context);
|
||||
this.thrown.expect(BeanCreationException.class);
|
||||
registerAndRefresh(EmbeddedDataSourceConfiguration.class,
|
||||
FlywayAutoConfiguration.class,
|
||||
|
||||
@@ -318,7 +318,8 @@ public class DataSourceAutoConfigurationTests {
|
||||
@Override
|
||||
protected Class<?> loadClass(String name, boolean resolve)
|
||||
throws ClassNotFoundException {
|
||||
for (EmbeddedDatabaseConnection candidate : EmbeddedDatabaseConnection.values()) {
|
||||
for (EmbeddedDatabaseConnection candidate : EmbeddedDatabaseConnection
|
||||
.values()) {
|
||||
if (name.equals(candidate.getDriverClassName())) {
|
||||
throw new ClassNotFoundException();
|
||||
}
|
||||
@@ -328,5 +329,4 @@ public class DataSourceAutoConfigurationTests {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -160,7 +160,8 @@ public class LiquibaseAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void testOverrideDefaultSchema() throws Exception {
|
||||
TestPropertyValues.of("spring.liquibase.default-schema:public").applyTo(this.context);
|
||||
TestPropertyValues.of("spring.liquibase.default-schema:public")
|
||||
.applyTo(this.context);
|
||||
this.context.register(EmbeddedDataSourceConfiguration.class,
|
||||
LiquibaseAutoConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
@@ -182,9 +183,8 @@ public class LiquibaseAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void testOverrideDataSource() throws Exception {
|
||||
TestPropertyValues
|
||||
.of("spring.liquibase.url:jdbc:hsqldb:mem:liquibase", "spring.liquibase.user:sa")
|
||||
.applyTo(this.context);
|
||||
TestPropertyValues.of("spring.liquibase.url:jdbc:hsqldb:mem:liquibase",
|
||||
"spring.liquibase.user:sa").applyTo(this.context);
|
||||
this.context.register(EmbeddedDataSourceConfiguration.class,
|
||||
LiquibaseAutoConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
@@ -198,7 +198,8 @@ public class LiquibaseAutoConfigurationTests {
|
||||
|
||||
@Test(expected = BeanCreationException.class)
|
||||
public void testChangeLogDoesNotExist() throws Exception {
|
||||
TestPropertyValues.of("spring.liquibase.change-log:classpath:/no-such-changelog.yaml")
|
||||
TestPropertyValues
|
||||
.of("spring.liquibase.change-log:classpath:/no-such-changelog.yaml")
|
||||
.applyTo(this.context);
|
||||
this.context.register(EmbeddedDataSourceConfiguration.class,
|
||||
LiquibaseAutoConfiguration.class,
|
||||
@@ -220,7 +221,8 @@ public class LiquibaseAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void testOverrideLabels() throws Exception {
|
||||
TestPropertyValues.of("spring.liquibase.labels:test, production").applyTo(this.context);
|
||||
TestPropertyValues.of("spring.liquibase.labels:test, production")
|
||||
.applyTo(this.context);
|
||||
this.context.register(EmbeddedDataSourceConfiguration.class,
|
||||
LiquibaseAutoConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
@@ -232,7 +234,8 @@ public class LiquibaseAutoConfigurationTests {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testOverrideParameters() throws Exception {
|
||||
TestPropertyValues.of("spring.liquibase.parameters.foo:bar").applyTo(this.context);
|
||||
TestPropertyValues.of("spring.liquibase.parameters.foo:bar")
|
||||
.applyTo(this.context);
|
||||
this.context.register(EmbeddedDataSourceConfiguration.class,
|
||||
LiquibaseAutoConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
|
||||
@@ -298,8 +298,8 @@ public class SecurityAutoConfigurationTests {
|
||||
this.context.setServletContext(new MockServletContext());
|
||||
this.context.register(SecurityAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
String password = this.outputCapture.toString().split("Using default security password: ")[1]
|
||||
.split("\n")[0].trim();
|
||||
String password = this.outputCapture.toString()
|
||||
.split("Using default security password: ")[1].split("\n")[0].trim();
|
||||
AuthenticationManager manager = this.context.getBean(AuthenticationManager.class);
|
||||
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(
|
||||
"user", password);
|
||||
@@ -307,16 +307,17 @@ public class SecurityAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomAuthenticationDoesNotCreateDefaultUser()
|
||||
throws Exception {
|
||||
public void testCustomAuthenticationDoesNotCreateDefaultUser() throws Exception {
|
||||
this.context = new AnnotationConfigWebApplicationContext();
|
||||
this.context.setServletContext(new MockServletContext());
|
||||
this.context.register(AuthenticationManagerCustomizer.class,
|
||||
SecurityAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
AuthenticationManager manager = this.context.getBean(AuthenticationManager.class);
|
||||
assertThat(this.outputCapture.toString()).doesNotContain("Using default security password: ");
|
||||
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("foo", "bar");
|
||||
assertThat(this.outputCapture.toString())
|
||||
.doesNotContain("Using default security password: ");
|
||||
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(
|
||||
"foo", "bar");
|
||||
assertThat(manager.authenticate(token)).isNotNull();
|
||||
}
|
||||
|
||||
|
||||
@@ -61,13 +61,12 @@ public class SecurityFilterAutoConfigurationEarlyInitializationTests {
|
||||
@Test
|
||||
public void testSecurityFilterDoesNotCauseEarlyInitialization() throws Exception {
|
||||
try (AnnotationConfigServletWebServerApplicationContext context = new AnnotationConfigServletWebServerApplicationContext()) {
|
||||
TestPropertyValues.of("server.port:0")
|
||||
.applyTo(context);
|
||||
TestPropertyValues.of("server.port:0").applyTo(context);
|
||||
context.register(Config.class);
|
||||
context.refresh();
|
||||
int port = context.getWebServer().getPort();
|
||||
String password = this.outputCapture.toString().split("Using default security password: ")[1]
|
||||
.split("\n")[0].trim();
|
||||
String password = this.outputCapture.toString()
|
||||
.split("Using default security password: ")[1].split("\n")[0].trim();
|
||||
new TestRestTemplate("user", password)
|
||||
.getForEntity("http://localhost:" + port, Object.class);
|
||||
// If early initialization occurred a ConverterNotFoundException is thrown
|
||||
@@ -80,8 +79,8 @@ public class SecurityFilterAutoConfigurationEarlyInitializationTests {
|
||||
ConverterBean.class })
|
||||
@ImportAutoConfiguration({ WebMvcAutoConfiguration.class,
|
||||
JacksonAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class,
|
||||
DispatcherServletAutoConfiguration.class,
|
||||
SecurityAutoConfiguration.class, SecurityFilterAutoConfiguration.class,
|
||||
DispatcherServletAutoConfiguration.class, SecurityAutoConfiguration.class,
|
||||
SecurityFilterAutoConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class })
|
||||
static class Config {
|
||||
|
||||
|
||||
@@ -46,15 +46,16 @@ public class SpringBootSecurityTests {
|
||||
|
||||
private MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
|
||||
private static String[] STATIC_RESOURCES = new String[]{"/css/**", "/js/**",
|
||||
"/images/**", "/webjars/**", "/**/favicon.ico"};
|
||||
private static String[] STATIC_RESOURCES = new String[] { "/css/**", "/js/**",
|
||||
"/images/**", "/webjars/**", "/**/favicon.ico" };
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
this.bootSecurity = new SpringBootSecurity(this.endpointPathResolver, this.errorController);
|
||||
this.bootSecurity = new SpringBootSecurity(this.endpointPathResolver,
|
||||
this.errorController);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -65,7 +66,8 @@ public class SpringBootSecurityTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void endpointIdsShouldReturnRequestMatcherWithEndpointPaths() throws Exception {
|
||||
public void endpointIdsShouldReturnRequestMatcherWithEndpointPaths()
|
||||
throws Exception {
|
||||
RequestMatcher requestMatcher = this.bootSecurity.endpointIds("id-1", "id-2");
|
||||
assertThat(requestMatcher).isInstanceOf(OrRequestMatcher.class);
|
||||
this.request.setServletPath("/test/id-1");
|
||||
@@ -77,8 +79,10 @@ public class SpringBootSecurityTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void endpointIdsShouldReturnRequestMatcherWithAllEndpointPaths() throws Exception {
|
||||
RequestMatcher requestMatcher = this.bootSecurity.endpointIds(SpringBootSecurity.ALL_ENDPOINTS);
|
||||
public void endpointIdsShouldReturnRequestMatcherWithAllEndpointPaths()
|
||||
throws Exception {
|
||||
RequestMatcher requestMatcher = this.bootSecurity
|
||||
.endpointIds(SpringBootSecurity.ALL_ENDPOINTS);
|
||||
this.request.setServletPath("/test/id-1");
|
||||
assertThat(requestMatcher.matches(this.request)).isTrue();
|
||||
this.request.setServletPath("/test/id-2");
|
||||
@@ -112,7 +116,8 @@ public class SpringBootSecurityTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void staticResourcesShouldReturnRequestMatcherWithStaticResources() throws Exception {
|
||||
public void staticResourcesShouldReturnRequestMatcherWithStaticResources()
|
||||
throws Exception {
|
||||
RequestMatcher requestMatcher = this.bootSecurity.staticResources();
|
||||
assertThat(requestMatcher).isInstanceOf(OrRequestMatcher.class);
|
||||
for (String resource : STATIC_RESOURCES) {
|
||||
@@ -122,7 +127,8 @@ public class SpringBootSecurityTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void errorShouldReturnRequestMatcherWithErrorControllerPath() throws Exception {
|
||||
public void errorShouldReturnRequestMatcherWithErrorControllerPath()
|
||||
throws Exception {
|
||||
RequestMatcher requestMatcher = this.bootSecurity.error();
|
||||
assertThat(requestMatcher).isInstanceOf(AntPathRequestMatcher.class);
|
||||
this.request.setServletPath("/test/error");
|
||||
@@ -152,6 +158,7 @@ public class SpringBootSecurityTests {
|
||||
public String getErrorPath() {
|
||||
return "/test/error";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Endpoint(id = "id-1")
|
||||
@@ -167,4 +174,5 @@ public class SpringBootSecurityTests {
|
||||
static class FakeEndpoint {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.junit.rules.ExpectedException;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.autoconfigure.security.SecurityProperties;
|
||||
import org.springframework.boot.autoconfigure.web.servlet.MockServletWebServerFactory;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
@@ -77,8 +78,7 @@ public class OAuth2RestOperationsConfigurationTests {
|
||||
TestPropertyValues.of("security.oauth2.client.client-id=acme")
|
||||
.applyTo(this.environment);
|
||||
initializeContext(ConfigForRequestScopedConfiguration.class, false);
|
||||
assertThat(this.context.containsBean("oauth2ClientContext"))
|
||||
.isTrue();
|
||||
assertThat(this.context.containsBean("oauth2ClientContext")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -93,8 +93,7 @@ public class OAuth2RestOperationsConfigurationTests {
|
||||
TestPropertyValues.of("security.oauth2.client.client-id=acme")
|
||||
.applyTo(this.environment);
|
||||
initializeContext(ConfigForSessionScopedConfiguration.class, false);
|
||||
assertThat(this.context.containsBean("oauth2ClientContext"))
|
||||
.isTrue();
|
||||
assertThat(this.context.containsBean("oauth2ClientContext")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -104,10 +103,11 @@ public class OAuth2RestOperationsConfigurationTests {
|
||||
this.context.getBean(DefaultOAuth2ClientContext.class);
|
||||
}
|
||||
|
||||
private void initializeContext(Class<?> configuration, boolean isClientCredentials) {
|
||||
private void initializeContext(Class<?> configuration, boolean clientCredentials) {
|
||||
this.context = new SpringApplicationBuilder(configuration)
|
||||
.environment(this.environment)
|
||||
.web(!isClientCredentials).run();
|
||||
.environment(this.environment).web(clientCredentials
|
||||
? WebApplicationType.NONE : WebApplicationType.SERVLET)
|
||||
.run();
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@@ -123,7 +123,8 @@ public class OAuth2RestOperationsConfigurationTests {
|
||||
|
||||
@Configuration
|
||||
@Import({ OAuth2ClientConfiguration.class, OAuth2RestOperationsConfiguration.class })
|
||||
protected static class ConfigForSessionScopedConfiguration extends WebApplicationConfiguration {
|
||||
protected static class ConfigForSessionScopedConfiguration
|
||||
extends WebApplicationConfiguration {
|
||||
|
||||
@Bean
|
||||
public SecurityProperties securityProperties() {
|
||||
@@ -133,7 +134,8 @@ public class OAuth2RestOperationsConfigurationTests {
|
||||
}
|
||||
|
||||
@Configuration
|
||||
protected static class ConfigForRequestScopedConfiguration extends WebApplicationConfiguration {
|
||||
protected static class ConfigForRequestScopedConfiguration
|
||||
extends WebApplicationConfiguration {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
Reference in New Issue
Block a user