From 2a9b9d3e591a13ef01a04fc28d48bd456d4cfa12 Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Fri, 2 Feb 2024 17:16:44 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E9=A1=B9=E7=9B=AE=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=8A=E4=BC=A0jar=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=94=E5=BC=80=E5=90=AF=E5=90=AF=E7=94=A8=E6=97=B6=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E6=88=90=E5=8A=9F=E5=90=AF=E7=94=A8jar=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E7=9A=84=E7=BC=BA=E9=99=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【【文件管理】-上传jar文件,开启启用开关,上传完成后,文件状态为禁用】 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001035154 --- .../ddl/V3.0.0_4__project_management.sql | 2 +- .../main/resources/i18n/commons.properties | 1 + .../resources/i18n/commons_en_US.properties | 1 + .../resources/i18n/commons_zh_CN.properties | 1 + .../resources/i18n/commons_zh_TW.properties | 1 + .../request/FileRepositoryCreateRequest.java | 1 + .../project/service/FileMetadataService.java | 2 +- .../FileManagementControllerTests.java | 6 +++++ .../FileRepositoryControllerTest.java | 26 +++++++++++++++++-- .../interceptor/ProjectInterceptor.java | 5 ++-- 10 files changed, 40 insertions(+), 6 deletions(-) diff --git a/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_4__project_management.sql b/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_4__project_management.sql index 207f5d1110..a6a037974d 100644 --- a/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_4__project_management.sql +++ b/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_4__project_management.sql @@ -130,7 +130,7 @@ CREATE TABLE IF NOT EXISTS file_module ( `id` VARCHAR(50) NOT NULL COMMENT 'ID', `project_id` VARCHAR(50) NOT NULL COMMENT '项目ID', - `name` VARCHAR(64) NOT NULL COMMENT '模块名称', + `name` VARCHAR(255) NOT NULL COMMENT '模块名称', `parent_id` VARCHAR(50) COMMENT '父级ID', `create_time` BIGINT NOT NULL COMMENT '创建时间', `update_time` BIGINT NOT NULL COMMENT '更新时间', diff --git a/backend/framework/sdk/src/main/resources/i18n/commons.properties b/backend/framework/sdk/src/main/resources/i18n/commons.properties index 8a00b031d6..2ac60370b4 100644 --- a/backend/framework/sdk/src/main/resources/i18n/commons.properties +++ b/backend/framework/sdk/src/main/resources/i18n/commons.properties @@ -1,6 +1,7 @@ #commons error_lang_invalid=语言参数错误 file_cannot_be_null=文件不能为空! +length.too.large=长度过长 cannot_be_null=不能为空 number=第 row=行 diff --git a/backend/framework/sdk/src/main/resources/i18n/commons_en_US.properties b/backend/framework/sdk/src/main/resources/i18n/commons_en_US.properties index f3d27470dc..df49b241b5 100644 --- a/backend/framework/sdk/src/main/resources/i18n/commons_en_US.properties +++ b/backend/framework/sdk/src/main/resources/i18n/commons_en_US.properties @@ -1,6 +1,7 @@ #commons error_lang_invalid=Invalid language parameter file_cannot_be_null=File cannot be empty! +length.too.large=too large cannot_be_null=\tCannot be empty number=Number row=row diff --git a/backend/framework/sdk/src/main/resources/i18n/commons_zh_CN.properties b/backend/framework/sdk/src/main/resources/i18n/commons_zh_CN.properties index 22f27bfe63..50a465df32 100644 --- a/backend/framework/sdk/src/main/resources/i18n/commons_zh_CN.properties +++ b/backend/framework/sdk/src/main/resources/i18n/commons_zh_CN.properties @@ -1,6 +1,7 @@ #commons error_lang_invalid=语言参数错误 file_cannot_be_null=文件不能为空! +length.too.large=长度过长 cannot_be_null=不能为空 number=第 row=行 diff --git a/backend/framework/sdk/src/main/resources/i18n/commons_zh_TW.properties b/backend/framework/sdk/src/main/resources/i18n/commons_zh_TW.properties index 3a6aa67b3d..3d53790da7 100644 --- a/backend/framework/sdk/src/main/resources/i18n/commons_zh_TW.properties +++ b/backend/framework/sdk/src/main/resources/i18n/commons_zh_TW.properties @@ -1,6 +1,7 @@ #commons error_lang_invalid=語言參數錯誤 file_cannot_be_null=文件不能為空! +length.too.large=長度過長 cannot_be_null=不能為空 number=第 row=行 diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/dto/filemanagement/request/FileRepositoryCreateRequest.java b/backend/services/project-management/src/main/java/io/metersphere/project/dto/filemanagement/request/FileRepositoryCreateRequest.java index 5ae9a01c7f..218a3fec10 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/dto/filemanagement/request/FileRepositoryCreateRequest.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/dto/filemanagement/request/FileRepositoryCreateRequest.java @@ -23,6 +23,7 @@ public class FileRepositoryCreateRequest { @Schema(description = "存储库地址", requiredMode = Schema.RequiredMode.REQUIRED) @NotBlank(message = "{file_repository.url.not_blank}") + @Size(min = 1, max = 255, message = "Url " + "{length.too.large}") private String url; @Schema(description = "存储库token", requiredMode = Schema.RequiredMode.REQUIRED) diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/FileMetadataService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/FileMetadataService.java index 21dfb2fd99..180d6d6069 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/FileMetadataService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/FileMetadataService.java @@ -176,7 +176,7 @@ public class FileMetadataService { fileMetadata.setPath(filePath); fileMetadata.setLatest(true); fileMetadata.setRefId(fileMetadata.getId()); - fileMetadata.setEnable(false); + fileMetadata.setEnable(enable); return fileMetadata; } diff --git a/backend/services/project-management/src/test/java/io/metersphere/project/controller/filemanagement/FileManagementControllerTests.java b/backend/services/project-management/src/test/java/io/metersphere/project/controller/filemanagement/FileManagementControllerTests.java index 4e5ea79f00..6b5a421c2f 100644 --- a/backend/services/project-management/src/test/java/io/metersphere/project/controller/filemanagement/FileManagementControllerTests.java +++ b/backend/services/project-management/src/test/java/io/metersphere/project/controller/filemanagement/FileManagementControllerTests.java @@ -503,6 +503,9 @@ public class FileManagementControllerTests extends BaseTest { LOG_CHECK_LIST.add( new CheckLogModel(returnId, OperationLogType.ADD, FileManagementRequestUtils.URL_FILE_UPLOAD) ); + //判断数据库里启用状态是否正确 + FileMetadata jarFileMeta = fileMetadataMapper.selectByPrimaryKey(returnId); + Assertions.assertEquals(jarFileMeta.getEnable(), fileUploadRequest.isEnable()); FILE_ID_PATH.put(returnId, filePath); jarFileId = returnId; uploadedFileTypes.add("jar"); @@ -519,6 +522,9 @@ public class FileManagementControllerTests extends BaseTest { LOG_CHECK_LIST.add( new CheckLogModel(returnId, OperationLogType.ADD, FileManagementRequestUtils.URL_FILE_UPLOAD) ); + //判断数据库里启用状态是否正确 + jarFileMeta = fileMetadataMapper.selectByPrimaryKey(returnId); + Assertions.assertEquals(jarFileMeta.getEnable(), fileUploadRequest.isEnable()); FILE_ID_PATH.put(returnId, filePath); fileUploadRequest.setEnable(false); diff --git a/backend/services/project-management/src/test/java/io/metersphere/project/controller/filemanagement/FileRepositoryControllerTest.java b/backend/services/project-management/src/test/java/io/metersphere/project/controller/filemanagement/FileRepositoryControllerTest.java index 30e32f8240..cd062ebd16 100644 --- a/backend/services/project-management/src/test/java/io/metersphere/project/controller/filemanagement/FileRepositoryControllerTest.java +++ b/backend/services/project-management/src/test/java/io/metersphere/project/controller/filemanagement/FileRepositoryControllerTest.java @@ -31,6 +31,7 @@ import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMock import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MvcResult; +import org.springframework.test.web.servlet.ResultActions; import org.testcontainers.shaded.org.apache.commons.lang3.StringUtils; import java.nio.charset.StandardCharsets; @@ -156,10 +157,31 @@ public class FileRepositoryControllerTest extends BaseTest { FileRepositoryCreateRequest createRequest = new FileRepositoryCreateRequest(); createRequest.setProjectId(project.getId()); createRequest.setPlatform(ModuleConstants.NODE_TYPE_GITEA); - createRequest.setUrl(GITEA_URL); createRequest.setToken(GITEA_TOKEN); - createRequest.setName("GITEA存储库"); + createRequest.setUrl(GITEA_URL); + //先测试名称长度过长 和 url过长 + StringBuilder repositoryName = new StringBuilder(); + while (repositoryName.length() < 256) { + repositoryName.append("t"); + } + createRequest.setName(repositoryName.toString()); + ResultActions badRequestAction = this.requestPost(FileManagementRequestUtils.URL_FILE_REPOSITORY_CREATE, createRequest); + badRequestAction.andExpect(status().isBadRequest()); + ResultHolder badRequestHolder = JSON.parseObject(badRequestAction.andReturn().getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class); + Assertions.assertFalse(StringUtils.contains(badRequestHolder.getMessage(), "Exception")); + StringBuilder repositoryTestUrl = new StringBuilder(); + while (repositoryTestUrl.length() < 256) { + repositoryTestUrl.append("t"); + } + createRequest.setName("GITEA存储库"); + createRequest.setUrl(repositoryTestUrl.toString()); + badRequestAction = this.requestPost(FileManagementRequestUtils.URL_FILE_REPOSITORY_CREATE, createRequest); + badRequestHolder = JSON.parseObject(badRequestAction.andReturn().getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class); + Assertions.assertFalse(StringUtils.contains(badRequestHolder.getMessage(), "Exception")); + + createRequest.setName("GITEA存储库"); + createRequest.setUrl(GITEA_URL); MvcResult result = this.requestPostWithOkAndReturn(FileManagementRequestUtils.URL_FILE_REPOSITORY_CREATE, createRequest); String returnStr = result.getResponse().getContentAsString(); ResultHolder rh = JSON.parseObject(returnStr, ResultHolder.class); diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/config/interceptor/ProjectInterceptor.java b/backend/services/system-setting/src/main/java/io/metersphere/system/config/interceptor/ProjectInterceptor.java index a2bc0c5e26..d234d7a63e 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/config/interceptor/ProjectInterceptor.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/config/interceptor/ProjectInterceptor.java @@ -1,8 +1,9 @@ package io.metersphere.system.config.interceptor; import io.metersphere.project.domain.CustomFunctionBlob; -import io.metersphere.project.domain.FileMetadataRepository; +import io.metersphere.project.domain.FileModuleRepository; import io.metersphere.sdk.util.CompressUtils; +import io.metersphere.sdk.util.EncryptUtils; import io.metersphere.system.utils.MybatisInterceptorConfig; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -16,7 +17,7 @@ public class ProjectInterceptor { public List projectCompressConfigs() { List configList = new ArrayList<>(); - configList.add(new MybatisInterceptorConfig(FileMetadataRepository.class, "gitInfo", CompressUtils.class, "zip", "unzip")); + configList.add(new MybatisInterceptorConfig(FileModuleRepository.class, "token", EncryptUtils.class, "aesEncrypt", "aesDecrypt")); configList.add(new MybatisInterceptorConfig(CustomFunctionBlob.class, "script", CompressUtils.class, "zip", "unzip")); configList.add(new MybatisInterceptorConfig(CustomFunctionBlob.class, "result", CompressUtils.class, "zip", "unzip")); configList.add(new MybatisInterceptorConfig(CustomFunctionBlob.class, "params", CompressUtils.class, "zip", "unzip"));