Search in sources :

Example 1 with AutoConfigurations

use of org.springframework.boot.autoconfigure.AutoConfigurations in project spring-boot by spring-projects.

the class ReactiveSessionAutoConfigurationMongoTests method sessionCookieConfigurationIsAppliedToAutoConfiguredWebSessionIdResolver.

@Test
void sessionCookieConfigurationIsAppliedToAutoConfiguredWebSessionIdResolver() {
    AutoConfigurations autoConfigurations = AutoConfigurations.of(MongoAutoConfiguration.class, MongoDataAutoConfiguration.class, MongoReactiveAutoConfiguration.class, MongoReactiveDataAutoConfiguration.class, WebSessionIdResolverAutoConfiguration.class);
    this.contextRunner.withConfiguration(autoConfigurations).withUserConfiguration(Config.class).withPropertyValues("spring.session.store-type=mongodb", "server.reactive.session.cookie.name:JSESSIONID", "server.reactive.session.cookie.domain:.example.com", "server.reactive.session.cookie.path:/example", "server.reactive.session.cookie.max-age:60", "server.reactive.session.cookie.http-only:false", "server.reactive.session.cookie.secure:false", "server.reactive.session.cookie.same-site:strict", "spring.data.mongodb.uri=" + mongoDb.getReplicaSetUrl()).run(assertExchangeWithSession((exchange) -> {
        List<ResponseCookie> cookies = exchange.getResponse().getCookies().get("JSESSIONID");
        assertThat(cookies).isNotEmpty();
        assertThat(cookies).allMatch((cookie) -> cookie.getDomain().equals(".example.com"));
        assertThat(cookies).allMatch((cookie) -> cookie.getPath().equals("/example"));
        assertThat(cookies).allMatch((cookie) -> cookie.getMaxAge().equals(Duration.ofSeconds(60)));
        assertThat(cookies).allMatch((cookie) -> !cookie.isHttpOnly());
        assertThat(cookies).allMatch((cookie) -> !cookie.isSecure());
        assertThat(cookies).allMatch((cookie) -> cookie.getSameSite().equals("Strict"));
    }));
}
Also used : MongoReactiveDataAutoConfiguration(org.springframework.boot.autoconfigure.data.mongo.MongoReactiveDataAutoConfiguration) AutoConfigurations(org.springframework.boot.autoconfigure.AutoConfigurations) ReactiveMongoSessionRepository(org.springframework.session.data.mongo.ReactiveMongoSessionRepository) MongoAutoConfiguration(org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration) MongoReactiveAutoConfiguration(org.springframework.boot.autoconfigure.mongo.MongoReactiveAutoConfiguration) Testcontainers(org.testcontainers.junit.jupiter.Testcontainers) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) WebSessionIdResolverAutoConfiguration(org.springframework.boot.autoconfigure.web.reactive.WebSessionIdResolverAutoConfiguration) MongoDBContainer(org.testcontainers.containers.MongoDBContainer) ContextConsumer(org.springframework.boot.test.context.runner.ContextConsumer) Test(org.junit.jupiter.api.Test) FilteredClassLoader(org.springframework.boot.test.context.FilteredClassLoader) List(java.util.List) ReactiveRedisSessionRepository(org.springframework.session.data.redis.ReactiveRedisSessionRepository) ReactiveWebApplicationContextRunner(org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner) MongoDataAutoConfiguration(org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration) Duration(java.time.Duration) DockerImageNames(org.springframework.boot.testsupport.testcontainers.DockerImageNames) AssertableReactiveWebApplicationContext(org.springframework.boot.test.context.assertj.AssertableReactiveWebApplicationContext) Container(org.testcontainers.junit.jupiter.Container) ResponseCookie(org.springframework.http.ResponseCookie) AutoConfigurations(org.springframework.boot.autoconfigure.AutoConfigurations) List(java.util.List) Test(org.junit.jupiter.api.Test)

Aggregations

Duration (java.time.Duration)1 List (java.util.List)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Test (org.junit.jupiter.api.Test)1 AutoConfigurations (org.springframework.boot.autoconfigure.AutoConfigurations)1 MongoDataAutoConfiguration (org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration)1 MongoReactiveDataAutoConfiguration (org.springframework.boot.autoconfigure.data.mongo.MongoReactiveDataAutoConfiguration)1 MongoAutoConfiguration (org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration)1 MongoReactiveAutoConfiguration (org.springframework.boot.autoconfigure.mongo.MongoReactiveAutoConfiguration)1 WebSessionIdResolverAutoConfiguration (org.springframework.boot.autoconfigure.web.reactive.WebSessionIdResolverAutoConfiguration)1 FilteredClassLoader (org.springframework.boot.test.context.FilteredClassLoader)1 AssertableReactiveWebApplicationContext (org.springframework.boot.test.context.assertj.AssertableReactiveWebApplicationContext)1 ContextConsumer (org.springframework.boot.test.context.runner.ContextConsumer)1 ReactiveWebApplicationContextRunner (org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner)1 DockerImageNames (org.springframework.boot.testsupport.testcontainers.DockerImageNames)1 ResponseCookie (org.springframework.http.ResponseCookie)1 ReactiveMongoSessionRepository (org.springframework.session.data.mongo.ReactiveMongoSessionRepository)1 ReactiveRedisSessionRepository (org.springframework.session.data.redis.ReactiveRedisSessionRepository)1 MongoDBContainer (org.testcontainers.containers.MongoDBContainer)1 Container (org.testcontainers.junit.jupiter.Container)1