use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class DefaultCorsProcessorTests method preflightRequestTestWithOriginButWithoutOtherHeaders.
@Test
public void preflightRequestTestWithOriginButWithoutOtherHeaders() throws Exception {
ServerWebExchange exchange = preFlightRequest().toExchange();
this.processor.processRequest(this.conf, exchange);
ServerHttpResponse response = exchange.getResponse();
assertFalse(response.getHeaders().containsKey(ACCESS_CONTROL_ALLOW_ORIGIN));
assertEquals(HttpStatus.FORBIDDEN, response.getStatusCode());
}
use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class DefaultCorsProcessorTests method preflightRequestCredentialsWithOriginWildcard.
@Test
public void preflightRequestCredentialsWithOriginWildcard() throws Exception {
ServerWebExchange exchange = preFlightRequest().header(ACCESS_CONTROL_REQUEST_METHOD, "GET").header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1").toExchange();
this.conf.addAllowedOrigin("http://domain1.com");
this.conf.addAllowedOrigin("*");
this.conf.addAllowedOrigin("http://domain3.com");
this.conf.addAllowedHeader("Header1");
this.conf.setAllowCredentials(true);
this.processor.processRequest(this.conf, exchange);
ServerHttpResponse response = exchange.getResponse();
assertTrue(response.getHeaders().containsKey(ACCESS_CONTROL_ALLOW_ORIGIN));
assertEquals("http://domain2.com", response.getHeaders().getFirst(ACCESS_CONTROL_ALLOW_ORIGIN));
assertNull(response.getStatusCode());
}
use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class DefaultCorsProcessorTests method actualRequestWithOriginHeader.
@Test
public void actualRequestWithOriginHeader() throws Exception {
ServerWebExchange exchange = actualRequest();
this.processor.processRequest(this.conf, exchange);
ServerHttpResponse response = exchange.getResponse();
assertFalse(response.getHeaders().containsKey(ACCESS_CONTROL_ALLOW_ORIGIN));
assertEquals(HttpStatus.FORBIDDEN, response.getStatusCode());
}
use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class DefaultCorsProcessorTests method preflightRequestMatchedAllowedMethod.
@Test
public void preflightRequestMatchedAllowedMethod() throws Exception {
ServerWebExchange exchange = preFlightRequest().header(ACCESS_CONTROL_REQUEST_METHOD, "GET").toExchange();
this.conf.addAllowedOrigin("*");
this.processor.processRequest(this.conf, exchange);
ServerHttpResponse response = exchange.getResponse();
assertNull(response.getStatusCode());
assertEquals("GET,HEAD", response.getHeaders().getFirst(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS));
}
use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class DefaultCorsProcessorTests method actualRequestWithOriginHeaderAndAllowedOrigin.
@Test
public void actualRequestWithOriginHeaderAndAllowedOrigin() throws Exception {
ServerWebExchange exchange = actualRequest();
this.conf.addAllowedOrigin("*");
this.processor.processRequest(this.conf, exchange);
ServerHttpResponse response = exchange.getResponse();
assertTrue(response.getHeaders().containsKey(ACCESS_CONTROL_ALLOW_ORIGIN));
assertEquals("*", response.getHeaders().getFirst(ACCESS_CONTROL_ALLOW_ORIGIN));
assertFalse(response.getHeaders().containsKey(HttpHeaders.ACCESS_CONTROL_MAX_AGE));
assertFalse(response.getHeaders().containsKey(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS));
assertNull(response.getStatusCode());
}
Aggregations