package com.baiyue.common.security; import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.support.StaticListableBeanFactory; import org.springframework.data.redis.core.StringRedisTemplate; import static org.assertj.core.api.Assertions.assertThatThrownBy; class UnifiedSessionModeTest { @Test void rejectsLegacySessionModesAndMissingRedisInsteadOfTrustingClaimsOrHeaders() { var configuration = new BaiyueSecurityAutoConfiguration(); var beans = new StaticListableBeanFactory(); var redis = beans.getBeanProvider(StringRedisTemplate.class); for (String mode : new String[]{"claims", "gateway", "unknown", "redis"}) { assertThatThrownBy(() -> configuration.jwtAuthenticationFilter(token -> null, new JwtClaimsMapper(), new JsonAuthenticationEntryPoint(new ObjectMapper()), redis, new ObjectMapper(), "baiyue:auth", mode, "http://auth:9100/internal/auth/accounts/sessions/validate", "test-token")) .isInstanceOf(IllegalStateException.class); } } }