简化 mock login 模拟登录的实现,由 TokenAuthenticationFilter 直接实现

This commit is contained in:
YunaiV
2022-05-08 00:17:48 +08:00
parent 73bf0b6f4f
commit baadb5a937
11 changed files with 67 additions and 86 deletions

View File

@ -1,5 +1,5 @@
### 请求 /login 接口 => 成功
POST {{baseUrl}}/system/login
POST {{baseUrl}}/system/auth/login
Content-Type: application/json
tenant-id: {{adminTenentId}}
@ -11,7 +11,7 @@ tenant-id: {{adminTenentId}}
}
### 请求 /login 接口 => 成功(无验证码)
POST {{baseUrl}}/system/login
POST {{baseUrl}}/system/auth/login
Content-Type: application/json
tenant-id: {{adminTenentId}}
@ -21,7 +21,7 @@ tenant-id: {{adminTenentId}}
}
### 请求 /get-permission-info 接口 => 成功
GET {{baseUrl}}/system/get-permission-info
GET {{baseUrl}}/system/auth/get-permission-info
Authorization: Bearer {{token}}
tenant-id: {{adminTenentId}}

View File

@ -82,19 +82,6 @@ public class AdminAuthServiceImpl implements AdminAuthService {
return AuthConvert.INSTANCE.convert2(user);
}
@Override
public LoginUser mockLogin(Long userId) {
// 获取用户编号对应的 AdminUserDO
AdminUserDO user = userService.getUser(userId);
if (user == null) {
throw new UsernameNotFoundException(String.valueOf(userId));
}
createLoginLog(userId, user.getUsername(), LoginLogTypeEnum.LOGIN_MOCK, LoginResultEnum.SUCCESS);
// 创建 LoginUser 对象
return buildLoginUser(user);
}
@Override
public String login(AuthLoginReqVO reqVO, String userIp, String userAgent) {
// 判断验证码是否正确

View File

@ -96,32 +96,6 @@ public class AuthServiceImplTest extends BaseDbUnitTest {
username); // 异常提示为 username
}
@Test
public void testMockLogin_success() {
// 准备参数
Long userId = randomLongId();
// mock 方法 01
AdminUserDO user = randomPojo(AdminUserDO.class, o -> o.setId(userId));
when(userService.getUser(eq(userId))).thenReturn(user);
// 调用
LoginUser loginUser = authService.mockLogin(userId);
// 断言
AssertUtils.assertPojoEquals(user, loginUser, "updateTime");
}
@Test
public void testMockLogin_userNotFound() {
// 准备参数
Long userId = randomLongId();
// mock 方法
// 调用, 并断言异常
assertThrows(UsernameNotFoundException.class, // 抛出 UsernameNotFoundException 异常
() -> authService.mockLogin(userId),
String.valueOf(userId)); // 异常提示为 userId
}
@Test
public void testLogin_captchaNotFound() {
// 准备参数