Tests #4573 X-Forwarded ordering
Added tests for header ordering fixed cut-and-paste error of _for to _host Signed-off-by: Greg Wilkins <gregw@webtide.com>
This commit is contained in:
parent
aaf6f17766
commit
652428ad70
|
@ -589,13 +589,14 @@ public class ForwardedRequestCustomizer implements Customizer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public void handleHost(HttpField field)
|
public void handleHost(HttpField field)
|
||||||
{
|
{
|
||||||
if (getForwardedPortAsAuthority() && !StringUtil.isEmpty(getForwardedPortHeader()))
|
if (getForwardedPortAsAuthority() && !StringUtil.isEmpty(getForwardedPortHeader()))
|
||||||
{
|
{
|
||||||
if (_host == null)
|
if (_host == null)
|
||||||
_host = new PossiblyPartialHostPort(getLeftMost(field.getValue()));
|
_host = new PossiblyPartialHostPort(getLeftMost(field.getValue()));
|
||||||
else if (_for instanceof PortSetHostPort)
|
else if (_host instanceof PortSetHostPort)
|
||||||
_host = new HostPort(HostPort.normalizeHost(getLeftMost(field.getValue())), _host.getPort());
|
_host = new HostPort(HostPort.normalizeHost(getLeftMost(field.getValue())), _host.getPort());
|
||||||
}
|
}
|
||||||
else if (_host == null)
|
else if (_host == null)
|
||||||
|
|
|
@ -397,6 +397,34 @@ public class ForwardedRequestCustomizerTest
|
||||||
.requestURL("http://myhost:4444/")
|
.requestURL("http://myhost:4444/")
|
||||||
.remoteAddr("192.168.1.200").remotePort(0)
|
.remoteAddr("192.168.1.200").remotePort(0)
|
||||||
),
|
),
|
||||||
|
Arguments.of(new Request("X-Forwarded-* (all headers except server)")
|
||||||
|
.headers(
|
||||||
|
"GET / HTTP/1.1",
|
||||||
|
"Host: myhost",
|
||||||
|
"X-Forwarded-Proto: https",
|
||||||
|
"X-Forwarded-Host: www.example.com",
|
||||||
|
"X-Forwarded-Port: 4333",
|
||||||
|
"X-Forwarded-For: 8.5.4.3:2222"
|
||||||
|
),
|
||||||
|
new Expectations()
|
||||||
|
.scheme("https").serverName("www.example.com").serverPort(4333)
|
||||||
|
.requestURL("https://www.example.com:4333/")
|
||||||
|
.remoteAddr("8.5.4.3").remotePort(2222)
|
||||||
|
),
|
||||||
|
Arguments.of(new Request("X-Forwarded-* (all headers except server, port first)")
|
||||||
|
.headers(
|
||||||
|
"GET / HTTP/1.1",
|
||||||
|
"Host: myhost",
|
||||||
|
"X-Forwarded-Proto: https",
|
||||||
|
"X-Forwarded-Port: 4333",
|
||||||
|
"X-Forwarded-Host: www.example.com",
|
||||||
|
"X-Forwarded-For: 8.5.4.3:2222"
|
||||||
|
),
|
||||||
|
new Expectations()
|
||||||
|
.scheme("https").serverName("www.example.com").serverPort(4333)
|
||||||
|
.requestURL("https://www.example.com:4333/")
|
||||||
|
.remoteAddr("8.5.4.3").remotePort(2222)
|
||||||
|
),
|
||||||
Arguments.of(new Request("X-Forwarded-* (all headers)")
|
Arguments.of(new Request("X-Forwarded-* (all headers)")
|
||||||
.headers(
|
.headers(
|
||||||
"GET / HTTP/1.1",
|
"GET / HTTP/1.1",
|
||||||
|
@ -427,6 +455,21 @@ public class ForwardedRequestCustomizerTest
|
||||||
.requestURL("https://www.example.com:4333/")
|
.requestURL("https://www.example.com:4333/")
|
||||||
.remoteAddr("8.5.4.3").remotePort(2222)
|
.remoteAddr("8.5.4.3").remotePort(2222)
|
||||||
),
|
),
|
||||||
|
Arguments.of(new Request("X-Forwarded-* (all headers reversed)")
|
||||||
|
.headers(
|
||||||
|
"GET / HTTP/1.1",
|
||||||
|
"Host: myhost",
|
||||||
|
"X-Forwarded-Server: fw.example.com",
|
||||||
|
"X-Forwarded-For: 8.5.4.3:2222",
|
||||||
|
"X-Forwarded-Port: 4333",
|
||||||
|
"X-Forwarded-Host: www.example.com",
|
||||||
|
"X-Forwarded-Proto: https"
|
||||||
|
),
|
||||||
|
new Expectations()
|
||||||
|
.scheme("https").serverName("www.example.com").serverPort(4333)
|
||||||
|
.requestURL("https://www.example.com:4333/")
|
||||||
|
.remoteAddr("8.5.4.3").remotePort(2222)
|
||||||
|
),
|
||||||
Arguments.of(new Request("X-Forwarded-* (Server and Port)")
|
Arguments.of(new Request("X-Forwarded-* (Server and Port)")
|
||||||
.headers(
|
.headers(
|
||||||
"GET / HTTP/1.1",
|
"GET / HTTP/1.1",
|
||||||
|
@ -440,6 +483,19 @@ public class ForwardedRequestCustomizerTest
|
||||||
.requestURL("http://fw.example.com:4333/")
|
.requestURL("http://fw.example.com:4333/")
|
||||||
.remoteAddr("8.5.4.3").remotePort(2222)
|
.remoteAddr("8.5.4.3").remotePort(2222)
|
||||||
),
|
),
|
||||||
|
Arguments.of(new Request("X-Forwarded-* (Port and Server)")
|
||||||
|
.headers(
|
||||||
|
"GET / HTTP/1.1",
|
||||||
|
"Host: myhost",
|
||||||
|
"X-Forwarded-Port: 4333",
|
||||||
|
"X-Forwarded-For: 8.5.4.3:2222",
|
||||||
|
"X-Forwarded-Server: fw.example.com"
|
||||||
|
),
|
||||||
|
new Expectations()
|
||||||
|
.scheme("http").serverName("fw.example.com").serverPort(4333)
|
||||||
|
.requestURL("http://fw.example.com:4333/")
|
||||||
|
.remoteAddr("8.5.4.3").remotePort(2222)
|
||||||
|
),
|
||||||
|
|
||||||
// =================================================================
|
// =================================================================
|
||||||
// Mixed Behavior
|
// Mixed Behavior
|
||||||
|
|
Loading…
Reference in New Issue