refactor(系统设置): 部分接口添加资源存在校验
This commit is contained in:
parent
fd96bde2e2
commit
ddf4611586
|
@ -3,9 +3,11 @@ package io.metersphere.sdk.controller.handler;
|
|||
import io.metersphere.sdk.controller.handler.result.IResultCode;
|
||||
import io.metersphere.sdk.controller.handler.result.MsHttpResultCode;
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.util.ServiceUtils;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.ShiroException;
|
||||
import org.apache.shiro.authz.UnauthorizedException;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
@ -74,17 +76,40 @@ public class RestControllerExceptionHandler {
|
|||
.body(ResultHolder.error(MsHttpResultCode.FAILED.getCode(), e.getMessage()));
|
||||
}
|
||||
|
||||
int code = errorCode.getCode();
|
||||
String message = errorCode.getMessage();
|
||||
message = Translator.get(message, message);
|
||||
|
||||
if (errorCode instanceof MsHttpResultCode) {
|
||||
// 如果是 MsHttpResultCode,则设置响应的状态码,取状态码的后三位
|
||||
return ResponseEntity.status(errorCode.getCode() % 1000)
|
||||
.body(ResultHolder.error(errorCode.getCode(), Translator.get(errorCode.getMessage(), errorCode.getMessage())));
|
||||
if (errorCode.equals(MsHttpResultCode.NOT_FOUND)) {
|
||||
message = getNotFoundMessage(message);
|
||||
}
|
||||
return ResponseEntity.status(code % 1000)
|
||||
.body(ResultHolder.error(code, message));
|
||||
} else {
|
||||
// 响应码返回 500,设置业务状态码
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
.body(ResultHolder.error(errorCode.getCode(), Translator.get(errorCode.getMessage(), errorCode.getMessage()), e.getMessage()));
|
||||
.body(ResultHolder.error(code, Translator.get(message, message), e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 当抛出 NOT_FOUND,拼接资源名称
|
||||
* @param message
|
||||
* @return
|
||||
*/
|
||||
private static String getNotFoundMessage(String message) {
|
||||
String resourceName = ServiceUtils.getResourceName();
|
||||
if (StringUtils.isNotBlank(resourceName)) {
|
||||
message = String.format(message, Translator.get(resourceName, resourceName));
|
||||
} else {
|
||||
message = String.format(message, Translator.get("resource.name"));
|
||||
}
|
||||
ServiceUtils.clearResourceName();
|
||||
return message;
|
||||
}
|
||||
|
||||
@ExceptionHandler({Exception.class})
|
||||
public ResponseEntity<ResultHolder> handlerException(Exception e) {
|
||||
return ResponseEntity.internalServerError()
|
||||
|
|
|
@ -11,7 +11,8 @@ public enum MsHttpResultCode implements IResultCode {
|
|||
FAILED(100500, "http_result_unknown_exception"),
|
||||
VALIDATE_FAILED(100400, "http_result_validate"),
|
||||
UNAUTHORIZED(100401, "http_result_unauthorized"),
|
||||
FORBIDDEN(100403, "http_result_forbidden");
|
||||
FORBIDDEN(100403, "http_result_forbidden"),
|
||||
NOT_FOUND(100404, "http_result_not_found");
|
||||
|
||||
private int code;
|
||||
private String message;
|
||||
|
|
|
@ -64,7 +64,7 @@ public class BaseUserRoleRelationService {
|
|||
|
||||
public UserRole getUserRole(String id) {
|
||||
UserRoleRelation userRoleRelation = userRoleRelationMapper.selectByPrimaryKey(id);
|
||||
return userRoleMapper.selectByPrimaryKey(userRoleRelation.getRoleId());
|
||||
return userRoleRelation == null ? null : userRoleMapper.selectByPrimaryKey(userRoleRelation.getRoleId());
|
||||
}
|
||||
|
||||
protected void delete(String id) {
|
||||
|
|
|
@ -6,6 +6,7 @@ import io.metersphere.sdk.dto.request.PermissionSettingUpdateRequest;
|
|||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.sdk.util.PermissionCache;
|
||||
import io.metersphere.sdk.util.ServiceUtils;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
import io.metersphere.system.domain.UserRole;
|
||||
import io.metersphere.system.domain.UserRoleExample;
|
||||
|
@ -140,6 +141,10 @@ public class BaseUserRoleService {
|
|||
return userRole;
|
||||
}
|
||||
|
||||
public UserRole checkResourceExist(UserRole userRole) {
|
||||
return ServiceUtils.checkResourceExist(userRole, "permission.system_user_role.name");
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户组,并且删除用户组与用户的关联关系,用户组与权限的关联关系
|
||||
*
|
||||
|
@ -175,6 +180,10 @@ public class BaseUserRoleService {
|
|||
return userRoleMapper.selectByPrimaryKey(id);
|
||||
}
|
||||
|
||||
public UserRole getWithCheck(String id) {
|
||||
return checkResourceExist(userRoleMapper.selectByPrimaryKey(id));
|
||||
}
|
||||
|
||||
public List<UserRole> getList(List<String> idList) {
|
||||
if (CollectionUtils.isEmpty(idList)) {
|
||||
return new ArrayList<>();
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
package io.metersphere.sdk.util;
|
||||
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
|
||||
import static io.metersphere.sdk.controller.handler.result.MsHttpResultCode.NOT_FOUND;
|
||||
|
||||
public class ServiceUtils {
|
||||
|
||||
/**
|
||||
* 保存资源名称,在处理 NOT_FOUND 异常时,拼接资源名称
|
||||
*/
|
||||
private static final ThreadLocal<String> resourceName = new ThreadLocal<>();
|
||||
|
||||
/**
|
||||
* 校验资源是否存在,不存在则抛出 NOT_FOUND 异常
|
||||
* @param resource 资源
|
||||
* @param name 资源名称,用户拼接异常信息
|
||||
* @return
|
||||
* @param <T>
|
||||
*/
|
||||
public static <T> T checkResourceExist(T resource, String name) {
|
||||
if (resource == null) {
|
||||
resourceName.set(name);
|
||||
throw new MSException(NOT_FOUND);
|
||||
}
|
||||
return resource;
|
||||
}
|
||||
|
||||
public static String getResourceName() {
|
||||
return resourceName.get();
|
||||
}
|
||||
|
||||
public static void clearResourceName() {
|
||||
resourceName.remove();
|
||||
}
|
||||
}
|
|
@ -37,6 +37,8 @@ not_authorized=not authorized.
|
|||
login_fail=Login fail
|
||||
user_apikey_limit=Can have up to 5 api keys
|
||||
please_logout_current_user=Please logout current user first
|
||||
resource.name=Resource
|
||||
|
||||
#load test
|
||||
edit_load_test_not_found=Cannot edit test, test not found=
|
||||
run_load_test_not_found=Cannot run test, test not found=
|
||||
|
@ -420,6 +422,7 @@ add=Add
|
|||
delete=Delete
|
||||
update=Update
|
||||
project_is_not_exist=Project is not exist
|
||||
|
||||
#permission
|
||||
permission.system.name=System
|
||||
permission.org.name=Organization
|
||||
|
|
|
@ -37,6 +37,8 @@ user_expires=用户过期
|
|||
not_authorized=未经授权
|
||||
user_apikey_limit=最多能有5个Api key
|
||||
please_logout_current_user=请先登出当前用户
|
||||
resource.name=资源
|
||||
|
||||
#load test
|
||||
edit_load_test_not_found=无法编辑测试,未找到测试:
|
||||
run_load_test_not_found=无法运行测试,未找到测试:
|
||||
|
@ -407,6 +409,7 @@ http_result_unknown_exception=系统未知异常
|
|||
http_result_validate=参数校验失败
|
||||
http_result_unauthorized=用户认证失败
|
||||
http_result_forbidden=权限认证失败
|
||||
http_result_not_found=%s不存在
|
||||
|
||||
enum_value_valid_message=枚举值不合法,必须为
|
||||
|
||||
|
|
|
@ -63,6 +63,7 @@ load_test_report_file_not_exist=當前報告沒有JTL文件,請等待或重新
|
|||
startTime_must_be_less_than_endTime=開始日期必須小於結束日期
|
||||
start_time_is_null=開始日期不能為空
|
||||
end_time_is_null=結束日期不能為空
|
||||
resource.name=資源
|
||||
|
||||
#organization
|
||||
organization_not_exists=組織不存在
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
package io.metersphere.system.service;
|
||||
|
||||
import io.metersphere.sdk.constants.UserRoleScope;
|
||||
import io.metersphere.sdk.dto.ExcludeOptionDTO;
|
||||
import io.metersphere.sdk.dto.TableBatchProcessResponse;
|
||||
import io.metersphere.sdk.dto.UserRoleRelationUserDTO;
|
||||
import io.metersphere.sdk.dto.request.GlobalUserRoleRelationUpdateRequest;
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.service.BaseUserRoleRelationService;
|
||||
import io.metersphere.sdk.service.BaseUserRoleService;
|
||||
import io.metersphere.sdk.util.BeanUtils;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
import io.metersphere.system.domain.UserRole;
|
||||
|
@ -40,6 +42,8 @@ public class GlobalUserRoleRelationService extends BaseUserRoleRelationService {
|
|||
private UserService userService;
|
||||
@Resource
|
||||
private UserToolService userToolService;
|
||||
@Resource
|
||||
private BaseUserRoleService baseUserRoleService;
|
||||
|
||||
public List<UserRoleRelationUserDTO> list(GlobalUserRoleRelationQueryRequest request) {
|
||||
List<UserRoleRelationUserDTO> userRoleRelationUserDTOS = extUserRoleRelationMapper.listGlobal(request);
|
||||
|
@ -127,6 +131,7 @@ public class GlobalUserRoleRelationService extends BaseUserRoleRelationService {
|
|||
@Override
|
||||
public void delete(String id) {
|
||||
UserRole userRole = getUserRole(id);
|
||||
baseUserRoleService.checkResourceExist(userRole);
|
||||
UserRoleRelation userRoleRelation = userRoleRelationMapper.selectByPrimaryKey(id);
|
||||
globalUserRoleService.checkSystemUserGroup(userRole);
|
||||
globalUserRoleService.checkGlobalUserRole(userRole);
|
||||
|
@ -139,4 +144,9 @@ public class GlobalUserRoleRelationService extends BaseUserRoleRelationService {
|
|||
throw new MSException(GLOBAL_USER_ROLE_LIMIT);
|
||||
}
|
||||
}
|
||||
|
||||
public List<ExcludeOptionDTO> getExcludeSelectOption(String roleId) {
|
||||
baseUserRoleService.getWithCheck(roleId);
|
||||
return super.getExcludeSelectOption(roleId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import io.metersphere.sdk.dto.PermissionDefinitionItem;
|
|||
import io.metersphere.sdk.dto.request.PermissionSettingUpdateRequest;
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.service.BaseUserRoleService;
|
||||
import io.metersphere.sdk.util.ServiceUtils;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
import io.metersphere.system.domain.UserRole;
|
||||
import io.metersphere.system.domain.UserRoleExample;
|
||||
|
@ -102,7 +103,7 @@ public class GlobalUserRoleService extends BaseUserRoleService {
|
|||
|
||||
@Override
|
||||
public UserRole update(UserRole userRole) {
|
||||
UserRole originUserRole = get(userRole.getId());
|
||||
UserRole originUserRole = getWithCheck(userRole.getId());
|
||||
checkGlobalUserRole(originUserRole);
|
||||
checkInternalUserRole(originUserRole);
|
||||
userRole.setInternal(false);
|
||||
|
@ -111,7 +112,7 @@ public class GlobalUserRoleService extends BaseUserRoleService {
|
|||
}
|
||||
|
||||
public void delete(String id, String currentUserId) {
|
||||
UserRole userRole = get(id);
|
||||
UserRole userRole = getWithCheck(id);
|
||||
checkGlobalUserRole(userRole);
|
||||
super.delete(userRole, MEMBER.getValue(), currentUserId);
|
||||
}
|
||||
|
@ -141,14 +142,14 @@ public class GlobalUserRoleService extends BaseUserRoleService {
|
|||
|
||||
|
||||
public List<PermissionDefinitionItem> getPermissionSetting(String id) {
|
||||
UserRole userRole = get(id);
|
||||
UserRole userRole = getWithCheck(id);
|
||||
checkGlobalUserRole(userRole);
|
||||
return getPermissionSetting(userRole);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePermissionSetting(PermissionSettingUpdateRequest request) {
|
||||
UserRole userRole = get(request.getUserRoleId());
|
||||
UserRole userRole = getWithCheck(request.getUserRoleId());
|
||||
checkGlobalUserRole(userRole);
|
||||
checkInternalUserRole(userRole);
|
||||
super.updatePermissionSetting(request);
|
||||
|
|
|
@ -12,6 +12,7 @@ import io.metersphere.sdk.service.BaseUserService;
|
|||
import io.metersphere.sdk.service.JdbcDriverPluginService;
|
||||
import io.metersphere.sdk.service.PluginLoadService;
|
||||
import io.metersphere.sdk.util.BeanUtils;
|
||||
import io.metersphere.sdk.util.ServiceUtils;
|
||||
import io.metersphere.system.domain.Plugin;
|
||||
import io.metersphere.system.domain.PluginExample;
|
||||
import io.metersphere.system.dto.PluginDTO;
|
||||
|
@ -34,6 +35,7 @@ import java.io.OutputStream;
|
|||
import java.sql.Driver;
|
||||
import java.util.*;
|
||||
|
||||
import static io.metersphere.sdk.controller.handler.result.MsHttpResultCode.NOT_FOUND;
|
||||
import static io.metersphere.system.controller.result.SystemResultCode.PLUGIN_EXIST;
|
||||
import static io.metersphere.system.controller.result.SystemResultCode.PLUGIN_TYPE_EXIST;
|
||||
|
||||
|
@ -157,6 +159,10 @@ public class PluginService {
|
|||
}
|
||||
}
|
||||
|
||||
public Plugin checkResourceExist(String id) {
|
||||
return ServiceUtils.checkResourceExist(pluginMapper.selectByPrimaryKey(id), "permission.system_plugin.name");
|
||||
}
|
||||
|
||||
private void checkPluginAddExist(Plugin plugin) {
|
||||
PluginExample example = new PluginExample();
|
||||
example.createCriteria()
|
||||
|
@ -192,6 +198,7 @@ public class PluginService {
|
|||
}
|
||||
|
||||
public Plugin update(PluginUpdateRequest request) {
|
||||
checkResourceExist(request.getId());
|
||||
request.setCreateUser(null);
|
||||
Plugin plugin = new Plugin();
|
||||
BeanUtils.copyBean(plugin, request);
|
||||
|
@ -222,6 +229,7 @@ public class PluginService {
|
|||
}
|
||||
|
||||
public void delete(String id) {
|
||||
checkResourceExist(id);
|
||||
pluginMapper.deleteByPrimaryKey(id);
|
||||
// 删除插件脚本
|
||||
pluginScriptService.deleteByPluginId(id);
|
||||
|
|
|
@ -7,6 +7,7 @@ import io.metersphere.sdk.service.PlatformPluginService;
|
|||
import io.metersphere.sdk.service.PluginLoadService;
|
||||
import io.metersphere.sdk.util.BeanUtils;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.sdk.util.ServiceUtils;
|
||||
import io.metersphere.system.domain.Plugin;
|
||||
import io.metersphere.system.domain.ServiceIntegration;
|
||||
import io.metersphere.system.domain.ServiceIntegrationExample;
|
||||
|
@ -39,6 +40,8 @@ public class ServiceIntegrationService {
|
|||
private PluginLoadService pluginLoadService;
|
||||
@Resource
|
||||
private PlatformPluginService platformPluginService;
|
||||
@Resource
|
||||
private PluginService pluginService;
|
||||
|
||||
public static final String PLUGIN_IMAGE_GET_PATH = "/plugin/image/%s?imagePath=%s";
|
||||
|
||||
|
@ -88,6 +91,7 @@ public class ServiceIntegrationService {
|
|||
}
|
||||
|
||||
public ServiceIntegration update(ServiceIntegrationUpdateRequest request) {
|
||||
checkResourceExist(request.getId());
|
||||
ServiceIntegration serviceIntegration = new ServiceIntegration();
|
||||
// 组织不能修改
|
||||
serviceIntegration.setOrganizationId(null);
|
||||
|
@ -99,7 +103,12 @@ public class ServiceIntegrationService {
|
|||
return serviceIntegration;
|
||||
}
|
||||
|
||||
private ServiceIntegration checkResourceExist(String id) {
|
||||
return ServiceUtils.checkResourceExist(serviceIntegrationMapper.selectByPrimaryKey(id), "permission.service_integration.name");
|
||||
}
|
||||
|
||||
public void delete(String id) {
|
||||
checkResourceExist(id);
|
||||
serviceIntegrationMapper.deleteByPrimaryKey(id);
|
||||
}
|
||||
|
||||
|
@ -114,12 +123,13 @@ public class ServiceIntegrationService {
|
|||
}
|
||||
|
||||
public void validate(String pluginId, Map<String, String> serviceIntegrationInfo) {
|
||||
pluginService.checkResourceExist(pluginId);
|
||||
Platform platform = platformPluginService.getPlatform(pluginId, StringUtils.EMPTY, JSON.toJSONString(serviceIntegrationInfo));
|
||||
platform.validateIntegrationConfig();
|
||||
}
|
||||
|
||||
public void validate(String id) {
|
||||
ServiceIntegration serviceIntegration = serviceIntegrationMapper.selectByPrimaryKey(id);
|
||||
ServiceIntegration serviceIntegration = checkResourceExist(id);;
|
||||
Platform platform = platformPluginService.getPlatform(serviceIntegration.getPluginId(), StringUtils.EMPTY);
|
||||
platform.validateIntegrationConfig();
|
||||
}
|
||||
|
@ -129,6 +139,7 @@ public class ServiceIntegrationService {
|
|||
}
|
||||
|
||||
public Object getPluginScript(String pluginId) {
|
||||
pluginService.checkResourceExist(pluginId);
|
||||
AbstractPlatformPlugin platformPlugin = pluginLoadService.getImplInstance(pluginId, AbstractPlatformPlugin.class);
|
||||
return pluginLoadService.getPluginScriptContent(pluginId, platformPlugin.getIntegrationScriptId());
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ import java.util.stream.Collectors;
|
|||
import static io.metersphere.sdk.constants.InternalUserRole.ADMIN;
|
||||
import static io.metersphere.sdk.constants.InternalUserRole.MEMBER;
|
||||
import static io.metersphere.sdk.controller.handler.result.CommonResultCode.INTERNAL_USER_ROLE_PERMISSION;
|
||||
import static io.metersphere.sdk.controller.handler.result.MsHttpResultCode.NOT_FOUND;
|
||||
import static io.metersphere.system.controller.result.SystemResultCode.GLOBAL_USER_ROLE_EXIST;
|
||||
import static io.metersphere.system.controller.result.SystemResultCode.GLOBAL_USER_ROLE_PERMISSION;
|
||||
|
||||
|
@ -132,6 +133,11 @@ class GlobalUserRoleControllerTests extends BaseTest {
|
|||
request.setName("系统管理员");
|
||||
assertErrorCode(this.requestPost(DEFAULT_UPDATE, request), GLOBAL_USER_ROLE_EXIST);
|
||||
|
||||
// @@校验 NOT_FOUND 异常
|
||||
request.setId("1111");
|
||||
request.setName("系统管理员1");
|
||||
assertErrorCode(this.requestPost(DEFAULT_UPDATE, request), NOT_FOUND);
|
||||
|
||||
// @@异常参数校验
|
||||
updatedGroupParamValidateTest(UserRoleUpdateRequestDefinition.class, DEFAULT_UPDATE);
|
||||
|
||||
|
@ -223,6 +229,10 @@ class GlobalUserRoleControllerTests extends BaseTest {
|
|||
request.setUserRoleId(ADMIN.getValue());
|
||||
assertErrorCode(this.requestPost(PERMISSION_UPDATE, request), INTERNAL_USER_ROLE_PERMISSION);
|
||||
|
||||
// @@校验 NOT_FOUND 异常
|
||||
request.setUserRoleId("1111");
|
||||
assertErrorCode(this.requestPost(PERMISSION_UPDATE, request), NOT_FOUND);
|
||||
|
||||
// @@异常参数校验
|
||||
paramValidateTest(PermissionSettingUpdateRequestDefinition.class, PERMISSION_UPDATE);
|
||||
|
||||
|
@ -276,6 +286,9 @@ class GlobalUserRoleControllerTests extends BaseTest {
|
|||
// @@操作非全局用户组异常
|
||||
assertErrorCode(this.requestGet(PERMISSION_SETTING, getNonGlobalUserRole().getId()), GLOBAL_USER_ROLE_PERMISSION);
|
||||
|
||||
// @@校验 NOT_FOUND 异常
|
||||
assertErrorCode(this.requestGet(PERMISSION_SETTING, "111"), NOT_FOUND);
|
||||
|
||||
// @@校验权限
|
||||
requestGetPermissionTest(PermissionConstants.SYSTEM_USER_ROLE_READ, PERMISSION_SETTING, ADMIN.getValue());
|
||||
}
|
||||
|
@ -314,6 +327,9 @@ class GlobalUserRoleControllerTests extends BaseTest {
|
|||
// @@操作内置用户组异常
|
||||
assertErrorCode(this.requestGet(DEFAULT_DELETE, ADMIN.getValue()), INTERNAL_USER_ROLE_PERMISSION);
|
||||
|
||||
// @@校验 NOT_FOUND 异常
|
||||
assertErrorCode(this.requestGet(DEFAULT_DELETE, "111"), NOT_FOUND);
|
||||
|
||||
// @@校验权限
|
||||
requestGetPermissionTest(PermissionConstants.SYSTEM_USER_ROLE_DELETE, DEFAULT_DELETE, addUserRole.getId());
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ import static io.metersphere.sdk.constants.InternalUserRole.ADMIN;
|
|||
import static io.metersphere.sdk.constants.InternalUserRole.ORG_ADMIN;
|
||||
import static io.metersphere.sdk.controller.handler.result.CommonResultCode.USER_ROLE_RELATION_EXIST;
|
||||
import static io.metersphere.sdk.controller.handler.result.CommonResultCode.USER_ROLE_RELATION_REMOVE_ADMIN_USER_PERMISSION;
|
||||
import static io.metersphere.sdk.controller.handler.result.MsHttpResultCode.NOT_FOUND;
|
||||
import static io.metersphere.system.controller.result.SystemResultCode.*;
|
||||
|
||||
@SpringBootTest
|
||||
|
@ -171,6 +172,9 @@ class GlobalUserRoleRelationControllerTests extends BaseTest {
|
|||
// 校验 exclude 字段
|
||||
Assertions.assertTrue(item.getExclude() == excludeUserIds.contains(item.getId()));
|
||||
});
|
||||
|
||||
// @@校验 NOT_FOUND 异常
|
||||
assertErrorCode(this.requestGet(USER_OPTION, "111"), NOT_FOUND);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -200,6 +204,9 @@ class GlobalUserRoleRelationControllerTests extends BaseTest {
|
|||
assertErrorCode(this.requestGet(DEFAULT_DELETE, userRoleRelations.get(0).getId()),
|
||||
USER_ROLE_RELATION_REMOVE_ADMIN_USER_PERMISSION);
|
||||
|
||||
// @@校验 NOT_FOUND 异常
|
||||
assertErrorCode(this.requestGet(DEFAULT_DELETE, "111"), NOT_FOUND);
|
||||
|
||||
// @@校验权限
|
||||
requestGetPermissionTest(PermissionConstants.SYSTEM_USER_ROLE_UPDATE, DEFAULT_DELETE, addUserRoleRelation.getId());
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ import java.util.*;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
import static io.metersphere.sdk.controller.handler.result.CommonResultCode.FILE_NAME_ILLEGAL;
|
||||
import static io.metersphere.sdk.controller.handler.result.MsHttpResultCode.NOT_FOUND;
|
||||
import static io.metersphere.system.controller.result.SystemResultCode.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
|
@ -236,6 +237,11 @@ public class PluginControllerTests extends BaseTest {
|
|||
|
||||
// @@校验日志
|
||||
checkLog(request.getId(), OperationLogType.UPDATE);
|
||||
|
||||
// @@校验 NOT_FOUND 异常
|
||||
request.setId("1111");
|
||||
assertErrorCode(this.requestPost(DEFAULT_UPDATE, request), NOT_FOUND);
|
||||
|
||||
// @@异常参数校验
|
||||
updatedGroupParamValidateTest(PluginUpdateRequestDefinition.class, DEFAULT_UPDATE);
|
||||
// @@校验权限
|
||||
|
@ -308,6 +314,9 @@ public class PluginControllerTests extends BaseTest {
|
|||
Assertions.assertEquals(new ArrayList<>(0), getScriptIdsByPlugId(addPlugin.getId()));
|
||||
this.requestGetWithOk(DEFAULT_DELETE, anotherAddPlugin.getId());
|
||||
|
||||
// @@校验 NOT_FOUND 异常
|
||||
assertErrorCode(this.requestGet(DEFAULT_DELETE, "1111"), NOT_FOUND);
|
||||
|
||||
// @@校验日志
|
||||
checkLog(addPlugin.getId(), OperationLogType.DELETE);
|
||||
// @@校验权限
|
||||
|
|
|
@ -35,6 +35,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
import static io.metersphere.sdk.constants.InternalUserRole.ADMIN;
|
||||
import static io.metersphere.sdk.controller.handler.result.MsHttpResultCode.NOT_FOUND;
|
||||
import static io.metersphere.system.controller.result.SystemResultCode.SERVICE_INTEGRATION_EXIST;
|
||||
import static io.metersphere.system.service.ServiceIntegrationService.PLUGIN_IMAGE_GET_PATH;
|
||||
import static org.mockserver.model.HttpRequest.request;
|
||||
|
@ -150,6 +151,11 @@ public class ServiceIntegrationControllerTests extends BaseTest {
|
|||
|
||||
// @@校验日志
|
||||
checkLog(request.getId(), OperationLogType.UPDATE);
|
||||
|
||||
// @@校验 NOT_FOUND 异常
|
||||
request.setId("1111");
|
||||
assertErrorCode(this.requestPost(DEFAULT_UPDATE, request), NOT_FOUND);
|
||||
|
||||
// @@异常参数校验
|
||||
updatedGroupParamValidateTest(ServiceIntegrationUpdateRequestDefinition.class, DEFAULT_UPDATE);
|
||||
// @@校验权限
|
||||
|
@ -200,6 +206,10 @@ public class ServiceIntegrationControllerTests extends BaseTest {
|
|||
|
||||
// @@请求成功
|
||||
this.requestGetWithOk(VALIDATE_GET, addServiceIntegration.getId());
|
||||
|
||||
// @@校验 NOT_FOUND 异常
|
||||
assertErrorCode(this.requestGet(VALIDATE_GET, "1111"), NOT_FOUND);
|
||||
|
||||
// @@校验权限
|
||||
requestGetPermissionTest(PermissionConstants.SYSTEM_SERVICE_INTEGRATION_UPDATE, VALIDATE_GET, addServiceIntegration.getId());
|
||||
}
|
||||
|
@ -212,6 +222,8 @@ public class ServiceIntegrationControllerTests extends BaseTest {
|
|||
Map<String, Object> integrationConfigMap = JSON.parseMap(JSON.toJSONString(integrationConfig));
|
||||
// @@请求成功
|
||||
this.requestPostWithOk(VALIDATE_POST, integrationConfigMap, plugin.getId());
|
||||
// @@校验 NOT_FOUND 异常
|
||||
assertErrorCode(this.requestPost(VALIDATE_POST, integrationConfigMap, "1111"), NOT_FOUND);
|
||||
// @@校验权限
|
||||
requestPostPermissionTest(PermissionConstants.SYSTEM_SERVICE_INTEGRATION_UPDATE, VALIDATE_POST, integrationConfigMap, plugin.getId());
|
||||
}
|
||||
|
@ -223,6 +235,8 @@ public class ServiceIntegrationControllerTests extends BaseTest {
|
|||
MvcResult mvcResult = this.requestGetWithOkAndReturn(SCRIPT_GET, plugin.getId());
|
||||
// 校验请求成功数据
|
||||
Assertions.assertTrue(StringUtils.isNotBlank(mvcResult.getResponse().getContentAsString()));
|
||||
// @@校验 NOT_FOUND 异常
|
||||
assertErrorCode(this.requestGet(SCRIPT_GET, "1111"), NOT_FOUND);
|
||||
// @@校验权限
|
||||
requestGetPermissionTest(PermissionConstants.SYSTEM_SERVICE_INTEGRATION_READ, SCRIPT_GET, plugin.getId());
|
||||
}
|
||||
|
@ -240,6 +254,10 @@ public class ServiceIntegrationControllerTests extends BaseTest {
|
|||
|
||||
// @@校验日志
|
||||
checkLog(addServiceIntegration.getId(), OperationLogType.DELETE);
|
||||
|
||||
// @@校验 NOT_FOUND 异常
|
||||
assertErrorCode(this.requestGet(DEFAULT_DELETE, "1111"), NOT_FOUND);
|
||||
|
||||
// @@校验权限
|
||||
requestGetPermissionTest(PermissionConstants.SYSTEM_SERVICE_INTEGRATION_DELETE, DEFAULT_DELETE, addServiceIntegration.getId());
|
||||
}
|
||||
|
@ -270,8 +288,8 @@ public class ServiceIntegrationControllerTests extends BaseTest {
|
|||
* 删除插件
|
||||
* @throws Exception
|
||||
*/
|
||||
public void deletePlugin() throws Exception {
|
||||
this.requestGetWithOk(DEFAULT_DELETE, plugin.getId());
|
||||
public void deletePlugin() {
|
||||
pluginService.delete(plugin.getId());
|
||||
}
|
||||
|
||||
@Getter
|
||||
|
|
Loading…
Reference in New Issue