|
|
|
@ -45,49 +45,41 @@ public class CorsTests extends BaseWebClientTests {
@@ -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") |
|
|
|
|
.exchange().block(); |
|
|
|
|
.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
|
|
|
|
|
// 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()); |
|
|
|
|
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()); |
|
|
|
|
} |
|
|
|
|
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 { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|