Search in sources :

Example 71 with MockServerHttpRequest

use of org.springframework.mock.http.server.reactive.MockServerHttpRequest in project spring-security by spring-projects.

the class ServerRequestCacheWebFilterTests method filterWhenRequestDoesNotMatchThenRequestDoesNotChange.

@Test
public void filterWhenRequestDoesNotMatchThenRequestDoesNotChange() {
    MockServerHttpRequest initialRequest = MockServerHttpRequest.get("/").build();
    ServerWebExchange exchange = MockServerWebExchange.from(initialRequest);
    given(this.requestCache.removeMatchingRequest(any())).willReturn(Mono.empty());
    this.requestCacheFilter.filter(exchange, this.chain).block();
    verify(this.chain).filter(this.exchangeCaptor.capture());
    ServerWebExchange updatedExchange = this.exchangeCaptor.getValue();
    assertThat(updatedExchange.getRequest()).isEqualTo(initialRequest);
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) MockServerWebExchange(org.springframework.mock.web.server.MockServerWebExchange) MockServerHttpRequest(org.springframework.mock.http.server.reactive.MockServerHttpRequest) Test(org.junit.jupiter.api.Test)

Example 72 with MockServerHttpRequest

use of org.springframework.mock.http.server.reactive.MockServerHttpRequest in project spring-security by spring-projects.

the class HttpStatusReturningServerLogoutSuccessHandlerTests method buildFilterExchange.

private static WebFilterExchange buildFilterExchange() {
    MockServerHttpRequest request = MockServerHttpRequest.get("/").build();
    MockServerWebExchange exchange = MockServerWebExchange.from(request);
    return new WebFilterExchange(exchange, mock(WebFilterChain.class));
}
Also used : MockServerHttpRequest(org.springframework.mock.http.server.reactive.MockServerHttpRequest) WebFilterChain(org.springframework.web.server.WebFilterChain) MockServerWebExchange(org.springframework.mock.web.server.MockServerWebExchange) WebFilterExchange(org.springframework.security.web.server.WebFilterExchange)

Example 73 with MockServerHttpRequest

use of org.springframework.mock.http.server.reactive.MockServerHttpRequest in project spring-security by spring-projects.

the class DelegatingReactiveAuthorizationManagerTests method setup.

@BeforeEach
public void setup() {
    MockitoAnnotations.initMocks(this);
    this.manager = DelegatingReactiveAuthorizationManager.builder().add(new ServerWebExchangeMatcherEntry<>(this.match1, this.delegate1)).add(new ServerWebExchangeMatcherEntry<>(this.match2, this.delegate2)).build();
    MockServerHttpRequest request = MockServerHttpRequest.get("/test").build();
    this.exchange = MockServerWebExchange.from(request);
}
Also used : ServerWebExchangeMatcherEntry(org.springframework.security.web.server.util.matcher.ServerWebExchangeMatcherEntry) MockServerHttpRequest(org.springframework.mock.http.server.reactive.MockServerHttpRequest) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 74 with MockServerHttpRequest

use of org.springframework.mock.http.server.reactive.MockServerHttpRequest in project spring-cloud-open-service-broker by spring-cloud.

the class ApiVersionWebFilterTest method setUpVersionResponse.

private void setUpVersionResponse(String version) {
    MockServerHttpRequest request;
    if (version == null) {
        request = MockServerHttpRequest.get(V2_API_PATH_PATTERN).build();
    } else {
        request = MockServerHttpRequest.get(V2_API_PATH_PATTERN).header("header", version).build();
    }
    this.exchange = MockServerWebExchange.from(request);
    openMocks(this);
    exchange.getResponse().setStatusCode(HttpStatus.OK);
    given(chain.filter(exchange)).willReturn(Mono.empty());
}
Also used : MockServerHttpRequest(org.springframework.mock.http.server.reactive.MockServerHttpRequest)

Example 75 with MockServerHttpRequest

use of org.springframework.mock.http.server.reactive.MockServerHttpRequest in project spring-cloud-open-service-broker by spring-cloud.

the class RequestIdentityWebFilterTest method requestIdentityHeader.

@Test
void requestIdentityHeader() {
    MockServerHttpRequest request = MockServerHttpRequest.get(V2_API_PATH_PATTERN).header(ServiceBrokerRequest.REQUEST_IDENTITY_HEADER, "request-id").build();
    this.exchange = MockServerWebExchange.from(request);
    openMocks(this);
    given(chain.filter(exchange)).willReturn(Mono.empty());
    RequestIdentityWebFilter webFilter = new RequestIdentityWebFilter();
    webFilter.filter(exchange, chain).block();
    assertThat(exchange.getResponse().getHeaders().getFirst(ServiceBrokerRequest.REQUEST_IDENTITY_HEADER)).isEqualTo("request-id");
}
Also used : MockServerHttpRequest(org.springframework.mock.http.server.reactive.MockServerHttpRequest) Test(org.junit.jupiter.api.Test)

Aggregations

MockServerHttpRequest (org.springframework.mock.http.server.reactive.MockServerHttpRequest)75 Test (org.junit.jupiter.api.Test)40 MockServerWebExchange (org.springframework.mock.web.server.MockServerWebExchange)35 Test (org.junit.Test)26 ServerWebExchange (org.springframework.web.server.ServerWebExchange)26 URI (java.net.URI)16 OAuth2AuthorizationRequest (org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest)11 HttpHeaders (org.springframework.http.HttpHeaders)9 BeforeEach (org.junit.jupiter.api.BeforeEach)7 ResponseStatusException (org.springframework.web.server.ResponseStatusException)7 AcceptHeaderLocaleContextResolver (org.springframework.web.server.i18n.AcceptHeaderLocaleContextResolver)6 Mono (reactor.core.publisher.Mono)6 InetSocketAddress (java.net.InetSocketAddress)5 Assertions.assertThatIllegalStateException (org.assertj.core.api.Assertions.assertThatIllegalStateException)5 Mockito.mock (org.mockito.Mockito.mock)5 ObjectError (org.springframework.validation.ObjectError)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)4 BDDMockito.given (org.mockito.BDDMockito.given)4