Update formatting
This commit is contained in:
@@ -25,16 +25,16 @@ import org.springframework.cloud.gateway.handler.RoutePredicateHandlerMapping;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
|
||||
/**
|
||||
* Configuration properties for global configuration of cors. See {@link RoutePredicateHandlerMapping}
|
||||
* Configuration properties for global configuration of cors. See
|
||||
* {@link RoutePredicateHandlerMapping}
|
||||
*/
|
||||
@ConfigurationProperties("spring.cloud.gateway.globalcors")
|
||||
public class GlobalCorsProperties {
|
||||
|
||||
private final Map<String, CorsConfiguration> corsConfigurations = new LinkedHashMap<>();
|
||||
|
||||
public Map<String, CorsConfiguration> getCorsConfigurations()
|
||||
{
|
||||
return corsConfigurations;
|
||||
}
|
||||
private final Map<String, CorsConfiguration> corsConfigurations = new LinkedHashMap<>();
|
||||
|
||||
public Map<String, CorsConfiguration> getCorsConfigurations() {
|
||||
return corsConfigurations;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -45,49 +45,41 @@ public class CorsTests extends BaseWebClientTests {
|
||||
@Test
|
||||
public void testPreFlightCorsRequest() {
|
||||
ClientResponse clientResponse = webClient.options().uri("/abc/123/function")
|
||||
.header("Origin", "domain.com")
|
||||
.header("Access-Control-Request-Method", "GET")
|
||||
.header("Origin", "domain.com")
|
||||
.header("Access-Control-Request-Method", "GET").exchange().block();
|
||||
HttpHeaders asHttpHeaders = clientResponse.headers().asHttpHeaders();
|
||||
Mono<String> bodyToMono = clientResponse.bodyToMono(String.class);
|
||||
// pre-flight request shouldn't return the response body
|
||||
assertNull(bodyToMono.block());
|
||||
assertEquals(
|
||||
"Missing header value in response: "
|
||||
+ HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN,
|
||||
"*", asHttpHeaders.getAccessControlAllowOrigin());
|
||||
assertEquals("Pre Flight call failed.", HttpStatus.OK,
|
||||
clientResponse.statusCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCorsRequest() {
|
||||
ClientResponse clientResponse = webClient.get().uri("/abc/123/function")
|
||||
.header("Origin", "domain.com").header(HttpHeaders.HOST, "www.path.org")
|
||||
.exchange().block();
|
||||
HttpHeaders asHttpHeaders = clientResponse.headers().asHttpHeaders();
|
||||
Mono<String> bodyToMono = clientResponse.bodyToMono(String.class);
|
||||
//pre-flight request shouldn't return the response body
|
||||
assertNull(bodyToMono.block());
|
||||
assertEquals("Missing header value in response: "+HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN,"*", asHttpHeaders.getAccessControlAllowOrigin());
|
||||
assertEquals("Pre Flight call failed.", HttpStatus.OK, clientResponse.statusCode());
|
||||
assertNotNull(bodyToMono.block());
|
||||
assertEquals(
|
||||
"Missing header value in response: "
|
||||
+ HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN,
|
||||
"*", asHttpHeaders.getAccessControlAllowOrigin());
|
||||
assertEquals("Pre Flight call failed.", HttpStatus.OK,
|
||||
clientResponse.statusCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCorsRequest() {
|
||||
ClientResponse clientResponse = webClient.get().uri("/abc/123/function")
|
||||
.header("Origin", "domain.com")
|
||||
.header(HttpHeaders.HOST, "www.path.org")
|
||||
.exchange().block();
|
||||
HttpHeaders asHttpHeaders = clientResponse.headers().asHttpHeaders();
|
||||
Mono<String> bodyToMono = clientResponse.bodyToMono(String.class);
|
||||
assertNotNull(bodyToMono.block());
|
||||
assertEquals("Missing header value in response: "+HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN,"*", asHttpHeaders.getAccessControlAllowOrigin());
|
||||
assertEquals("Pre Flight call failed.", HttpStatus.OK, clientResponse.statusCode());
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
@SpringBootConfiguration
|
||||
@Import(DefaultTestConfig.class)
|
||||
public static class TestConfig {
|
||||
|
||||
// this enables the access-control-allow-origin header from the target MS
|
||||
// @Bean
|
||||
// public WebFluxConfigurer corsConfigurer() {
|
||||
// return new WebFluxConfigurerComposite() {
|
||||
//
|
||||
// @Override
|
||||
// public void addCorsMappings(CorsRegistry registry) {
|
||||
// registry.addMapping("/**")
|
||||
// .allowedOrigins("*")
|
||||
// .allowedMethods("*");
|
||||
// }
|
||||
// };
|
||||
// }
|
||||
|
||||
public static class TestConfig {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user