fix(鉴权): 单设备开关关闭时登录清除登出吊销标记
开关关掉后登录不再写 users.machine,而登出吊销借 machine 写 revoked@ 标记, 没人覆盖就永久留存——此后每次登录都先成功、再被 assertNotRevoked 判成 401「登录已过期,请重新登录」(2026-10-24 现网 admin 被锁死即此)。 登录成功即视为新会话,遇吊销标记时清空(仍不写设备号)。
This commit is contained in:
+24
-1
@@ -1,6 +1,7 @@
|
||||
package com.nanri.aiimage.modules.auth.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
||||
import com.nanri.aiimage.common.exception.BusinessException;
|
||||
import com.nanri.aiimage.common.security.AccountExpiryService;
|
||||
@@ -22,6 +23,7 @@ import static org.assertj.core.api.Assertions.assertThatCode;
|
||||
import static org.assertj.core.api.Assertions.catchThrowableOfType;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.argThat;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
@@ -62,7 +64,7 @@ class AuthServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void loginSkipsBindingWhenSingleDeviceDisabled() {
|
||||
void loginSkipsBindingWhenSingleDeviceDisabledAndNotRevoked() {
|
||||
Fixture f = fixture(false);
|
||||
when(f.loginUserMapper.selectOne(any())).thenReturn(f.user("devA"));
|
||||
when(f.passwordEncoder.matches("pwd", "hash")).thenReturn(true);
|
||||
@@ -78,6 +80,27 @@ class AuthServiceTest {
|
||||
verify(f.loginUserMapper, never()).update(any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void loginClearsLogoutRevocationMarkerWhenSingleDeviceDisabled() {
|
||||
// 开关关掉后登录不再写 machine,登出标记若不清掉,新 token 会被 assertNotRevoked
|
||||
// 判成「登录已过期」——表现是登录成功后又弹登录页(2026-10-24 现网 admin 锁死)。
|
||||
Fixture f = fixture(false);
|
||||
when(f.loginUserMapper.selectOne(any())).thenReturn(f.user("revoked@7#20261024185618"));
|
||||
when(f.passwordEncoder.matches("pwd", "hash")).thenReturn(true);
|
||||
when(f.jwtService.issue(eq(7L), anyString(), anyString())).thenReturn("jwt-token");
|
||||
|
||||
LoginRequest request = new LoginRequest();
|
||||
request.setUsername("u7");
|
||||
request.setPassword("pwd");
|
||||
request.setDeviceId("devB");
|
||||
|
||||
assertThatCode(() -> f.service.login(request)).doesNotThrowAnyException();
|
||||
|
||||
verify(f.loginUserMapper, times(1)).update(any(),
|
||||
argThat(wrapper -> wrapper instanceof LambdaUpdateWrapper
|
||||
&& ((LambdaUpdateWrapper<?>) wrapper).getSqlSet().contains("machine")));
|
||||
}
|
||||
|
||||
// ---------- check_login:被顶下线必须拦截且不续期 ----------
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user