Compare commits
3 Commits
3fd2ce5e44
...
e4aeb9b3cf
Author | SHA1 | Date |
---|---|---|
黄昕 | e4aeb9b3cf | |
黄昕 | d38a21094e | |
黄昕 | 8f314bcf79 |
|
@ -5,6 +5,7 @@ import com.cmhi.cf.restapi.pojo.base.BaseRespStatus;
|
|||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
@ -12,6 +13,7 @@ import lombok.NoArgsConstructor;
|
|||
@Schema(name = "资源操作结果")
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Data
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonPropertyOrder({"rid", "path", "resTypeId", "httpMethod", "status", "message"})
|
||||
|
|
|
@ -6,14 +6,18 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
|||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Schema(name = "资源信息")
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ResourceInfo {
|
||||
@Schema(description = "资源路径")
|
||||
@NotNull(message = "path 资源 URL 不能为 NULL", groups = ValidGroups.ResourceInfoValid.class)
|
||||
|
|
|
@ -4,9 +4,11 @@ import com.cmhi.cf.database.authentication.entity.Role;
|
|||
import com.cmhi.cf.restapi.pojo.base.BaseRespStatus;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -15,6 +17,8 @@ import java.util.List;
|
|||
@Data
|
||||
@Builder
|
||||
@JsonPropertyOrder({"roles", "status", "message"})
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class GetRoleResp extends BaseRespStatus {
|
||||
@Schema(description = "当前用户组")
|
||||
private List<Role> roles;
|
||||
|
|
|
@ -5,7 +5,9 @@ import com.mybatisflex.annotation.Id;
|
|||
import com.mybatisflex.annotation.KeyType;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 权限(Role)表实体类
|
||||
|
@ -16,6 +18,8 @@ import lombok.Data;
|
|||
@Data
|
||||
@Schema(name = "Role", description = "权限")
|
||||
@Table("rbac_role")
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Role {
|
||||
/**
|
||||
* id
|
||||
|
|
|
@ -212,11 +212,17 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|||
.enable(k.getAuthorize())
|
||||
.build()));
|
||||
|
||||
res = resDataMapper.selectAll().stream().filter(
|
||||
res = resDataMapper.selectAllWithRelations().stream().filter(
|
||||
k -> roleRes.stream().noneMatch(m -> m.getResources().getPath().equals(k.getPath()))).toList();
|
||||
|
||||
res.forEach(k -> result.add(ResPermInfo.builder().id(k.getId()).name(k.getName()).path(k.getPath()).httpMethod(
|
||||
k.getHttpMethod()).enable(false).build()));
|
||||
res.forEach(k -> result.add(ResPermInfo.builder()
|
||||
.id(k.getId())
|
||||
.name(k.getName())
|
||||
.path(k.getPath())
|
||||
.httpMethod(k.getHttpMethod())
|
||||
.resTypeId(k.getResType().getTypeId())
|
||||
.enable(false)
|
||||
.build()));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -253,11 +259,17 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|||
.enable(k.getAuthorize())
|
||||
.build()));
|
||||
|
||||
res = resDataMapper.selectAll().stream().filter(
|
||||
res = resDataMapper.selectAllWithRelations().stream().filter(
|
||||
k -> roleRes.stream().noneMatch(m -> m.getResources().getPath().equals(k.getPath()))).toList();
|
||||
|
||||
res.forEach(k -> result.add(ResPermInfo.builder().id(k.getId()).name(k.getName()).path(k.getPath()).httpMethod(
|
||||
k.getHttpMethod()).enable(false).build()));
|
||||
res.forEach(k -> result.add(ResPermInfo.builder()
|
||||
.id(k.getId())
|
||||
.name(k.getName())
|
||||
.path(k.getPath())
|
||||
.resTypeId(k.getResType().getTypeId())
|
||||
.httpMethod(k.getHttpMethod())
|
||||
.enable(false)
|
||||
.build()));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
package com.cmhi.cf.restapi.config;
|
||||
|
||||
import com.cmhi.cf.common.BaseEnum;
|
||||
import com.houkunlin.system.dict.starter.DictEnum;
|
||||
import com.houkunlin.system.dict.starter.json.DictType;
|
||||
|
||||
public enum ProtoCryptoType implements BaseEnum {
|
||||
@DictType(value = "ProtoCryptoType", comment = "协议加密类型")
|
||||
public enum ProtoCryptoType implements BaseEnum, DictEnum<Integer> {
|
||||
CRYPTO_NONE(0, "不加密"),
|
||||
CRYPTO_BASE64(1, "Base64编码"),
|
||||
CRYPTO_AES128(2, "AES128加密"),
|
||||
|
@ -27,6 +30,11 @@ public enum ProtoCryptoType implements BaseEnum {
|
|||
return this.code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return this.readme;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return this.readme;
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
import com.cmhi.cf.controller.CommonFrameworkApiTest;
|
||||
import com.cmhi.cf.controller.OperationLogApiTest;
|
||||
import com.cmhi.cf.controller.PermissionManagerApiTest;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.platform.suite.api.SelectClasses;
|
||||
import org.junit.platform.suite.api.Suite;
|
||||
|
||||
@SelectClasses({CommonFrameworkApiTest.class, OperationLogApiTest.class})
|
||||
@SelectClasses({CommonFrameworkApiTest.class,
|
||||
OperationLogApiTest.class,
|
||||
PermissionManagerApiTest.class})
|
||||
@DisplayName("接口集成测试")
|
||||
@Suite
|
||||
public class IntegrationTestSuite {
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.cmhi.cf.controller;
|
|||
import com.cmhi.cf.common.TestBaseAuthentication;
|
||||
import com.cmhi.cf.restapi.pojo.vo.VersionResp;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
@ -15,6 +16,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
|||
@Transactional
|
||||
public class CommonFrameworkApiTest extends TestBaseAuthentication {
|
||||
@Test
|
||||
@DisplayName("获取版本信息")
|
||||
void testGetVersion() throws Exception {
|
||||
VersionResp resp = (VersionResp) performanceRestful(RequestMethod.GET, null, "/api/version", new Class[]{VersionResp.class});
|
||||
AssertValidCommonResp(resp);
|
||||
|
@ -29,6 +31,7 @@ public class CommonFrameworkApiTest extends TestBaseAuthentication {
|
|||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("获取版本信息(POST)")
|
||||
void testGetVersionV2() throws Exception {
|
||||
VersionResp resp = (VersionResp) performanceRestful(RequestMethod.POST, null, "/api/version", new Class[]{VersionResp.class});
|
||||
AssertValidCommonResp(resp);
|
||||
|
|
|
@ -8,6 +8,7 @@ import com.cmhi.cf.restapi.pojo.dto.OperationLogReq;
|
|||
import com.cmhi.cf.restapi.pojo.po.OperationLogSummary;
|
||||
import com.cmhi.cf.restapi.pojo.vo.OperationLogDetailsResp;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -32,6 +33,7 @@ public class OperationLogApiTest extends TestBaseAuthentication {
|
|||
|
||||
@Test
|
||||
@Order(1)
|
||||
@DisplayName("获取操作日志摘要(分页)")
|
||||
void testGetSummary() throws Exception {
|
||||
final long pageSize = 10L;
|
||||
final long pageNumber = 1L;
|
||||
|
@ -80,6 +82,7 @@ public class OperationLogApiTest extends TestBaseAuthentication {
|
|||
|
||||
@Test
|
||||
@Order(2)
|
||||
@DisplayName("获取操作日志详情")
|
||||
void testGetDetails() throws Exception {
|
||||
Assertions.assertFalse(optIdArray.isEmpty());
|
||||
|
||||
|
|
|
@ -1,25 +1,46 @@
|
|||
package com.cmhi.cf.controller;
|
||||
|
||||
import com.cmhi.cf.authentication.pojo.dto.IdArrayReq;
|
||||
import com.cmhi.cf.authentication.pojo.dto.RegisterResourceReq;
|
||||
import com.cmhi.cf.authentication.pojo.dto.UserIdReq;
|
||||
import com.cmhi.cf.authentication.pojo.po.ResourceInfo;
|
||||
import com.cmhi.cf.authentication.pojo.vo.GetRoleResp;
|
||||
import com.cmhi.cf.authentication.pojo.vo.RegisterResourceResp;
|
||||
import com.cmhi.cf.authentication.pojo.vo.UserResPermInfoResp;
|
||||
import com.cmhi.cf.common.ErrorCode;
|
||||
import com.cmhi.cf.common.TestBaseAuthentication;
|
||||
import com.cmhi.cf.database.authentication.entity.User;
|
||||
import com.cmhi.cf.database.authentication.service.UserService;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@ExtendWith({SpringExtension.class})
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
||||
@Transactional
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class PermissionManagerApiTest extends TestBaseAuthentication {
|
||||
public class PermissionManagerApiTest extends TestBaseAuthentication {
|
||||
private final List<String> addResUid = new ArrayList<>();
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Test
|
||||
@DisplayName("获取当前用户资源信息")
|
||||
void testGetCurrentUserResourcePermission() throws Exception {
|
||||
UserResPermInfoResp resp = (UserResPermInfoResp) performanceRestful(RequestMethod.GET, null, "/api/permission/resourcePermission",
|
||||
new Class[] {UserResPermInfoResp.class});
|
||||
|
@ -41,57 +62,163 @@ class PermissionManagerApiTest extends TestBaseAuthentication {
|
|||
}
|
||||
|
||||
@Test
|
||||
void testGetCurrentUserResourcePermission_AuthUsersServiceReturnsNull() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetCurrentUserResourcePermission_UserServiceReturnsNoItems() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("获取用户资源信息")
|
||||
void testGetUserResourcePermission() throws Exception {
|
||||
User user = userService.getAccountUserByName("admin");
|
||||
Assertions.assertNotNull(user);
|
||||
AssertValidString(user.getUid());
|
||||
UserResPermInfoResp resp = (UserResPermInfoResp) performanceRestful(RequestMethod.POST, new UserIdReq(user.getUid()),
|
||||
"/api/permission/resourcePermission",
|
||||
new Class[] {UserResPermInfoResp.class});
|
||||
AssertValidCommonResp(resp);
|
||||
Assertions.assertNotNull(resp.getResPermission());
|
||||
AssertValidString(resp.getUserId());
|
||||
AssertValidString(resp.getUsername());
|
||||
|
||||
Assertions.assertFalse(resp.getResPermission().isEmpty());
|
||||
|
||||
resp.getResPermission().forEach(k -> {
|
||||
Assertions.assertNotNull(k.getId());
|
||||
AssertValidString(k.getHttpMethod());
|
||||
AssertValidString(k.getPath());
|
||||
AssertValidString(k.getName());
|
||||
Assertions.assertNotNull(k.getResTypeId());
|
||||
Assertions.assertNotNull(k.getEnable());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetUserResourcePermission_UserServiceGetAccountUserByUidReturnsNull() throws Exception {
|
||||
|
||||
@DisplayName("不存在的用户获取资源信息")
|
||||
void testGetUserResourcePermission_UserServiceGetAccountUserByUidReturnsNull() {
|
||||
User user = userService.getAccountUserByUid("ff99fd68-14bf-4fd6-9320-bab85839245c");
|
||||
Assertions.assertNull(user);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("获取用户资源信息, 当前用户无资源")
|
||||
void testGetUserResourcePermission_UserServiceGetUserResourcePermReturnsNoItems() throws Exception {
|
||||
User user = userService.getAccountUserByName("guest");
|
||||
Assertions.assertNotNull(user);
|
||||
AssertValidString(user.getUid());
|
||||
UserResPermInfoResp resp = (UserResPermInfoResp) performanceRestful(RequestMethod.POST, new UserIdReq(user.getUid()),
|
||||
"/api/permission/resourcePermission",
|
||||
new Class[] {UserResPermInfoResp.class});
|
||||
AssertValidCommonResp(resp);
|
||||
Assertions.assertNotNull(resp.getResPermission());
|
||||
AssertValidString(resp.getUserId());
|
||||
AssertValidString(resp.getUsername());
|
||||
|
||||
Assertions.assertFalse(resp.getResPermission().isEmpty());
|
||||
|
||||
resp.getResPermission().forEach(k -> {
|
||||
Assertions.assertNotNull(k.getId());
|
||||
AssertValidString(k.getHttpMethod());
|
||||
AssertValidString(k.getPath());
|
||||
AssertValidString(k.getName());
|
||||
Assertions.assertNotNull(k.getResTypeId());
|
||||
Assertions.assertNotNull(k.getEnable());
|
||||
Assertions.assertFalse(k.getEnable());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("获取当前所有用户组")
|
||||
void testGetAllRoles() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetAllRoles_RoleMapperReturnsNoItems() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRegisterResource() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRegisterResource_UserServiceReturnsNoItems() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRemoveResourceById() throws Exception {
|
||||
|
||||
GetRoleResp resp = (GetRoleResp) performanceRestful(RequestMethod.GET, null, "/api/permission/allRoles",
|
||||
new Class[] {GetRoleResp.class});
|
||||
AssertValidCommonResp(resp);
|
||||
Assertions.assertNotNull(resp.getRoles());
|
||||
Assertions.assertFalse(resp.getRoles().isEmpty());
|
||||
resp.getRoles().forEach(k -> {
|
||||
Assertions.assertNotNull(k.getId());
|
||||
AssertValidString(k.getDescription());
|
||||
Assertions.assertNotNull(k.getName());
|
||||
Assertions.assertNotNull(k.getAvailable());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("删除不存在的资源")
|
||||
void testRemoveResourceById_UserServiceReturnsNoItems() throws Exception {
|
||||
List<String> rid = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
rid.add(UUID.randomUUID().toString());
|
||||
}
|
||||
|
||||
IdArrayReq req = new IdArrayReq(rid);
|
||||
|
||||
RegisterResourceResp resp = (RegisterResourceResp) performanceRestful(RequestMethod.DELETE, req,
|
||||
"/api/permission/resource",
|
||||
new Class[] {RegisterResourceResp.class});
|
||||
AssertValidCommonResp(resp);
|
||||
Assertions.assertNotNull(resp.getResult());
|
||||
Assertions.assertEquals(resp.getResult().size(), rid.size());
|
||||
|
||||
resp.getResult().forEach(k -> {
|
||||
Assertions.assertEquals(k.getStatus(), ErrorCode.ERR_NOSUCHITEM.getCode());
|
||||
Assertions.assertNotNull(k.getRid());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("注册新资源")
|
||||
void testRegisterResource() throws Exception {
|
||||
addResUid.clear();
|
||||
List<ResourceInfo> resList = new ArrayList<>();
|
||||
resList.add(ResourceInfo.builder()
|
||||
.path("/api/custom/show")
|
||||
.name("show")
|
||||
.resTypeId(0)
|
||||
.httpMethod(new ArrayList<>() {{add("POST");}})
|
||||
.build());
|
||||
|
||||
resList.add(ResourceInfo.builder()
|
||||
.path("/api/custom/List")
|
||||
.name("List")
|
||||
.resTypeId(1)
|
||||
.httpMethod(new ArrayList<>() {{add("PUT");}})
|
||||
.build());
|
||||
|
||||
RegisterResourceReq req = RegisterResourceReq.builder()
|
||||
.resources(resList)
|
||||
.build();
|
||||
|
||||
RegisterResourceResp resp = (RegisterResourceResp) performanceRestful(RequestMethod.PUT, req,
|
||||
"/api/permission/resource",
|
||||
new Class[] {RegisterResourceResp.class});
|
||||
|
||||
AssertValidCommonResp(resp);
|
||||
Assertions.assertNotNull(resp.getResult());
|
||||
Assertions.assertEquals(resp.getResult().size(), resList.size());
|
||||
|
||||
resp.getResult().forEach(k -> {
|
||||
AssertValidCommonResp(k);
|
||||
AssertValidString(k.getRid());
|
||||
AssertValidString(k.getPath());
|
||||
AssertValidString(k.getHttpMethod());
|
||||
Assertions.assertNotNull(k.getResTypeId());
|
||||
addResUid.add(k.getRid());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("删除资源")
|
||||
void testRemoveResourceById() throws Exception {
|
||||
testRegisterResource();
|
||||
IdArrayReq req = new IdArrayReq(addResUid);
|
||||
|
||||
RegisterResourceResp resp = (RegisterResourceResp) performanceRestful(RequestMethod.DELETE, req,
|
||||
"/api/permission/resource",
|
||||
new Class[] {RegisterResourceResp.class});
|
||||
AssertValidCommonResp(resp);
|
||||
Assertions.assertNotNull(resp.getResult());
|
||||
Assertions.assertEquals(resp.getResult().size(), addResUid.size());
|
||||
|
||||
resp.getResult().forEach(k -> {
|
||||
AssertValidCommonResp(k);
|
||||
AssertValidString(k.getRid());
|
||||
Assertions.assertTrue(addResUid.contains(k.getRid()));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue