Disable Security for tests

This commit is contained in:
Spencer Gibb
2017-10-04 18:45:35 -04:00
parent e1e78c8c4a
commit a13939bfa2
5 changed files with 24 additions and 13 deletions

View File

@@ -138,6 +138,7 @@ public class GatewayAutoConfiguration {
}
@Bean
@ConditionalOnMissingBean
public PropertiesRouteDefinitionLocator propertiesRouteDefinitionLocator(GatewayProperties properties) {
return new PropertiesRouteDefinitionLocator(properties);
}

View File

@@ -24,7 +24,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
*/
@ConfigurationProperties("spring.cloud.gateway.filter.secure-headers")
public class SecureHeadersProperties {
public static final String X_XSS_PROTECTION_HEADER_DEFAULT = "1; mode=block";
public static final String X_XSS_PROTECTION_HEADER_DEFAULT = "1 ; mode=block";
public static final String STRICT_TRANSPORT_SECURITY_HEADER_DEFAULT = "max-age=631138519"; //; includeSubDomains preload")
public static final String X_FRAME_OPTIONS_HEADER_DEFAULT = "DENY"; //SAMEORIGIN = ALLOW-FROM
public static final String X_CONTENT_TYPE_OPTIONS_HEADER_DEFAULT = "nosniff";

View File

@@ -34,12 +34,11 @@ import org.springframework.cloud.netflix.ribbon.RibbonClients;
import org.springframework.cloud.netflix.ribbon.StaticServerList;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.annotation.Order;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.codec.multipart.Part;
import org.springframework.security.config.web.server.HttpSecurity;
import org.springframework.security.web.server.SecurityWebFilterChain;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -85,6 +84,7 @@ public class BaseWebClientTests {
@RibbonClient(name = "testservice", configuration = TestRibbonConfig.class),
@RibbonClient(name = "myservice", configuration = TestRibbonConfig.class)
})
@Import(PermitAllSecurityConfiguration.class)
protected static class DefaultTestConfig {
private static final Log log = LogFactory.getLog(DefaultTestConfig.class);
@@ -183,16 +183,6 @@ public class BaseWebClientTests {
return chain.filter(exchange);
};
}
@Bean
SecurityWebFilterChain springWebFilterChain(HttpSecurity http) throws Exception {
return http.authorizeExchange()
//.pathMatchers("/admin/**").hasRole("ADMIN")
.anyExchange().permitAll()
.and()
.build();
}
}
protected static class TestRibbonConfig {

View File

@@ -0,0 +1,17 @@
package org.springframework.cloud.gateway.test;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.web.server.HttpSecurity;
import org.springframework.security.web.server.SecurityWebFilterChain;
@Configuration
public class PermitAllSecurityConfiguration {
@Bean
SecurityWebFilterChain springWebFilterChain(HttpSecurity http) throws Exception {
return http.authorizeExchange()
.anyExchange().permitAll()
.and()
.build();
}
}

View File

@@ -37,11 +37,13 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.Routes;
import org.springframework.cloud.gateway.test.PermitAllSecurityConfiguration;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.Lifecycle;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.http.HttpHeaders;
import org.springframework.http.server.reactive.HttpHandler;
@@ -292,6 +294,7 @@ public class WebSocketIntegrationTests {
@Configuration
@EnableAutoConfiguration
@Import(PermitAllSecurityConfiguration.class)
protected static class GatewayConfig {
@Value("${ws.server.port}")