暂存提交

This commit is contained in:
2026-07-31 13:52:35 +08:00
parent 11e740706d
commit bc3c18a6e9
35 changed files with 421 additions and 121 deletions
@@ -1,6 +1,8 @@
package com.baiyue.auth.service;
import com.baiyue.auth.dto.AccountManagementDtos.ChangePasswordRequest;
import com.baiyue.auth.dto.AccountManagementDtos.CreateAccountRequest;
import com.baiyue.auth.dto.AccountManagementDtos.UpdateAccountProfileRequest;
import com.baiyue.auth.dto.AccountManagementDtos.UpdateAccountStatusRequest;
import com.baiyue.auth.entity.AuthAccount;
import com.baiyue.auth.repository.AuthAccountRepository;
@@ -49,4 +51,41 @@ class AccountManagementServiceTest {
assertEquals("DISABLED", account.getAccountStatus());
verify(sessions).revokeAll(10L);
}
@Test void 创建平台账号保存平台应用域且密码仅保存摘要() {
when(repository.findById(20L)).thenReturn(null);
when(repository.existsByUsername("platform.user")).thenReturn(false);
var result = service.create(new CreateAccountRequest(20L, "platform.user", "Password1",
"平台用户", 0L, 30L, "PLATFORM"));
assertEquals("platform.user", result.username());
var captor = org.mockito.ArgumentCaptor.forClass(AuthAccount.class);
verify(repository).insert(captor.capture());
assertEquals("PLATFORM", captor.getValue().getDefaultAppCode());
assertTrue(encoder.matches("Password1", captor.getValue().getPasswordHash()));
assertNotEquals("Password1", captor.getValue().getPasswordHash());
}
@Test void 相同账号标识和归属重试时幂等返回() {
account.setUsername("platform.user"); account.setDisplayName("平台用户");
account.setDefaultTenantId(0L); account.setOperatorTenantId(0L);
account.setDefaultMembershipId(30L); account.setDefaultAppCode("PLATFORM"); account.setDeleted(0);
var result = service.create(new CreateAccountRequest(10L, "platform.user", "Password1",
"平台用户", 0L, 30L, "PLATFORM"));
assertEquals(10L, result.accountId());
verify(repository, never()).insert(any());
}
@Test void 同步显示名撤销已有会话() {
account.setDisplayName("旧名称");
service.updateProfile(10L, new UpdateAccountProfileRequest("新名称"));
assertEquals("新名称", account.getDisplayName());
verify(repository).save(account);
verify(sessions).revokeAll(10L);
}
}