package com.baiyue.eventbridge.security; import org.junit.jupiter.api.Test; import org.springframework.web.server.ResponseStatusException; import static org.assertj.core.api.Assertions.assertThatCode; import static org.assertj.core.api.Assertions.assertThatThrownBy; class InternalServiceTokenGuardTest { @Test void 正确令牌允许访问() { InternalServiceTokenGuard guard = new InternalServiceTokenGuard("a-secure-internal-token"); assertThatCode(() -> guard.verify("a-secure-internal-token")).doesNotThrowAnyException(); } @Test void 未配置令牌时默认关闭接收接口() { InternalServiceTokenGuard guard = new InternalServiceTokenGuard(""); assertThatThrownBy(() -> guard.verify("anything")) .isInstanceOf(ResponseStatusException.class) .hasMessageContaining("接口已关闭"); } @Test void 错误令牌被拒绝() { InternalServiceTokenGuard guard = new InternalServiceTokenGuard("expected"); assertThatThrownBy(() -> guard.verify("wrong")) .isInstanceOf(ResponseStatusException.class) .hasMessageContaining("令牌无效"); } }