use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.
the class DispatcherHandlerTests method preFlightRequest.
@Test
void preFlightRequest() {
WebHandler webHandler = mock(WebHandler.class);
HandlerMapping handlerMapping = mock(HandlerMapping.class);
given((handlerMapping).getHandler(any())).willReturn(Mono.just(webHandler));
StaticApplicationContext context = new StaticApplicationContext();
context.registerBean("handlerMapping", HandlerMapping.class, () -> handlerMapping);
context.registerBean(HandlerAdapter.class, SimpleHandlerAdapter::new);
context.registerBean(HandlerResultHandler.class, StringHandlerResultHandler::new);
context.refresh();
MockServerHttpRequest request = MockServerHttpRequest.options("/").header(HttpHeaders.ORIGIN, "https://domain.com").header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET").build();
MockServerWebExchange exchange = MockServerWebExchange.from(request);
new DispatcherHandler(context).handle(exchange).block(Duration.ofSeconds(0));
verifyNoInteractions(webHandler);
}
use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.
the class CorsUtilsTests method isSameOriginWithDifferentSchemes.
// SPR-16362
@Test
@SuppressWarnings("deprecation")
public void isSameOriginWithDifferentSchemes() {
MockServerHttpRequest request = MockServerHttpRequest.get("http://mydomain1.example").header(HttpHeaders.ORIGIN, "https://mydomain1.example").build();
assertThat(CorsUtils.isSameOrigin(request)).isFalse();
}
use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.
the class DefaultCorsProcessorTests method preventDuplicatedVaryHeaders.
@Test
public void preventDuplicatedVaryHeaders() {
MockServerHttpRequest request = MockServerHttpRequest.method(HttpMethod.GET, "http://domain1.example/test.html").header(HttpHeaders.ORIGIN, "http://domain1.example").build();
ServerWebExchange exchange = MockServerWebExchange.from(request);
ServerHttpResponse response = exchange.getResponse();
HttpHeaders responseHeaders = response.getHeaders();
responseHeaders.add(VARY, ORIGIN);
responseHeaders.add(VARY, ACCESS_CONTROL_REQUEST_METHOD);
responseHeaders.add(VARY, ACCESS_CONTROL_REQUEST_HEADERS);
this.processor.process(this.conf, exchange);
assertThat(responseHeaders.get(VARY)).containsOnlyOnce(ORIGIN, ACCESS_CONTROL_REQUEST_METHOD, ACCESS_CONTROL_REQUEST_HEADERS);
}
use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.
the class HandshakeWebSocketServiceTests method sessionAttributePredicate.
@Test
public void sessionAttributePredicate() {
MockWebSession session = new MockWebSession();
session.getAttributes().put("a1", "v1");
session.getAttributes().put("a2", "v2");
session.getAttributes().put("a3", "v3");
session.getAttributes().put("a4", "v4");
session.getAttributes().put("a5", "v5");
MockServerHttpRequest request = initHandshakeRequest();
MockServerWebExchange exchange = MockServerWebExchange.builder(request).session(session).build();
TestRequestUpgradeStrategy upgradeStrategy = new TestRequestUpgradeStrategy();
HandshakeWebSocketService service = new HandshakeWebSocketService(upgradeStrategy);
service.setSessionAttributePredicate(name -> Arrays.asList("a1", "a3", "a5").contains(name));
service.handleRequest(exchange, mock(WebSocketHandler.class)).block();
HandshakeInfo info = upgradeStrategy.handshakeInfo;
assertThat(info).isNotNull();
Map<String, Object> attributes = info.getAttributes();
assertThat(attributes).hasSize(3).containsEntry("a1", "v1").containsEntry("a3", "v3").containsEntry("a5", "v5");
}
use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.
the class DefaultPartHttpMessageReaderTests method noEndBoundary.
@ParameterizedDefaultPartHttpMessageReaderTest
public void noEndBoundary(String displayName, DefaultPartHttpMessageReader reader) {
MockServerHttpRequest request = createRequest(new ClassPathResource("no-end-boundary.multipart", getClass()), "boundary");
Flux<Part> result = reader.read(forClass(Part.class), request, emptyMap());
StepVerifier.create(result).expectError(DecodingException.class).verify();
}
Aggregations