暂存提交
This commit is contained in:
@@ -8,6 +8,7 @@ import com.baiyue.auth.entity.AuthAccount;
|
||||
import com.baiyue.auth.repository.AuthAccountRepository;
|
||||
import com.baiyue.common.core.exception.BizException;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
@@ -15,6 +16,7 @@ import org.springframework.test.util.ReflectionTestUtils;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@DisplayName("账号管理服务")
|
||||
class AccountManagementServiceTest {
|
||||
private final AuthAccountRepository repository = mock(AuthAccountRepository.class);
|
||||
private final TokenSessionStore sessions = mock(TokenSessionStore.class);
|
||||
@@ -31,7 +33,7 @@ class AccountManagementServiceTest {
|
||||
when(repository.findById(10L)).thenReturn(account);
|
||||
}
|
||||
|
||||
@Test void 修改密码校验旧密码并撤销全部会话() {
|
||||
@Test void changePasswordValidatesCurrentPasswordAndRevokesAllSessions() {
|
||||
service.changePassword(10L, new ChangePasswordRequest("OldPass1", "NewPass2"));
|
||||
assertTrue(encoder.matches("NewPass2", account.getPasswordHash()));
|
||||
assertEquals(3, account.getTokenVersion());
|
||||
@@ -39,20 +41,20 @@ class AccountManagementServiceTest {
|
||||
verify(sessions).revokeAll(10L);
|
||||
}
|
||||
|
||||
@Test void 原密码错误不得写入() {
|
||||
@Test void changePasswordDoesNotPersistWhenCurrentPasswordIsInvalid() {
|
||||
assertThrows(BizException.class,
|
||||
() -> service.changePassword(10L, new ChangePasswordRequest("WrongPass1", "NewPass2")));
|
||||
verify(repository, never()).save(any());
|
||||
verify(sessions, never()).revokeAll(any());
|
||||
}
|
||||
|
||||
@Test void 停用账号撤销全部会话() {
|
||||
@Test void disableAccountRevokesAllSessions() {
|
||||
service.updateStatus(10L, new UpdateAccountStatusRequest("DISABLED"));
|
||||
assertEquals("DISABLED", account.getAccountStatus());
|
||||
verify(sessions).revokeAll(10L);
|
||||
}
|
||||
|
||||
@Test void 创建平台账号保存平台应用域且密码仅保存摘要() {
|
||||
@Test void createPlatformAccountPersistsPlatformAppCodeAndPasswordHashOnly() {
|
||||
when(repository.findById(20L)).thenReturn(null);
|
||||
when(repository.existsByUsername("platform.user")).thenReturn(false);
|
||||
|
||||
@@ -67,7 +69,7 @@ class AccountManagementServiceTest {
|
||||
assertNotEquals("Password1", captor.getValue().getPasswordHash());
|
||||
}
|
||||
|
||||
@Test void 相同账号标识和归属重试时幂等返回() {
|
||||
@Test void createAccountRetriesIdempotentlyForSameAccountAndOwner() {
|
||||
account.setUsername("platform.user"); account.setDisplayName("平台用户");
|
||||
account.setDefaultTenantId(0L); account.setOperatorTenantId(0L);
|
||||
account.setDefaultMembershipId(30L); account.setDefaultAppCode("PLATFORM"); account.setDeleted(0);
|
||||
@@ -79,7 +81,7 @@ class AccountManagementServiceTest {
|
||||
verify(repository, never()).insert(any());
|
||||
}
|
||||
|
||||
@Test void 同步显示名撤销已有会话() {
|
||||
@Test void synchronizeDisplayNameRevokesExistingSessions() {
|
||||
account.setDisplayName("旧名称");
|
||||
|
||||
service.updateProfile(10L, new UpdateAccountProfileRequest("新名称"));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.baiyue.auth.service;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.data.redis.core.ValueOperations;
|
||||
@@ -16,6 +17,7 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.Mockito.eq;
|
||||
|
||||
@DisplayName("令牌会话存储")
|
||||
class TokenSessionStoreTest {
|
||||
@Test
|
||||
void storesAccessAndHashedRefreshWithIndependentTtls() {
|
||||
|
||||
Reference in New Issue
Block a user