Validate that we actually have a hostname when using a load balanced URI. Fixes #779
This commit is contained in:
@@ -68,6 +68,12 @@ public class RouteToRequestUrlFilter implements GlobalFilter, Ordered {
|
||||
routeUri = URI.create(routeUri.getSchemeSpecificPart());
|
||||
}
|
||||
|
||||
if("lb".equalsIgnoreCase(routeUri.getScheme()) && routeUri.getHost() == null) {
|
||||
//Load balanced URIs should always have a host. If the host is null it is most
|
||||
//likely because the host name was invalid (for example included an underscore)
|
||||
throw new IllegalStateException("Invalid host: " + routeUri.toString());
|
||||
}
|
||||
|
||||
URI mergedUrl = UriComponentsBuilder.fromUri(uri)
|
||||
// .uri(routeUri)
|
||||
.scheme(routeUri.getScheme())
|
||||
|
||||
@@ -66,6 +66,14 @@ public class RouteToRequestUrlFilterTests {
|
||||
assertThat(uri).hasScheme("lb").hasHost("myhost");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void invalidHost() {
|
||||
MockServerHttpRequest request = MockServerHttpRequest
|
||||
.get("http://localhost/getb")
|
||||
.build();
|
||||
testFilter(request, "lb://my_host");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void happyPathLbPlusScheme() {
|
||||
MockServerHttpRequest request = MockServerHttpRequest
|
||||
|
||||
Reference in New Issue
Block a user