test: add test for JWTAuthenticationFilter.getMessage

pull/1194/head
lucca 2 years ago
parent b909874a69
commit fd96f51612

@ -119,7 +119,7 @@ public class JWTAuthenticationFilter extends UsernamePasswordAuthenticationFilte
/** /**
* Return different echo information to the front end according to different exception types * Return different echo information to the front end according to different exception types
*/ */
protected String getMessage(AuthenticationException failed) { private String getMessage(AuthenticationException failed) {
String message = "Server Error"; String message = "Server Error";
if (failed instanceof UsernameNotFoundException) { if (failed instanceof UsernameNotFoundException) {
message = "用户不存在"; message = "用户不存在";

@ -0,0 +1,19 @@
package cn.hippo4j.auth.filter;
import cn.hippo4j.common.toolkit.ReflectUtil;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
class JWTAuthenticationFilterTest {
@Test
void getMessageTest() {
JWTAuthenticationFilter filter = new JWTAuthenticationFilter(null);
Assertions.assertEquals("用户不存在", ReflectUtil.invoke(filter,
"getMessage", new UsernameNotFoundException("")));
Assertions.assertEquals("密码错误", ReflectUtil.invoke(filter,
"getMessage", new BadCredentialsException("")));
}
}
Loading…
Cancel
Save