Search in sources :

Example 76 with ServerWebExchange

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());
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) ServerHttpResponse(org.springframework.http.server.reactive.ServerHttpResponse) Test(org.junit.Test)

Example 77 with ServerWebExchange

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());
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) ServerHttpResponse(org.springframework.http.server.reactive.ServerHttpResponse) Test(org.junit.Test)

Example 78 with ServerWebExchange

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());
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) ServerHttpResponse(org.springframework.http.server.reactive.ServerHttpResponse) Test(org.junit.Test)

Example 79 with ServerWebExchange

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));
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) ServerHttpResponse(org.springframework.http.server.reactive.ServerHttpResponse) Test(org.junit.Test)

Example 80 with ServerWebExchange

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());
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) ServerHttpResponse(org.springframework.http.server.reactive.ServerHttpResponse) Test(org.junit.Test)

Aggregations

ServerWebExchange (org.springframework.web.server.ServerWebExchange)158 Test (org.junit.Test)138 MockServerWebExchange (org.springframework.mock.http.server.reactive.test.MockServerWebExchange)53 Mono (reactor.core.publisher.Mono)22 ServerHttpResponse (org.springframework.http.server.reactive.ServerHttpResponse)20 MediaType (org.springframework.http.MediaType)18 BindingContext (org.springframework.web.reactive.BindingContext)17 MethodParameter (org.springframework.core.MethodParameter)15 List (java.util.List)14 ResolvableType (org.springframework.core.ResolvableType)14 Map (java.util.Map)12 Collections (java.util.Collections)11 HttpStatus (org.springframework.http.HttpStatus)11 StepVerifier (reactor.test.StepVerifier)11 Assert.assertEquals (org.junit.Assert.assertEquals)10 MockServerHttpRequest (org.springframework.mock.http.server.reactive.test.MockServerHttpRequest)10 ResponseStatusException (org.springframework.web.server.ResponseStatusException)9 ServerWebInputException (org.springframework.web.server.ServerWebInputException)9 ReactiveAdapterRegistry (org.springframework.core.ReactiveAdapterRegistry)8 NotAcceptableStatusException (org.springframework.web.server.NotAcceptableStatusException)8