23 lines
1.0 KiB
Java
23 lines
1.0 KiB
Java
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))
|
||
|
|
.isInstanceOf(IllegalStateException.class);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|