Browse Source

This proves a bug with the ForwardedHeadersFilter (#440)

pull/441/head
Tillmann Heigel 6 years ago
parent
commit
84ac4963e8
  1. 37
      spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/headers/ForwardedHeadersFilterTests.java

37
spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/headers/ForwardedHeadersFilterTests.java

@ -17,6 +17,9 @@ @@ -17,6 +17,9 @@
package org.springframework.cloud.gateway.filter.headers;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.cloud.gateway.filter.headers.ForwardedHeadersFilter.FORWARDED_HEADER;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
@ -27,16 +30,12 @@ import java.util.List; @@ -27,16 +30,12 @@ import java.util.List;
import java.util.Map;
import org.junit.Test;
import org.springframework.cloud.gateway.filter.headers.ForwardedHeadersFilter.Forwarded;
import org.springframework.http.HttpHeaders;
import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
import org.springframework.mock.web.server.MockServerWebExchange;
import org.springframework.util.StringUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.cloud.gateway.filter.headers.ForwardedHeadersFilter.FORWARDED_HEADER;
/**
* @author Spencer Gibb
*/
@ -67,6 +66,36 @@ public class ForwardedHeadersFilterTests { @@ -67,6 +66,36 @@ public class ForwardedHeadersFilterTests {
.containsEntry("for", "\"10.0.0.1:80\"");
}
@Test
public void forwardedHeaderExists() throws UnknownHostException {
MockServerHttpRequest request = MockServerHttpRequest
.get("http://localhost/get")
.remoteAddress(new InetSocketAddress(InetAddress.getByName("10.0.0.1"), 80))
.header(FORWARDED_HEADER, "for=12.34.56.78;host=example.com;proto=https; for=23.45.67.89")
.build();
ForwardedHeadersFilter filter = new ForwardedHeadersFilter();
HttpHeaders headers = filter.filter(request.getHeaders(), MockServerWebExchange.from(request));
assertThat(headers.get(FORWARDED_HEADER)).hasSize(2);
List<Forwarded> forwardeds = ForwardedHeadersFilter.parse(headers.get(FORWARDED_HEADER));
assertThat(forwardeds).hasSize(2);
Forwarded addedForwardedHeader = forwardeds.get(0);
Forwarded existingForwardedHeader = forwardeds.get(1);
assertThat(existingForwardedHeader.getValues())
.containsEntry("proto", "http")
.containsEntry("for", "\"10.0.0.1:80\"");
assertThat(addedForwardedHeader.getValues())
.containsEntry("proto", "https")
.containsEntry("for", "23.45.67.89");
}
@Test
public void noHostHeader() throws UnknownHostException {
MockServerHttpRequest request = MockServerHttpRequest

Loading…
Cancel
Save