@ -352,6 +352,7 @@ class ServletWebServerFactoryAutoConfigurationTests {
assertThat ( context ) . hasSingleBean ( FilterRegistrationBean . class ) ;
assertThat ( context ) . hasSingleBean ( FilterRegistrationBean . class ) ;
Filter filter = context . getBean ( FilterRegistrationBean . class ) . getFilter ( ) ;
Filter filter = context . getBean ( FilterRegistrationBean . class ) . getFilter ( ) ;
assertThat ( filter ) . isInstanceOf ( ForwardedHeaderFilter . class ) ;
assertThat ( filter ) . isInstanceOf ( ForwardedHeaderFilter . class ) ;
assertThat ( filter ) . extracting ( "relativeRedirects" ) . isEqualTo ( false ) ;
} ) ;
} ) ;
}
}
@ -368,6 +369,48 @@ class ServletWebServerFactoryAutoConfigurationTests {
. run ( ( context ) - > assertThat ( context ) . hasSingleBean ( FilterRegistrationBean . class ) ) ;
. run ( ( context ) - > assertThat ( context ) . hasSingleBean ( FilterRegistrationBean . class ) ) ;
}
}
@Test
void relativeRedirectsShouldBeEnabledWhenUsingTomcatContainerAndUseRelativeRedirects ( ) {
WebApplicationContextRunner runner = new WebApplicationContextRunner (
AnnotationConfigServletWebServerApplicationContext : : new )
. withConfiguration ( AutoConfigurations . of ( ServletWebServerFactoryAutoConfiguration . class ) )
. withPropertyValues ( "server.forward-headers-strategy=framework" ,
"server.tomcat.use-relative-redirects=true" ) ;
runner . run ( ( context ) - > {
Filter filter = context . getBean ( FilterRegistrationBean . class ) . getFilter ( ) ;
assertThat ( filter ) . isInstanceOf ( ForwardedHeaderFilter . class ) ;
assertThat ( filter ) . extracting ( "relativeRedirects" ) . isEqualTo ( true ) ;
} ) ;
}
@Test
void relativeRedirectsShouldNotBeEnabledWhenUsingTomcatContainerAndNotUsingRelativeRedirects ( ) {
WebApplicationContextRunner runner = new WebApplicationContextRunner (
AnnotationConfigServletWebServerApplicationContext : : new )
. withConfiguration ( AutoConfigurations . of ( ServletWebServerFactoryAutoConfiguration . class ) )
. withPropertyValues ( "server.forward-headers-strategy=framework" ,
"server.tomcat.use-relative-redirects=false" ) ;
runner . run ( ( context ) - > {
Filter filter = context . getBean ( FilterRegistrationBean . class ) . getFilter ( ) ;
assertThat ( filter ) . isInstanceOf ( ForwardedHeaderFilter . class ) ;
assertThat ( filter ) . extracting ( "relativeRedirects" ) . isEqualTo ( false ) ;
} ) ;
}
@Test
void relativeRedirectsShouldNotBeEnabledWhenNotUsingTomcatContainer ( ) {
WebApplicationContextRunner runner = new WebApplicationContextRunner (
AnnotationConfigServletWebServerApplicationContext : : new )
. withClassLoader ( new FilteredClassLoader ( Tomcat . class ) )
. withConfiguration ( AutoConfigurations . of ( ServletWebServerFactoryAutoConfiguration . class ) )
. withPropertyValues ( "server.forward-headers-strategy=framework" ) ;
runner . run ( ( context ) - > {
Filter filter = context . getBean ( FilterRegistrationBean . class ) . getFilter ( ) ;
assertThat ( filter ) . isInstanceOf ( ForwardedHeaderFilter . class ) ;
assertThat ( filter ) . extracting ( "relativeRedirects" ) . isEqualTo ( false ) ;
} ) ;
}
private ContextConsumer < AssertableWebApplicationContext > verifyContext ( ) {
private ContextConsumer < AssertableWebApplicationContext > verifyContext ( ) {
return this : : verifyContext ;
return this : : verifyContext ;
}
}