|
109 | 109 | import org.springframework.web.server.i18n.FixedLocaleContextResolver;
|
110 | 110 | import org.springframework.web.server.i18n.LocaleContextResolver;
|
111 | 111 | import org.springframework.web.server.session.CookieWebSessionIdResolver;
|
| 112 | +import org.springframework.web.server.session.DefaultWebSessionManager; |
| 113 | +import org.springframework.web.server.session.InMemoryWebSessionStore; |
112 | 114 | import org.springframework.web.server.session.WebSessionIdResolver;
|
113 | 115 | import org.springframework.web.server.session.WebSessionManager;
|
| 116 | +import org.springframework.web.server.session.WebSessionStore; |
114 | 117 | import org.springframework.web.util.pattern.PathPattern;
|
115 | 118 |
|
116 | 119 | import static org.assertj.core.api.Assertions.assertThat;
|
@@ -620,6 +623,20 @@ void customSessionTimeoutConfigurationShouldBeApplied() {
|
620 | 623 | })));
|
621 | 624 | }
|
622 | 625 |
|
| 626 | + @Test |
| 627 | + void customSessionMaxSessionsConfigurationShouldBeApplied() { |
| 628 | + this.contextRunner.withPropertyValues("server.reactive.session.max-sessions:123") |
| 629 | + .run((context) -> assertMaxSessionsWithWebSession(123)); |
| 630 | + } |
| 631 | + |
| 632 | + @Test |
| 633 | + void defaultSessionMaxSessionsConfigurationShouldBeInSync() { |
| 634 | + this.contextRunner.run((context) -> { |
| 635 | + int defaultMaxSessions = new InMemoryWebSessionStore().getMaxSessions(); |
| 636 | + assertMaxSessionsWithWebSession(defaultMaxSessions); |
| 637 | + }); |
| 638 | + } |
| 639 | + |
623 | 640 | @Test
|
624 | 641 | void customSessionCookieConfigurationShouldBeApplied() {
|
625 | 642 | this.contextRunner.withPropertyValues("server.reactive.session.cookie.name:JSESSIONID",
|
@@ -751,6 +768,17 @@ private ContextConsumer<ReactiveWebApplicationContext> assertSessionTimeoutWithW
|
751 | 768 | };
|
752 | 769 | }
|
753 | 770 |
|
| 771 | + private ContextConsumer<ReactiveWebApplicationContext> assertMaxSessionsWithWebSession( |
| 772 | + int maxSessions) { |
| 773 | + return (context) -> { |
| 774 | + WebSessionManager sessionManager = context.getBean(WebSessionManager.class); |
| 775 | + assertThat(sessionManager).isInstanceOf(DefaultWebSessionManager.class); |
| 776 | + WebSessionStore sessionStore = ((DefaultWebSessionManager) sessionManager).getSessionStore(); |
| 777 | + assertThat(sessionStore).isInstanceOf(InMemoryWebSessionStore.class); |
| 778 | + assertThat(((InMemoryWebSessionStore) sessionStore).getMaxSessions()).isEqualTo(maxSessions); |
| 779 | + }; |
| 780 | + } |
| 781 | + |
754 | 782 | private Map<PathPattern, Object> getHandlerMap(ApplicationContext context) {
|
755 | 783 | HandlerMapping mapping = context.getBean("resourceHandlerMapping", HandlerMapping.class);
|
756 | 784 | if (mapping instanceof SimpleUrlHandlerMapping simpleMapping) {
|
|
0 commit comments