|
|
@ -16,6 +16,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.autoconfigure.session;
|
|
|
|
package org.springframework.boot.autoconfigure.session;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.time.Duration;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.EnumSet;
|
|
|
|
import java.util.EnumSet;
|
|
|
|
|
|
|
|
|
|
|
@ -23,9 +24,10 @@ import javax.servlet.DispatcherType;
|
|
|
|
|
|
|
|
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.BeanCreationException;
|
|
|
|
|
|
|
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
|
|
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
|
|
|
|
|
|
|
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
|
|
|
import org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration;
|
|
|
|
import org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration;
|
|
|
|
|
|
|
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
|
|
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
|
|
|
|
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
|
|
|
|
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
|
|
|
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
|
|
|
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext;
|
|
|
|
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext;
|
|
|
@ -98,14 +100,22 @@ public class SessionAutoConfigurationTests extends AbstractSessionAutoConfigurat
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void springSessionTimeoutIsNotAValidProperty() {
|
|
|
|
public void autoConfigWhenSpringSessionTimeoutIsSetShouldUseThat() {
|
|
|
|
this.contextRunner.withUserConfiguration(SessionRepositoryConfiguration.class)
|
|
|
|
this.contextRunner.withUserConfiguration(ServerPropertiesConfiguration.class,
|
|
|
|
.withPropertyValues("spring.session.timeout=3000").run((context) -> {
|
|
|
|
SessionRepositoryConfiguration.class)
|
|
|
|
assertThat(context).hasFailed();
|
|
|
|
.withPropertyValues("server.servlet.session.timeout=1",
|
|
|
|
assertThat(context).getFailure()
|
|
|
|
"spring.session.timeout=3").run((context) ->
|
|
|
|
.isInstanceOf(BeanCreationException.class);
|
|
|
|
assertThat(context.getBean(SessionProperties.class).getTimeout())
|
|
|
|
assertThat(context).getFailure()
|
|
|
|
.isEqualTo(Duration.ofSeconds(3)));
|
|
|
|
.hasMessageContaining("Could not bind");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void autoConfigWhenSpringSessionTimeoutIsNotSetShouldUseServerSessionTimeout() {
|
|
|
|
|
|
|
|
this.contextRunner.withUserConfiguration(ServerPropertiesConfiguration.class,
|
|
|
|
|
|
|
|
SessionRepositoryConfiguration.class)
|
|
|
|
|
|
|
|
.withPropertyValues("server.servlet.session.timeout=3").run((context) -> {
|
|
|
|
|
|
|
|
assertThat(context.getBean(SessionProperties.class).getTimeout())
|
|
|
|
|
|
|
|
.isEqualTo(Duration.ofSeconds(3));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -184,4 +194,9 @@ public class SessionAutoConfigurationTests extends AbstractSessionAutoConfigurat
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@EnableConfigurationProperties(ServerProperties.class)
|
|
|
|
|
|
|
|
static class ServerPropertiesConfiguration {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|