use of org.springframework.mock.http.server.reactive.MockServerHttpRequest in project spring-cloud-gateway by spring-cloud.
the class CookieRoutePredicateFactoryTests method noCookiesForYou.
@Test
public void noCookiesForYou() {
MockServerHttpRequest request = MockServerHttpRequest.get("http://example.com").build();
MockServerWebExchange exchange = MockServerWebExchange.from(request);
Predicate<ServerWebExchange> predicate = new CookieRoutePredicateFactory().apply(new Config().setName("mycookie").setRegexp("ch.p"));
assertThat(predicate.test(exchange)).isFalse();
}
use of org.springframework.mock.http.server.reactive.MockServerHttpRequest in project spring-cloud-gateway by spring-cloud.
the class XForwardedHeadersFilterTests method xForwardedHeadersDoNotExist.
@Test
public void xForwardedHeadersDoNotExist() throws Exception {
MockServerHttpRequest request = MockServerHttpRequest.get("http://localhost:8080/get").remoteAddress(new InetSocketAddress(InetAddress.getByName("10.0.0.1"), 80)).header(HttpHeaders.HOST, "myhost").build();
XForwardedHeadersFilter filter = new XForwardedHeadersFilter();
HttpHeaders headers = filter.filter(request.getHeaders(), MockServerWebExchange.from(request));
assertThat(headers).containsKeys(X_FORWARDED_FOR_HEADER, X_FORWARDED_HOST_HEADER, X_FORWARDED_PORT_HEADER, X_FORWARDED_PROTO_HEADER);
assertThat(headers.getFirst(X_FORWARDED_FOR_HEADER)).isEqualTo("10.0.0.1");
assertThat(headers.getFirst(X_FORWARDED_HOST_HEADER)).isEqualTo("localhost:8080");
assertThat(headers.getFirst(X_FORWARDED_PORT_HEADER)).isEqualTo("8080");
assertThat(headers.getFirst(X_FORWARDED_PROTO_HEADER)).isEqualTo("http");
}
use of org.springframework.mock.http.server.reactive.MockServerHttpRequest in project spring-cloud-gateway by spring-cloud.
the class XForwardedHeadersFilterTests method defaultPort.
@Test
public void defaultPort() throws Exception {
MockServerHttpRequest request = MockServerHttpRequest.get("http://localhost/get").remoteAddress(new InetSocketAddress(InetAddress.getByName("10.0.0.1"), 80)).header(HttpHeaders.HOST, "myhost").build();
XForwardedHeadersFilter filter = new XForwardedHeadersFilter();
HttpHeaders headers = filter.filter(request.getHeaders(), MockServerWebExchange.from(request));
assertThat(headers).containsKeys(X_FORWARDED_FOR_HEADER, X_FORWARDED_HOST_HEADER, X_FORWARDED_PORT_HEADER, X_FORWARDED_PROTO_HEADER);
assertThat(headers.getFirst(X_FORWARDED_FOR_HEADER)).isEqualTo("10.0.0.1");
assertThat(headers.getFirst(X_FORWARDED_HOST_HEADER)).isEqualTo("localhost");
assertThat(headers.getFirst(X_FORWARDED_PORT_HEADER)).isEqualTo("80");
assertThat(headers.getFirst(X_FORWARDED_PROTO_HEADER)).isEqualTo("http");
}
use of org.springframework.mock.http.server.reactive.MockServerHttpRequest in project spring-cloud-gateway by spring-cloud.
the class XForwardedHeadersFilterTests method appendsValues.
@Test
public void appendsValues() throws Exception {
MockServerHttpRequest request = MockServerHttpRequest.get("http://localhost:8080/get").remoteAddress(new InetSocketAddress(InetAddress.getByName("10.0.0.1"), 80)).header(X_FORWARDED_FOR_HEADER, "192.168.0.2").header(X_FORWARDED_HOST_HEADER, "example.com").header(X_FORWARDED_PORT_HEADER, "443").header(X_FORWARDED_PROTO_HEADER, "https").build();
XForwardedHeadersFilter filter = new XForwardedHeadersFilter();
HttpHeaders headers = filter.filter(request.getHeaders(), MockServerWebExchange.from(request));
assertThat(headers).containsKeys(X_FORWARDED_FOR_HEADER, X_FORWARDED_HOST_HEADER, X_FORWARDED_PORT_HEADER, X_FORWARDED_PROTO_HEADER);
assertThat(headers.getFirst(X_FORWARDED_FOR_HEADER)).isEqualTo("192.168.0.2,10.0.0.1");
assertThat(headers.getFirst(X_FORWARDED_HOST_HEADER)).isEqualTo("example.com,localhost:8080");
assertThat(headers.getFirst(X_FORWARDED_PORT_HEADER)).isEqualTo("443,8080");
assertThat(headers.getFirst(X_FORWARDED_PROTO_HEADER)).isEqualTo("https,http");
}
use of org.springframework.mock.http.server.reactive.MockServerHttpRequest in project spring-cloud-gateway by spring-cloud.
the class XForwardedHeadersFilterTests method allDisabled.
@Test
public void allDisabled() throws Exception {
MockServerHttpRequest request = MockServerHttpRequest.get("http://localhost:8080/get").remoteAddress(new InetSocketAddress(InetAddress.getByName("10.0.0.1"), 80)).build();
XForwardedHeadersFilter filter = new XForwardedHeadersFilter();
filter.setForEnabled(false);
filter.setHostEnabled(false);
filter.setPortEnabled(false);
filter.setProtoEnabled(false);
HttpHeaders headers = filter.filter(request.getHeaders(), MockServerWebExchange.from(request));
assertThat(headers).isEmpty();
}
Aggregations