暂存提交
This commit is contained in:
@@ -3,6 +3,7 @@ package com.baiyue.iam.service;
|
||||
import com.baiyue.common.core.api.ResultCode;
|
||||
import com.baiyue.common.core.exception.BizException;
|
||||
import com.baiyue.iam.dto.AuthorizationDtos.SnapshotRequest;
|
||||
import com.baiyue.common.security.AuthenticatedUser;
|
||||
import com.baiyue.iam.mapper.AuthorizationQueryMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
@@ -56,6 +57,43 @@ class AuthorizationSnapshotServiceTest {
|
||||
verify(mapper).countActiveIdentity(42L, 7L, 9L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void loadsCurrentPlatformPermissionsWithoutRoleManagementPermission() {
|
||||
AuthorizationQueryMapper mapper = mock(AuthorizationQueryMapper.class);
|
||||
when(mapper.countActiveIdentity(42L, 0L, 9L)).thenReturn(1);
|
||||
when(mapper.findRoles(42L, 0L, 9L, "PLATFORM")).thenReturn(List.of("ORDER_OPERATOR"));
|
||||
when(mapper.findPermissions(42L, 0L, 9L, "PLATFORM"))
|
||||
.thenReturn(List.of("platform:order:list"));
|
||||
|
||||
var result = service(mapper).currentPermissions(new AuthenticatedUser(42L, 0L, 0L, 9L,
|
||||
"operator", "PLATFORM", "PLATFORM", java.util.Set.of()), "PLATFORM");
|
||||
|
||||
assertThat(result).containsExactly("platform:order:list");
|
||||
verify(mapper).findPermissions(42L, 0L, 9L, "PLATFORM");
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsIncompleteCurrentIdentityAsBusinessError() {
|
||||
assertThatThrownBy(() -> service(mock(AuthorizationQueryMapper.class))
|
||||
.currentPermissions(new AuthenticatedUser(42L, 0L, 0L, null,
|
||||
"operator", "PLATFORM", "PLATFORM", java.util.Set.of()), "PLATFORM"))
|
||||
.isInstanceOfSatisfying(BizException.class,
|
||||
exception -> assertThat(exception.getResultCode()).isEqualTo(ResultCode.UNAUTHORIZED));
|
||||
}
|
||||
|
||||
@Test
|
||||
void 空角色和权限查询结果不应触发五百错误() {
|
||||
AuthorizationQueryMapper mapper = mock(AuthorizationQueryMapper.class);
|
||||
when(mapper.countActiveIdentity(42L, 0L, 9L)).thenReturn(1);
|
||||
when(mapper.findRoles(42L, 0L, 9L, "PLATFORM")).thenReturn(null);
|
||||
when(mapper.findPermissions(42L, 0L, 9L, "PLATFORM")).thenReturn(null);
|
||||
|
||||
var result = service(mapper).currentPermissions(new AuthenticatedUser(42L, 0L, 0L, 9L,
|
||||
"operator", "PLATFORM", "PLATFORM", java.util.Set.of()), "PLATFORM");
|
||||
|
||||
assertThat(result).isEmpty();
|
||||
}
|
||||
|
||||
private AuthorizationSnapshotService service(AuthorizationQueryMapper mapper) {
|
||||
AuthorizationSnapshotService service = new AuthorizationSnapshotService();
|
||||
ReflectionTestUtils.setField(service, "mapper", mapper);
|
||||
|
||||
Reference in New Issue
Block a user