From e28284be97a7662e2810ab42ad36a913f14be9a3 Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Thu, 29 Feb 2024 19:18:30 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E7=94=A8=E4=BE=8B=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=87=E4=BB=B6=E5=A4=A7=E4=BA=8E50M?= =?UTF-8?q?=E6=97=B6=E6=B2=A1=E6=9C=89=E6=8F=90=E7=A4=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1036494 --user=郭雨琦 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001036494 --- .../sdk/src/main/resources/i18n/project.properties | 2 +- .../sdk/src/main/resources/i18n/project_en_US.properties | 2 +- .../sdk/src/main/resources/i18n/project_zh_CN.properties | 2 +- .../sdk/src/main/resources/i18n/project_zh_TW.properties | 2 +- .../service/FunctionalCaseAttachmentService.java | 3 +++ .../controller/FunctionalCaseControllerTests.java | 9 +++++++-- 6 files changed, 14 insertions(+), 6 deletions(-) diff --git a/backend/framework/sdk/src/main/resources/i18n/project.properties b/backend/framework/sdk/src/main/resources/i18n/project.properties index 1b0c6da9fa..dd1faf8b28 100644 --- a/backend/framework/sdk/src/main/resources/i18n/project.properties +++ b/backend/framework/sdk/src/main/resources/i18n/project.properties @@ -504,7 +504,7 @@ file.log.association.update=更新了关联了文件 file.log.association.delete=取消关联了文件 file.log.transfer.association=转存并关联了文件 file.name.cannot.be.empty=文件名称不能为空 -file.size.is.too.large=文件过大 +file.size.is.too.large=文件不能超过50M file.is.empty=文件为空 file.name.error=文件名不合法 #file management over diff --git a/backend/framework/sdk/src/main/resources/i18n/project_en_US.properties b/backend/framework/sdk/src/main/resources/i18n/project_en_US.properties index b37c6f7258..dca5ecca26 100644 --- a/backend/framework/sdk/src/main/resources/i18n/project_en_US.properties +++ b/backend/framework/sdk/src/main/resources/i18n/project_en_US.properties @@ -540,7 +540,7 @@ file.log.association.update=updated file file.log.association.delete=delete file file.log.transfer.association=transfer and association file file.name.cannot.be.empty=File name cannot be empty -file.size.is.too.large=File is too large +file.size.is.too.large=File cannot exceed 50M file.is.empty=File is empty file.name.error=File name error #file management over diff --git a/backend/framework/sdk/src/main/resources/i18n/project_zh_CN.properties b/backend/framework/sdk/src/main/resources/i18n/project_zh_CN.properties index 7fb68c7459..b789aed055 100644 --- a/backend/framework/sdk/src/main/resources/i18n/project_zh_CN.properties +++ b/backend/framework/sdk/src/main/resources/i18n/project_zh_CN.properties @@ -539,7 +539,7 @@ file.log.association.update=更新了关联了文件 file.log.association.delete=取消关联了文件 file.log.transfer.association=转存并关联了文件 file.name.cannot.be.empty=文件名称不能为空 -file.size.is.too.large=文件过大 +file.size.is.too.large=文件不能超过50M file.is.empty=文件为空 file.name.error=文件名不合法 #file management over diff --git a/backend/framework/sdk/src/main/resources/i18n/project_zh_TW.properties b/backend/framework/sdk/src/main/resources/i18n/project_zh_TW.properties index 25e4ca7119..ceeea422c2 100644 --- a/backend/framework/sdk/src/main/resources/i18n/project_zh_TW.properties +++ b/backend/framework/sdk/src/main/resources/i18n/project_zh_TW.properties @@ -539,7 +539,7 @@ file.log.association.update=更新了關聯了文件 file.log.association.delete=取消關聯了文件 file.log.transfer.association=轉存並關聯了文件 file.name.cannot.be.empty=文件名稱不能為空 -file.size.is.too.large=文件過大 +file.size.is.too.large=文件不能超過50M file.is.empty=文件為空 file.name.error=文件名不合法 #file management over diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseAttachmentService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseAttachmentService.java index 7bfe8993fd..cf71f81db2 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseAttachmentService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseAttachmentService.java @@ -104,6 +104,9 @@ public class FunctionalCaseAttachmentService { fileRequest.setFileName(file.getOriginalFilename()); fileRequest.setFolder(DefaultRepositoryDir.getFunctionalCaseDir(projectId, caseId) + "/" + fileId); fileRequest.setStorage(StorageType.MINIO.name()); + if (file.getSize() > maxFileSize.toBytes()) { + throw new MSException(Translator.get("file.size.is.too.large")); + } try { fileService.upload(file, fileRequest); } catch (Exception e) { diff --git a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseControllerTests.java b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseControllerTests.java index d2fd3e544e..42e3d2d6ad 100644 --- a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseControllerTests.java +++ b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseControllerTests.java @@ -49,6 +49,7 @@ import org.springframework.mock.web.MockMultipartFile; import org.springframework.test.context.jdbc.Sql; import org.springframework.test.context.jdbc.SqlConfig; import org.springframework.test.web.servlet.MvcResult; +import org.springframework.test.web.servlet.ResultActions; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.util.LinkedMultiValueMap; import org.springframework.web.multipart.MultipartFile; @@ -218,8 +219,12 @@ public class FunctionalCaseControllerTests extends BaseTest { functionalCaseAttachmentExample.createCriteria().andCaseIdEqualTo(functionalCase.getId()).andFileIdEqualTo(newFileId); functionalCaseAttachments = functionalCaseAttachmentMapper.selectByExample(functionalCaseAttachmentExample); Assertions.assertEquals(1, functionalCaseAttachments.size()); - - + byte[] array = new byte[55 * 1024 * 1024]; + file = new MockMultipartFile("file", "file_re-upload.JPG", MediaType.APPLICATION_OCTET_STREAM_VALUE, array); + files.add(file); + paramMap.add("files", files); + ResultActions resultActions = this.requestMultipart(FUNCTIONAL_CASE_ADD_URL, paramMap); + resultActions.andExpect(status().is5xxServerError()); } public String uploadTemp(MultipartFile file) {