diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/parse/HarParser.java b/backend/src/main/java/io/metersphere/api/dto/definition/parse/HarParser.java index d91768c26e..37903a96d9 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/parse/HarParser.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/parse/HarParser.java @@ -46,7 +46,7 @@ public class HarParser extends HarAbstractParser { MSException.throwException(e.getMessage()); LogUtil.error(e.getMessage(), e); } - if (ObjectUtils.isEmpty(har)) { + if (ObjectUtils.isEmpty(har) || har.log == null) { MSException.throwException("解析失败,请确认选择的是 Har 格式!"); } ApiDefinitionImport definitionImport = new ApiDefinitionImport(); diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/parse/MsDefinitionParser.java b/backend/src/main/java/io/metersphere/api/dto/definition/parse/MsDefinitionParser.java index 3896f9bb35..63f333b511 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/parse/MsDefinitionParser.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/parse/MsDefinitionParser.java @@ -11,6 +11,7 @@ import io.metersphere.api.parse.MsAbstractParser; import io.metersphere.base.domain.ApiDefinitionWithBLOBs; import io.metersphere.base.domain.ApiTestCaseWithBLOBs; import io.metersphere.commons.constants.ApiImportPlatform; +import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.commons.utils.LogUtil; import io.metersphere.commons.utils.SessionUtils; @@ -32,7 +33,9 @@ public class MsDefinitionParser extends MsAbstractParser { String testStr = getApiTestStr(source); JSONObject testObject = JSONObject.parseObject(testStr, Feature.DisableSpecialKeyDetect); this.projectId = request.getProjectId(); - + if (this.projectId == null) { + MSException.throwException("wrong format"); + } if (testObject.get("projectName") != null || testObject.get("projectId") != null) {// metersphere 格式导入 return parseMsFormat(testStr, request); } else { // chrome 插件录制格式导入 @@ -154,5 +157,5 @@ public class MsDefinitionParser extends MsAbstractParser { return null; } } - + } diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/parse/PostmanDefinitionParser.java b/backend/src/main/java/io/metersphere/api/dto/definition/parse/PostmanDefinitionParser.java index e617b05360..cb0f25bf25 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/parse/PostmanDefinitionParser.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/parse/PostmanDefinitionParser.java @@ -1,6 +1,7 @@ package io.metersphere.api.dto.definition.parse; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.parser.Feature; import io.metersphere.api.dto.ApiTestImportRequest; import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy; @@ -14,6 +15,7 @@ import io.metersphere.base.domain.ApiTestCaseWithBLOBs; import io.metersphere.base.domain.Project; import io.metersphere.base.mapper.ProjectMapper; import io.metersphere.commons.constants.ProjectApplicationType; +import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.BeanUtils; import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.dto.ProjectConfig; @@ -29,6 +31,16 @@ public class PostmanDefinitionParser extends PostmanAbstractParserParser variables = postmanCollection.getVariable(); ApiDefinitionImport apiImport = new ApiDefinitionImport(); @@ -72,7 +84,7 @@ public class PostmanDefinitionParser extends PostmanAbstractParserParser tagTree, StringBuilder modulePath) { + if (tagTree == null) { + return ""; + } for (String s : tagTree) { if (s.contains("/")) { String[] split = s.split("/"); diff --git a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java index ea306a2261..d67ea6ead3 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java @@ -1252,9 +1252,24 @@ public class ApiDefinitionService { public ApiDefinitionImport apiTestImport(MultipartFile file, ApiTestImportRequest request) { //通过platform,获取对应的导入解析类型。 + String originalFilename = file.getOriginalFilename(); + String suffixName = originalFilename.substring(originalFilename.indexOf(".")); + if (suffixName.equalsIgnoreCase("jmx")) { + if (!request.getPlatform().equalsIgnoreCase("JMeter")) { + MSException.throwException("文件格式不符合要求"); + } + } + if (suffixName.equalsIgnoreCase("har")) { + if (!request.getPlatform().equalsIgnoreCase("Har")) { + MSException.throwException("文件格式不符合要求"); + } + } ApiImportParser runService = ApiDefinitionImportParserFactory.getApiImportParser(request.getPlatform()); ApiDefinitionImport apiImport = null; if (StringUtils.isNotBlank(request.getSwaggerUrl())) { + if (!request.getPlatform().equalsIgnoreCase("Swagger2")) { + MSException.throwException("文件格式不符合要求"); + } if (!UrlTestUtils.testUrlWithTimeOut(request.getSwaggerUrl(), 30000)) { MSException.throwException(Translator.get("connection_timeout")); } @@ -1274,7 +1289,11 @@ public class ApiDefinitionService { if (StringUtils.contains(returnThrowException, "模块树最大深度为")) { MSException.throwException(returnThrowException); } else { - MSException.throwException(Translator.get("parse_data_error")); + if (returnThrowException.equals("wrong format")) { + MSException.throwException("文件格式不符合要求"); + } else { + MSException.throwException(Translator.get("parse_data_error")); + } } // 发送通知 if (StringUtils.equals(request.getType(), "schedule")) { @@ -1589,11 +1608,6 @@ public class ApiDefinitionService { (query) -> extApiDefinitionMapper.selectIds(query)); this.removeToGc(request.getIds()); -// ApiDefinitionExampleWithOperation example = new ApiDefinitionExampleWithOperation(); -// example.createCriteria().andIdIn(request.getIds()); -// example.setOperator(SessionUtils.getUserId()); -// example.setOperationTime(System.currentTimeMillis()); -// extApiDefinitionMapper.removeToGcByExample(example); } public Pager> listRelevance(ApiDefinitionRequest request, int goPage, int pageSize) { diff --git a/backend/src/main/java/io/metersphere/api/service/ApiModuleService.java b/backend/src/main/java/io/metersphere/api/service/ApiModuleService.java index b27df48e1f..a433c5f058 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiModuleService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiModuleService.java @@ -89,13 +89,6 @@ public class ApiModuleService extends NodeTreeService { Map> filters = new LinkedHashMap<>(); filters.put("status", list); request.setFilters(filters); -// apiModules.forEach(node -> { -// List moduleIds = new ArrayList<>(); -// moduleIds = this.nodeList(apiModules, node.getId(), moduleIds); -// moduleIds.add(node.getId()); -// request.setModuleIds(moduleIds); -// node.setCaseNum(extApiDefinitionMapper.moduleCount(request)); -// }); //优化: 所有统计SQL一次查询出来 List allModuleIdList = new ArrayList<>(); @@ -786,6 +779,8 @@ public class ApiModuleService extends NodeTreeService { apiDefinitionWithBLOBs.setVersionId(v.getVersionId()); apiDefinitionWithBLOBs.setModuleId(v.getModuleId()); apiDefinitionWithBLOBs.setModulePath(v.getModulePath()); + apiDefinitionWithBLOBs.setNum(v.getNum()); + apiDefinitionWithBLOBs.setStatus(v.getStatus()); toUpdateList.add(apiDefinitionWithBLOBs); } }); @@ -801,6 +796,8 @@ public class ApiModuleService extends NodeTreeService { if (apiDefinitionWithBLOBs != null) { apiDefinitionWithBLOBs.setId(v.getId()); apiDefinitionWithBLOBs.setVersionId(v.getVersionId()); + apiDefinitionWithBLOBs.setNum(v.getNum()); + apiDefinitionWithBLOBs.setStatus(v.getStatus()); toUpdateList.add(apiDefinitionWithBLOBs); } }); @@ -964,6 +961,8 @@ public class ApiModuleService extends NodeTreeService { api.setOrder(definitionWithBLOBs.getOrder()); api.setRefId(apiDefinitionWithBLOBs.getRefId()); api.setLatest(apiDefinitionWithBLOBs.getLatest()); + api.setNum(definitionWithBLOBs.getNum()); + api.setStatus(definitionWithBLOBs.getStatus()); coverApiList.add(api); } optionData.remove(apiDefinitionWithBLOBs); @@ -981,6 +980,8 @@ public class ApiModuleService extends NodeTreeService { ApiDefinitionWithBLOBs api = new ApiDefinitionWithBLOBs(); BeanUtils.copyBean(api, apiDefinitionWithBLOBs); api.setId(definitionWithBLOBs.getId()); + api.setNum(definitionWithBLOBs.getNum()); + api.setStatus(definitionWithBLOBs.getStatus()); api.setVersionId(definitionWithBLOBs.getVersionId()); api.setModuleId(definitionWithBLOBs.getModuleId()); api.setModulePath(definitionWithBLOBs.getModulePath()); diff --git a/backend/src/main/java/io/metersphere/api/service/ApiScenarioModuleService.java b/backend/src/main/java/io/metersphere/api/service/ApiScenarioModuleService.java index a505473f68..e264411616 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiScenarioModuleService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiScenarioModuleService.java @@ -621,6 +621,8 @@ public class ApiScenarioModuleService extends NodeTreeService